Skip to content

Commit a2a78c0

Browse files
committed
build: Add support for linking with DT_RELR
This adds the -Wl,-z,pack-relative-relocs linking options. This reduces the size of some binaries. This is only supported on i386, x86_64, aarch64 and loongarch64 in binutils. This feature is not support for MIPS. musl libc supports it since version 1.2.4 . glibc supports it since vesion 2.36. binutils ld supports it since version 2.38 for x86 and since version 2.43 for LoongArch. This reduces the size of the armsr default root file system from 5,262,198 bytes to 5,200,950 bytes by 61,248 bytes. Link: openwrt/openwrt#20679 Signed-off-by: Hauke Mehrtens <[email protected]>
1 parent 08997df commit a2a78c0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config/Config-build.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ menu "Global build settings"
383383
bool "Full"
384384
endchoice
385385

386+
config PKG_DT_RELR
387+
bool "Link with relative relocations (RELR)"
388+
depends on (aarch64 || i386 || loongarch64 || x86_64)
389+
default y
390+
help
391+
Link all applications with -Wl,-z,pack-relative-relocs.
392+
This will reduce the size of many applications.
393+
This is only supported on a limited number of architectures.
394+
386395
config TARGET_ROOTFS_SECURITY_LABELS
387396
bool
388397
select KERNEL_SQUASHFS_XATTR

include/hardening.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PKG_ASLR_PIE_REGULAR ?= 0
88
PKG_SSP ?= 1
99
PKG_FORTIFY_SOURCE ?= 1
1010
PKG_RELRO ?= 1
11+
PKG_DT_RELR ?= 1
1112

1213
ifdef CONFIG_PKG_CHECK_FORMAT_SECURITY
1314
ifeq ($(strip $(PKG_CHECK_FORMAT_SECURITY)),1)
@@ -69,3 +70,10 @@ ifdef CONFIG_PKG_RELRO_FULL
6970
endif
7071
endif
7172

73+
ifdef CONFIG_PKG_DT_RELR
74+
ifeq ($(strip $(PKG_DT_RELR)),1)
75+
TARGET_CFLAGS += -Wl,-z,pack-relative-relocs
76+
TARGET_LDFLAGS += -zpack-relative-relocs
77+
endif
78+
endif
79+

0 commit comments

Comments
 (0)