diff options
author | Joseph Myers <joseph@codesourcery.com> | 2023-05-11 10:07:00 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2023-05-11 10:08:50 +0200 |
commit | c49d51fa8134f6c7e6c7cf6e4e3007c4fea617c5 (patch) | |
tree | a8c22969127dd684e5f417daf7b0620dfb70163b /include | |
parent | 5e05361e2fef586b0e04ee81220ad0217401cc4d (diff) | |
download | gcc-c49d51fa8134f6c7e6c7cf6e4e3007c4fea617c5.zip gcc-c49d51fa8134f6c7e6c7cf6e4e3007c4fea617c5.tar.gz gcc-c49d51fa8134f6c7e6c7cf6e4e3007c4fea617c5.tar.bz2 |
Implement LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook [PR109128]
This is one part of the fix for PR109128, along with a corresponding
binutils's linker 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.
PR middle-end/109128
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.
lto-plugin/
* lto-plugin.c (register_claim_file_v2): New.
(claim_file_handler_v2): New.
(claim_file_handler): Wrap claim_file_handler_v2.
(onload): Handle LDPT_REGISTER_CLAIM_FILE_HOOK_V2.
Diffstat (limited to 'include')
-rw-r--r-- | include/plugin-api.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/plugin-api.h b/include/plugin-api.h index 379828b..395d5bc 100644 --- a/include/plugin-api.h +++ b/include/plugin-api.h @@ -260,6 +260,13 @@ enum ld_plugin_status (*ld_plugin_claim_file_handler) ( const struct ld_plugin_input_file *file, int *claimed); +/* The plugin library's "claim file" handler, version 2. */ + +typedef +enum ld_plugin_status +(*ld_plugin_claim_file_handler_v2) ( + const struct ld_plugin_input_file *file, int *claimed, int known_used); + /* The plugin library's "all symbols read" handler. */ typedef @@ -278,6 +285,13 @@ typedef enum ld_plugin_status (*ld_plugin_register_claim_file) (ld_plugin_claim_file_handler handler); +/* The linker's interface for registering the "claim file" handler, + version 2. */ + +typedef +enum ld_plugin_status +(*ld_plugin_register_claim_file_v2) (ld_plugin_claim_file_handler_v2 handler); + /* The linker's interface for registering the "all symbols read" handler. */ typedef @@ -553,6 +567,7 @@ enum ld_plugin_tag LDPT_GET_WRAP_SYMBOLS, LDPT_ADD_SYMBOLS_V2, LDPT_GET_API_VERSION, + LDPT_REGISTER_CLAIM_FILE_HOOK_V2 }; /* The plugin transfer vector. */ @@ -565,6 +580,7 @@ struct ld_plugin_tv int tv_val; const char *tv_string; ld_plugin_register_claim_file tv_register_claim_file; + ld_plugin_register_claim_file_v2 tv_register_claim_file_v2; ld_plugin_register_all_symbols_read tv_register_all_symbols_read; ld_plugin_register_cleanup tv_register_cleanup; ld_plugin_add_symbols tv_add_symbols; |