diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2023-05-19 15:11:51 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-01-09 06:45:38 -0800 |
commit | 9167304255940e29423517f63d11bdd968d7685e (patch) | |
tree | f704f8797b1f1158275014ee401bcd54e2be4d5e /ld | |
parent | 2e93abb858ae4ff2b8605b4a94988068869c0ff1 (diff) | |
download | binutils-9167304255940e29423517f63d11bdd968d7685e.zip binutils-9167304255940e29423517f63d11bdd968d7685e.tar.gz binutils-9167304255940e29423517f63d11bdd968d7685e.tar.bz2 |
elf: Add elf_backend_add_glibc_version_dependency
When -z mark-plt is used to add DT_X86_64_PLT, DT_X86_64_PLTSZ and
DT_X86_64_PLTENT, the r_addend field of the R_X86_64_JUMP_SLOT relocation
stores the offset of the indirect branch instruction. However, glibc
versions which don't have this commit in glibc 2.36:
commit f8587a61892cbafd98ce599131bf4f103466f084
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri May 20 19:21:48 2022 -0700
x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
According to x86-64 psABI, r_addend should be ignored for R_X86_64_GLOB_DAT
and R_X86_64_JUMP_SLOT. Since linkers always set their r_addends to 0, we
can ignore their r_addends.
Reviewed-by: Fangrui Song <maskray@google.com>
won't ignore the r_addend value in the R_X86_64_JUMP_SLOT relocation.
Although this commit has been backported to glibc 2.33/2.34/2.35 release
branches, it is safer to require glibc 2.36 for such binaries.
Extend the glibc version dependency of GLIBC_ABI_DT_RELR for DT_RELR to
also add GLIBC_2.36 version dependency for -z mark-plt on the shared C
library if it provides a GLIBC_2.XX symbol version.
* elflink.c (elf_find_verdep_info): Moved to ...
* elf-bfd.h (elf_find_verdep_info): Here.
(elf_backend_data): Add elf_backend_add_glibc_version_dependency.
(_bfd_elf_link_add_glibc_version_dependency): New function.
(_bfd_elf_link_add_dt_relr_dependency): Likewise.
* elf64-x86-64.c (elf_x86_64_add_glibc_version_dependency):
Likewise.
(elf_backend_add_glibc_version_dependency): New.
* elflink.c (elf_link_add_dt_relr_dependency): Renamed to ...
(elf_link_add_glibc_verneed): This. Modified to support other
glibc dependencies.
(_bfd_elf_link_add_glibc_version_dependency): Likewise.
(_bfd_elf_link_add_dt_relr_dependency): Likewise.
(bfd_elf_size_dynamic_sections): Call
elf_backend_add_glibc_version_dependency instead of
elf_link_add_dt_relr_dependency.
* elfxx-target.h (elf_backend_add_glibc_version_dependency): New.
(elfNN_bed): Add elf_backend_add_glibc_version_dependency.
ld/
* testsuite/ld-x86-64/mark-plt-1a.rd: New file.
* testsuite/ld-x86-64/mark-plt-1b.rd: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run -z mark-plt test for
GLIBC_2.36 dependency.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/testsuite/ld-x86-64/mark-plt-1a.rd | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/mark-plt-1b.rd | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/x86-64.exp | 14 |
3 files changed, 28 insertions, 0 deletions
diff --git a/ld/testsuite/ld-x86-64/mark-plt-1a.rd b/ld/testsuite/ld-x86-64/mark-plt-1a.rd new file mode 100644 index 0000000..1234fbe --- /dev/null +++ b/ld/testsuite/ld-x86-64/mark-plt-1a.rd @@ -0,0 +1,7 @@ +#... +Version needs section '.gnu.version_r' contains 1 entry: + Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\) + +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+ +#... + 0x[a-f0-9]+: Name: GLIBC_2.36 Flags: none Version: [0-9]+ +#pass diff --git a/ld/testsuite/ld-x86-64/mark-plt-1b.rd b/ld/testsuite/ld-x86-64/mark-plt-1b.rd new file mode 100644 index 0000000..6556a6d --- /dev/null +++ b/ld/testsuite/ld-x86-64/mark-plt-1b.rd @@ -0,0 +1,7 @@ +#... +Version needs section '.gnu.version_r' contains 1 entry: + Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\) + +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+ +#... + 0x[a-f0-9]+: Name: GLIBC_ABI_DT_RELR Flags: none Version: [0-9]+ +#pass diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 03266cb..a1a0422 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -2259,4 +2259,18 @@ run_dump_test "mark-plt-1b-x32" run_dump_test "mark-plt-1c-x32" run_dump_test "mark-plt-1d-x32" +if { [check_compiler_available] } { + run_cc_link_tests [list \ + [list \ + "Build mark-plt-1.so" \ + "-shared -Wl,-z,mark-plt,-z,pack-relative-relocs" \ + "-fPIC" \ + { mark-plt-1.s } \ + {{readelf {-W --version-info} mark-plt-1a.rd} \ + {readelf {-W --version-info} mark-plt-1b.rd}} \ + "mark-plt-1.so" \ + ] \ + ] +} + set ASFLAGS "$saved_ASFLAGS" |