Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] Config.in: add option to ban textrels
@ 2024-04-19 14:52 J. Neuschäfer via buildroot
  2024-05-09 15:40 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 3+ messages in thread
From: J. Neuschäfer via buildroot @ 2024-04-19 14:52 UTC (permalink / raw)
  To: buildroot; +Cc: J. Neuschäfer

Ideally, this option would default to yes when a musl-based toolchain is
used, as musl doesn't support TEXTRELs[1] and programs with TEXTRELs
will crash on start-up under musl.

However, to avoid a large build fallout, it defaults to "no" for now.
After this option has been enabled in build tests for a while and some
of the fallout has been fixed, the default can be changed.

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

Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
---
 Config.in           | 13 +++++++++++++
 package/Makefile.in |  4 ++++
 2 files changed, 17 insertions(+)

diff --git a/Config.in b/Config.in
index e4f58f3f66..26964a6bac 100644
--- a/Config.in
+++ b/Config.in
@@ -906,6 +906,19 @@ endchoice
 comment "RELocation Read Only (RELRO) needs shared libraries"
 	depends on !BR2_SHARED_LIBS

+config BR2_LINK_ZTEXT
+	bool "Disallow text section relocations (TEXTRELs)"
+	depends on BR2_SHARED_LIBS
+	default n # ideally: BR2_TOOLCHAIN_USES_MUSL
+	help
+	  Pass "-z text" to the linker to detect TEXTRELs and throw an error if
+	  they occur.
+
+	  This is recommended when building a system with musl-libc, because
+	  TEXTRELs are not supported on musl-libc:
+
+	    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 3e276d23d6..de93defb3b 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -149,6 +149,10 @@ endif

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

+ifeq ($(BR2_LINK_ZTEXT),y)
+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: 256aa8ed85f8fd65ea0f0f242adb55f95a13eb2b
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] 3+ messages in thread

end of thread, other threads:[~2024-05-10 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-19 14:52 [Buildroot] [PATCH] Config.in: add option to ban textrels J. Neuschäfer via buildroot
2024-05-09 15:40 ` Thomas Petazzoni via buildroot
2024-05-10 13:26   ` 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