package/Makefile.in: ban textrels on musl toolchains

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 <j.neuschaefer@gmx.net>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
J. Neuschäfer 2024-07-19 17:27:19 +02:00 committed by Thomas Petazzoni
parent 4c4afb4157
commit a1a2f498d7

View File

@ -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