config: add a knob to use the mold linker for packages
authorAndre Heider <a.heider@gmail.com>
Fri, 27 Jan 2023 16:13:15 +0000 (17:13 +0100)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 4 Jul 2023 18:25:40 +0000 (20:25 +0200)
Building it requires gcc >= 10.2 or clang >= 12.

Using sstrip with its -z argument can produce non-working binaries, like
a segfaulting `getrandom`, so don't allow that combination.

Signed-off-by: Andre Heider <a.heider@gmail.com>
config/Config-build.in
config/check-hostcxx.sh [new file with mode: 0755]

index f8d0f8e0bd238d2cdbef263b1539ee6aeed0647a..5f9a1be8586267ba56fb0bd499bdd586ead0501a 100644 (file)
@@ -159,6 +159,19 @@ menu "Global build settings"
                  Adds LTO flags to the CFLAGS and LDFLAGS.
                  Packages can choose to opt-out via setting PKG_BUILD_FLAGS:=no-lto
 
+       config MOLD
+               depends on (aarch64 || arm || i386 || i686 || m68k || powerpc || powerpc64 || sh4 || x86_64)
+               depends on !GCC_USE_VERSION_11
+               def_bool $(shell, ./config/check-hostcxx.sh 10 2 12)
+
+       config USE_MOLD
+               bool
+               prompt "Use the mold linker for all packages"
+               depends on MOLD
+               help
+                 Link packages with mold, a modern linker
+                 Packages can opt-out via setting PKG_BUILD_FLAGS:=no-mold
+
        config IPV6
                def_bool y
 
@@ -200,7 +213,7 @@ menu "Global build settings"
 
        config SSTRIP_DISCARD_TRAILING_ZEROES
                bool "Strip trailing zero bytes"
-               depends on USE_SSTRIP
+               depends on USE_SSTRIP && !USE_MOLD
                default y
                help
                  Use sstrip's -z option to discard trailing zero bytes
diff --git a/config/check-hostcxx.sh b/config/check-hostcxx.sh
new file mode 100755 (executable)
index 0000000..442f4cf
--- /dev/null
@@ -0,0 +1,12 @@
+cat << EOF | "$STAGING_DIR_HOST/bin/g++" -c -x c++ -o /dev/null - >/dev/null 2>&1
+#if __clang__
+  #if __clang_major__ < $3
+    #error "clang too old"
+  #endif
+#else
+  #if __GNUC__ < $1 || (__GNUC__ == $1 && (__GNUC_MINOR__ < $2))
+    #error "gcc too old"
+  #endif
+#endif
+EOF
+[ $? -eq 0 ] && echo y || echo n