Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v5] Config.in: ban textrels on musl toolchains
@ 2024-07-19 15:27 J. Neuschäfer via buildroot
  2024-07-22 16:31 ` Thomas Petazzoni via buildroot
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: J. Neuschäfer via buildroot @ 2024-07-19 15:27 UTC (permalink / raw)
  To: buildroot; +Cc: Yann E. MORIN, Thomas Petazzoni, J. Neuschäfer

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>
---
Changes in v5:
- Fix boolean logic (ifeq...)
- Link to v4: https://lore.kernel.org/r/20240718-ztext-v4-1-15a9744f1edb@gmx.net

Changes in v4:
- Remove Config.in option, implement the whole logic in
  package/Makefile.in
- Document how to verify
- Link to v3: https://lore.kernel.org/r/20240704-ztext-v3-1-9195d06c8bd0@gmx.net

Changes in v3:
- drop micropython patch (already merged)
- rewrite to positive logic, as suggested by Yann E. MORIN
- Link to v2: https://lore.kernel.org/r/20240529-ztext-v2-0-82985032f169@gmx.net

Changes in v2:
- Slightly different wording
- Enable the option by default on musl toolchains
- Add patch to fix build of micropython

Link to v1:
- https://lore.kernel.org/r/20240419-ztext-v1-1-a8d5c2cfcf57@gmx.net
---
---
 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

---
base-commit: 89e3b2fb846506217b4767fe9165f1641a407314
change-id: 20240417-ztext-5accbab61c0a

Best regards,
--
J. Neuschäfer <j.neuschaefer@gmx.net>

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-08-24 19:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-19 15:27 [Buildroot] [PATCH v5] Config.in: ban textrels on musl toolchains J. Neuschäfer via buildroot
2024-07-22 16:31 ` Thomas Petazzoni via buildroot
2024-07-30 22:03 ` Thomas Petazzoni via buildroot
2024-08-04 22:31   ` J. Neuschäfer via buildroot
2024-08-13  9:09 ` yann.morin
2024-08-23 10:21   ` J. Neuschäfer via buildroot
2024-08-24 19:36   ` J. Neuschäfer via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox