@@ -149,25 +149,6 @@ 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
-#
-# NOTE: We're using "-ztext" instead of "-Wl,-z,text" here, because some
-# packages pass TARGET_LDFLAGS directly to ld rather than gcc, and ld doesn't
-# support -Wl,[...]. -z is supported by both gcc and clang, so it probably
-# won't cause us problems.
-#
-# We're using "-ztext" instead of "-z text" here, because some buildsystems
-# (like scons, for gpsd) will reorder and/or drop LDFLAGS, causing a lone
-# "-z" to be passed and the "text" keyword to be dropped otherwise. Both
-# gcc and ld supports that, so it probably won't cause us problems.
-ifeq ($(BR2_TOOLCHAIN_USES_MUSL):$(BR2_STATIC_LIBS),y:)
-TARGET_LDFLAGS += -ztext
-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
@@ -51,10 +51,11 @@ static char _date_[sizeof("-D__DATE__=\"MMM DD YYYY\"")];
* -Wno-builtin-macro-redefined
* -Wl,-z,now
* -Wl,-z,relro
+ * -Wl,-z,text
* -fPIE
* -pie
*/
-#define EXCLUSIVE_ARGS 10
+#define EXCLUSIVE_ARGS 11
static char *predef_args[] = {
#ifdef BR_CCACHE
@@ -486,6 +487,9 @@ int main(int argc, char **argv)
break;
}
if (i == argc) {
+#ifdef BR2_ZTEXT
+ *cur++ = "-Wl,-z,text";
+#endif
/* https://wiki.gentoo.org/wiki/Hardened/Toolchain#Mark_Read-Only_Appropriate_Sections */
#ifdef BR2_RELRO_PARTIAL
*cur++ = "-Wl,-z,relro";
@@ -83,6 +83,15 @@ else ifeq ($(BR2_RELRO_FULL),y)
TOOLCHAIN_WRAPPER_ARGS += -DBR2_RELRO_FULL
endif
+# 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:)
+TOOLCHAIN_WRAPPER_ARGS += -DBR2_ZTEXT
+endif
+
define TOOLCHAIN_WRAPPER_BUILD
$(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \
-s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \