Fix dynamic link of driver symbols with pkgconf
cover Fix dynamic link of driver symbols with pkgconf
When building against dynamic libraries using pkg-config, linking fails because symbols exposed by drivers are not found:
/usr/bin/x86_64-linux-gnu-ld.bfd: ....o:(.data.rel.ro+0x148): undefined reference to `rte_pci_dump'
That symbol is in librte_bus_pci.so which is *not* listed in the libs section of the pkg-config file.
This series is about fixing this.
Robin Jarry (2):
meson: rename static drivers list
meson: add drivers to dynamic libraries
app/meson.build | 2 +- buildtools/pkg-config/meson.build | 2 +- buildtools/subproject/meson.build | 2 +- drivers/meson.build | 5 ++++- examples/meson.build | 2 +- meson.build | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.0
PATCH 1/2 meson: rename static drivers list
This list contains a list of *static* driver libraries. Reflect that in its name.
--- app/meson.build | 2 +- buildtools/pkg-config/meson.build | 2 +- buildtools/subproject/meson.build | 2 +- drivers/meson.build | 2 +- examples/meson.build | 2 +- meson.build | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
app/meson.build +1 -1
@@ -107,7 +107,7 @@ foreach app:apps dpdk_apps_enabled += app link_libs = [] if get_option('default_library') == 'static' - link_libs = dpdk_static_libraries + dpdk_drivers + link_libs = dpdk_static_libraries + dpdk_static_drivers endif exec = executable('dpdk-' + name,
buildtools/pkg-config/meson.build +1 -1
@@ -49,7 +49,7 @@ Note that CFLAGS might contain an -march flag higher than typical baseline. This is required for a number of static inline functions in the public headers.''', requires: ['libdpdk-libs'], libraries_private: ['-Wl,--whole-archive'] + - dpdk_drivers + dpdk_static_libraries + + dpdk_static_drivers + dpdk_static_libraries + ['-Wl,--no-whole-archive'] + platform_flags )
buildtools/subproject/meson.build +1 -1
@@ -13,7 +13,7 @@ if get_option('default_library') == 'static' compile_args: subproject_cflags, # static library deps in DPDK build don't include "link_with" parameters, # so explicitly link-in both libs and drivers - link_whole: dpdk_static_libraries + dpdk_drivers, + link_whole: dpdk_static_libraries + dpdk_static_drivers, link_args: dpdk_extra_ldflags) else dpdk_dep = declare_dependency(
drivers/meson.build +1 -1
@@ -404,7 +404,7 @@ foreach subpath:subdirs include_directories: includes, dependencies: static_deps) - dpdk_drivers += static_lib + dpdk_static_drivers += static_lib set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep)
examples/meson.build +1 -1
@@ -3,7 +3,7 @@ link_whole_libs = [] if get_option('default_library') == 'static' - link_whole_libs = dpdk_static_libraries + dpdk_drivers + link_whole_libs = dpdk_static_libraries + dpdk_static_drivers endif # list of all example apps. Keep 1-3 per line, in alphabetical order.
meson.build +1 -1
@@ -44,7 +44,7 @@ dpdk_headers = [] dpdk_indirect_headers = [] dpdk_drivers_headers = [] dpdk_driver_classes = [] -dpdk_drivers = [] +dpdk_static_drivers = [] dpdk_extra_ldflags = [] dpdk_libs_deprecated = [] dpdk_apps_disabled = []
Signature · 1 line
2.56.0
Re: [PATCH dpdk 1/2] meson: rename static drivers list
Quoted 4 lines · Robin Jarry
This list contains a list of *static* driver libraries. Reflect that in its name.
Signed-off-by Robin Jarry <[email protected]>
Quoted 8 lines
--- app/meson.build | 2 +- buildtools/pkg-config/meson.build | 2 +- buildtools/subproject/meson.build | 2 +- drivers/meson.build | 2 +- examples/meson.build | 2 +- meson.build | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
PATCH 2/2 meson: add drivers to dynamic libraries
In reply to Robin Jarrydpdk_shared_lib_deps only collects library dependencies, so DPDK built as a meson subproject with shared libraries never links against drivers that install public headers (e.g. bus/pci, bus/vdev). Add these drivers to dpdk_shared_lib_deps as well, mirroring what is already done for libraries in lib/meson.build.
--- drivers/meson.build | 3 +++ 1 file changed, 3 insertions(+)
drivers/meson.build +3 -0
@@ -405,6 +405,9 @@ foreach subpath:subdirs dependencies: static_deps) dpdk_static_drivers += static_lib + if headers.length() > 0 + dpdk_shared_lib_deps += shared_dep + endif set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep)
Signature · 1 line
2.56.0
Re: [PATCH dpdk 2/2] meson: add drivers to dynamic libraries
Quoted 11 lines · Robin Jarry
dpdk_shared_lib_depsonly collects library dependencies, so DPDK built as a meson subproject with shared libraries never links against drivers that install public headers (e.g. bus/pci, bus/vdev). Add these drivers todpdk_shared_lib_depsas well, mirroring what is already done for libraries inlib/meson.build.Signed-off-by Robin Jarry <[email protected]>--- drivers/meson.build | 3 +++ 1 file changed, 3 insertions(+)
Quoted 17 lines
drivers/meson.build +3
-0@@ -405,6 +405,9 @@ foreach subpath:subdirs dependencies: static_deps) dpdk_static_drivers += static_lib + if headers.length() > 0 + dpdk_shared_lib_deps += shared_dep + endif set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep)Signature · 1 line
2.56.0
Quoted 11 lines · Robin Jarry
When building against dynamic libraries using pkg-config, linking fails because symbols exposed by drivers are not found:
/usr/bin/x86_64-linux-gnu-ld.bfd: ....o:(.data.rel.ro+0x148): undefined reference to `rte_pci_dump'That symbol is in librte_bus_pci.so which is *not* listed in the libs section of the pkg-config file.
This series is about fixing this.
While the changes in the two patches are ok, I don't see how they affect pkg-config. The first patch just renames a variable for clarity, and the second only affects applications linking using a meson subproject rather than a .pc file.
/Bruce
Bruce Richardson, Oct 15, 2026 at 12:41:
Quoted 4 lines
While the changes in the two patches are ok, I don't see how they affect pkg-config. The first patch just renames a variable for clarity, and the second only affects applications linking using a meson subproject rather than a .pc file.
Indeed, I had forgotten about updating the correct variable. v2 should be good.
Signature · 3 lines
Robin # To order, call toll-free.
v2 cover Fix dynamic link of driver symbols with pkgconf
In reply to Robin JarryWhen building against dynamic libraries using pkg-config, linking fails because symbols exposed by drivers are not found:
/usr/bin/x86_64-linux-gnu-ld.bfd: ....o:(.data.rel.ro+0x148): undefined reference to `rte_pci_dump'
That symbol is in librte_bus_pci.so which is *not* listed in the libs section of the pkg-config file.
This series is about fixing this.
v2: Added missing update to dpdk_libraries for pkg-config
Robin Jarry (2):
meson: rename static drivers list
meson: add drivers to dynamic libraries
app/meson.build | 2 +- buildtools/pkg-config/meson.build | 2 +- buildtools/subproject/meson.build | 2 +- drivers/meson.build | 6 +++++- examples/meson.build | 2 +- meson.build | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.0
PATCH v2 1/2 meson: rename static drivers list
This list contains a list of *static* driver libraries. Reflect that in its name.
--- app/meson.build | 2 +- buildtools/pkg-config/meson.build | 2 +- buildtools/subproject/meson.build | 2 +- drivers/meson.build | 2 +- examples/meson.build | 2 +- meson.build | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
app/meson.build +1 -1
@@ -107,7 +107,7 @@ foreach app:apps dpdk_apps_enabled += app link_libs = [] if get_option('default_library') == 'static' - link_libs = dpdk_static_libraries + dpdk_drivers + link_libs = dpdk_static_libraries + dpdk_static_drivers endif exec = executable('dpdk-' + name,
buildtools/pkg-config/meson.build +1 -1
@@ -49,7 +49,7 @@ Note that CFLAGS might contain an -march flag higher than typical baseline. This is required for a number of static inline functions in the public headers.''', requires: ['libdpdk-libs'], libraries_private: ['-Wl,--whole-archive'] + - dpdk_drivers + dpdk_static_libraries + + dpdk_static_drivers + dpdk_static_libraries + ['-Wl,--no-whole-archive'] + platform_flags )
buildtools/subproject/meson.build +1 -1
@@ -13,7 +13,7 @@ if get_option('default_library') == 'static' compile_args: subproject_cflags, # static library deps in DPDK build don't include "link_with" parameters, # so explicitly link-in both libs and drivers - link_whole: dpdk_static_libraries + dpdk_drivers, + link_whole: dpdk_static_libraries + dpdk_static_drivers, link_args: dpdk_extra_ldflags) else dpdk_dep = declare_dependency(
drivers/meson.build +1 -1
@@ -404,7 +404,7 @@ foreach subpath:subdirs include_directories: includes, dependencies: static_deps) - dpdk_drivers += static_lib + dpdk_static_drivers += static_lib set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep)
examples/meson.build +1 -1
@@ -3,7 +3,7 @@ link_whole_libs = [] if get_option('default_library') == 'static' - link_whole_libs = dpdk_static_libraries + dpdk_drivers + link_whole_libs = dpdk_static_libraries + dpdk_static_drivers endif # list of all example apps. Keep 1-3 per line, in alphabetical order.
meson.build +1 -1
@@ -44,7 +44,7 @@ dpdk_headers = [] dpdk_indirect_headers = [] dpdk_drivers_headers = [] dpdk_driver_classes = [] -dpdk_drivers = [] +dpdk_static_drivers = [] dpdk_extra_ldflags = [] dpdk_libs_deprecated = [] dpdk_apps_disabled = []
Signature · 1 line
2.56.0
PATCH v2 2/2 meson: add drivers to dynamic libraries
In reply to Robin Jarrydpdk_shared_lib_deps only collects library dependencies, so DPDK built as a meson subproject with shared libraries never links against drivers that install public headers (e.g. bus/pci, bus/vdev). Add these drivers to dpdk_shared_lib_deps as well, mirroring what is already done for libraries in lib/meson.build.
---
Notes:
v2: added driver shared libs to the list for pkg-config
drivers/meson.build | 4 ++++ 1 file changed, 4 insertions(+)
drivers/meson.build +4 -0
@@ -405,6 +405,10 @@ foreach subpath:subdirs dependencies: static_deps) dpdk_static_drivers += static_lib + if headers.length() > 0 + dpdk_libraries += shared_lib + dpdk_shared_lib_deps += shared_dep + endif set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep)
Signature · 1 line
2.56.0
Re: [PATCH dpdk v2 2/2] meson: add drivers to dynamic libraries
Quoted 21 lines · Robin Jarry
dpdk_shared_lib_depsonly collects library dependencies, so DPDK built as a meson subproject with shared libraries never links against drivers that install public headers (e.g. bus/pci, bus/vdev). Add these drivers todpdk_shared_lib_depsas well, mirroring what is already done for libraries inlib/meson.build.Signed-off-by Robin Jarry <[email protected]>Acked-by Bruce Richardson <[email protected]>---
Notes:
v2: added driver shared libs to the list for pkg-configdrivers/meson.build | 4 ++++ 1 file changed, 4 insertions(+)drivers/meson.build +0
-0
drivers/meson.build foreach subpath:subdirs · line 412
Quoted 8 lines
drivers/meson.build +4
-0@@ -405,6 +405,10 @@ foreach subpath:subdirs dependencies: static_deps) dpdk_static_drivers += static_lib + if headers.length() > 0 + dpdk_libraries += shared_lib + dpdk_shared_lib_deps += shared_dep + endif
I think this changes significantly how out pkg-config files are working, vs our original intention, so I think it actually needs more discussion.
As originally designed, when dynamically linking against DPDK the pkg-config --libs libdpdk call was only meant to list out the libraries, with drivers being dynamically loaded at runtime. Since drivers were never meant to have a public API that was generally used, I believe the idea was that anyone using driver-specific APIs was required themselves to pass the driver explicitly to the linker. Otherwise everyone who does not use that driver could end up (depending on their linker flags) with a dependency on that unused driver. This change modifies that assumption and, while it makes it easier for those using driver-specific APIs, it does change how things have worked up till now.
On my system using a default build, this adds 33 drivers to the list of libraries to link against when using pkg-config --libs.
/Bruce
Re: [PATCH dpdk v2 2/2] meson: add drivers to dynamic libraries
Bruce Richardson, Oct 15, 2026 at 13:52:
Quoted 14 lines
I think this changes significantly how out pkg-config files are working, vs our original intention, so I think it actually needs more discussion.
As originally designed, when dynamically linking against DPDK the pkg-config --libs libdpdk call was only meant to list out the libraries, with drivers being dynamically loaded at runtime. Since drivers were never meant to have a public API that was generally used, I believe the idea was that anyone using driver-specific APIs was required themselves to pass the driver explicitly to the linker. Otherwise everyone who does not use that driver could end up (depending on their linker flags) with a dependency on that unused driver. This change modifies that assumption and, while it makes it easier for those using driver-specific APIs, it does change how things have worked up till now.
Quoted 2 lines
On my system using a default build, this adds 33 drivers to the list of libraries to link against when using pkg-config --libs.
But since these libraries are preceded by -Wl,--as-needed, only ones that expose symbols that your binary uses will be linked. I don't think it would change anything in the final result.
Also, this aligns with what the static build is doing: list all drivers as well albeit with -Wl,--whole-archive and *without* -Wl,--as-needed.
What do you think?
Signature · 3 lines
Robin # Do not try this at home.
Re: [PATCH dpdk v2 2/2] meson: add drivers to dynamic libraries
Quoted 18 lines · Robin Jarry
Bruce Richardson, Oct 15, 2026 at 13:52:
Quoted 14 lines
I think this changes significantly how out pkg-config files are working, vs our original intention, so I think it actually needs more discussion.
As originally designed, when dynamically linking against DPDK the pkg-config --libs libdpdk call was only meant to list out the libraries, with drivers being dynamically loaded at runtime. Since drivers were never meant to have a public API that was generally used, I believe the idea was that anyone using driver-specific APIs was required themselves to pass the driver explicitly to the linker. Otherwise everyone who does not use that driver could end up (depending on their linker flags) with a dependency on that unused driver. This change modifies that assumption and, while it makes it easier for those using driver-specific APIs, it does change how things have worked up till now.
Quoted 2 lines
On my system using a default build, this adds 33 drivers to the list of libraries to link against when using pkg-config --libs.
Quoted 7 lines
But since these libraries are preceded by -Wl,--as-needed, only ones that expose symbols that your binary uses will be linked. I don't think it would change anything in the final result.
Also, this aligns with what the static build is doing: list all drivers as well albeit with -Wl,--whole-archive and *without* -Wl,--as-needed.
Yes, static builds link in everything, and that was always the design since static builds don't load drivers at runtime, everything has to be linked into the final object.
Personally, I don't that strongly object to the change because - as you point out - the as-needed flag should prevent overlinking. If we do this, I'd suggest making both drivers and libs full lists, rather than distinguishing between drivers with public headers and those without, because that should allow us to simplify our package config files. Right now we have this strange split into two .pc files, as that was the only way I could find to get correct behaviour for both static and shared builds, where static included everything and shared was libs only. [IIRC, the complication was that, when you pass --static to pkg-config, the extra link args from the pc file get listed *after* the normal libs, while they need to get listed *before* in order to satisfy the dependencies drivers have on the libs]
/Bruce
Re: [PATCH dpdk v2 2/2] meson: add drivers to dynamic libraries
Bruce Richardson, Oct 15, 2026 at 14:18:
Quoted 4 lines
Yes, static builds link in everything, and that was always the design since static builds don't load drivers at runtime, everything has to be linked into the final object.
Quoted 12 lines
Personally, I don't that strongly object to the change because - as you point out - the as-needed flag should prevent overlinking. If we do this, I'd suggest making both drivers and libs full lists, rather than distinguishing between drivers with public headers and those without, because that should allow us to simplify our package config files. Right now we have this strange split into two .pc files, as that was the only way I could find to get correct behaviour for both static and shared builds, where static included everything and shared was libs only. [IIRC, the complication was that, when you pass --static to pkg-config, the extra link args from the pc file get listed *after* the normal libs, while they need to get listed *before* in order to satisfy the dependencies drivers have on the libs]
Thanks. I will see what I can do.
v3 cover Fix dynamic link of driver symbols with pkgconf
In reply to Robin JarryWhen building against dynamic libraries using pkg-config, linking fails because symbols exposed by drivers are not found:
/usr/bin/x86_64-linux-gnu-ld.bfd: ....o:(.data.rel.ro+0x148): undefined reference to `rte_pci_dump'
That symbol is in librte_bus_pci.so which is *not* listed in the libs section of the pkg-config file.
This series is about fixing this.
v3:
- Added all shared driver libs to pkg-config, regardless if they have a public API. -Wl,--as-needed prevents overlinking at build time.
- Simplified to a single .pc file now that all libraries are listed in the correct order.
v2: Added missing update to dpdk_libraries for pkg-config
Robin Jarry (2):
meson: rename static drivers list
meson: add all drivers to dynamic libraries
app/meson.build | 2 +- buildtools/pkg-config/meson.build | 65 ++++++++++++++++--------------- buildtools/subproject/meson.build | 2 +- drivers/meson.build | 4 +- examples/meson.build | 2 +- meson.build | 3 +- 6 files changed, 42 insertions(+), 36 deletions(-)
Signature · 1 line
2.56.0
PATCH v3 1/2 meson: rename static drivers list
This list contains a list of *static* driver libraries. Reflect that in its name.
--- app/meson.build | 2 +- buildtools/pkg-config/meson.build | 2 +- buildtools/subproject/meson.build | 2 +- drivers/meson.build | 2 +- examples/meson.build | 2 +- meson.build | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
app/meson.build +1 -1
@@ -108,7 +108,7 @@ foreach app:apps dpdk_apps_enabled += app link_libs = [] if get_option('default_library') == 'static' - link_libs = dpdk_static_libraries + dpdk_drivers + link_libs = dpdk_static_libraries + dpdk_static_drivers endif exec = executable('dpdk-' + name,
buildtools/pkg-config/meson.build +1 -1
@@ -49,7 +49,7 @@ Note that CFLAGS might contain an -march flag higher than typical baseline. This is required for a number of static inline functions in the public headers.''', requires: ['libdpdk-libs'], libraries_private: ['-Wl,--whole-archive'] + - dpdk_drivers + dpdk_static_libraries + + dpdk_static_drivers + dpdk_static_libraries + ['-Wl,--no-whole-archive'] + platform_flags )
buildtools/subproject/meson.build +1 -1
@@ -13,7 +13,7 @@ if get_option('default_library') == 'static' compile_args: subproject_cflags, # static library deps in DPDK build don't include "link_with" parameters, # so explicitly link-in both libs and drivers - link_whole: dpdk_static_libraries + dpdk_drivers, + link_whole: dpdk_static_libraries + dpdk_static_drivers, link_args: dpdk_extra_ldflags) else dpdk_dep = declare_dependency(
drivers/meson.build +1 -1
@@ -404,7 +404,7 @@ foreach subpath:subdirs include_directories: includes, dependencies: static_deps) - dpdk_drivers += static_lib + dpdk_static_drivers += static_lib set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep)
examples/meson.build +1 -1
@@ -3,7 +3,7 @@ link_whole_libs = [] if get_option('default_library') == 'static' - link_whole_libs = dpdk_static_libraries + dpdk_drivers + link_whole_libs = dpdk_static_libraries + dpdk_static_drivers endif # list of all example apps. Keep 1-3 per line, in alphabetical order.
meson.build +1 -1
@@ -44,7 +44,7 @@ dpdk_headers = [] dpdk_indirect_headers = [] dpdk_drivers_headers = [] dpdk_driver_classes = [] -dpdk_drivers = [] +dpdk_static_drivers = [] dpdk_extra_ldflags = [] dpdk_libs_deprecated = [] dpdk_apps_disabled = []
Signature · 1 line
2.56.0
PATCH v3 2/2 meson: add all drivers to dynamic libraries
In reply to Robin Jarrydpdk_shared_lib_deps only collects library dependencies, so DPDK built as a meson subproject with shared libraries never links against the drivers, even those that install public headers (e.g. bus/pci, bus/vdev). Add all drivers to dpdk_shared_lib_deps as well, mirroring what is already done for libraries in lib/meson.build.
Listing every driver (not only the ones with public headers) lets the pkg-config files be simplified. The two .pc files existed only to get the link order right: drivers must come before the libraries they depend on, but pkg-config emits Libs.private after Libs, so the libraries had to live in a separate file pulled in through Requires. With the drivers and libraries both present in a single Libs.private block, a second file is no longer needed and libdpdk-libs.pc can be folded back into libdpdk.pc. The --as-needed flag keeps shared builds from overlinking.
Listing the drivers in the shared Libs field is safe with respect to the constructor functions that drivers use to register themselves, which must run exactly once. Thanks to --as-needed, a driver whose symbols are not referenced by the application is dropped from the binary NEEDED list, so its constructor does not run at startup and EAL loads the driver once at runtime with dlopen() as before. If the application does reference a driver symbol, the driver stays in NEEDED and its constructor runs at startup, but EAL's later dlopen() of the same file is deduplicated by the dynamic loader (same soname and inode, since the plugin directory holds symlinks to the installed libraries) and does not run the constructor again. The constructor runs exactly once in both cases.
---
Notes:
v3:
- Added all shared driver libs to pkg-config, regardless if they have a public API. -Wl,--as-needed prevents overlinking.
- Simplified to a single .pc file now that all libraries are listed in the correct order.
v2: added driver shared libs to the list for pkg-config
buildtools/pkg-config/meson.build | 63 ++++++++++++++++--------------- drivers/meson.build | 2 + meson.build | 1 + 3 files changed, 36 insertions(+), 30 deletions(-)
buildtools/pkg-config/meson.build +33 -30
@@ -7,35 +7,36 @@ if is_freebsd pkg_extra_cflags += ['-D__BSD_VISIBLE'] endif -# When calling pkg-config --static --libs, pkg-config will always output the -# regular libs first, and then the extra libs from Libs.private field, -# since the assumption is that those are additional dependencies for building -# statically that the .a files depend upon. The output order of .pc fields is: +# The output order of the .pc file fields used by pkg-config is: # Libs Libs.private Requires Requires.private -# The fields Requires* are for package names. -# The flags of the DPDK libraries must be defined in Libs* fields. -# However, the DPDK drivers are linked only in static builds (Libs.private), -# and those need to come *before* the regular libraries (Libs field). -# This requirement is satisfied by moving the regular libs in a separate file -# included in the field Requires (after Libs.private). -# Another requirement is to allow linking dependencies as shared libraries, -# while linking static DPDK libraries and drivers. It is satisfied by -# listing the static files in Libs.private with the explicit syntax -l:libfoo.a. -# As a consequence, the regular DPDK libraries are already listed as static -# in the field Libs.private. The second occurences of DPDK libraries, -# included from Requires and used for shared library linkage case, -# are skipped in the case of static linkage thanks to the flag --as-needed. - - -pkg.generate(name: 'dpdk-libs', - filebase: 'libdpdk-libs', - description: '''Internal-only DPDK pkgconfig file. Not for direct use. -Use libdpdk.pc instead of this file to query DPDK compile/link arguments''', - version: meson.project_version(), - subdirs: [get_option('include_subdir_arch'), '.'], - extra_cflags: pkg_extra_cflags, - libraries: ['-Wl,--as-needed'] + dpdk_libraries, - libraries_private: dpdk_extra_ldflags) +# The Requires* fields are for package names, while the flags of the DPDK +# libraries and drivers must be defined in the Libs* fields. +# +# For shared linking, only the Libs field is used, and it lists the DPDK +# libraries and drivers, all with the --as-needed flag to avoid overlinking +# against components that the application does not actually use. +# +# Listing the drivers here is safe even though they are normally loaded at +# runtime with dlopen(). DPDK drivers register themselves through constructor +# functions that must run exactly once. Thanks to --as-needed, a driver whose +# symbols are not referenced by the application is dropped from the binary's +# NEEDED list entirely, so its constructor does not run at startup and EAL +# loads it once at runtime as usual. If the application does reference a driver +# symbol, the driver stays in NEEDED and its constructor runs at startup; EAL's +# later dlopen() of the same file is deduplicated by the dynamic loader (same +# soname and inode, the plugin directory holds symlinks to the installed +# libraries) and does not run the constructor a second time. Either way, the +# constructor runs exactly once. +# +# For static linking, pkg-config appends the Libs.private field after Libs. +# The DPDK drivers must be linked before the libraries they depend upon, so +# both the drivers and the libraries are listed in Libs.private, wrapped in +# --whole-archive so that drivers register themselves at load time. The +# static files are listed with the explicit -l:libfoo.a syntax so that DPDK +# itself is linked statically while its external dependencies may still be +# linked as shared libraries. The DPDK libraries from the Libs field appear a +# second time before Libs.private, but those occurrences are skipped thanks to +# the --as-needed flag. platform_flags = [] if not is_windows
@@ -47,10 +48,12 @@ pkg.generate(name: 'DPDK', # main DPDK pkgconfig file description: '''The Data Plane Development Kit (DPDK). Note that CFLAGS might contain an -march flag higher than typical baseline. This is required for a number of static inline functions in the public headers.''', - requires: ['libdpdk-libs'], + subdirs: [get_option('include_subdir_arch'), '.'], + extra_cflags: pkg_extra_cflags, + libraries: ['-Wl,--as-needed'] + dpdk_libraries + dpdk_shared_drivers, libraries_private: ['-Wl,--whole-archive'] + dpdk_static_drivers + dpdk_static_libraries + - ['-Wl,--no-whole-archive'] + platform_flags + ['-Wl,--no-whole-archive'] + dpdk_extra_ldflags + platform_flags ) # For static linking with dependencies as shared libraries,
drivers/meson.build +2 -0
@@ -405,6 +405,8 @@ foreach subpath:subdirs dependencies: static_deps) dpdk_static_drivers += static_lib + dpdk_shared_drivers += shared_lib + dpdk_shared_lib_deps += shared_dep set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep)
meson.build +1 -0
@@ -45,6 +45,7 @@ dpdk_indirect_headers = [] dpdk_drivers_headers = [] dpdk_driver_classes = [] dpdk_static_drivers = [] +dpdk_shared_drivers = [] dpdk_extra_ldflags = [] dpdk_libs_deprecated = [] dpdk_apps_disabled = []
Signature · 1 line
2.56.0