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/elf-bfd.h | |
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/elf-bfd.h')
-rw-r--r-- | bfd/elf-bfd.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index a611349..3ed22fa 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -957,6 +957,19 @@ typedef struct elf_property_list struct elf_property property; } elf_property_list; +/* This structure is used to pass information to + elf_backend_add_glibc_version_dependency. */ + +struct elf_find_verdep_info +{ + /* General link information. */ + struct bfd_link_info *info; + /* The number of dependencies. */ + unsigned int vers; + /* Whether we had a failure. */ + bool failed; +}; + struct bfd_elf_section_reloc_data; struct elf_backend_data @@ -1488,6 +1501,10 @@ struct elf_backend_data bool (*elf_backend_write_section) (bfd *, struct bfd_link_info *, asection *, bfd_byte *); + /* This function adds glibc version dependency. */ + void (*elf_backend_add_glibc_version_dependency) + (struct elf_find_verdep_info *); + /* This function, if defined, returns TRUE if it is section symbols only that are considered local for the purpose of partitioning the symbol table into local and global symbols. This should be NULL @@ -2583,6 +2600,12 @@ extern bool _bfd_elf_link_output_relocs (bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *, struct elf_link_hash_entry **); +extern void _bfd_elf_link_add_glibc_version_dependency + (struct elf_find_verdep_info *, const char *[]); + +extern void _bfd_elf_link_add_dt_relr_dependency + (struct elf_find_verdep_info *); + extern bool _bfd_elf_adjust_dynamic_copy (struct bfd_link_info *, struct elf_link_hash_entry *, asection *); |