1 /* Plugin control for the GNU linker.
2 Copyright 2010 Free Software Foundation, Inc.
4 This file is part of the GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 #include "libiberty.h"
33 #include "plugin-api.h"
35 #if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
39 /* The suffix to append to the name of the real (claimed) object file
40 when generating a dummy BFD to hold the IR symbols sent from the
42 #define IRONLY_SUFFIX ".ironly\004"
44 /* This is sizeof an array of chars, not sizeof a const char *. We
45 also have to avoid inadvertently counting the trailing NUL. */
46 #define IRONLY_SUFFIX_LEN (sizeof (IRONLY_SUFFIX) - 1)
48 /* Stores a single argument passed to a plugin. */
49 typedef struct plugin_arg
51 struct plugin_arg *next;
55 /* Holds all details of a single plugin. */
58 /* Next on the list of plugins, or NULL at end of chain. */
60 /* The argument string given to --plugin. */
62 /* The shared library handle returned by dlopen. */
64 /* The list of argument string given to --plugin-opt. */
66 /* Number of args in the list, for convenience. */
68 /* The plugin's event handlers. */
69 ld_plugin_claim_file_handler claim_file_handler;
70 ld_plugin_all_symbols_read_handler all_symbols_read_handler;
71 ld_plugin_cleanup_handler cleanup_handler;
72 /* TRUE if the cleanup handlers have been called. */
73 bfd_boolean cleanup_done;
76 /* The master list of all plugins. */
77 static plugin_t *plugins_list = NULL;
79 /* We keep a tail pointer for easy linking on the end. */
80 static plugin_t **plugins_tail_chain_ptr = &plugins_list;
82 /* The last plugin added to the list, for receiving args. */
83 static plugin_t *last_plugin = NULL;
85 /* The tail of the arg chain of the last plugin added to the list. */
86 static plugin_arg_t **last_plugin_args_tail_chain_ptr = NULL;
88 /* The plugin which is currently having a callback executed. */
89 static plugin_t *called_plugin = NULL;
91 /* Last plugin to cause an error, if any. */
92 static const char *error_plugin = NULL;
94 /* A hash table that records symbols referenced by non-IR files. Used
95 at get_symbols time to determine whether any prevailing defs from
96 IR files are referenced only from other IR files, so tthat we can
97 we can distinguish the LDPR_PREVAILING_DEF and LDPR_PREVAILING_DEF_IRONLY
98 cases when establishing symbol resolutions. */
99 static struct bfd_hash_table *non_ironly_hash = NULL;
101 /* Set at all symbols read time, to avoid recursively offering the plugin
102 its own newly-added input files and libs to claim. */
103 static bfd_boolean no_more_claiming = FALSE;
105 /* If the --allow-multiple-definition command-line option is active, we
106 have to disable it so that BFD always calls our hook, and simulate the
107 effect (when not resolving IR vs. real symbols) ourselves by ensuring
108 TRUE is returned from the hook. */
109 static bfd_boolean plugin_cached_allow_multiple_defs = FALSE;
111 /* List of tags to set in the constant leading part of the tv array. */
112 static const enum ld_plugin_tag tv_header_tags[] =
119 LDPT_REGISTER_CLAIM_FILE_HOOK,
120 LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK,
121 LDPT_REGISTER_CLEANUP_HOOK,
124 LDPT_RELEASE_INPUT_FILE,
127 LDPT_ADD_INPUT_LIBRARY,
128 LDPT_SET_EXTRA_LIBRARY_PATH
131 /* How many entries in the constant leading part of the tv array. */
132 static const size_t tv_header_size = ARRAY_SIZE (tv_header_tags);
134 #if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
136 #define RTLD_NOW 0 /* Dummy value. */
139 dlopen (const char *file, int mode ATTRIBUTE_UNUSED)
141 return LoadLibrary (file);
145 dlsym (void *handle, const char *name)
147 return GetProcAddress (handle, name);
151 dlclose (void *handle)
153 FreeLibrary (handle);
157 #endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H) */
159 /* Helper function for exiting with error status. */
161 set_plugin_error (const char *plugin)
163 error_plugin = plugin;
167 /* Test if an error occurred. */
169 plugin_error_p (void)
171 return error_plugin != NULL;
174 /* Return name of plugin which caused an error if any. */
176 plugin_error_plugin (void)
178 return error_plugin ? error_plugin : _("<no plugin>");
181 /* Handle -plugin arg: find and load plugin, or return error. */
183 plugin_opt_plugin (const char *plugin)
187 newplug = xmalloc (sizeof *newplug);
188 memset (newplug, 0, sizeof *newplug);
189 newplug->name = plugin;
190 newplug->dlhandle = dlopen (plugin, RTLD_NOW);
191 if (!newplug->dlhandle)
192 return set_plugin_error (plugin);
194 /* Chain on end, so when we run list it is in command-line order. */
195 *plugins_tail_chain_ptr = newplug;
196 plugins_tail_chain_ptr = &newplug->next;
198 /* Record it as current plugin for receiving args. */
199 last_plugin = newplug;
200 last_plugin_args_tail_chain_ptr = &newplug->args;
204 /* Accumulate option arguments for last-loaded plugin, or return
207 plugin_opt_plugin_arg (const char *arg)
209 plugin_arg_t *newarg;
212 return set_plugin_error (_("<no plugin>"));
214 newarg = xmalloc (sizeof *newarg);
218 /* Chain on end to preserve command-line order. */
219 *last_plugin_args_tail_chain_ptr = newarg;
220 last_plugin_args_tail_chain_ptr = &newarg->next;
221 last_plugin->n_args++;
225 /* Create a dummy BFD. */
227 plugin_get_ir_dummy_bfd (const char *name, bfd *srctemplate)
232 bfd_use_reserved_id = 1;
233 abfd = bfd_create (concat (name, IRONLY_SUFFIX, (const char *)NULL),
235 bfd_set_arch_info (abfd, bfd_get_arch_info (srctemplate));
236 bfd_make_writable (abfd);
237 /* Create a minimal set of sections to own the symbols. */
238 sec = bfd_make_section_old_way (abfd, ".text");
239 bfd_set_section_flags (abfd, sec,
240 (SEC_CODE | SEC_HAS_CONTENTS | SEC_READONLY
241 | SEC_ALLOC | SEC_LOAD | SEC_KEEP));
242 sec->output_section = sec;
243 sec->output_offset = 0;
247 /* Check if the BFD passed in is an IR dummy object file. */
249 is_ir_dummy_bfd (const bfd *abfd)
255 namlen = strlen (abfd->filename);
256 if (namlen < IRONLY_SUFFIX_LEN)
258 return !strcmp (abfd->filename + namlen - IRONLY_SUFFIX_LEN, IRONLY_SUFFIX);
261 /* Helpers to convert between BFD and GOLD symbol formats. */
262 static enum ld_plugin_status
263 asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
264 const struct ld_plugin_symbol *ldsym)
266 flagword flags = BSF_NO_FLAGS;
267 struct bfd_section *section;
269 asym->the_bfd = abfd;
270 asym->name = (ldsym->version
271 ? concat (ldsym->name, "@", ldsym->version, NULL)
281 section = bfd_get_section_by_name (abfd, ".text");
288 section = bfd_und_section_ptr;
293 section = bfd_com_section_ptr;
294 asym->value = ldsym->size;
295 /* For ELF targets, set alignment of common symbol to 1. */
296 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
297 ((elf_symbol_type *) asym)->internal_elf_sym.st_value = 1;
304 asym->section = section;
306 /* Visibility only applies on ELF targets. */
307 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
309 elf_symbol_type *elfsym = elf_symbol_from (abfd, asym);
311 einfo (_("%P%F: %s: non-ELF symbol in ELF BFD!"), asym->name);
312 elfsym->internal_elf_sym.st_other &= ~3;
313 elfsym->internal_elf_sym.st_other |= ldsym->visibility;
319 /* Register a claim-file handler. */
320 static enum ld_plugin_status
321 register_claim_file (ld_plugin_claim_file_handler handler)
323 ASSERT (called_plugin);
324 called_plugin->claim_file_handler = handler;
328 /* Register an all-symbols-read handler. */
329 static enum ld_plugin_status
330 register_all_symbols_read (ld_plugin_all_symbols_read_handler handler)
332 ASSERT (called_plugin);
333 called_plugin->all_symbols_read_handler = handler;
337 /* Register a cleanup handler. */
338 static enum ld_plugin_status
339 register_cleanup (ld_plugin_cleanup_handler handler)
341 ASSERT (called_plugin);
342 called_plugin->cleanup_handler = handler;
346 /* Add symbols from a plugin-claimed input file. */
347 static enum ld_plugin_status
348 add_symbols (void *handle, int nsyms, const struct ld_plugin_symbol *syms)
353 ASSERT (called_plugin);
354 symptrs = xmalloc (nsyms * sizeof *symptrs);
355 for (n = 0; n < nsyms; n++)
357 enum ld_plugin_status rv;
358 asymbol *bfdsym = bfd_make_empty_symbol (abfd);
360 rv = asymbol_from_plugin_symbol (abfd, bfdsym, syms + n);
364 bfd_set_symtab (abfd, symptrs, nsyms);
368 /* Get the input file information with an open (possibly re-opened)
370 static enum ld_plugin_status
371 get_input_file (const void *handle, struct ld_plugin_input_file *file)
373 ASSERT (called_plugin);
379 /* Release the input file. */
380 static enum ld_plugin_status
381 release_input_file (const void *handle)
383 ASSERT (called_plugin);
388 /* Return TRUE if a defined symbol might be reachable from outside the
389 universe of claimed objects. */
390 static inline bfd_boolean
391 is_visible_from_outside (struct ld_plugin_symbol *lsym, asection *section,
392 struct bfd_link_hash_entry *blhe)
394 /* Section's owner may be NULL if it is the absolute
395 section, fortunately is_ir_dummy_bfd handles that. */
396 if (!is_ir_dummy_bfd (section->owner))
398 if (link_info.relocatable)
400 if (link_info.export_dynamic || link_info.shared)
402 /* Only ELF symbols really have visibility. */
403 if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour)
405 struct elf_link_hash_entry *el = (struct elf_link_hash_entry *)blhe;
406 int vis = ELF_ST_VISIBILITY (el->other);
407 return vis == STV_DEFAULT || vis == STV_PROTECTED;
409 /* On non-ELF targets, we can safely make inferences by considering
410 what visibility the plugin would have liked to apply when it first
411 sent us the symbol. During ELF symbol processing, visibility only
412 ever becomes more restrictive, not less, when symbols are merged,
413 so this is a conservative estimate; it may give false positives,
414 declaring something visible from outside when it in fact would
415 not have been, but this will only lead to missed optimisation
416 opportunities during LTRANS at worst; it will not give false
417 negatives, which can lead to the disastrous conclusion that the
418 related symbol is IRONLY. (See GCC PR46319 for an example.) */
419 return lsym->visibility == LDPV_DEFAULT
420 || lsym->visibility == LDPV_PROTECTED;
425 /* Get the symbol resolution info for a plugin-claimed input file. */
426 static enum ld_plugin_status
427 get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms)
429 const bfd *abfd = handle;
431 ASSERT (called_plugin);
432 for (n = 0; n < nsyms; n++)
434 struct bfd_link_hash_entry *blhe;
438 blhe = bfd_link_hash_lookup (link_info.hash, syms[n].name,
442 syms[n].resolution = LDPR_UNKNOWN;
446 /* Determine resolution from blhe type and symbol's original type. */
447 if (blhe->type == bfd_link_hash_undefined
448 || blhe->type == bfd_link_hash_undefweak)
450 syms[n].resolution = LDPR_UNDEF;
453 if (blhe->type != bfd_link_hash_defined
454 && blhe->type != bfd_link_hash_defweak
455 && blhe->type != bfd_link_hash_common)
457 /* We should not have a new, indirect or warning symbol here. */
458 einfo ("%P%F: %s: plugin symbol table corrupt (sym type %d)",
459 called_plugin->name, blhe->type);
462 /* Find out which section owns the symbol. Since it's not undef,
463 it must have an owner; if it's not a common symbol, both defs
464 and weakdefs keep it in the same place. */
465 owner_sec = (blhe->type == bfd_link_hash_common)
466 ? blhe->u.c.p->section
467 : blhe->u.def.section;
469 /* We need to know if the sym is referenced from non-IR files. Or
470 even potentially-referenced, perhaps in a future final link if
471 this is a partial one, perhaps dynamically at load-time if the
472 symbol is externally visible. */
473 ironly = !is_visible_from_outside (&syms[n], owner_sec, blhe)
474 && !bfd_hash_lookup (non_ironly_hash, syms[n].name, FALSE, FALSE);
476 /* If it was originally undefined or common, then it has been
477 resolved; determine how. */
478 if (syms[n].def == LDPK_UNDEF
479 || syms[n].def == LDPK_WEAKUNDEF
480 || syms[n].def == LDPK_COMMON)
482 if (owner_sec->owner == link_info.output_bfd)
483 syms[n].resolution = LDPR_RESOLVED_EXEC;
484 else if (owner_sec->owner == abfd)
485 syms[n].resolution = (ironly
486 ? LDPR_PREVAILING_DEF_IRONLY
487 : LDPR_PREVAILING_DEF);
488 else if (is_ir_dummy_bfd (owner_sec->owner))
489 syms[n].resolution = LDPR_RESOLVED_IR;
490 else if (owner_sec->owner->flags & DYNAMIC)
491 syms[n].resolution = LDPR_RESOLVED_DYN;
493 syms[n].resolution = LDPR_RESOLVED_EXEC;
497 /* Was originally def, or weakdef. Does it prevail? If the
498 owner is the original dummy bfd that supplied it, then this
499 is the definition that has prevailed. */
500 if (owner_sec->owner == link_info.output_bfd)
501 syms[n].resolution = LDPR_PREEMPTED_REG;
502 else if (owner_sec->owner == abfd)
504 syms[n].resolution = (ironly
505 ? LDPR_PREVAILING_DEF_IRONLY
506 : LDPR_PREVAILING_DEF);
510 /* Was originally def, weakdef, or common, but has been pre-empted. */
511 syms[n].resolution = is_ir_dummy_bfd (owner_sec->owner)
513 : LDPR_PREEMPTED_REG;
518 /* Add a new (real) input file generated by a plugin. */
519 static enum ld_plugin_status
520 add_input_file (const char *pathname)
522 ASSERT (called_plugin);
523 if (!lang_add_input_file (xstrdup (pathname), lang_input_file_is_file_enum,
529 /* Add a new (real) library required by a plugin. */
530 static enum ld_plugin_status
531 add_input_library (const char *pathname)
533 ASSERT (called_plugin);
534 if (!lang_add_input_file (xstrdup (pathname), lang_input_file_is_l_enum,
540 /* Set the extra library path to be used by libraries added via
541 add_input_library. */
542 static enum ld_plugin_status
543 set_extra_library_path (const char *path)
545 ASSERT (called_plugin);
546 ldfile_add_library_path (xstrdup (path), FALSE);
550 /* Issue a diagnostic message from a plugin. */
551 static enum ld_plugin_status
552 message (int level, const char *format, ...)
555 va_start (args, format);
560 vfinfo (stdout, format, args, FALSE);
563 vfinfo (stdout, format, args, TRUE);
569 char *newfmt = ACONCAT ((level == LDPL_FATAL ? "%F" : "%X",
571 vfinfo (stderr, newfmt, args, TRUE);
580 /* Helper to size leading part of tv array and set it up. */
582 set_tv_header (struct ld_plugin_tv *tv)
587 static const unsigned int major = (unsigned)(BFD_VERSION / 100000000UL);
588 static const unsigned int minor = (unsigned)(BFD_VERSION / 1000000UL) % 100;
591 return tv_header_size;
593 for (i = 0; i < tv_header_size; i++)
595 tv[i].tv_tag = tv_header_tags[i];
596 #define TVU(x) tv[i].tv_u.tv_ ## x
597 switch (tv[i].tv_tag)
600 TVU(message) = message;
602 case LDPT_API_VERSION:
603 TVU(val) = LD_PLUGIN_API_VERSION;
605 case LDPT_GNU_LD_VERSION:
606 TVU(val) = major * 100 + minor;
608 case LDPT_LINKER_OUTPUT:
609 TVU(val) = (link_info.relocatable
611 : (link_info.shared ? LDPO_DYN : LDPO_EXEC));
613 case LDPT_OUTPUT_NAME:
614 TVU(string) = output_filename;
616 case LDPT_REGISTER_CLAIM_FILE_HOOK:
617 TVU(register_claim_file) = register_claim_file;
619 case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK:
620 TVU(register_all_symbols_read) = register_all_symbols_read;
622 case LDPT_REGISTER_CLEANUP_HOOK:
623 TVU(register_cleanup) = register_cleanup;
625 case LDPT_ADD_SYMBOLS:
626 TVU(add_symbols) = add_symbols;
628 case LDPT_GET_INPUT_FILE:
629 TVU(get_input_file) = get_input_file;
631 case LDPT_RELEASE_INPUT_FILE:
632 TVU(release_input_file) = release_input_file;
634 case LDPT_GET_SYMBOLS:
635 TVU(get_symbols) = get_symbols;
637 case LDPT_ADD_INPUT_FILE:
638 TVU(add_input_file) = add_input_file;
640 case LDPT_ADD_INPUT_LIBRARY:
641 TVU(add_input_library) = add_input_library;
643 case LDPT_SET_EXTRA_LIBRARY_PATH:
644 TVU(set_extra_library_path) = set_extra_library_path;
647 /* Added a new entry to the array without adding
648 a new case to set up its value is a bug. */
653 return tv_header_size;
656 /* Append the per-plugin args list and trailing LDPT_NULL to tv. */
658 set_tv_plugin_args (plugin_t *plugin, struct ld_plugin_tv *tv)
660 plugin_arg_t *arg = plugin->args;
663 tv->tv_tag = LDPT_OPTION;
664 tv->tv_u.tv_string = arg->arg;
668 tv->tv_tag = LDPT_NULL;
672 /* Return true if any plugins are active this run. Only valid
673 after options have been processed. */
675 plugin_active_plugins_p (void)
677 return plugins_list != NULL;
680 /* Load up and initialise all plugins after argument parsing. */
682 plugin_load_plugins (void)
684 struct ld_plugin_tv *my_tv;
685 unsigned int max_args = 0;
686 plugin_t *curplug = plugins_list;
688 /* If there are no plugins, we need do nothing this run. */
692 /* First pass over plugins to find max # args needed so that we
693 can size and allocate the tv array. */
696 if (curplug->n_args > max_args)
697 max_args = curplug->n_args;
698 curplug = curplug->next;
701 /* Allocate tv array and initialise constant part. */
702 my_tv = xmalloc ((max_args + 1 + tv_header_size) * sizeof *my_tv);
703 set_tv_header (my_tv);
705 /* Pass over plugins again, activating them. */
706 curplug = plugins_list;
709 enum ld_plugin_status rv;
710 ld_plugin_onload onloadfn = dlsym (curplug->dlhandle, "onload");
712 onloadfn = dlsym (curplug->dlhandle, "_onload");
714 return set_plugin_error (curplug->name);
715 set_tv_plugin_args (curplug, &my_tv[tv_header_size]);
716 called_plugin = curplug;
717 rv = (*onloadfn) (my_tv);
718 called_plugin = NULL;
720 return set_plugin_error (curplug->name);
721 curplug = curplug->next;
724 /* Since plugin(s) inited ok, assume they're going to want symbol
725 resolutions, which needs us to track which symbols are referenced
726 by non-IR files using the linker's notice callback. */
727 link_info.notice_all = TRUE;
732 /* Call 'claim file' hook for all plugins. */
734 plugin_call_claim_file (const struct ld_plugin_input_file *file, int *claimed)
736 plugin_t *curplug = plugins_list;
738 if (no_more_claiming)
740 while (curplug && !*claimed)
742 if (curplug->claim_file_handler)
744 enum ld_plugin_status rv;
745 called_plugin = curplug;
746 rv = (*curplug->claim_file_handler) (file, claimed);
747 called_plugin = NULL;
749 set_plugin_error (curplug->name);
751 curplug = curplug->next;
753 return plugin_error_p () ? -1 : 0;
756 /* Call 'all symbols read' hook for all plugins. */
758 plugin_call_all_symbols_read (void)
760 plugin_t *curplug = plugins_list;
762 /* Disable any further file-claiming. */
763 no_more_claiming = TRUE;
765 /* If --allow-multiple-definition is in effect, we need to disable it,
766 as the plugin infrastructure relies on the multiple_definition
767 callback to swap out the dummy IR-only BFDs for new real ones
768 when it starts opening the files added during this callback. */
769 plugin_cached_allow_multiple_defs = link_info.allow_multiple_definition;
770 link_info.allow_multiple_definition = FALSE;
774 if (curplug->all_symbols_read_handler)
776 enum ld_plugin_status rv;
777 called_plugin = curplug;
778 rv = (*curplug->all_symbols_read_handler) ();
779 called_plugin = NULL;
781 set_plugin_error (curplug->name);
783 curplug = curplug->next;
785 return plugin_error_p () ? -1 : 0;
788 /* Call 'cleanup' hook for all plugins. */
790 plugin_call_cleanup (void)
792 plugin_t *curplug = plugins_list;
795 if (curplug->cleanup_handler && !curplug->cleanup_done)
797 enum ld_plugin_status rv;
798 curplug->cleanup_done = TRUE;
799 called_plugin = curplug;
800 rv = (*curplug->cleanup_handler) ();
801 called_plugin = NULL;
803 set_plugin_error (curplug->name);
804 dlclose (curplug->dlhandle);
806 curplug = curplug->next;
808 return plugin_error_p () ? -1 : 0;
811 /* Lazily init the non_ironly hash table. */
813 init_non_ironly_hash (void)
815 if (non_ironly_hash == NULL)
818 (struct bfd_hash_table *) xmalloc (sizeof (struct bfd_hash_table));
819 if (!bfd_hash_table_init_n (non_ironly_hash,
821 sizeof (struct bfd_hash_entry),
823 einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
827 /* To determine which symbols should be resolved LDPR_PREVAILING_DEF
828 and which LDPR_PREVAILING_DEF_IRONLY, we notice all the symbols as
829 the linker adds them to the linker hash table. If we see a symbol
830 being referenced from a non-IR file, we add it to the non_ironly hash
831 table. If we can't find it there at get_symbols time, we know that
832 it was referenced only by IR files. We have to notice_all symbols,
833 because we won't necessarily know until later which ones will be
834 contributed by IR files. */
836 plugin_notice (struct bfd_link_info *info ATTRIBUTE_UNUSED,
837 const char *name, bfd *abfd,
838 asection *section, bfd_vma value ATTRIBUTE_UNUSED)
840 bfd_boolean is_ref = bfd_is_und_section (section);
841 bfd_boolean is_dummy = is_ir_dummy_bfd (abfd);
842 init_non_ironly_hash ();
843 /* We only care about refs, not defs, indicated by section pointing
844 to the undefined section (according to the bfd linker notice callback
845 interface definition). */
846 if (is_ref && !is_dummy)
848 /* This is a ref from a non-IR file, so note the ref'd symbol
849 in the non-IR-only hash. */
850 if (!bfd_hash_lookup (non_ironly_hash, name, TRUE, TRUE))
851 einfo (_("%P%X: %s: hash table failure adding symbol %s"),
852 abfd->filename, name);
854 else if (!is_ref && is_dummy)
856 /* No further processing since this is a def from an IR dummy BFD. */
860 /* Continue with cref/nocrossref/trace-sym processing. */
864 /* When we add new object files to the link at all symbols read time,
865 these contain the real code and symbols generated from the IR files,
866 and so duplicate all the definitions already supplied by the dummy
867 IR-only BFDs that we created at claim files time. We use the linker's
868 multiple-definitions callback hook to fix up the clash, discarding
869 the symbol from the IR-only BFD in favour of the symbol from the
870 real BFD. We return true if this was not-really-a-clash because
871 we've fixed it up, or anyway if --allow-multiple-definition was in
872 effect (before we disabled it to ensure we got called back). */
874 plugin_multiple_definition (struct bfd_link_info *info, const char *name,
875 bfd *obfd, asection *osec ATTRIBUTE_UNUSED,
876 bfd_vma oval ATTRIBUTE_UNUSED,
877 bfd *nbfd, asection *nsec, bfd_vma nval)
879 if (is_ir_dummy_bfd (obfd))
881 struct bfd_link_hash_entry *blhe
882 = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, FALSE);
884 einfo (_("%P%X: %s: can't find IR symbol '%s'"), nbfd->filename,
886 else if (blhe->type != bfd_link_hash_defined)
887 einfo (_("%P%x: %s: bad IR symbol type %d"), name, blhe->type);
888 /* Replace it with new details. */
889 blhe->u.def.section = nsec;
890 blhe->u.def.value = nval;
893 return plugin_cached_allow_multiple_defs;