1 // plugin.cc -- plugin manager for gold -*- C++ -*-
3 // Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
4 // Written by Cary Coutant <ccoutant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
35 #include "parameters.h"
51 // The linker's exported interfaces.
56 static enum ld_plugin_status
57 register_claim_file(ld_plugin_claim_file_handler handler
);
59 static enum ld_plugin_status
60 register_all_symbols_read(ld_plugin_all_symbols_read_handler handler
);
62 static enum ld_plugin_status
63 register_cleanup(ld_plugin_cleanup_handler handler
);
65 static enum ld_plugin_status
66 add_symbols(void *handle
, int nsyms
, const struct ld_plugin_symbol
*syms
);
68 static enum ld_plugin_status
69 get_input_file(const void *handle
, struct ld_plugin_input_file
*file
);
71 static enum ld_plugin_status
72 release_input_file(const void *handle
);
74 static enum ld_plugin_status
75 get_symbols(const void *handle
, int nsyms
, struct ld_plugin_symbol
*syms
);
77 static enum ld_plugin_status
78 add_input_file(char *pathname
);
80 static enum ld_plugin_status
81 add_input_library(char *pathname
);
83 static enum ld_plugin_status
84 message(int level
, const char *format
, ...);
88 #endif // ENABLE_PLUGINS
90 static Pluginobj
* make_sized_plugin_object(Input_file
* input_file
,
91 off_t offset
, off_t filesize
);
95 // Load one plugin library.
100 #ifdef ENABLE_PLUGINS
101 // Load the plugin library.
102 // FIXME: Look for the library in standard locations.
103 this->handle_
= dlopen(this->filename_
.c_str(), RTLD_NOW
);
104 if (this->handle_
== NULL
)
106 gold_error(_("%s: could not load plugin library"),
107 this->filename_
.c_str());
111 // Find the plugin's onload entry point.
112 void* ptr
= dlsym(this->handle_
, "onload");
115 gold_error(_("%s: could not find onload entry point"),
116 this->filename_
.c_str());
119 ld_plugin_onload onload
;
120 gold_assert(sizeof(onload
) == sizeof(ptr
));
121 memcpy(&onload
, &ptr
, sizeof(ptr
));
123 // Get the linker's version number.
124 const char* ver
= get_version_string();
127 sscanf(ver
, "%d.%d", &major
, &minor
);
129 // Allocate and populate a transfer vector.
130 const int tv_fixed_size
= 15;
131 int tv_size
= this->args_
.size() + tv_fixed_size
;
132 ld_plugin_tv
*tv
= new ld_plugin_tv
[tv_size
];
134 // Put LDPT_MESSAGE at the front of the list so the plugin can use it
135 // while processing subsequent entries.
137 tv
[i
].tv_tag
= LDPT_MESSAGE
;
138 tv
[i
].tv_u
.tv_message
= message
;
141 tv
[i
].tv_tag
= LDPT_API_VERSION
;
142 tv
[i
].tv_u
.tv_val
= LD_PLUGIN_API_VERSION
;
145 tv
[i
].tv_tag
= LDPT_GOLD_VERSION
;
146 tv
[i
].tv_u
.tv_val
= major
* 100 + minor
;
149 tv
[i
].tv_tag
= LDPT_LINKER_OUTPUT
;
150 if (parameters
->options().relocatable())
151 tv
[i
].tv_u
.tv_val
= LDPO_REL
;
152 else if (parameters
->options().shared())
153 tv
[i
].tv_u
.tv_val
= LDPO_DYN
;
155 tv
[i
].tv_u
.tv_val
= LDPO_EXEC
;
158 tv
[i
].tv_tag
= LDPT_OUTPUT_NAME
;
159 tv
[i
].tv_u
.tv_string
= parameters
->options().output();
161 for (unsigned int j
= 0; j
< this->args_
.size(); ++j
)
164 tv
[i
].tv_tag
= LDPT_OPTION
;
165 tv
[i
].tv_u
.tv_string
= this->args_
[j
].c_str();
169 tv
[i
].tv_tag
= LDPT_REGISTER_CLAIM_FILE_HOOK
;
170 tv
[i
].tv_u
.tv_register_claim_file
= register_claim_file
;
173 tv
[i
].tv_tag
= LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK
;
174 tv
[i
].tv_u
.tv_register_all_symbols_read
= register_all_symbols_read
;
177 tv
[i
].tv_tag
= LDPT_REGISTER_CLEANUP_HOOK
;
178 tv
[i
].tv_u
.tv_register_cleanup
= register_cleanup
;
181 tv
[i
].tv_tag
= LDPT_ADD_SYMBOLS
;
182 tv
[i
].tv_u
.tv_add_symbols
= add_symbols
;
185 tv
[i
].tv_tag
= LDPT_GET_INPUT_FILE
;
186 tv
[i
].tv_u
.tv_get_input_file
= get_input_file
;
189 tv
[i
].tv_tag
= LDPT_RELEASE_INPUT_FILE
;
190 tv
[i
].tv_u
.tv_release_input_file
= release_input_file
;
193 tv
[i
].tv_tag
= LDPT_GET_SYMBOLS
;
194 tv
[i
].tv_u
.tv_get_symbols
= get_symbols
;
197 tv
[i
].tv_tag
= LDPT_ADD_INPUT_FILE
;
198 tv
[i
].tv_u
.tv_add_input_file
= add_input_file
;
201 tv
[i
].tv_tag
= LDPT_ADD_INPUT_LIBRARY
;
202 tv
[i
].tv_u
.tv_add_input_library
= add_input_library
;
205 tv
[i
].tv_tag
= LDPT_NULL
;
206 tv
[i
].tv_u
.tv_val
= 0;
208 gold_assert(i
== tv_size
- 1);
210 // Call the onload entry point.
214 #endif // ENABLE_PLUGINS
217 // Call the plugin claim-file handler.
220 Plugin::claim_file(struct ld_plugin_input_file
*plugin_input_file
)
224 if (this->claim_file_handler_
!= NULL
)
226 (*this->claim_file_handler_
)(plugin_input_file
, &claimed
);
233 // Call the all-symbols-read handler.
236 Plugin::all_symbols_read()
238 if (this->all_symbols_read_handler_
!= NULL
)
239 (*this->all_symbols_read_handler_
)();
242 // Call the cleanup handler.
247 if (this->cleanup_handler_
!= NULL
&& !this->cleanup_done_
)
249 // Set this flag before calling to prevent a recursive plunge
250 // in the event that a plugin's cleanup handler issues a
252 this->cleanup_done_
= true;
253 (*this->cleanup_handler_
)();
257 // Plugin_manager methods.
259 Plugin_manager::~Plugin_manager()
261 for (Plugin_list::iterator p
= this->plugins_
.begin();
262 p
!= this->plugins_
.end();
265 this->plugins_
.clear();
266 for (Object_list::iterator obj
= this->objects_
.begin();
267 obj
!= this->objects_
.end();
270 this->objects_
.clear();
273 // Load all plugin libraries.
276 Plugin_manager::load_plugins()
278 for (this->current_
= this->plugins_
.begin();
279 this->current_
!= this->plugins_
.end();
281 (*this->current_
)->load();
284 // Call the plugin claim-file handlers in turn to see if any claim the file.
287 Plugin_manager::claim_file(Input_file
* input_file
, off_t offset
,
290 if (this->in_replacement_phase_
)
293 unsigned int handle
= this->objects_
.size();
294 this->input_file_
= input_file
;
295 this->plugin_input_file_
.name
= input_file
->filename().c_str();
296 this->plugin_input_file_
.fd
= input_file
->file().descriptor();
297 this->plugin_input_file_
.offset
= offset
;
298 this->plugin_input_file_
.filesize
= filesize
;
299 this->plugin_input_file_
.handle
= reinterpret_cast<void*>(handle
);
301 for (this->current_
= this->plugins_
.begin();
302 this->current_
!= this->plugins_
.end();
305 if ((*this->current_
)->claim_file(&this->plugin_input_file_
))
307 if (this->objects_
.size() > handle
)
308 return this->objects_
[handle
];
310 // If the plugin claimed the file but did not call the
311 // add_symbols callback, we need to create the Pluginobj now.
312 Pluginobj
* obj
= this->make_plugin_object(handle
);
320 // Call the all-symbols-read handlers.
323 Plugin_manager::all_symbols_read(Workqueue
* workqueue
, Task
* task
,
324 Input_objects
* input_objects
,
325 Symbol_table
* symtab
, Layout
* layout
,
326 Dirsearch
* dirpath
, Mapfile
* mapfile
,
327 Task_token
** last_blocker
)
329 this->in_replacement_phase_
= true;
330 this->workqueue_
= workqueue
;
332 this->input_objects_
= input_objects
;
333 this->symtab_
= symtab
;
334 this->layout_
= layout
;
335 this->dirpath_
= dirpath
;
336 this->mapfile_
= mapfile
;
337 this->this_blocker_
= NULL
;
339 for (this->current_
= this->plugins_
.begin();
340 this->current_
!= this->plugins_
.end();
342 (*this->current_
)->all_symbols_read();
344 *last_blocker
= this->this_blocker_
;
347 // Layout deferred objects.
350 Plugin_manager::layout_deferred_objects()
352 Deferred_layout_list::iterator obj
;
354 for (obj
= this->deferred_layout_objects_
.begin();
355 obj
!= this->deferred_layout_objects_
.end();
357 (*obj
)->layout_deferred_sections(this->layout_
);
360 // Call the cleanup handlers.
363 Plugin_manager::cleanup()
365 for (this->current_
= this->plugins_
.begin();
366 this->current_
!= this->plugins_
.end();
368 (*this->current_
)->cleanup();
371 // Make a new Pluginobj object. This is called when the plugin calls
372 // the add_symbols API.
375 Plugin_manager::make_plugin_object(unsigned int handle
)
377 // Make sure we aren't asked to make an object for the same handle twice.
378 if (this->objects_
.size() != handle
)
381 Pluginobj
* obj
= make_sized_plugin_object(this->input_file_
,
382 this->plugin_input_file_
.offset
,
383 this->plugin_input_file_
.filesize
);
384 this->objects_
.push_back(obj
);
388 // Get the input file information with an open (possibly re-opened)
392 Plugin_manager::get_input_file(unsigned int handle
,
393 struct ld_plugin_input_file
*file
)
395 Pluginobj
* obj
= this->object(handle
);
397 return LDPS_BAD_HANDLE
;
399 obj
->lock(this->task_
);
400 file
->name
= obj
->filename().c_str();
401 file
->fd
= obj
->descriptor();
402 file
->offset
= obj
->offset();
403 file
->filesize
= obj
->filesize();
404 file
->handle
= reinterpret_cast<void*>(handle
);
408 // Release the input file.
411 Plugin_manager::release_input_file(unsigned int handle
)
413 Pluginobj
* obj
= this->object(handle
);
415 return LDPS_BAD_HANDLE
;
417 obj
->unlock(this->task_
);
421 // Add a new input file.
424 Plugin_manager::add_input_file(char *pathname
, bool is_lib
)
426 Input_file_argument
file(pathname
,
428 ? Input_file_argument::INPUT_FILE_TYPE_LIBRARY
429 : Input_file_argument::INPUT_FILE_TYPE_FILE
),
430 "", false, this->options_
);
431 Input_argument
* input_argument
= new Input_argument(file
);
432 Task_token
* next_blocker
= new Task_token(true);
433 next_blocker
->add_blocker();
434 if (this->layout_
->incremental_inputs())
435 gold_error(_("input files added by plug-ins in --incremental mode not "
437 this->workqueue_
->queue_soon(new Read_symbols(this->input_objects_
,
448 this->this_blocker_
= next_blocker
;
454 Pluginobj::Pluginobj(const std::string
& name
, Input_file
* input_file
,
455 off_t offset
, off_t filesize
)
456 : Object(name
, input_file
, false, offset
),
457 nsyms_(0), syms_(NULL
), symbols_(), filesize_(filesize
), comdat_map_()
461 // Return TRUE if a defined symbol might be reachable from outside the
462 // universe of claimed objects.
465 is_visible_from_outside(Symbol
* lsym
)
467 if (lsym
->in_real_elf())
469 if (parameters
->options().relocatable())
471 if (parameters
->options().export_dynamic() || parameters
->options().shared())
472 return lsym
->is_externally_visible();
476 // Get symbol resolution info.
479 Pluginobj::get_symbol_resolution_info(int nsyms
, ld_plugin_symbol
* syms
) const
481 if (nsyms
> this->nsyms_
)
484 if (static_cast<size_t>(nsyms
) > this->symbols_
.size())
486 // We never decided to include this object. We mark all symbols as
488 gold_assert (this->symbols_
.size() == 0);
489 for (int i
= 0; i
< nsyms
; i
++)
490 syms
[i
].resolution
= LDPR_PREEMPTED_REG
;
494 for (int i
= 0; i
< nsyms
; i
++)
496 ld_plugin_symbol
* isym
= &syms
[i
];
497 Symbol
* lsym
= this->symbols_
[i
];
498 ld_plugin_symbol_resolution res
= LDPR_UNKNOWN
;
500 if (lsym
->is_undefined())
501 // The symbol remains undefined.
503 else if (isym
->def
== LDPK_UNDEF
504 || isym
->def
== LDPK_WEAKUNDEF
505 || isym
->def
== LDPK_COMMON
)
507 // The original symbol was undefined or common.
508 if (lsym
->source() != Symbol::FROM_OBJECT
)
509 res
= LDPR_RESOLVED_EXEC
;
510 else if (lsym
->object()->pluginobj() == this)
511 res
= (is_visible_from_outside(lsym
)
512 ? LDPR_PREVAILING_DEF
513 : LDPR_PREVAILING_DEF_IRONLY
);
514 else if (lsym
->object()->pluginobj() != NULL
)
515 res
= LDPR_RESOLVED_IR
;
516 else if (lsym
->object()->is_dynamic())
517 res
= LDPR_RESOLVED_DYN
;
519 res
= LDPR_RESOLVED_EXEC
;
523 // The original symbol was a definition.
524 if (lsym
->source() != Symbol::FROM_OBJECT
)
525 res
= LDPR_PREEMPTED_REG
;
526 else if (lsym
->object() == static_cast<const Object
*>(this))
527 res
= (is_visible_from_outside(lsym
)
528 ? LDPR_PREVAILING_DEF
529 : LDPR_PREVAILING_DEF_IRONLY
);
531 res
= (lsym
->object()->pluginobj() != NULL
533 : LDPR_PREEMPTED_REG
);
535 isym
->resolution
= res
;
540 // Return TRUE if the comdat group with key COMDAT_KEY from this object
544 Pluginobj::include_comdat_group(std::string comdat_key
, Layout
* layout
)
546 std::pair
<Comdat_map::iterator
, bool> ins
=
547 this->comdat_map_
.insert(std::make_pair(comdat_key
, false));
549 // If this is the first time we've seen this comdat key, ask the
550 // layout object whether it should be included.
552 ins
.first
->second
= layout
->find_or_add_kept_section(comdat_key
,
556 return ins
.first
->second
;
559 // Class Sized_pluginobj.
561 template<int size
, bool big_endian
>
562 Sized_pluginobj
<size
, big_endian
>::Sized_pluginobj(
563 const std::string
& name
,
564 Input_file
* input_file
,
567 : Pluginobj(name
, input_file
, offset
, filesize
)
571 // Read the symbols. Not used for plugin objects.
573 template<int size
, bool big_endian
>
575 Sized_pluginobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
580 // Lay out the input sections. Not used for plugin objects.
582 template<int size
, bool big_endian
>
584 Sized_pluginobj
<size
, big_endian
>::do_layout(Symbol_table
*, Layout
*,
590 // Add the symbols to the symbol table.
592 template<int size
, bool big_endian
>
594 Sized_pluginobj
<size
, big_endian
>::do_add_symbols(Symbol_table
* symtab
,
598 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
599 unsigned char symbuf
[sym_size
];
600 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
601 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
603 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
605 this->symbols_
.resize(this->nsyms_
);
607 for (int i
= 0; i
< this->nsyms_
; ++i
)
609 const struct ld_plugin_symbol
*isym
= &this->syms_
[i
];
610 const char* name
= isym
->name
;
611 const char* ver
= isym
->version
;
612 elfcpp::Elf_Half shndx
;
616 if (name
!= NULL
&& name
[0] == '\0')
618 if (ver
!= NULL
&& ver
[0] == '\0')
625 bind
= elfcpp::STB_WEAK
;
631 bind
= elfcpp::STB_GLOBAL
;
639 shndx
= elfcpp::SHN_ABS
;
642 shndx
= elfcpp::SHN_COMMON
;
647 shndx
= elfcpp::SHN_UNDEF
;
651 switch (isym
->visibility
)
654 vis
= elfcpp::STV_PROTECTED
;
657 vis
= elfcpp::STV_INTERNAL
;
660 vis
= elfcpp::STV_HIDDEN
;
664 vis
= elfcpp::STV_DEFAULT
;
668 if (isym
->comdat_key
!= NULL
669 && isym
->comdat_key
[0] != '\0'
670 && !this->include_comdat_group(isym
->comdat_key
, layout
))
671 shndx
= elfcpp::SHN_UNDEF
;
674 osym
.put_st_value(0);
675 osym
.put_st_size(static_cast<Elf_size_type
>(isym
->size
));
676 osym
.put_st_info(bind
, elfcpp::STT_NOTYPE
);
677 osym
.put_st_other(vis
, 0);
678 osym
.put_st_shndx(shndx
);
681 symtab
->add_from_pluginobj
<size
, big_endian
>(this, name
, ver
, &sym
);
685 template<int size
, bool big_endian
>
686 Archive::Should_include
687 Sized_pluginobj
<size
, big_endian
>::do_should_include_member(
688 Symbol_table
* symtab
, Read_symbols_data
*, std::string
* why
)
691 size_t tmpbuflen
= 0;
693 for (int i
= 0; i
< this->nsyms_
; ++i
) {
694 const struct ld_plugin_symbol
& sym
= this->syms_
[i
];
695 const char* name
= sym
.name
;
697 Archive::Should_include t
= Archive::should_include_member(symtab
, name
,
701 if (t
== Archive::SHOULD_INCLUDE_YES
)
710 return Archive::SHOULD_INCLUDE_UNKNOWN
;
713 // Get the size of a section. Not used for plugin objects.
715 template<int size
, bool big_endian
>
717 Sized_pluginobj
<size
, big_endian
>::do_section_size(unsigned int)
723 // Get the name of a section. Not used for plugin objects.
725 template<int size
, bool big_endian
>
727 Sized_pluginobj
<size
, big_endian
>::do_section_name(unsigned int)
730 return std::string();
733 // Return a view of the contents of a section. Not used for plugin objects.
735 template<int size
, bool big_endian
>
737 Sized_pluginobj
<size
, big_endian
>::do_section_contents(unsigned int)
745 // Return section flags. Not used for plugin objects.
747 template<int size
, bool big_endian
>
749 Sized_pluginobj
<size
, big_endian
>::do_section_flags(unsigned int)
755 // Return section entsize. Not used for plugin objects.
757 template<int size
, bool big_endian
>
759 Sized_pluginobj
<size
, big_endian
>::do_section_entsize(unsigned int)
765 // Return section address. Not used for plugin objects.
767 template<int size
, bool big_endian
>
769 Sized_pluginobj
<size
, big_endian
>::do_section_address(unsigned int)
775 // Return section type. Not used for plugin objects.
777 template<int size
, bool big_endian
>
779 Sized_pluginobj
<size
, big_endian
>::do_section_type(unsigned int)
785 // Return the section link field. Not used for plugin objects.
787 template<int size
, bool big_endian
>
789 Sized_pluginobj
<size
, big_endian
>::do_section_link(unsigned int)
795 // Return the section link field. Not used for plugin objects.
797 template<int size
, bool big_endian
>
799 Sized_pluginobj
<size
, big_endian
>::do_section_info(unsigned int)
805 // Return the section alignment. Not used for plugin objects.
807 template<int size
, bool big_endian
>
809 Sized_pluginobj
<size
, big_endian
>::do_section_addralign(unsigned int)
815 // Return the Xindex structure to use. Not used for plugin objects.
817 template<int size
, bool big_endian
>
819 Sized_pluginobj
<size
, big_endian
>::do_initialize_xindex()
825 // Get symbol counts. Not used for plugin objects.
827 template<int size
, bool big_endian
>
829 Sized_pluginobj
<size
, big_endian
>::do_get_global_symbol_counts(const Symbol_table
*,
830 size_t*, size_t*) const
835 // Get symbols. Not used for plugin objects.
837 template<int size
, bool big_endian
>
838 const Object::Symbols
*
839 Sized_pluginobj
<size
, big_endian
>::do_get_global_symbols() const
844 // Class Plugin_finish. This task runs after all replacement files have
845 // been added. It calls each plugin's cleanup handler.
847 class Plugin_finish
: public Task
850 Plugin_finish(Task_token
* this_blocker
, Task_token
* next_blocker
)
851 : this_blocker_(this_blocker
), next_blocker_(next_blocker
)
856 if (this->this_blocker_
!= NULL
)
857 delete this->this_blocker_
;
863 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
864 return this->this_blocker_
;
869 locks(Task_locker
* tl
)
870 { tl
->add(this, this->next_blocker_
); }
875 Plugin_manager
* plugins
= parameters
->options().plugins();
876 gold_assert(plugins
!= NULL
);
882 { return "Plugin_finish"; }
885 Task_token
* this_blocker_
;
886 Task_token
* next_blocker_
;
889 // Class Plugin_hook.
891 Plugin_hook::~Plugin_hook()
895 // Return whether a Plugin_hook task is runnable.
898 Plugin_hook::is_runnable()
900 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
901 return this->this_blocker_
;
905 // Return a Task_locker for a Plugin_hook task. We don't need any
909 Plugin_hook::locks(Task_locker
*)
913 // Run the "all symbols read" plugin hook.
916 Plugin_hook::run(Workqueue
* workqueue
)
918 gold_assert(this->options_
.has_plugins());
919 this->options_
.plugins()->all_symbols_read(workqueue
,
921 this->input_objects_
,
926 &this->this_blocker_
);
927 workqueue
->queue_soon(new Plugin_finish(this->this_blocker_
,
928 this->next_blocker_
));
931 // The C interface routines called by the plugins.
933 #ifdef ENABLE_PLUGINS
935 // Register a claim-file handler.
937 static enum ld_plugin_status
938 register_claim_file(ld_plugin_claim_file_handler handler
)
940 gold_assert(parameters
->options().has_plugins());
941 parameters
->options().plugins()->set_claim_file_handler(handler
);
945 // Register an all-symbols-read handler.
947 static enum ld_plugin_status
948 register_all_symbols_read(ld_plugin_all_symbols_read_handler handler
)
950 gold_assert(parameters
->options().has_plugins());
951 parameters
->options().plugins()->set_all_symbols_read_handler(handler
);
955 // Register a cleanup handler.
957 static enum ld_plugin_status
958 register_cleanup(ld_plugin_cleanup_handler handler
)
960 gold_assert(parameters
->options().has_plugins());
961 parameters
->options().plugins()->set_cleanup_handler(handler
);
965 // Add symbols from a plugin-claimed input file.
967 static enum ld_plugin_status
968 add_symbols(void* handle
, int nsyms
, const ld_plugin_symbol
*syms
)
970 gold_assert(parameters
->options().has_plugins());
971 Pluginobj
* obj
= parameters
->options().plugins()->make_plugin_object(
972 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
)));
975 obj
->store_incoming_symbols(nsyms
, syms
);
979 // Get the input file information with an open (possibly re-opened)
982 static enum ld_plugin_status
983 get_input_file(const void *handle
, struct ld_plugin_input_file
*file
)
985 gold_assert(parameters
->options().has_plugins());
986 unsigned int obj_index
=
987 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
));
988 return parameters
->options().plugins()->get_input_file(obj_index
, file
);
991 // Release the input file.
993 static enum ld_plugin_status
994 release_input_file(const void *handle
)
996 gold_assert(parameters
->options().has_plugins());
997 unsigned int obj_index
=
998 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
));
999 return parameters
->options().plugins()->release_input_file(obj_index
);
1002 // Get the symbol resolution info for a plugin-claimed input file.
1004 static enum ld_plugin_status
1005 get_symbols(const void * handle
, int nsyms
, ld_plugin_symbol
* syms
)
1007 gold_assert(parameters
->options().has_plugins());
1008 Pluginobj
* obj
= parameters
->options().plugins()->object(
1009 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
)));
1012 return obj
->get_symbol_resolution_info(nsyms
, syms
);
1015 // Add a new (real) input file generated by a plugin.
1017 static enum ld_plugin_status
1018 add_input_file(char *pathname
)
1020 gold_assert(parameters
->options().has_plugins());
1021 return parameters
->options().plugins()->add_input_file(pathname
, false);
1024 // Add a new (real) library required by a plugin.
1026 static enum ld_plugin_status
1027 add_input_library(char *pathname
)
1029 gold_assert(parameters
->options().has_plugins());
1030 return parameters
->options().plugins()->add_input_file(pathname
, true);
1033 // Issue a diagnostic message from a plugin.
1035 static enum ld_plugin_status
1036 message(int level
, const char * format
, ...)
1039 va_start(args
, format
);
1044 parameters
->errors()->info(format
, args
);
1047 parameters
->errors()->warning(format
, args
);
1051 parameters
->errors()->error(format
, args
);
1054 parameters
->errors()->fatal(format
, args
);
1062 #endif // ENABLE_PLUGINS
1064 // Allocate a Pluginobj object of the appropriate size and endianness.
1067 make_sized_plugin_object(Input_file
* input_file
, off_t offset
, off_t filesize
)
1069 Pluginobj
* obj
= NULL
;
1071 parameters_force_valid_target();
1072 const Target
& target(parameters
->target());
1074 if (target
.get_size() == 32)
1076 if (target
.is_big_endian())
1077 #ifdef HAVE_TARGET_32_BIG
1078 obj
= new Sized_pluginobj
<32, true>(input_file
->filename(),
1079 input_file
, offset
, filesize
);
1081 gold_error(_("%s: not configured to support "
1082 "32-bit big-endian object"),
1083 input_file
->filename().c_str());
1086 #ifdef HAVE_TARGET_32_LITTLE
1087 obj
= new Sized_pluginobj
<32, false>(input_file
->filename(),
1088 input_file
, offset
, filesize
);
1090 gold_error(_("%s: not configured to support "
1091 "32-bit little-endian object"),
1092 input_file
->filename().c_str());
1095 else if (target
.get_size() == 64)
1097 if (target
.is_big_endian())
1098 #ifdef HAVE_TARGET_64_BIG
1099 obj
= new Sized_pluginobj
<64, true>(input_file
->filename(),
1100 input_file
, offset
, filesize
);
1102 gold_error(_("%s: not configured to support "
1103 "64-bit big-endian object"),
1104 input_file
->filename().c_str());
1107 #ifdef HAVE_TARGET_64_LITTLE
1108 obj
= new Sized_pluginobj
<64, false>(input_file
->filename(),
1109 input_file
, offset
, filesize
);
1111 gold_error(_("%s: not configured to support "
1112 "64-bit little-endian object"),
1113 input_file
->filename().c_str());
1117 gold_assert(obj
!= NULL
);
1121 } // End namespace gold.