From a1a2f498d7ecdd643b5c057f1c737e082a105384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Neusch=C3=A4fer?= Date: Fri, 19 Jul 2024 17:27:19 +0200 Subject: [PATCH] package/Makefile.in: ban textrels on musl toolchains MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit musl-libc doesn't support TEXTRELs[1] and programs with TEXTRELs will crash on start-up under musl. This patch forbids the use of TEXTRELs on musl toolchains with dynamic linking. To verify this patch: - Delete package/micropython/0001-py-nlrthumb-Make-non-Thumb2-long-jump-workaround-opt.patch - Build micropython (before v1.23) with a musl toolchain and BR2_SHARED_LIBS. The build should abort while linking micropython. [1]: https://www.openwall.com/lists/musl/2020/09/25/4 Signed-off-by: J. Neuschäfer Signed-off-by: Thomas Petazzoni --- package/Makefile.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/package/Makefile.in b/package/Makefile.in index 47a89f1ae1..1cedfefa7e 100644 --- a/package/Makefile.in +++ b/package/Makefile.in @@ -149,6 +149,15 @@ endif TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS)) +# musl's dynamic loader doesn't support DT_TEXTREL, which results in a runtime +# crash if it gets used. The "-z text" linker option issues a build-time error +# when DT_TEXREL is used, so we capture the problem earlier. +# +# See also: https://www.openwall.com/lists/musl/2020/09/25/4 +ifeq ($(BR2_TOOLCHAIN_USES_MUSL):$(BR2_STATIC_LIBS),y:) +TARGET_LDFLAGS += -Wl,-z,text +endif + # By design, _FORTIFY_SOURCE requires gcc optimization to be enabled. # Therefore, we need to pass _FORTIFY_SOURCE and the optimization level # through the same mechanism, i.e currently through CFLAGS. Passing