diff options
| author | Hauke Mehrtens | 2026-04-05 11:53:32 +0000 |
|---|---|---|
| committer | Hauke Mehrtens | 2026-06-18 00:27:10 +0000 |
| commit | 8e7ae1b936eedb086a898a00489b49a9f72bb403 (patch) | |
| tree | 49b6cd9fed7ca4a2ef9de16921b6ab8acc47f19f | |
| parent | 9c0c586eedee6b789ca13680349452b02ac6474c (diff) | |
| download | openwrt-8e7ae1b936eedb086a898a00489b49a9f72bb403.tar.gz | |
build: set max-page-size linker flag to match target page size
ELF binaries embed the maximum page size used during linking in the
PT_LOAD segment alignment. If this value is larger than the actual
system page size, the kernel will still load the binary but wastes
memory due to over-alignment. If it is smaller, the binary may fail
to load or cause incorrect behavior with features like RELRO.
Most architectures use 4KB pages, but loongarch64 uses 16KB pages
(CONFIG_PAGE_SIZE_16KB). Explicitly pass -z max-page-size to the
linker so that binaries are built with the correct page alignment for
the target, avoiding issues with RELRO segment padding and ensuring
correct memory mapping on the target system.
Before binutils 2.39 RELRO sections were padded to common page size
which is 4K on MIPS, with binutils 3.29 the padding was changed to
max page size which is 64K on MIPS. With this change we will pad them to
4K again.
This reduces the size of user space binaries in OpenWrt.
The size of the uncompressed root file system of a mips malta be build
decreased by about 20%.
old file size:
```
$ du -s build_dir/target-mips_24kc_musl/root-malta/
15844 build_dir/target-mips_24kc_musl/root-malta/
```
New file size:
```
$ du -s build_dir/target-mips_24kc_musl/root-malta/
12564 build_dir/target-mips_24kc_musl/root-malta/
```
The size of the image did not decrease much because of the strong
compression used by OpenWrt.
Link: https://github.com/openwrt/openwrt/pull/22800
(cherry picked from commit 04f10eb796dd817d3e03e52d745dc92de735e77a)
Link: https://github.com/openwrt/openwrt/pull/23210
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
| -rw-r--r-- | include/package.mk | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/include/package.mk b/include/package.mk index da9fc7d4eb..af594eff0c 100644 --- a/include/package.mk +++ b/include/package.mk @@ -62,6 +62,15 @@ ifdef CONFIG_USE_MOLD endif endif +# loongarch64 sets CONFIG_PAGE_SIZE_16KB, all other targets set CONFIG_PAGE_SIZE_4KB only. +ifeq ($(ARCH),loongarch64) + TARGET_CFLAGS += -Wl,-z,max-page-size=16384 + TARGET_LDFLAGS += -zmax-page-size=16384 +else + TARGET_CFLAGS += -Wl,-z,max-page-size=4096 + TARGET_LDFLAGS += -zmax-page-size=4096 +endif + include $(INCLUDE_DIR)/hardening.mk include $(INCLUDE_DIR)/prereq.mk include $(INCLUDE_DIR)/unpack.mk |