diff options
Diffstat (limited to 'lto-plugin/lto-plugin.c')
-rw-r--r-- | lto-plugin/lto-plugin.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c index 33d49571d0e..1192ea8e6da 100644 --- a/lto-plugin/lto-plugin.c +++ b/lto-plugin/lto-plugin.c @@ -158,6 +158,7 @@ enum symbol_style static char *arguments_file_name; static ld_plugin_register_claim_file register_claim_file; +static ld_plugin_register_claim_file_v2 register_claim_file_v2; static ld_plugin_register_all_symbols_read register_all_symbols_read; static ld_plugin_get_symbols get_symbols, get_symbols_v2; static ld_plugin_register_cleanup register_cleanup; @@ -1147,10 +1148,15 @@ process_offload_section (void *data, const char *name, off_t offset, off_t len) } /* Callback used by a linker to check if the plugin will claim FILE. Writes - the result in CLAIMED. */ + the result in CLAIMED. If KNOWN_USED, the object is known by the linker + to be used, or an older API version is in use that does not provide that + information; otherwise, the linker is only determining whether this is + a plugin object and it should not be registered as having offload data if + not claimed by the plugin. */ static enum ld_plugin_status -claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) +claim_file_handler_v2 (const struct ld_plugin_input_file *file, int *claimed, + int known_used) { enum ld_plugin_status status; struct plugin_objfile obj; @@ -1260,7 +1266,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) if (*claimed && obj.offload == 0 && offload_files_last_lto == NULL) offload_files_last_lto = offload_files_last; - if (obj.offload == 1) + if (obj.offload && (known_used || obj.found > 0)) { /* Add file to the list. The order must be exactly the same as the final order after recompilation and linking, otherwise host and target tables @@ -1321,6 +1327,15 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) return LDPS_OK; } +/* Callback used by a linker to check if the plugin will claim FILE. Writes + the result in CLAIMED. */ + +static enum ld_plugin_status +claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) +{ + return claim_file_handler_v2 (file, claimed, true); +} + /* Parse the plugin options. */ static void @@ -1400,6 +1415,9 @@ onload (struct ld_plugin_tv *tv) case LDPT_REGISTER_CLAIM_FILE_HOOK: register_claim_file = p->tv_u.tv_register_claim_file; break; + case LDPT_REGISTER_CLAIM_FILE_HOOK_V2: + register_claim_file_v2 = p->tv_u.tv_register_claim_file_v2; + break; case LDPT_ADD_SYMBOLS_V2: add_symbols_v2 = p->tv_u.tv_add_symbols; break; @@ -1450,6 +1468,13 @@ onload (struct ld_plugin_tv *tv) check (status == LDPS_OK, LDPL_FATAL, "could not register the claim_file callback"); + if (register_claim_file_v2) + { + status = register_claim_file_v2 (claim_file_handler_v2); + check (status == LDPS_OK, LDPL_FATAL, + "could not register the claim_file_v2 callback"); + } + if (register_cleanup) { status = register_cleanup (cleanup_handler); |