Makefile: use -z pack-relative-relocs
PATCH v2 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, try -z pack-relative-relocs, which is supported since LLD 15. Keep supporting --pack-dyn-relocs=relr as well for older LLD versions.
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 | 3 ++- scripts/tools-support-relr.sh | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
---
Changes from v1:
* Keep supporting --pack-dyn-relocs=relr for older ld.lld versions
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 +6 -2
@@ -7,8 +7,12 @@ 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. +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 +fi # 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 19 lines · Fangrui Song
Commit
27f2a4db76e8("Makefile: fix GDB warning withCONFIG_RELR") added --use-android-relr-tags to fix a GDB warningBFD: /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, try -z pack-relative-relocs, which is supported since LLD 15. Keep supporting --pack-dyn-relocs=relr as well for older LLD versions.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.
Quoted 3 lines
Thanks v2 looks better. IIUC, this will first try to test+use --pack-dyn-relocs=relr in preference to -z pack-relative-relocs. Do we want to reorder the preference, for both the test and actual flag used?
Quoted 44 lines
--- Makefile | 3 ++- scripts/tools-support-relr.sh | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)---
Changes from v1:
* Keep supporting --pack-dyn-relocs=relr for older ld.lld versionsMakefile +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 thescripts/tools-support-relr.sh +6
-3@@ -7,8 +7,12 @@ 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. +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 +fi # 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 21 lines · Nick Desaulniers
Quoted 19 lines · Fangrui Song
Commit
27f2a4db76e8("Makefile: fix GDB warning withCONFIG_RELR") added --use-android-relr-tags to fix a GDB warningBFD: /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, try -z pack-relative-relocs, which is supported since LLD 15. Keep supporting --pack-dyn-relocs=relr as well for older LLD versions.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.
Quoted 8 lines
Quoted 3 lines
Thanks v2 looks better. IIUC, this will first try to test+use
--pack-dyn-relocs=relrin preference to-z pack-relative-relocs. Do we want to reorder the preference, for both the test and actual flag used?
Thanks for the comment. The order is deliberate and there is no obsolescence indication of --pack-dyn-relocs=relr.
GNU ld and newer lld report warnings (instead of errors) for unknown -z options, and only errors lead to non-zero exit codes.
Therefore, $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs) has to place --pack-dyn-relocs=relr first. scripts/tools-support-relr.sh has to test --pack-dyn-relocs=relr first as well.
Quoted 49 lines
Quoted 42 lines
--- Makefile | 3 ++- scripts/tools-support-relr.sh | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)---
Changes from v1:
* Keep supporting --pack-dyn-relocs=relr for older ld.lld versionsMakefile +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 thescripts/tools-support-relr.sh +6
-3@@ -7,8 +7,12 @@ 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. +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 +fi # 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. --Quoted 2 lines
2.40.0.348.gf938b09366-goog
--
Thanks,
~Nick Desaulniers
Signature · 1 line
宋方睿
Nick Desaulniers
Reviewed-byQuoted 33 lines · Fangrui Song
Quoted 21 lines · Nick Desaulniers
Quoted 19 lines · Fangrui Song
Commit
27f2a4db76e8("Makefile: fix GDB warning withCONFIG_RELR") added --use-android-relr-tags to fix a GDB warningBFD: /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, try -z pack-relative-relocs, which is supported since LLD 15. Keep supporting --pack-dyn-relocs=relr as well for older LLD versions.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.Quoted 8 lines
Quoted 3 lines
Thanks v2 looks better. IIUC, this will first try to test+use
--pack-dyn-relocs=relrin preference to-z pack-relative-relocs. Do we want to reorder the preference, for both the test and actual flag used?
Quoted 5 lines
Thanks for the comment. The order is deliberate and there is no obsolescence indication of --pack-dyn-relocs=relr.
GNU ld and newer lld report warnings (instead of errors) for unknown -z options, and only errors lead to non-zero exit codes.
That makes sense; consider adding a note about that intention to the commit message in a v3 along with:
Quoted 59 lines
Therefore, $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs) has to place --pack-dyn-relocs=relr first.
scripts/tools-support-relr.shhas to test --pack-dyn-relocs=relr first as well.Quoted 39 lines
Quoted 39 lines
--- Makefile | 3 ++- scripts/tools-support-relr.sh | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)---
Changes from v1:
* Keep supporting --pack-dyn-relocs=relr for older ld.lld versionsMakefile +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 thescripts/tools-support-relr.sh +6
-2@@ -7,8 +7,12 @@ 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. +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 +fiQuoted 10 lines
Quoted 5 lines
scripts/tools-support-relr.sh +0
-1# 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
--
Thanks,
~Nick Desaulniers--
宋方睿
Signature · 2 lines
Thanks, ~Nick Desaulniers