package/mesa3d: dri: link statically libmegadriver_stub after libdricommon
PATCH 1/1 package/mesa3d: dri: link statically libmegadriver_stub after libdricommon
Meson build system enable by default -Wl,--as-needed in the linker command line [1] and due to this the megadriver_stub build can fail with some toolchain:
/home/buildroot/autobuild/run/instance-1/output-1/host/bin/arm-none-linux-gnueabi-g++
-o src/mesa/drivers/dri/libmesa_dri_drivers.so
-Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -shared -fPIC -Wl,--start-group -Wl,-soname,libmesa_dri_drivers.so -Wl,--whole-archive src/mesa/drivers/dri/radeon/libr100.a src/mesa/drivers/dri/nouveau/libnouveau_vieux.a -Wl,--no-whole-archive
src/mesa/drivers/dri/common/libmegadriver_stub.a src/mesa/drivers/dri/common/libdricommon.a
src/mapi/shared-glapi/libglapi.so.0.0.0
src/mesa/libmesa_classic.a src/mesa/libmesa_common.a
src/compiler/glsl/libglsl.a src/compiler/glsl/glcpp/libglcpp.a
src/util/libmesa_util.a src/util/format/libmesa_format.a
src/compiler/nir/libnir.a src/compiler/libcompiler.a
src/util/libxmlconfig.a
[...]
src/mesa/drivers/dri/common/libmegadriver_stub.a(megadriver_stub.c.o): In function `megadriver_stub_init':
megadriver_stub.c:(.text.startup+0x20): undefined reference to dladdr' megadriver_stub.c:(.text.startup+0xbc): undefined reference to dlsym'
collect2: error: ld returned 1 exit status
This is because the static librairies needs to be correcly sorted by dependency. libmegadriver_stub include dri_util.h that internally include dri_interface.h needed for dlsym and dladdr definition.
[1] https://mesonbuild.com/Builtin-options.html
Fixes:
http://autobuild.buildroot.net/results/eec39a4fbfbfaa58980fab36f2fd902a16eecf0f/build-end.log
--- ...lly-libmegadriver_stub-after-libdric.patch | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch
package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch new file +58 -0
@@ -0,0 +1,58 @@ +From b4f68629937eac22f122b9b069e4e5acbcc51a75 Mon Sep 17 00:00:00 2001 +From: Romain Naour <[email protected]> +Date: Tue, 9 Jun 2020 16:49:32 +0200 +Subject: [PATCH] dri: link statically libmegadriver_stub after libdricommon + +Meson build system enable by default -Wl,--as-needed in the linker command line [1] and +due to this the megadriver_stub build can fail with some toolchain: + +/home/buildroot/autobuild/run/instance-1/output-1/host/bin/arm-none-linux-gnueabi-g++ + -o src/mesa/drivers/dri/libmesa_dri_drivers.so + -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -shared -fPIC -Wl,--start-group + -Wl,-soname,libmesa_dri_drivers.so -Wl,--whole-archive + src/mesa/drivers/dri/radeon/libr100.a src/mesa/drivers/dri/nouveau/libnouveau_vieux.a + -Wl,--no-whole-archive + src/mesa/drivers/dri/common/libmegadriver_stub.a + src/mesa/drivers/dri/common/libdricommon.a + src/mapi/shared-glapi/libglapi.so.0.0.0 + src/mesa/libmesa_classic.a src/mesa/libmesa_common.a + src/compiler/glsl/libglsl.a src/compiler/glsl/glcpp/libglcpp.a + src/util/libmesa_util.a src/util/format/libmesa_format.a + src/compiler/nir/libnir.a src/compiler/libcompiler.a + src/util/libxmlconfig.a + [...] +src/mesa/drivers/dri/common/libmegadriver_stub.a(megadriver_stub.c.o): In function `megadriver_stub_init': +megadriver_stub.c:(.text.startup+0x20): undefined reference to `dladdr' +megadriver_stub.c:(.text.startup+0xbc): undefined reference to `dlsym' +collect2: error: ld returned 1 exit status + +This is because the static librairies needs to be correcly sorted by dependency. +libmegadriver_stub include dri_util.h that internally include dri_interface.h needed for +dlsym and dladdr definition. + +[1] https://mesonbuild.com/Builtin-options.html + +Fixes: +http://autobuild.buildroot.net/results/eec39a4fbfbfaa58980fab36f2fd902a16eecf0f/build-end.log + +Signed-off-by: Romain Naour <[email protected]> +--- + src/mesa/drivers/dri/meson.build | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/mesa/drivers/dri/meson.build b/src/mesa/drivers/dri/meson.build +index b09ca16e38a..9ac6731c522 100644 +--- a/src/mesa/drivers/dri/meson.build ++++ b/src/mesa/drivers/dri/meson.build +@@ -59,7 +59,7 @@ if _dri_drivers != [] + [], + link_whole : _dri_drivers, + link_with : [ +- libmegadriver_stub, libdricommon, libglapi, ++ libdricommon, libmegadriver_stub, libglapi, + libmesa_classic, + ], + dependencies : [ +-- +2.25.4 +
Signature · 1 line
2.25.4
PATCH 1/1 package/mesa3d: dri: link statically libmegadriver_stub after libdricommon
Quoted 65 lines · On Tue, 9 Jun 2020 17:20:07 +0200 Romain Naour <[email protected]> wrote:
Meson build system enable by default -Wl,--as-needed in the linker command line [1] and due to this the
megadriver_stubbuild can fail with some toolchain:
/home/buildroot/autobuild/run/instance-1/output-1/host/bin/arm-none-linux-gnueabi-g++
-o src/mesa/drivers/dri/libmesa_dri_drivers.so
-Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -shared -fPIC -Wl,--start-group -Wl,-soname,libmesa_dri_drivers.so -Wl,--whole-archive src/mesa/drivers/dri/radeon/libr100.a src/mesa/drivers/dri/nouveau/libnouveau_vieux.a -Wl,--no-whole-archive
src/mesa/drivers/dri/common/libmegadriver_stub.a src/mesa/drivers/dri/common/libdricommon.a
src/mapi/shared-glapi/libglapi.so.0.0.0
src/mesa/libmesa_classic.a src/mesa/libmesa_common.a
src/compiler/glsl/libglsl.a src/compiler/glsl/glcpp/libglcpp.a
src/util/libmesa_util.a src/util/format/libmesa_format.a
src/compiler/nir/libnir.a src/compiler/libcompiler.a
src/util/libxmlconfig.a
[...]
src/mesa/drivers/dri/common/libmegadriver_stub.a(megadriver_stub.c.o): In function `megadriver_stub_init':
megadriver_stub.c:(.text.startup+0x20): undefined reference todladdr' megadriver_stub.c:(.text.startup+0xbc): undefined reference todlsym'
collect2: error: ld returned 1 exit statusThis is because the static librairies needs to be correcly sorted by dependency.
libmegadriver_stubincludedri_util.hthat internally includedri_interface.hneeded for dlsym and dladdr definition.[1] https://mesonbuild.com/Builtin-options.html
Fixes:
http://autobuild.buildroot.net/results/eec39a4fbfbfaa58980fab36f2fd902a16eecf0f/build-end.logSigned-off-by Romain Naour <[email protected]>--- ...lly-libmegadriver_stub-after-libdric.patch | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patchpackage/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch new file +21
-0@@ -0,0 +1,58 @@ +From b4f68629937eac22f122b9b069e4e5acbcc51a75 Mon Sep 17 00:00:00 2001 +From: Romain Naour <[email protected]> +Date: Tue, 9 Jun 2020 16:49:32 +0200 +Subject: [PATCH] dri: link statically libmegadriver_stub after libdricommon + +Meson build system enable by default -Wl,--as-needed in the linker command line [1] and +due to this the megadriver_stub build can fail with some toolchain: + +/home/buildroot/autobuild/run/instance-1/output-1/host/bin/arm-none-linux-gnueabi-g++ + -o src/mesa/drivers/dri/libmesa_dri_drivers.so + -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -shared -fPIC -Wl,--start-group + -Wl,-soname,libmesa_dri_drivers.so -Wl,--whole-archive + src/mesa/drivers/dri/radeon/libr100.a src/mesa/drivers/dri/nouveau/libnouveau_vieux.a + -Wl,--no-whole-archive + src/mesa/drivers/dri/common/libmegadriver_stub.a + src/mesa/drivers/dri/common/libdricommon.a + src/mapi/shared-glapi/libglapi.so.0.0.0 + src/mesa/libmesa_classic.a src/mesa/libmesa_common.a + src/compiler/glsl/libglsl.a src/compiler/glsl/glcpp/libglcpp.a + src/util/libmesa_util.a src/util/format/libmesa_format.a + src/compiler/nir/libnir.a src/compiler/libcompiler.a
package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch line 31
Quoted 10 lines
package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch new file +10
-0+ src/util/libxmlconfig.a + [...] +src/mesa/drivers/dri/common/libmegadriver_stub.a(megadriver_stub.c.o): In function `megadriver_stub_init': +megadriver_stub.c:(.text.startup+0x20): undefined reference to `dladdr' +megadriver_stub.c:(.text.startup+0xbc): undefined reference to `dlsym' +collect2: error: ld returned 1 exit status + +This is because the static librairies needs to be correcly sorted by dependency. +libmegadriver_stub include dri_util.h that internally include dri_interface.h needed for +dlsym and dladdr definition.
Why do .h files matter here? This sort of linking issue really should have nothing to do with header files inclusion/ordering, but just about object file/library ordering at link time.
Could you clarify what is happening here? dladdr and dlsym are provided by the C library, so I'm not sure why the ordering between libdricommon and libmegadriver_stub can matter here.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/1 package/mesa3d: dri: link statically libmegadriver_stub after libdricommon
Hi Thomas,
Le 10/06/2020 ? 22:59, Thomas Petazzoni a ?crit?:
Quoted 74 lines
Quoted 71 lines · On Tue, 9 Jun 2020 17:20:07 +0200 Romain Naour <[email protected]> wrote:
Meson build system enable by default -Wl,--as-needed in the linker command line [1] and due to this the
megadriver_stubbuild can fail with some toolchain:
/home/buildroot/autobuild/run/instance-1/output-1/host/bin/arm-none-linux-gnueabi-g++
-o src/mesa/drivers/dri/libmesa_dri_drivers.so
-Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -shared -fPIC -Wl,--start-group -Wl,-soname,libmesa_dri_drivers.so -Wl,--whole-archive src/mesa/drivers/dri/radeon/libr100.a src/mesa/drivers/dri/nouveau/libnouveau_vieux.a -Wl,--no-whole-archive
src/mesa/drivers/dri/common/libmegadriver_stub.a src/mesa/drivers/dri/common/libdricommon.a
src/mapi/shared-glapi/libglapi.so.0.0.0
src/mesa/libmesa_classic.a src/mesa/libmesa_common.a
src/compiler/glsl/libglsl.a src/compiler/glsl/glcpp/libglcpp.a
src/util/libmesa_util.a src/util/format/libmesa_format.a
src/compiler/nir/libnir.a src/compiler/libcompiler.a
src/util/libxmlconfig.a
[...]
src/mesa/drivers/dri/common/libmegadriver_stub.a(megadriver_stub.c.o): In function `megadriver_stub_init':
megadriver_stub.c:(.text.startup+0x20): undefined reference todladdr' megadriver_stub.c:(.text.startup+0xbc): undefined reference todlsym'
collect2: error: ld returned 1 exit statusThis is because the static librairies needs to be correcly sorted by dependency.
libmegadriver_stubincludedri_util.hthat internally includedri_interface.hneeded for dlsym and dladdr definition.[1] https://mesonbuild.com/Builtin-options.html
Fixes:
http://autobuild.buildroot.net/results/eec39a4fbfbfaa58980fab36f2fd902a16eecf0f/build-end.logSigned-off-by Romain Naour <[email protected]>--- ...lly-libmegadriver_stub-after-libdric.patch | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patchpackage/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch new file +27
-0@@ -0,0 +1,58 @@ +From b4f68629937eac22f122b9b069e4e5acbcc51a75 Mon Sep 17 00:00:00 2001 +From: Romain Naour <[email protected]> +Date: Tue, 9 Jun 2020 16:49:32 +0200 +Subject: [PATCH] dri: link statically libmegadriver_stub after libdricommon + +Meson build system enable by default -Wl,--as-needed in the linker command line [1] and +due to this the megadriver_stub build can fail with some toolchain: + +/home/buildroot/autobuild/run/instance-1/output-1/host/bin/arm-none-linux-gnueabi-g++ + -o src/mesa/drivers/dri/libmesa_dri_drivers.so + -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -shared -fPIC -Wl,--start-group + -Wl,-soname,libmesa_dri_drivers.so -Wl,--whole-archive + src/mesa/drivers/dri/radeon/libr100.a src/mesa/drivers/dri/nouveau/libnouveau_vieux.a + -Wl,--no-whole-archive + src/mesa/drivers/dri/common/libmegadriver_stub.a + src/mesa/drivers/dri/common/libdricommon.a + src/mapi/shared-glapi/libglapi.so.0.0.0 + src/mesa/libmesa_classic.a src/mesa/libmesa_common.a + src/compiler/glsl/libglsl.a src/compiler/glsl/glcpp/libglcpp.a + src/util/libmesa_util.a src/util/format/libmesa_format.a + src/compiler/nir/libnir.a src/compiler/libcompiler.a + src/util/libxmlconfig.a + [...] +src/mesa/drivers/dri/common/libmegadriver_stub.a(megadriver_stub.c.o): In function `megadriver_stub_init': +megadriver_stub.c:(.text.startup+0x20): undefined reference to `dladdr' +megadriver_stub.c:(.text.startup+0xbc): undefined reference to `dlsym' +collect2: error: ld returned 1 exit status
Quoted 8 lines
package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch line 31
Quoted 4 lines
package/mesa3d/0009-dri-link-statically-libmegadriver_stub-after-libdric.patch new file +4
-0+ +This is because the static librairies needs to be correcly sorted by dependency. +libmegadriver_stub include dri_util.h that internally include dri_interface.h needed for +dlsym and dladdr definition.Why do .h files matter here? This sort of linking issue really should have nothing to do with header files inclusion/ordering, but just about object file/library ordering at link time.
I noticed that linker flag --as-needed is important to trigger the issue, I disabled it by using -Db_asneeded=false in MESA3D_CONF_OPTS. The .h was here to try to "explain" why we have a dependency between static libraries when --as-needed is used.
Quoted 4 lines
Could you clarify what is happening here? dladdr and dlsym are provided by the C library, so I'm not sure why the ordering between libdricommon and
libmegadriver_stubcan matter here.
I tried with more recent toolchain and there is no issue.
The toolchain used to reproduce the issue is the old ARM codesourcery 2014.05.
I discover an interesting commit and bug report in binutils about --as-needed option before version 2.25.
https://sourceware.org/bugzilla/show_bug.cgi?id=17287
I can reproduce the issue issue with the codesourcery toolchain and Linaro 4.9-4.9-2014.11 but not with 5.2-2015.11-2 toolchain:
Linaro 4.9-4.9-2014.11: OK (binutils linaro_binutils-2_24-branch) Linaro 5.2-2015.11-2: OK (binutils 2.25)
But for both Linaro toolchain mesa3d build correctly, I gess it's because Linaro binutils 2.24 is patched with another patch related to --as-needed:
http://git.linaro.org/toolchain/binutils-gdb.git/commit/?id=72f758d066732d56d50851a97dd67a31f331e2b3
So either we reorder the libraries in the meson build system (like the patch does) or we can disable --as-needed for this toolchain by using -Db_asneeded=false.
Best regards,
Romain
Quoted 3 lines
Thomas