Makefile: use -z pack-relative-relocs
PATCH 1/1 Makefile: use -z pack-relative-relocs
Commit 27f2a4db76e8 ("Makefile: fix GDB warning with CONFIG_RELR") added --use-android-relr-tags to fix a GDB warning
BFD: /android0/linux-next/vmlinux: unknown type [0x13] section `.relr.dyn'
The GDB warning has been fixed in version 11.2.
The DT_ANDROID_RELR tag was deprecated since DT_RELR was standardized. Thus, --use-android-relr-tags should be removed. While making the change, replace --pack-dyn-relocs=relr with -z pack-relative-relocs, which is supported since LLD 15.
As of today, GNU ld supports the latter option for x86 and powerpc64 ports and has no intention to support --pack-dyn-relocs=relr. In the absence of the glibc symbol version GLIBC_ABI_DT_RELR, --pack-dyn-relocs=relr and -z pack-relative-relocs are identical in ld.lld.
--- Makefile | 2 +- scripts/tools-support-relr.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
Makefile +1 -1
@@ -1113,7 +1113,7 @@ LDFLAGS_vmlinux += -X endif ifeq ($(CONFIG_RELR),y) -LDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags +LDFLAGS_vmlinux += -z pack-relative-relocs endif # We never want expected sections to be placed heuristically by the
scripts/tools-support-relr.sh +1 -2
@@ -7,8 +7,7 @@ trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT cat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1 void *p = &p; END -$LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr \ - --use-android-relr-tags -o $tmp_file +$LD $tmp_file.o -shared -Bsymbolic -z pack-relative-relocs -o $tmp_file # Despite printing an error message, GNU nm still exits with exit code 0 if it # sees a relr section. So we need to check that nothing is printed to stderr.
Signature · 1 line
2.40.0.348.gf938b09366-goog
Hi Fangrui,
Thanks for the patches!
Quoted 4 lines · Fangrui Song
Commit
27f2a4db76e8("Makefile: fix GDB warning withCONFIG_RELR") added --use-android-relr-tags to fix a GDB warning
Quoted 8 lines
BFD: /android0/linux-next/vmlinux: unknown type [
0x13] section `.relr.dyn'The GDB warning has been fixed in version 11.2.
The
DT_ANDROID_RELRtag was deprecated sinceDT_RELRwas standardized. Thus, --use-android-relr-tags should be removed. While making the change, replace --pack-dyn-relocs=relr with -z pack-relative-relocs, which is supported since LLD 15.
Looks like
commit 4a8de2832a2a ("[ELF] Add -z pack-relative-relocs")
Quoted 6 lines
As of today, GNU ld supports the latter option for x86 and powerpc64 ports and has no intention to support --pack-dyn-relocs=relr. In the absence of the glibc symbol version
GLIBC_ABI_DT_RELR, --pack-dyn-relocs=relr and -z pack-relative-relocs are identical in ld.lld.
Won't this regress support for CONFIG_TOOLS_SUPPORT_RELR for LLD 11-14? (which we still support, see Documentation/process/changes.rst; I guess we don't list LLD explicitly, but it's effectively under the llvm umbrella there).
IIUC, looks like lld 7.0+ should support SHT_RELR based on looking at commit 11479daf2f06 ("lld: add experimental support for SHT_RELR sections.")
So we might want to invoke the linker twice, once with the new flag, and again with the old if we fail the first time?
Quoted 39 lines
Link https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=a619b58721f0a03fd91c27670d3e4c2fb0d88f1eSigned-off-by Fangrui Song <[email protected]>--- Makefile | 2 +- scripts/tools-support-relr.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)Makefile +1
-1@@ -1113,7 +1113,7 @@ LDFLAGS_vmlinux += -X endif ifeq ($(CONFIG_RELR),y) -LDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags +LDFLAGS_vmlinux += -z pack-relative-relocs endif # We never want expected sections to be placed heuristically by thescripts/tools-support-relr.sh +1
-3@@ -7,8 +7,7 @@ trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT cat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1 void *p = &p; END -$LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr \ - --use-android-relr-tags -o $tmp_file +$LD $tmp_file.o -shared -Bsymbolic -z pack-relative-relocs -o $tmp_file # Despite printing an error message, GNU nm still exits with exit code 0 if it # sees a relr section. So we need to check that nothing is printed to stderr. --2.40.0.348.gf938b09366-goog
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 32 lines · Nick Desaulniers
Hi Fangrui,
Thanks for the patches!Quoted 4 lines · Fangrui Song
Commit
27f2a4db76e8("Makefile: fix GDB warning withCONFIG_RELR") added --use-android-relr-tags to fix a GDB warningQuoted 8 lines
BFD: /android0/linux-next/vmlinux: unknown type [
0x13] section `.relr.dyn'The GDB warning has been fixed in version 11.2.
The
DT_ANDROID_RELRtag was deprecated sinceDT_RELRwas standardized. Thus, --use-android-relr-tags should be removed. While making the change, replace --pack-dyn-relocs=relr with -z pack-relative-relocs, which is supported since LLD 15.Looks like
commit4a8de2832a2a("[ELF] Add -z pack-relative-relocs")Quoted 6 lines
As of today, GNU ld supports the latter option for x86 and powerpc64 ports and has no intention to support --pack-dyn-relocs=relr. In the absence of the glibc symbol version
GLIBC_ABI_DT_RELR, --pack-dyn-relocs=relr and -z pack-relative-relocs are identical in ld.lld.Won't this regress support for
CONFIG_TOOLS_SUPPORT_RELRfor LLD 11-14? (which we still support, seeDocumentation/process/changes.rst; I guess we don't list LLD explicitly, but it's effectively under the llvm umbrella there).
Quoted 5 lines
IIUC, looks like lld 7.0+ should support
SHT_RELRbased on looking at commit11479daf2f06("lld: add experimental support forSHT_RELRsections.")So we might want to invoke the linker twice, once with the new flag, and again with the old if we fail the first time?
Yes, I am aware of the increased linker and debugger requirement and was thinking the CONFIG_RELR=y case with ld.lld<15 did not matter.
Since you raised this, it seems that we should ld.lld<15. How about the following diff?
Makefile +2 -1
@@ -1113,7 +1113,8 @@ LDFLAGS_vmlinux += -X endif ifeq ($(CONFIG_RELR),y) -LDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags +# ld.lld before 15 did not support -z pack-relative-relocs. +LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs) endif # We never want expected sections to be placed heuristically by the
scripts/tools-support-relr.sh +3 -2
@@ -7,8 +7,9 @@ trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT cat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1 void *p = &p; END -$LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr \ - --use-android-relr-tags -o $tmp_file +# ld.lld before 15 did not support -z pack-relative-relocs. +$LD $tmp_file.o -shared -Bsymbolic -z pack-relative-relocs -o $tmp_file || \ + $LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr -o $tmp_file # Despite printing an error message, GNU nm still exits with exit code 0 if it # sees a relr section. So we need to check that nothing is printed to stderr.
Signature · 1 line
2.40.0.348.gf938b09366-goog
Quoted 44 lines
Quoted 39 lines
Link https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=a619b58721f0a03fd91c27670d3e4c2fb0d88f1eSigned-off-by Fangrui Song <[email protected]>--- Makefile | 2 +- scripts/tools-support-relr.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)Makefile +1
-1@@ -1113,7 +1113,7 @@ LDFLAGS_vmlinux += -X endif ifeq ($(CONFIG_RELR),y) -LDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags +LDFLAGS_vmlinux += -z pack-relative-relocs endif # We never want expected sections to be placed heuristically by thescripts/tools-support-relr.sh +1
-3@@ -7,8 +7,7 @@ trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT cat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1 void *p = &p; END -$LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr \ - --use-android-relr-tags -o $tmp_file +$LD $tmp_file.o -shared -Bsymbolic -z pack-relative-relocs -o $tmp_file # Despite printing an error message, GNU nm still exits with exit code 0 if it # sees a relr section. So we need to check that nothing is printed to stderr. --2.40.0.348.gf938b09366-goog
Signature · 2 lines
Thanks, ~Nick Desaulniers
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Fangrui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on masahiroy-kbuild/for-next]
[also build test WARNING on masahiroy-kbuild/fixes linus/master v6.3-rc3 next-20230323] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Fangrui-Song/Makefile-use-z-pack-relative-relocs/20230324-044515 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next patch link: https://lore.kernel.org/r/20230323204427.3594372-1-maskray%40google.com patch subject: [PATCH] Makefile: use -z pack-relative-relocs config: arm64-randconfig-r022-20230322 (https://download.01.org/0day-ci/archive/20230324/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/8f47a36faf182f96a2bbf4d3b9305fe9a90c5cde
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Fangrui-Song/Makefile-use-z-pack-relative-relocs/20230324-044515 git checkout 8f47a36faf182f96a2bbf4d3b9305fe9a90c5cde
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> aarch64-linux-ld: warning: -z pack-relative-relocs ignored >> aarch64-linux-ld: warning: -z pack-relative-relocs ignored >> aarch64-linux-ld: warning: -z pack-relative-relocs ignored
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Quoted 35 lines · kernel test robot
Hi Fangrui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on masahiroy-kbuild/for-next]
[also build test WARNING on masahiroy-kbuild/fixes linus/master v6.3-rc3 next-20230323] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Fangrui-Song/Makefile-use-z-pack-relative-relocs/20230324-044515 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next patch link: https://lore.kernel.org/r/20230323204427.3594372-1-maskray%40google.com patch subject: [PATCH] Makefile: use -z pack-relative-relocs config: arm64-randconfig-r022-20230322 (https://download.01.org/0day-ci/archive/20230324/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 12.1.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/8f47a36faf182f96a2bbf4d3b9305fe9a90c5cde
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Fangrui-Song/Makefile-use-z-pack-relative-relocs/20230324-044515 git checkout8f47a36faf182f96a2bbf4d3b9305fe9a90c5cde
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bashIf you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
aarch64-linux-ld: warning: -z pack-relative-relocs ignored
aarch64-linux-ld: warning: -z pack-relative-relocs ignored
aarch64-linux-ld: warning: -z pack-relative-relocs ignored--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
I forgot to check aarch64-linux-gnu-ld. To address the issue I can use:
# ld.lld before 15 did not support -z pack-relative-relocs.
if ! $LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr -o
$tmp_file 2>/dev/null; then
$LD $tmp_file.o -shared -Bsymbolic -z pack-relative-relocs -o
$tmp_file 2>&1 |
grep -q pack-relative-relocs && exit 1
fiSignature · 1 line
宋方睿