diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2022-02-02 14:40:03 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2022-03-09 18:23:43 -0800 |
commit | 320fdefef139160c93089a19ba41a2fcc4121203 (patch) | |
tree | d845e8df9ccc432cfb3d06d97cb6d2082a78da93 /bfd | |
parent | 399f9ba236fa8026ca8115cb030ee87a1408ce8b (diff) | |
download | gdb-320fdefef139160c93089a19ba41a2fcc4121203.zip gdb-320fdefef139160c93089a19ba41a2fcc4121203.tar.gz gdb-320fdefef139160c93089a19ba41a2fcc4121203.tar.bz2 |
ld: Add a before_plugin_all_symbols_read hook
Add a before_plugin_all_symbols_read hook to load symbol references from
DT_NEEDED entries, included from --copy-dt-needed-entries, before reading
plugin symbols to properly resolve plugin symbol references.
bfd/
PR ld/28849
* elf-bfd.h (elf_link_hash_table): Add handling_dt_needed.
* elflink.c (_bfd_elf_merge_symbol): Don't set non_ir_ref_dynamic
before plugin 'all symbols read' hook is called.
ld/
PR ld/28849
* ldelf.c (ldelf_handle_dt_needed): New function.
(ldelf_before_plugin_all_symbols_read): Likewise.
(ldelf_after_open): Call ldelf_handle_dt_needed.
* ldelf.h (ldelf_before_plugin_all_symbols_read): New.
* ldemul.c (ldemul_before_plugin_all_symbols_read): Likewise.
* ldemul.h (ldemul_before_plugin_all_symbols_read): Likewise.
(ld_emulation_xfer_struct): Add before_plugin_all_symbols_read.
* ldlang.c (lang_process): Call
ldemul_before_plugin_all_symbols_read before calling
plugin_call_all_symbols_read.
* emultempl/elf.em
(gld${EMULATION_NAME}_before_plugin_all_symbols_read): New.
(LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): New.
* emultempl/emulation.em (ld_${EMULATION_NAME}_emulation):
Initialize the before_plugin_all_symbols_read field.
* testsuite/ld-plugin/lto.exp: Run PR ld/28849 tests.
* testsuite/ld-plugin/pr28849.d: New file.
* testsuite/ld-plugin/pr28849a.c: Likewise.
* testsuite/ld-plugin/pr28849b.c: Likewise.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/elf-bfd.h | 3 | ||||
-rw-r--r-- | bfd/elflink.c | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 889a474..4904e1e 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -599,6 +599,9 @@ struct elf_link_hash_table /* TRUE if DT_JMPREL is a required dynamic tag. */ bool dt_jmprel_required; + /* TRUE when we are handling DT_NEEDED entries. */ + bool handling_dt_needed; + /* The BFD used to hold special sections created by the linker. This will be the first BFD found which requires these sections to be created. */ diff --git a/bfd/elflink.c b/bfd/elflink.c index f852142..5a070a2 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -1090,6 +1090,7 @@ _bfd_elf_merge_symbol (bfd *abfd, const struct elf_backend_data *bed; char *new_version; bool default_sym = *matched; + struct elf_link_hash_table *htab; *skip = false; *override = NULL; @@ -1220,6 +1221,8 @@ _bfd_elf_merge_symbol (bfd *abfd, symbols. */ bfd_elf_link_mark_dynamic_symbol (info, h, sym); + htab = elf_hash_table (info); + /* NEWDYN and OLDDYN indicate whether the new or old symbol, respectively, is from a dynamic object. */ @@ -1283,7 +1286,9 @@ _bfd_elf_merge_symbol (bfd *abfd, olddyn = (oldsec->symbol->flags & BSF_DYNAMIC) != 0; } - if (oldbfd != NULL + /* Set non_ir_ref_dynamic only when not handling DT_NEEDED entries. */ + if (!htab->handling_dt_needed + && oldbfd != NULL && (oldbfd->flags & BFD_PLUGIN) != (abfd->flags & BFD_PLUGIN)) { if (newdyn != olddyn) |