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 /bfd/elf64-x86-64.c | |
parent | 2e93abb858ae4ff2b8605b4a94988068869c0ff1 (diff) | |
download | gdb-9167304255940e29423517f63d11bdd968d7685e.zip gdb-9167304255940e29423517f63d11bdd968d7685e.tar.gz gdb-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 'bfd/elf64-x86-64.c')
-rw-r--r-- | bfd/elf64-x86-64.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index f8905fb..f125375 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -5572,6 +5572,31 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info) return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table); } +static void +elf_x86_64_add_glibc_version_dependency + (struct elf_find_verdep_info *rinfo) +{ + unsigned int i = 0; + const char *version[3] = { NULL, NULL, NULL }; + struct elf_x86_link_hash_table *htab; + + if (rinfo->info->enable_dt_relr) + { + version[i] = "GLIBC_ABI_DT_RELR"; + i++; + } + + htab = elf_x86_hash_table (rinfo->info, X86_64_ELF_DATA); + if (htab != NULL && htab->params->mark_plt) + { + version[i] = "GLIBC_2.36"; + i++; + } + + if (i != 0) + _bfd_elf_link_add_glibc_version_dependency (rinfo, version); +} + static const struct bfd_elf_special_section elf_x86_64_special_sections[]= { @@ -5656,6 +5681,8 @@ elf_x86_64_special_sections[]= elf_x86_64_link_setup_gnu_properties #define elf_backend_hide_symbol \ _bfd_x86_elf_hide_symbol +#define elf_backend_add_glibc_version_dependency \ + elf_x86_64_add_glibc_version_dependency #undef elf64_bed #define elf64_bed elf64_x86_64_bed |