diff --git a/README.md b/README.md index bfbe862af..f4d98d933 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,6 @@ sudo apt-get install -y clang-15 export USE_GLIBC=y ``` -### 启用 [GCC13](https://gcc.gnu.org/gcc-13/) 工具链编译 -##### 只需在构建固件前执行以下命令即可启用 GCC13 工具链 - -``` -export USE_GCC13=y -``` - ### 启用 [eBPF](https://docs.kernel.org/bpf/) 支持 ##### 只需在构建固件前执行以下命令即可启用 eBPF 支持 diff --git a/openwrt/build.sh b/openwrt/build.sh index 2d5f2d9e7..ad75f72dd 100644 --- a/openwrt/build.sh +++ b/openwrt/build.sh @@ -84,11 +84,14 @@ export platform=$2 [ "$platform" = "x86_64" ] && export platform="x86_64" toolchain_arch="x86_64" # gcc 13 -export USE_GCC13=$USE_GCC13 +USE_GCC13=y # use glibc export USE_GLIBC=$USE_GLIBC +# use mold +USE_MOLD=y + # lrng export ENABLE_LRNG=$ENABLE_LRNG @@ -122,6 +125,7 @@ fi echo -e "${GREEN_COLOR}Date: $CURRENT_DATE${RES}\r\n" [ "$USE_GCC13" = "y" ] && echo -e "${GREEN_COLOR}GCC VERSION: 13${RES}" || echo -e "${GREEN_COLOR}GCC VERSION: 11${RES}" +[ "$USE_MOLD" = "y" ] && echo -e "${GREEN_COLOR}USE_MOLD: true${RES}" || echo -e "${GREEN_COLOR}USE_MOLD: false${RES}" [ "$ENABLE_OTA" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_OTA: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_OTA: false${RES}" [ "$ENABLE_BPF" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_BPF: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_BPF: false${RES}" [ "$ENABLE_LTO" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_LTO: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_LTO: false${RES}" @@ -249,6 +253,9 @@ export ENABLE_LTO=$ENABLE_LTO sed -i '/NaiveProxy/d' .config } +# mold +[ "$USE_MOLD" = "y" ] && echo 'CONFIG_USE_MOLD=y' >> .config + # openwrt-23.05 gcc11/13 if [ "$USE_GCC13" = "y" ]; then curl -s https://$mirror/openwrt/generic/config-gcc13 >> .config diff --git a/openwrt/patch/openwrt-6.x/mold/0001-build-add-support-to-use-the-mold-linker-for-package.patch b/openwrt/patch/openwrt-6.x/mold/0001-build-add-support-to-use-the-mold-linker-for-package.patch new file mode 100644 index 000000000..e508e0786 --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0001-build-add-support-to-use-the-mold-linker-for-package.patch @@ -0,0 +1,32 @@ +From 18d4007ad731dfa625a6c03d1a946c453d7b92f2 Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Fri, 27 Jan 2023 16:35:46 +0100 +Subject: [PATCH 1/8] build: add support to use the mold linker for packages + +If CONFIG_USE_MOLD is set, all target packages will use the mold linker. +Except the ones which opted-out via setting PKG_BUILD_FLAGS:=no-mold. + +Signed-off-by: Andre Heider +--- + include/package.mk | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/include/package.mk b/include/package.mk +index c391d320aa..1791d6d9d4 100644 +--- a/include/package.mk ++++ b/include/package.mk +@@ -55,6 +55,11 @@ ifeq ($(call pkg_build_flag,lto,$(if $(CONFIG_USE_LTO),1,0)),1) + TARGET_CXXFLAGS+= -flto=auto -fno-fat-lto-objects + TARGET_LDFLAGS+= -flto=auto -fuse-linker-plugin + endif ++ifdef CONFIG_USE_MOLD ++ ifeq ($(call pkg_build_flag,mold,1),1) ++ TARGET_LINKER:=mold ++ endif ++endif + + include $(INCLUDE_DIR)/hardening.mk + include $(INCLUDE_DIR)/prereq.mk +-- +2.39.3 + diff --git a/openwrt/patch/openwrt-6.x/mold/0002-treewide-opt-out-of-tree-wide-mold-usage.patch b/openwrt/patch/openwrt-6.x/mold/0002-treewide-opt-out-of-tree-wide-mold-usage.patch new file mode 100644 index 000000000..fb91d1e3f --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0002-treewide-opt-out-of-tree-wide-mold-usage.patch @@ -0,0 +1,81 @@ +From b7619a40b1497d974fef2bcc07bfef6da93e049a Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Fri, 27 Jan 2023 18:22:43 +0100 +Subject: [PATCH 2/8] treewide: opt-out of tree-wide mold usage + +These use linker scripts, which mold doesn't support. + +Signed-off-by: Andre Heider +--- + include/package.mk | 2 +- + package/boot/grub2/Makefile | 2 +- + package/kernel/lantiq/ltq-ifxos/Makefile | 1 + + package/kernel/lantiq/ltq-vdsl-vr11-mei/Makefile | 1 + + package/kernel/lantiq/ltq-vdsl-vr11/Makefile | 1 + + 5 files changed, 5 insertions(+), 2 deletions(-) + +diff --git a/include/package.mk b/include/package.mk +index 1791d6d9d4..61a26f0c43 100644 +--- a/include/package.mk ++++ b/include/package.mk +@@ -24,7 +24,7 @@ PKG_JOBS?=$(if $(PKG_BUILD_PARALLEL),$(MAKE_J),-j1) + endif + + PKG_BUILD_FLAGS?= +-__unknown_flags=$(filter-out no-iremap no-mips16 gc-sections no-gc-sections lto no-lto,$(PKG_BUILD_FLAGS)) ++__unknown_flags=$(filter-out no-iremap no-mips16 gc-sections no-gc-sections lto no-lto no-mold,$(PKG_BUILD_FLAGS)) + ifneq ($(__unknown_flags),) + $(error unknown PKG_BUILD_FLAGS: $(__unknown_flags)) + endif +diff --git a/package/boot/grub2/Makefile b/package/boot/grub2/Makefile +index 865feee9ad..44dafe1ef1 100644 +--- a/package/boot/grub2/Makefile ++++ b/package/boot/grub2/Makefile +@@ -25,7 +25,7 @@ ifneq ($(BUILD_VARIANT),none) + endif + + PKG_FLAGS:=nonshared +-PKG_BUILD_FLAGS:=no-lto ++PKG_BUILD_FLAGS:=no-lto no-mold + + include $(INCLUDE_DIR)/host-build.mk + include $(INCLUDE_DIR)/package.mk +diff --git a/package/kernel/lantiq/ltq-ifxos/Makefile b/package/kernel/lantiq/ltq-ifxos/Makefile +index d941a9d56f..97f7ca78ce 100644 +--- a/package/kernel/lantiq/ltq-ifxos/Makefile ++++ b/package/kernel/lantiq/ltq-ifxos/Makefile +@@ -23,6 +23,7 @@ PKG_LICENSE_FILES:=LICENSE + PKG_EXTMOD_SUBDIRS:=src + + PKG_FIXUP:=autoreconf ++PKG_BUILD_FLAGS:=no-mold + + include $(INCLUDE_DIR)/package.mk + +diff --git a/package/kernel/lantiq/ltq-vdsl-vr11-mei/Makefile b/package/kernel/lantiq/ltq-vdsl-vr11-mei/Makefile +index f2dcf8db84..7b8a948179 100644 +--- a/package/kernel/lantiq/ltq-vdsl-vr11-mei/Makefile ++++ b/package/kernel/lantiq/ltq-vdsl-vr11-mei/Makefile +@@ -25,6 +25,7 @@ PKG_EXTMOD_SUBDIRS:=src + + PKG_FIXUP:=autoreconf + PKG_FLAGS:=nonshared ++PKG_BUILD_FLAGS:=no-mold + + include $(INCLUDE_DIR)/package.mk + +diff --git a/package/kernel/lantiq/ltq-vdsl-vr11/Makefile b/package/kernel/lantiq/ltq-vdsl-vr11/Makefile +index 8284cba9a7..11f96d744a 100644 +--- a/package/kernel/lantiq/ltq-vdsl-vr11/Makefile ++++ b/package/kernel/lantiq/ltq-vdsl-vr11/Makefile +@@ -23,6 +23,7 @@ PKG_LICENSE:=GPL-2.0 BSD-2-Clause + PKG_LICENSE_FILES:=LICENSE + + PKG_FIXUP:=autoreconf ++PKG_BUILD_FLAGS:=no-mold + + include $(INCLUDE_DIR)/package.mk + +-- +2.39.3 + diff --git a/openwrt/patch/openwrt-6.x/mold/0003-toolchain-add-mold-as-additional-linker.patch b/openwrt/patch/openwrt-6.x/mold/0003-toolchain-add-mold-as-additional-linker.patch new file mode 100644 index 000000000..a53e07e98 --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0003-toolchain-add-mold-as-additional-linker.patch @@ -0,0 +1,58 @@ +From a667acae2ed1d0a99a52e07916b01f42bc9f8f9d Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Fri, 27 Jan 2023 17:53:02 +0100 +Subject: [PATCH 3/8] toolchain: add mold as additional linker + +Install it as $tripple-ld.mold in order to use -fuse-ld=mold. + +Signed-off-by: Andre Heider +--- + toolchain/Makefile | 2 +- + toolchain/mold/Makefile | 22 ++++++++++++++++++++++ + 2 files changed, 23 insertions(+), 1 deletion(-) + create mode 100644 toolchain/mold/Makefile + +diff --git a/toolchain/Makefile b/toolchain/Makefile +index c0046293c9..09c16f72a7 100644 +--- a/toolchain/Makefile ++++ b/toolchain/Makefile +@@ -27,7 +27,7 @@ + curdir:=toolchain + + # subdirectories to descend into +-$(curdir)/builddirs := $(if $(CONFIG_GDB),gdb) $(if $(CONFIG_EXTERNAL_TOOLCHAIN),wrapper,kernel-headers binutils gcc/initial gcc/final $(LIBC) fortify-headers) $(if $(CONFIG_NASM),nasm) ++$(curdir)/builddirs := $(if $(CONFIG_GDB),gdb) $(if $(CONFIG_EXTERNAL_TOOLCHAIN),wrapper,kernel-headers binutils gcc/initial gcc/final $(LIBC) fortify-headers) $(if $(CONFIG_NASM),nasm) $(if $(CONFIG_USE_MOLD),mold) + + # builddir dependencies + ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),) +diff --git a/toolchain/mold/Makefile b/toolchain/mold/Makefile +new file mode 100644 +index 0000000000..a2acba89d3 +--- /dev/null ++++ b/toolchain/mold/Makefile +@@ -0,0 +1,22 @@ ++# ++# This is free software, licensed under the GNU General Public License v2. ++# See /LICENSE for more information. ++# ++include $(TOPDIR)/rules.mk ++include $(INCLUDE_DIR)/toolchain-build.mk ++ ++define Host/Configure ++endef ++ ++define Host/Compile ++endef ++ ++define Host/Install ++ $(INSTALL_DIR) $(TOOLCHAIN_DIR)/bin ++ $(INSTALL_BIN) $(STAGING_DIR_HOST)/bin/mold $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-ld.mold ++endef ++ ++define Host/Clean ++endef ++ ++$(eval $(call HostBuild)) +-- +2.39.3 + diff --git a/openwrt/patch/openwrt-6.x/mold/0004-tools-add-mold-a-modern-linker.patch b/openwrt/patch/openwrt-6.x/mold/0004-tools-add-mold-a-modern-linker.patch new file mode 100644 index 000000000..64a2ddbc9 --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0004-tools-add-mold-a-modern-linker.patch @@ -0,0 +1,71 @@ +From a500032a30152630e058c3ee6afbbe787325db43 Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Fri, 27 Jan 2023 17:53:02 +0100 +Subject: [PATCH 4/8] tools: add mold, a modern linker + +mold is a faster drop-in replacement for existing Unix linkers. + +A single binary is able to link various targets, which is why this lives +in tools/. + +All toolchain builds then just need to copy the linker over, hence avoiding +multiple builds with the same outcome. + +Signed-off-by: Andre Heider +--- + tools/Makefile | 2 ++ + tools/mold/Makefile | 22 ++++++++++++++++++++++ + 2 files changed, 24 insertions(+) + create mode 100644 tools/mold/Makefile + +diff --git a/tools/Makefile b/tools/Makefile +index 40c3ec1ab0..bf525d34a0 100644 +--- a/tools/Makefile ++++ b/tools/Makefile +@@ -83,6 +83,7 @@ tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_TARGET_tegra),y) += cbootimage + tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USES_MINOR),y) += kernel2minor + tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_SPARSE),y) += sparse + tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_LLVM_BUILD),y) += llvm-bpf ++tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_MOLD),y) += mold + + # builddir dependencies + $(curdir)/autoconf/compile := $(curdir)/m4/compile +@@ -114,6 +115,7 @@ $(curdir)/meson/compile := $(curdir)/ninja/compile + $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile + $(curdir)/mkimage/compile += $(curdir)/bison/compile $(curdir)/libressl/compile + $(curdir)/mklibs/compile := $(curdir)/libtool/compile ++$(curdir)/mold/compile := $(curdir)/cmake/compile $(curdir)/zlib/compile $(curdir)/zstd/compile + $(curdir)/mpc/compile := $(curdir)/mpfr/compile $(curdir)/gmp/compile + $(curdir)/mpfr/compile := $(curdir)/gmp/compile + $(curdir)/mtd-utils/compile := $(curdir)/libtool/compile $(curdir)/e2fsprogs/compile $(curdir)/zlib/compile +diff --git a/tools/mold/Makefile b/tools/mold/Makefile +new file mode 100644 +index 0000000000..e8fcecbfed +--- /dev/null ++++ b/tools/mold/Makefile +@@ -0,0 +1,22 @@ ++# SPDX-License-Identifier: GPL-2.0-only ++ ++include $(TOPDIR)/rules.mk ++ ++PKG_NAME:=mold ++PKG_VERSION:=1.11.0 ++ ++PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz ++PKG_SOURCE_URL_FILE:=v$(PKG_VERSION).tar.gz ++PKG_SOURCE_URL:=https://github.com/rui314/mold/archive/refs/tags ++PKG_HASH:=99318eced81b09a77e4c657011076cc8ec3d4b6867bd324b8677974545bc4d6f ++ ++include $(INCLUDE_DIR)/host-build.mk ++include $(INCLUDE_DIR)/cmake.mk ++ ++CMAKE_HOST_OPTIONS += \ ++ -DMOLD_LTO=ON \ ++ -DMOLD_MOSTLY_STATIC=ON \ ++ -DMOLD_USE_SYSTEM_MIMALLOC=OFF \ ++ -DMOLD_USE_SYSTEM_TBB=OFF ++ ++$(eval $(call HostBuild)) +-- +2.39.3 + diff --git a/openwrt/patch/openwrt-6.x/mold/0005-build-replace-SSTRIP_ARGS-with-SSTRIP_DISCARD_TRAILI.patch b/openwrt/patch/openwrt-6.x/mold/0005-build-replace-SSTRIP_ARGS-with-SSTRIP_DISCARD_TRAILI.patch new file mode 100644 index 000000000..13fae5050 --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0005-build-replace-SSTRIP_ARGS-with-SSTRIP_DISCARD_TRAILI.patch @@ -0,0 +1,63 @@ +From 55d51626b8a3fd48a980e5d033ecdbef071137c4 Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Sat, 28 Jan 2023 21:16:16 +0100 +Subject: [PATCH 5/8] build: replace SSTRIP_ARGS with + SSTRIP_DISCARD_TRAILING_ZEROES + +sstrip only has one functional arg. Make that a bool option, which can +easily depend on other knobs then. + +This is required to be disabled for the mold linker. + +Signed-off-by: Andre Heider +--- + config/Config-build.in | 10 ++++------ + rules.mk | 2 +- + 2 files changed, 5 insertions(+), 7 deletions(-) + +diff --git a/config/Config-build.in b/config/Config-build.in +index fe16d81d36..a96ed2f63b 100644 +--- a/config/Config-build.in ++++ b/config/Config-build.in +@@ -190,7 +190,6 @@ menu "Global build settings" + help + This will install binaries stripped using strip from binutils. + +- + config USE_SSTRIP + bool "sstrip" + depends on !USE_GLIBC +@@ -207,13 +206,12 @@ menu "Global build settings" + help + Specifies arguments passed to the strip command when stripping binaries. + +- config SSTRIP_ARGS +- string +- prompt "Sstrip arguments" ++ config SSTRIP_DISCARD_TRAILING_ZEROES ++ bool "Strip trailing zero bytes" + depends on USE_SSTRIP +- default "-z" ++ default y + help +- Specifies arguments passed to the sstrip command when stripping binaries. ++ Use sstrip's -z option to discard trailing zero bytes + + config STRIP_KERNEL_EXPORTS + bool "Strip unnecessary exports from the kernel image" +diff --git a/rules.mk b/rules.mk +index 58c53705a2..c768ccc9b3 100644 +--- a/rules.mk ++++ b/rules.mk +@@ -325,7 +325,7 @@ else + STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS)) + else + ifneq ($(CONFIG_USE_SSTRIP),) +- STRIP:=$(STAGING_DIR_HOST)/bin/sstrip $(call qstrip,$(CONFIG_SSTRIP_ARGS)) ++ STRIP:=$(STAGING_DIR_HOST)/bin/sstrip $(if $(CONFIG_SSTRIP_DISCARD_TRAILING_ZEROES),-z) + endif + endif + RSTRIP= \ +-- +2.39.3 + diff --git a/openwrt/patch/openwrt-6.x/mold/0006-config-add-a-knob-to-use-the-mold-linker-for-package.patch b/openwrt/patch/openwrt-6.x/mold/0006-config-add-a-knob-to-use-the-mold-linker-for-package.patch new file mode 100644 index 000000000..878fefc14 --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0006-config-add-a-knob-to-use-the-mold-linker-for-package.patch @@ -0,0 +1,71 @@ +From 9826d03b0c6829bf72f11a2eed85fc07abaf3f67 Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Fri, 27 Jan 2023 17:13:15 +0100 +Subject: [PATCH 6/8] config: add a knob to use the mold linker for packages + +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 +--- + config/Config-build.in | 15 ++++++++++++++- + config/check-hostcxx.sh | 12 ++++++++++++ + 2 files changed, 26 insertions(+), 1 deletion(-) + create mode 100755 config/check-hostcxx.sh + +diff --git a/config/Config-build.in b/config/Config-build.in +index a96ed2f63b..ebfce8add4 100644 +--- a/config/Config-build.in ++++ b/config/Config-build.in +@@ -167,6 +167,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 + +@@ -208,7 +221,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 +index 0000000000..442f4cfb40 +--- /dev/null ++++ b/config/check-hostcxx.sh +@@ -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 +-- +2.39.3 + diff --git a/openwrt/patch/openwrt-6.x/mold/0007-rules-prepare-to-use-different-linkers.patch b/openwrt/patch/openwrt-6.x/mold/0007-rules-prepare-to-use-different-linkers.patch new file mode 100644 index 000000000..be0e82c96 --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0007-rules-prepare-to-use-different-linkers.patch @@ -0,0 +1,49 @@ +From 2741764fdd20c3f2d0ceaa5f9206f83182305de8 Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Fri, 27 Jan 2023 16:32:31 +0100 +Subject: [PATCH 7/8] rules: prepare to use different linkers + +This explicitely adds the default linker to the target LDFLAGS. + +No functional change intended. + +Signed-off-by: Andre Heider +--- + rules.mk | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/rules.mk b/rules.mk +index c768ccc9b3..ca27583d27 100644 +--- a/rules.mk ++++ b/rules.mk +@@ -211,6 +211,10 @@ ifndef DUMP + endif + endif + endif ++ ++TARGET_LINKER?=bfd ++TARGET_LDFLAGS+= -fuse-ld=$(TARGET_LINKER) ++ + TARGET_PATH_PKG:=$(STAGING_DIR)/host/bin:$(STAGING_DIR_HOSTPKG)/bin:$(TARGET_PATH) + + ifeq ($(CONFIG_SOFT_FLOAT),y) +@@ -252,6 +256,7 @@ TARGET_RANLIB:=$(TARGET_CROSS)gcc-ranlib + TARGET_NM:=$(TARGET_CROSS)gcc-nm + TARGET_CC:=$(TARGET_CROSS)gcc + TARGET_CXX:=$(TARGET_CROSS)g++ ++TARGET_LD:=$(TARGET_CROSS)ld.$(TARGET_LINKER) + KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh + FILECMD:=$(STAGING_DIR_HOST)/bin/file + SED:=$(STAGING_DIR_HOST)/bin/sed -i -e +@@ -305,7 +310,7 @@ endif + TARGET_CONFIGURE_OPTS = \ + AR="$(TARGET_AR)" \ + AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \ +- LD=$(TARGET_CROSS)ld \ ++ LD="$(TARGET_LD)" \ + NM="$(TARGET_NM)" \ + CC="$(TARGET_CC)" \ + GCC="$(TARGET_CC)" \ +-- +2.39.3 + diff --git a/openwrt/patch/openwrt-6.x/mold/0008-tools-mold-update-to-2.4.0.patch b/openwrt/patch/openwrt-6.x/mold/0008-tools-mold-update-to-2.4.0.patch new file mode 100644 index 000000000..4585d21f8 --- /dev/null +++ b/openwrt/patch/openwrt-6.x/mold/0008-tools-mold-update-to-2.4.0.patch @@ -0,0 +1,33 @@ +From 7273b6009d71769f8d8e5e9cb475ee7f65385573 Mon Sep 17 00:00:00 2001 +From: sbwml +Date: Wed, 17 Jan 2024 20:27:59 +0800 +Subject: [PATCH 8/8] tools/mold: update to 2.4.0 + +Signed-off-by: sbwml +--- + tools/mold/Makefile | 7 +++---- + 1 file changed, 3 insertions(+), 4 deletions(-) + +diff --git a/tools/mold/Makefile b/tools/mold/Makefile +index e8fcecbfed..8effd08aa1 100644 +--- a/tools/mold/Makefile ++++ b/tools/mold/Makefile +@@ -3,12 +3,11 @@ + include $(TOPDIR)/rules.mk + + PKG_NAME:=mold +-PKG_VERSION:=1.11.0 ++PKG_VERSION:=2.4.0 + + PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +-PKG_SOURCE_URL_FILE:=v$(PKG_VERSION).tar.gz +-PKG_SOURCE_URL:=https://github.com/rui314/mold/archive/refs/tags +-PKG_HASH:=99318eced81b09a77e4c657011076cc8ec3d4b6867bd324b8677974545bc4d6f ++PKG_SOURCE_URL:=https://codeload.github.com/rui314/mold/tar.gz/v$(PKG_VERSION)? ++PKG_HASH:=be65f3d785d32ece7b3204ecaa57810847fdd25c232cf704cbfff2dafb1ac107 + + include $(INCLUDE_DIR)/host-build.mk + include $(INCLUDE_DIR)/cmake.mk +-- +2.39.3 + diff --git a/openwrt/scripts/00-prepare_base.sh b/openwrt/scripts/00-prepare_base.sh index 9a5ce4b4d..e9bcad2b5 100644 --- a/openwrt/scripts/00-prepare_base.sh +++ b/openwrt/scripts/00-prepare_base.sh @@ -78,6 +78,20 @@ if [ "$USE_GLIBC" = "y" ]; then sed -i "/disable-profile/d" toolchain/glibc/common.mk fi +# mold +if [ "$USE_MOLD" = "y" ]; then + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0001-build-add-support-to-use-the-mold-linker-for-package.patch | patch -p1 + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0002-treewide-opt-out-of-tree-wide-mold-usage.patch | patch -p1 + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0003-toolchain-add-mold-as-additional-linker.patch | patch -p1 + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0004-tools-add-mold-a-modern-linker.patch | patch -p1 + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0005-build-replace-SSTRIP_ARGS-with-SSTRIP_DISCARD_TRAILI.patch | patch -p1 + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0006-config-add-a-knob-to-use-the-mold-linker-for-package.patch | patch -p1 + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0007-rules-prepare-to-use-different-linkers.patch | patch -p1 + curl -s https://$mirror/openwrt/patch/openwrt-6.x/mold/0008-tools-mold-update-to-2.4.0.patch | patch -p1 + # no-mold + sed -i '/PKG_BUILD_PARALLEL/aPKG_BUILD_FLAGS:=no-mold' feeds/packages/utils/attr/Makefile +fi + # Mbedtls AES & GCM Crypto Extensions if [ ! "$platform" = "x86_64" ]; then rm -rf package/libs/mbedtls