From b21318bd2c29fcca8f99c1de7facdaa5cb2e66e2 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 11 May 2023 14:31:09 +0000 Subject: Add LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook [GCC PR109128] This is one part of the fix for GCC PR109128, along with a corresponding GCC change. Without this patch, what happens in the linker, when an unused object in a .a file has offload data, is that elf_link_is_defined_archive_symbol calls bfd_link_plugin_object_p, which ends up calling the plugin's claim_file_handler, which then records the object as one with offload data. That is, the linker never decides to use the object in the first place, but use of this _p interface (called as part of trying to decide whether to use the object) results in the plugin deciding to use its offload data (and a consequent mismatch in the offload data present at runtime). The new hook allows the linker plugin to distinguish calls to claim_file_handler that know the object is being used by the linker (from ldmain.c:add_archive_element), from calls that don't know it's being used by the linker (from elf_link_is_defined_archive_symbol); in the latter case, the plugin should avoid recording the object as one with offload data. bfd/ * plugin.c (struct plugin_list_entry): Add claim_file_v2. (register_claim_file_v2): New. (try_load_plugin): Use LDPT_REGISTER_CLAIM_FILE_HOOK_V2. (ld_plugin_object_p): Take second argument. (bfd_link_plugin_object_p): Update call to ld_plugin_object_p. (register_ld_plugin_object_p): Update argument prototype. (bfd_plugin_object_p): Update call to ld_plugin_object_p. * plugin.h (register_ld_plugin_object_p): Update argument prototype. include/ * plugin.api.h (ld_plugin_claim_file_handler_v2) (ld_plugin_register_claim_file_v2) (LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New. (struct ld_plugin_tv): Add tv_register_claim_file_v2. ld/ * plugin.c (struct plugin): Add claim_file_handler_v2. (LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New. (plugin_object_p): Add second argument. Update call to plugin_call_claim_file. (register_claim_file_v2): New. (set_tv_header): Handle LDPT_REGISTER_CLAIM_FILE_HOOK_V2. (plugin_call_claim_file): Add argument known_used. (plugin_maybe_claim): Update call to plugin_object_p. * testplug.c, testplug2.c, testplug3.c, testplug4.c: Handle LDPT_REGISTER_CLAIM_FILE_HOOK_V2. * testsuite/ld-plugin/plugin-1.d, testsuite/ld-plugin/plugin-10.d, testsuite/ld-plugin/plugin-11.d, testsuite/ld-plugin/plugin-13.d, testsuite/ld-plugin/plugin-14.d, testsuite/ld-plugin/plugin-15.d, testsuite/ld-plugin/plugin-16.d, testsuite/ld-plugin/plugin-17.d, testsuite/ld-plugin/plugin-18.d, testsuite/ld-plugin/plugin-19.d, testsuite/ld-plugin/plugin-2.d, testsuite/ld-plugin/plugin-26.d, testsuite/ld-plugin/plugin-3.d, testsuite/ld-plugin/plugin-30.d, testsuite/ld-plugin/plugin-4.d, testsuite/ld-plugin/plugin-5.d, testsuite/ld-plugin/plugin-6.d, testsuite/ld-plugin/plugin-7.d, testsuite/ld-plugin/plugin-8.d, testsuite/ld-plugin/plugin-9.d: Update test expectations. --- ld/testplug.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ld/testplug.c') diff --git a/ld/testplug.c b/ld/testplug.c index 796d67f..4b1bb8e 100644 --- a/ld/testplug.c +++ b/ld/testplug.c @@ -82,6 +82,7 @@ static const tag_name_t tag_names[] = ADDENTRY(LDPT_LINKER_OUTPUT), ADDENTRY(LDPT_OPTION), ADDENTRY(LDPT_REGISTER_CLAIM_FILE_HOOK), + ADDENTRY(LDPT_REGISTER_CLAIM_FILE_HOOK_V2), ADDENTRY(LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK), ADDENTRY(LDPT_REGISTER_CLEANUP_HOOK), ADDENTRY(LDPT_ADD_SYMBOLS), @@ -100,6 +101,7 @@ static const tag_name_t tag_names[] = /* Function pointers to cache hooks passed at onload time. */ static ld_plugin_register_claim_file tv_register_claim_file = 0; +static ld_plugin_register_claim_file_v2 tv_register_claim_file_v2 = 0; static ld_plugin_register_all_symbols_read tv_register_all_symbols_read = 0; static ld_plugin_register_cleanup tv_register_cleanup = 0; static ld_plugin_add_symbols tv_add_symbols = 0; @@ -389,6 +391,7 @@ dump_tv_tag (size_t n, struct ld_plugin_tv *tv) tv->tv_u.tv_string); break; case LDPT_REGISTER_CLAIM_FILE_HOOK: + case LDPT_REGISTER_CLAIM_FILE_HOOK_V2: case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK: case LDPT_REGISTER_CLEANUP_HOOK: case LDPT_ADD_SYMBOLS: @@ -440,6 +443,9 @@ parse_tv_tag (struct ld_plugin_tv *tv) case LDPT_REGISTER_CLAIM_FILE_HOOK: SETVAR(tv_register_claim_file); break; + case LDPT_REGISTER_CLAIM_FILE_HOOK_V2: + SETVAR(tv_register_claim_file_v2); + break; case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK: SETVAR(tv_register_all_symbols_read); break; -- cgit v1.1