* [dpdk-users] DPDK library link issue with __attribute__((constructor)) @ 2018-03-05 5:08 Hui Liu 2018-03-05 9:15 ` Hui Liu 0 siblings, 1 reply; 4+ messages in thread From: Hui Liu @ 2018-03-05 5:08 UTC (permalink / raw) To: users Hi Guys, I am using DPDK with the yocto build system. I found some static library is not linked because of the linker's as-needed decision. Some .a file use __attribute__((constructor)) to register their APIs, we only know if we use these APIs at runtime, but linker make the decision early and then discarded them. I tried a lot to link the library I need: 1, use -Wl, --no-as-needed, for example: gcc a.c *-Wl, --no-as-needed* -ldl -ldpdk 2, Put the library explicitly to the linker like this: gcc a.c -Wl, --no-as-needed -ldl -ldpdk *-lrte_mempool* At last, I still didn't find my library in the elf file. Is there anything else I can try to link these library? -- Thanks & Best Regards Liu Hui -- ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-users] DPDK library link issue with __attribute__((constructor)) 2018-03-05 5:08 [dpdk-users] DPDK library link issue with __attribute__((constructor)) Hui Liu @ 2018-03-05 9:15 ` Hui Liu 2018-03-05 13:28 ` Wiles, Keith 0 siblings, 1 reply; 4+ messages in thread From: Hui Liu @ 2018-03-05 9:15 UTC (permalink / raw) To: users I tried to put all the library into the command, but it still doesn't work. That's wired... x86_64-poky-linux-gcc -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse --sysroot=/home/hliu/atomos/build-temp/build/tmp/work/core2-64-poky-linux/unittest/0.0-r0/recipe-sysroot -Wl,--hash-style=gnu -Wl,--no-as-needed -o l2_ut_dpdk l2_ut_dpdk.c -Wall -Werror -g -lrte_mempool_stack -lrte_pmd_i40e -lrte_pmd_ark -lrte_ethdev -lrte_pmd_null -lrte_pmd_null_crypto -lrte_lpm -lrte_pmd_ena -lrte_kvargs -lrte_cmdline -lrte_pmd_tap -lrte_pmd_sw_event -lrte_latencystats -lrte_bitratestats -lrte_efd -lrte_sched -lrte_pmd_kni -lrte_pmd_qede -lrte_hash -lrte_pmd_enic -lrte_pdump -lrte_pmd_lio -lrte_acl -lrte_pmd_af_packet -lrte_eventdev -lrte_port -lrte_ip_frag -lrte_pmd_bond -lrte_pmd_sfc_efx -lrte_pmd_e1000 -lrte_mbuf -lrte_pmd_virtio -lrte_metrics -lrte_cryptodev -lrte_reorder -lrte_pmd_ring -lrte_eal -lrte_distributor -lrte_vhost -lrte_pmd_bnxt -lrte_timer -lrte_pmd_avp -lrte_pmd_crypto_scheduler -lrte_pmd_thunderx_nicvf -lrte_pmd_skeleton_event -lrte_pmd_nfp -lrte_jobstats -lrte_net -lrte_mempool -lrte_pmd_ixgbe -lrte_mempool_ring -lrte_pipeline -lrte_pmd_octeontx_ssovf -lrte_pmd_vhost -lrte_meter -lrte_pmd_cxgbe -lrte_kni -lrte_pmd_vmxnet3_uio -lrte_ring -lrte_pmd_fm10k -lrte_table -lrte_cfgfile -lpthread -ldl On Sun, Mar 4, 2018 at 9:08 PM, Hui Liu <onlyflyer@gmail.com> wrote: > Hi Guys, > > I am using DPDK with the yocto build system. > > I found some static library is not linked because of the linker's > as-needed decision. > > Some .a file use __attribute__((constructor)) to register their APIs, > we only know if we use these APIs at runtime, but linker make the decision > early and then discarded them. > > I tried a lot to link the library I need: > > 1, use -Wl, --no-as-needed, for example: > gcc a.c *-Wl, --no-as-needed* -ldl -ldpdk > > 2, Put the library explicitly to the linker like this: > gcc a.c -Wl, --no-as-needed -ldl -ldpdk *-lrte_mempool* > > At last, I still didn't find my library in the elf file. > > Is there anything else I can try to link these library? > > -- > Thanks & Best Regards > Liu Hui > -- > -- Thanks & Best Regards Liu Hui -- ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-users] DPDK library link issue with __attribute__((constructor)) 2018-03-05 9:15 ` Hui Liu @ 2018-03-05 13:28 ` Wiles, Keith 2018-03-07 1:02 ` Hui Liu 0 siblings, 1 reply; 4+ messages in thread From: Wiles, Keith @ 2018-03-05 13:28 UTC (permalink / raw) To: Hui Liu; +Cc: users > On Mar 5, 2018, at 3:15 AM, Hui Liu <onlyflyer@gmail.com> wrote: > > I tried to put all the library into the command, but it still doesn't work. > That's wired... > > x86_64-poky-linux-gcc -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse > --sysroot=/home/hliu/atomos/build-temp/build/tmp/work/core2-64-poky-linux/unittest/0.0-r0/recipe-sysroot > -Wl,--hash-style=gnu -Wl,--no-as-needed -o l2_ut_dpdk l2_ut_dpdk.c -Wall > -Werror -g -lrte_mempool_stack -lrte_pmd_i40e -lrte_pmd_ark -lrte_ethdev > -lrte_pmd_null -lrte_pmd_null_crypto -lrte_lpm -lrte_pmd_ena -lrte_kvargs > -lrte_cmdline -lrte_pmd_tap -lrte_pmd_sw_event -lrte_latencystats > -lrte_bitratestats -lrte_efd -lrte_sched -lrte_pmd_kni -lrte_pmd_qede > -lrte_hash -lrte_pmd_enic -lrte_pdump -lrte_pmd_lio -lrte_acl > -lrte_pmd_af_packet -lrte_eventdev -lrte_port -lrte_ip_frag -lrte_pmd_bond > -lrte_pmd_sfc_efx -lrte_pmd_e1000 -lrte_mbuf -lrte_pmd_virtio -lrte_metrics > -lrte_cryptodev -lrte_reorder -lrte_pmd_ring -lrte_eal -lrte_distributor > -lrte_vhost -lrte_pmd_bnxt -lrte_timer -lrte_pmd_avp > -lrte_pmd_crypto_scheduler -lrte_pmd_thunderx_nicvf > -lrte_pmd_skeleton_event -lrte_pmd_nfp -lrte_jobstats -lrte_net > -lrte_mempool -lrte_pmd_ixgbe -lrte_mempool_ring -lrte_pipeline > -lrte_pmd_octeontx_ssovf -lrte_pmd_vhost -lrte_meter -lrte_pmd_cxgbe > -lrte_kni -lrte_pmd_vmxnet3_uio -lrte_ring -lrte_pmd_fm10k -lrte_table > -lrte_cfgfile -lpthread -ldl One way with the above is to use —whole-archive … —no-whole-archive around the archives you want to force include. The other way to is include the .o files as part of the link line instead of the .a file. The problem with —whole-archive is it pulls in the complete archive and increases footprint. Using the .o method is normally used here and they include these .o files in the application Makefile. > > On Sun, Mar 4, 2018 at 9:08 PM, Hui Liu <onlyflyer@gmail.com> wrote: > >> Hi Guys, >> >> I am using DPDK with the yocto build system. >> >> I found some static library is not linked because of the linker's >> as-needed decision. >> >> Some .a file use __attribute__((constructor)) to register their APIs, >> we only know if we use these APIs at runtime, but linker make the decision >> early and then discarded them. >> >> I tried a lot to link the library I need: >> >> 1, use -Wl, --no-as-needed, for example: >> gcc a.c *-Wl, --no-as-needed* -ldl -ldpdk >> >> 2, Put the library explicitly to the linker like this: >> gcc a.c -Wl, --no-as-needed -ldl -ldpdk *-lrte_mempool* >> >> At last, I still didn't find my library in the elf file. >> >> Is there anything else I can try to link these library? >> >> -- >> Thanks & Best Regards >> Liu Hui >> -- >> > > > > -- > Thanks & Best Regards > Liu Hui > -- Regards, Keith ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-users] DPDK library link issue with __attribute__((constructor)) 2018-03-05 13:28 ` Wiles, Keith @ 2018-03-07 1:02 ` Hui Liu 0 siblings, 0 replies; 4+ messages in thread From: Hui Liu @ 2018-03-07 1:02 UTC (permalink / raw) To: Wiles, Keith; +Cc: users Hi Keith, Thanks a lot, that resolved my issue. The key is to use --whole-archive instead of --no-as-needed. --no-as-needed doesn't work. Thanks, Hui On Mon, Mar 5, 2018 at 5:28 AM, Wiles, Keith <keith.wiles@intel.com> wrote: > > > > On Mar 5, 2018, at 3:15 AM, Hui Liu <onlyflyer@gmail.com> wrote: > > > > I tried to put all the library into the command, but it still doesn't > work. > > That's wired... > > > > x86_64-poky-linux-gcc -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse > > --sysroot=/home/hliu/atomos/build-temp/build/tmp/work/ > core2-64-poky-linux/unittest/0.0-r0/recipe-sysroot > > -Wl,--hash-style=gnu -Wl,--no-as-needed -o l2_ut_dpdk l2_ut_dpdk.c -Wall > > -Werror -g -lrte_mempool_stack -lrte_pmd_i40e -lrte_pmd_ark -lrte_ethdev > > -lrte_pmd_null -lrte_pmd_null_crypto -lrte_lpm -lrte_pmd_ena -lrte_kvargs > > -lrte_cmdline -lrte_pmd_tap -lrte_pmd_sw_event -lrte_latencystats > > -lrte_bitratestats -lrte_efd -lrte_sched -lrte_pmd_kni -lrte_pmd_qede > > -lrte_hash -lrte_pmd_enic -lrte_pdump -lrte_pmd_lio -lrte_acl > > -lrte_pmd_af_packet -lrte_eventdev -lrte_port -lrte_ip_frag > -lrte_pmd_bond > > -lrte_pmd_sfc_efx -lrte_pmd_e1000 -lrte_mbuf -lrte_pmd_virtio > -lrte_metrics > > -lrte_cryptodev -lrte_reorder -lrte_pmd_ring -lrte_eal -lrte_distributor > > -lrte_vhost -lrte_pmd_bnxt -lrte_timer -lrte_pmd_avp > > -lrte_pmd_crypto_scheduler -lrte_pmd_thunderx_nicvf > > -lrte_pmd_skeleton_event -lrte_pmd_nfp -lrte_jobstats -lrte_net > > -lrte_mempool -lrte_pmd_ixgbe -lrte_mempool_ring -lrte_pipeline > > -lrte_pmd_octeontx_ssovf -lrte_pmd_vhost -lrte_meter -lrte_pmd_cxgbe > > -lrte_kni -lrte_pmd_vmxnet3_uio -lrte_ring -lrte_pmd_fm10k -lrte_table > > -lrte_cfgfile -lpthread -ldl > > One way with the above is to use —whole-archive … —no-whole-archive around > the archives you want to force include. The other way to is include the .o > files as part of the link line instead of the .a file. The problem with > —whole-archive is it pulls in the complete archive and increases footprint. > Using the .o method is normally used here and they include these .o files > in the application Makefile. > > > > > > On Sun, Mar 4, 2018 at 9:08 PM, Hui Liu <onlyflyer@gmail.com> wrote: > > > >> Hi Guys, > >> > >> I am using DPDK with the yocto build system. > >> > >> I found some static library is not linked because of the linker's > >> as-needed decision. > >> > >> Some .a file use __attribute__((constructor)) to register their APIs, > >> we only know if we use these APIs at runtime, but linker make the > decision > >> early and then discarded them. > >> > >> I tried a lot to link the library I need: > >> > >> 1, use -Wl, --no-as-needed, for example: > >> gcc a.c *-Wl, --no-as-needed* -ldl -ldpdk > >> > >> 2, Put the library explicitly to the linker like this: > >> gcc a.c -Wl, --no-as-needed -ldl -ldpdk *-lrte_mempool* > >> > >> At last, I still didn't find my library in the elf file. > >> > >> Is there anything else I can try to link these library? > >> > >> -- > >> Thanks & Best Regards > >> Liu Hui > >> -- > >> > > > > > > > > -- > > Thanks & Best Regards > > Liu Hui > > -- > > Regards, > Keith > > -- Thanks & Best Regards Liu Hui -- ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-03-07 1:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-03-05 5:08 [dpdk-users] DPDK library link issue with __attribute__((constructor)) Hui Liu 2018-03-05 9:15 ` Hui Liu 2018-03-05 13:28 ` Wiles, Keith 2018-03-07 1:02 ` Hui Liu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).