Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v3] Config.in: ban textrels on musl toolchains
@ 2024-07-04 18:05 J. Neuschäfer via buildroot
  2024-07-15  8:51 ` Arnout Vandecappelle via buildroot
  0 siblings, 1 reply; 4+ messages in thread
From: J. Neuschäfer via buildroot @ 2024-07-04 18:05 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, but adds an option to
either forbid them on other libcs as well, or allow them on musl.

[1]: https://www.openwall.com/lists/musl/2020/09/25/4

Signed-off-by: J. Neuschäfer <j.neuschaefer@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
---

I'm not sure about the Kconfig help text for BR2_LINK_ALLOW_TEXTREL.
Perhaps it could be written a little nicer.


v3:
- rewrite to positive logic, as suggested by Yann E. MORIN
- adjust the name and help text accordingly

v2:
- slightly different wording
- default to yes on musl toolchains
- fix check-package warnings
- depends on BR2_SHARED_LIBS -> depends on !BR2_STATIC_LIBS
---
 Config.in           | 14 ++++++++++++++
 package/Makefile.in |  4 ++++
 2 files changed, 18 insertions(+)

diff --git a/Config.in b/Config.in
index bdf5fa8647..c8b52c0d74 100644
--- a/Config.in
+++ b/Config.in
@@ -910,6 +910,20 @@ endchoice
 comment "RELocation Read Only (RELRO) needs shared libraries"
 	depends on !BR2_SHARED_LIBS

+config BR2_LINK_ALLOW_TEXTREL
+	bool "Allow text section relocations (TEXTRELs)"
+	default y  # Legacy
+	depends on !BR2_TOOLCHAIN_USES_MUSL
+	depends on !BR2_STATIC_LIBS
+	help
+	  Enable this option to allow TEXTRELs. Otherwise "-z text" will be
+	  passed to the linker to detect them and throw an error if they occur.
+
+	  TEXTRELs are not supported on musl-libc's dynamic loader and will
+	  result in a run-time crash:
+
+	    https://www.openwall.com/lists/musl/2020/09/25/4
+
 config BR2_FORTIFY_SOURCE_ARCH_SUPPORTS
 	bool
 	default y
diff --git a/package/Makefile.in b/package/Makefile.in
index 5476234c7e..3f1a1d3a35 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -149,6 +149,10 @@ endif

 TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))

+ifeq ($(BR2_LINK_ALLOW_TEXTREL),)
+TARGET_LDFLAGS += -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: 3ebc7c69d56430c34eba4c869d1d4fe4d1e8de55
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] 4+ messages in thread

end of thread, other threads:[~2024-07-17 11:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-04 18:05 [Buildroot] [PATCH v3] Config.in: ban textrels on musl toolchains J. Neuschäfer via buildroot
2024-07-15  8:51 ` Arnout Vandecappelle via buildroot
2024-07-15  9:06   ` Thomas Petazzoni via buildroot
2024-07-17 11:52   ` 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