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.
There is no indication of obsolescence for --pack-dyn-relocs=relr.
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.
GNU ld and newer versions of LLD report warnings (instead of errors) for
unknown -z options. Only errors lead to non-zero exit codes. Therefore,
we should test --pack-dyn-relocs=relr before testing
-z pack-relative-relocs.
Link: https://github.com/ClangBuiltLinux/linux/issues/1057
Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=a619b58721f0a03fd91c27670d3e4c2fb0d88f1e
Signed-off-by: Fangrui Song <[email protected]>
Reviewed-by: Nick Desaulniers <[email protected]>
---
Makefile | 3 ++-
scripts/tools-support-relr.sh | 8 ++++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 5aeea3d98fc0..d9c6d1839cf0 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/scripts/tools-support-relr.sh b/scripts/tools-support-relr.sh
index cb55878bd5b8..4c121946e517 100755
--- a/scripts/tools-support-relr.sh
+++ b/scripts/tools-support-relr.sh
@@ -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.577.gac1e443424-goog
On Tue, Apr 11, 2023 at 08:09:44PM +0000, Fangrui Song wrote:
> 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.
> There is no indication of obsolescence for --pack-dyn-relocs=relr.
>
> 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.
>
> GNU ld and newer versions of LLD report warnings (instead of errors) for
> unknown -z options. Only errors lead to non-zero exit codes. Therefore,
> we should test --pack-dyn-relocs=relr before testing
> -z pack-relative-relocs.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1057
> Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=a619b58721f0a03fd91c27670d3e4c2fb0d88f1e
> Signed-off-by: Fangrui Song <[email protected]>
> Reviewed-by: Nick Desaulniers <[email protected]>
> ---
> Makefile | 3 ++-
> scripts/tools-support-relr.sh | 8 ++++++--
> 2 files changed, 8 insertions(+), 3 deletions(-)
Acked-by: Will Deacon <[email protected]>
Masahiro -- are you happy to pick this one up? If not, I can take it via
arm64 (as the only arch currently using this reloc format).
Cheers,
Will
On Thu, Apr 13, 2023 at 11:55 PM Will Deacon <[email protected]> wrote:
>
> On Tue, Apr 11, 2023 at 08:09:44PM +0000, Fangrui Song wrote:
> > 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.
> > There is no indication of obsolescence for --pack-dyn-relocs=relr.
> >
> > 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.
> >
> > GNU ld and newer versions of LLD report warnings (instead of errors) for
> > unknown -z options. Only errors lead to non-zero exit codes. Therefore,
> > we should test --pack-dyn-relocs=relr before testing
> > -z pack-relative-relocs.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1057
> > Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=a619b58721f0a03fd91c27670d3e4c2fb0d88f1e
> > Signed-off-by: Fangrui Song <[email protected]>
> > Reviewed-by: Nick Desaulniers <[email protected]>
> > ---
> > Makefile | 3 ++-
> > scripts/tools-support-relr.sh | 8 ++++++--
> > 2 files changed, 8 insertions(+), 3 deletions(-)
>
> Acked-by: Will Deacon <[email protected]>
>
> Masahiro -- are you happy to pick this one up?
Sure. Applied to linux-kbuild.
(I will push it next week.)
> If not, I can take it via
> arm64 (as the only arch currently using this reloc format).
>
> Cheers,
>
> Will
--
Best Regards
Masahiro Yamada