diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2024-07-09 01:30:19 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-07-09 01:37:35 -0700 |
commit | eb7892c4019bd5d00175c0eb80eb0c5a47a42ca1 (patch) | |
tree | 4b2c8a1afc827974d57319b37aadf0cf8747b478 /ld | |
parent | de9dfbb3859df7cfd0d3b70461459f521e2208e5 (diff) | |
download | gdb-eb7892c4019bd5d00175c0eb80eb0c5a47a42ca1.zip gdb-eb7892c4019bd5d00175c0eb80eb0c5a47a42ca1.tar.gz gdb-eb7892c4019bd5d00175c0eb80eb0c5a47a42ca1.tar.bz2 |
LTO: Properly check wrapper symbol
Add wrapper_symbol to bfd_link_hash_entry and set it to true for wrapper
symbol. Set wrap_status to wrapper if wrapper_symbol is true in LTO.
Note: Calling unwrap_hash_lookup to check for the wrapper symbol works
only when there is a definition for the wrapped symbol since references
to the wrapped symbol have been redirected to the wrapper symbol.
bfd/
PR ld/31956
* linker.c (bfd_wrapped_link_hash_lookup): Set wrapper_symbol
for wrapper symbol.
include/
PR ld/31956
* bfdlink.h (bfd_link_hash_entry): Add wrapper_symbol.
ld/
PR ld/31956
* plugin.c (get_symbols): Set wrap_status to wrapper if
wrapper_symbol is set.
* testsuite/ld-plugin/lto.exp: Run PR ld/31956 tests.
* testsuite/ld-plugin/pr31956a.c: New file.
* testsuite/ld-plugin/pr31956b.c: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'ld')
-rw-r--r-- | ld/plugin.c | 11 | ||||
-rw-r--r-- | ld/testsuite/ld-plugin/lto.exp | 16 | ||||
-rw-r--r-- | ld/testsuite/ld-plugin/pr31956a.c | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-plugin/pr31956b.c | 23 |
4 files changed, 45 insertions, 8 deletions
diff --git a/ld/plugin.c b/ld/plugin.c index 8107841..03ee988 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -777,14 +777,9 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms, if (syms[n].def != LDPK_UNDEF && syms[n].def != LDPK_WEAKUNDEF) { blhe = h; - if (blhe && link_info.wrap_hash != NULL) - { - /* Check if a symbol is a wrapper symbol. */ - struct bfd_link_hash_entry *unwrap - = unwrap_hash_lookup (&link_info, (bfd *) abfd, blhe); - if (unwrap && unwrap != h) - wrap_status = wrapper; - } + /* Check if a symbol is a wrapper symbol. */ + if (blhe && blhe->wrapper_symbol) + wrap_status = wrapper; } else { diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index 7b4b349..9476caf 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -531,6 +531,22 @@ set lto_link_elf_tests [list \ "pr29086" \ ] \ [list \ + "PR ld/31956 (a)" \ + "-Wl,--wrap=parse_line" \ + "-O2 -flto" \ + {pr31956a.c pr31956b.c} \ + {} \ + "pr31956a" \ + ] \ + [list \ + "PR ld/31956 (b)" \ + "-Wl,--wrap=parse_line" \ + "-O2 -flto" \ + {pr31956b.c pr31956a.c} \ + {} \ + "pr31956b" \ + ] \ + [list \ "Build pr30281.so" \ "-shared -Wl,--version-script,pr30281.t \ -O2 -fPIC -flto-partition=max -flto=2" \ diff --git a/ld/testsuite/ld-plugin/pr31956a.c b/ld/testsuite/ld-plugin/pr31956a.c new file mode 100644 index 0000000..48df8c5 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31956a.c @@ -0,0 +1,3 @@ +extern void parse_line(void); +void _cmocka_run_group_tests(void *) {} +void argv_parse_cmd(void) { parse_line(); } diff --git a/ld/testsuite/ld-plugin/pr31956b.c b/ld/testsuite/ld-plugin/pr31956b.c new file mode 100644 index 0000000..1b06931 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr31956b.c @@ -0,0 +1,23 @@ +struct CMUnitTest { + void *test_func; +}; + +extern void _cmocka_run_group_tests(void *); + +extern void argv_parse_cmd(void); +void __wrap_parse_line(void) {}; + +void foo (void) { + argv_parse_cmd(); +} + +struct CMUnitTest main_tests = { + foo +}; + +int +main (void) +{ + _cmocka_run_group_tests (&main_tests); + return 0; +} |