1 // plugin.c -- plugin manager for gold -*- C++ -*-
3 // Copyright 2008, 2009 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.
31 #include "parameters.h"
47 // The linker's exported interfaces.
52 static enum ld_plugin_status
53 register_claim_file(ld_plugin_claim_file_handler handler
);
55 static enum ld_plugin_status
56 register_all_symbols_read(ld_plugin_all_symbols_read_handler handler
);
58 static enum ld_plugin_status
59 register_cleanup(ld_plugin_cleanup_handler handler
);
61 static enum ld_plugin_status
62 add_symbols(void *handle
, int nsyms
, const struct ld_plugin_symbol
*syms
);
64 static enum ld_plugin_status
65 get_input_file(const void *handle
, struct ld_plugin_input_file
*file
);
67 static enum ld_plugin_status
68 release_input_file(const void *handle
);
70 static enum ld_plugin_status
71 get_symbols(const void *handle
, int nsyms
, struct ld_plugin_symbol
*syms
);
73 static enum ld_plugin_status
74 add_input_file(char *pathname
);
76 static enum ld_plugin_status
77 message(int level
, const char *format
, ...);
81 #endif // ENABLE_PLUGINS
83 static Pluginobj
* make_sized_plugin_object(Input_file
* input_file
,
84 off_t offset
, off_t filesize
);
88 // Load one plugin library.
94 // Load the plugin library.
95 // FIXME: Look for the library in standard locations.
96 this->handle_
= dlopen(this->filename_
.c_str(), RTLD_NOW
);
97 if (this->handle_
== NULL
)
99 gold_error(_("%s: could not load plugin library"),
100 this->filename_
.c_str());
104 // Find the plugin's onload entry point.
105 ld_plugin_onload onload
= reinterpret_cast<ld_plugin_onload
>
106 (dlsym(this->handle_
, "onload"));
109 gold_error(_("%s: could not find onload entry point"),
110 this->filename_
.c_str());
114 // Get the linker's version number.
115 const char* ver
= get_version_string();
118 sscanf(ver
, "%d.%d", &major
, &minor
);
120 // Allocate and populate a transfer vector.
121 const int tv_fixed_size
= 13;
122 int tv_size
= this->args_
.size() + tv_fixed_size
;
123 ld_plugin_tv
*tv
= new ld_plugin_tv
[tv_size
];
125 // Put LDPT_MESSAGE at the front of the list so the plugin can use it
126 // while processing subsequent entries.
128 tv
[i
].tv_tag
= LDPT_MESSAGE
;
129 tv
[i
].tv_u
.tv_message
= message
;
132 tv
[i
].tv_tag
= LDPT_API_VERSION
;
133 tv
[i
].tv_u
.tv_val
= LD_PLUGIN_API_VERSION
;
136 tv
[i
].tv_tag
= LDPT_GOLD_VERSION
;
137 tv
[i
].tv_u
.tv_val
= major
* 100 + minor
;
140 tv
[i
].tv_tag
= LDPT_LINKER_OUTPUT
;
141 if (parameters
->options().relocatable())
142 tv
[i
].tv_u
.tv_val
= LDPO_REL
;
143 else if (parameters
->options().shared())
144 tv
[i
].tv_u
.tv_val
= LDPO_DYN
;
146 tv
[i
].tv_u
.tv_val
= LDPO_EXEC
;
148 for (unsigned int j
= 0; j
< this->args_
.size(); ++j
)
151 tv
[i
].tv_tag
= LDPT_OPTION
;
152 tv
[i
].tv_u
.tv_string
= this->args_
[j
].c_str();
156 tv
[i
].tv_tag
= LDPT_REGISTER_CLAIM_FILE_HOOK
;
157 tv
[i
].tv_u
.tv_register_claim_file
= register_claim_file
;
160 tv
[i
].tv_tag
= LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK
;
161 tv
[i
].tv_u
.tv_register_all_symbols_read
= register_all_symbols_read
;
164 tv
[i
].tv_tag
= LDPT_REGISTER_CLEANUP_HOOK
;
165 tv
[i
].tv_u
.tv_register_cleanup
= register_cleanup
;
168 tv
[i
].tv_tag
= LDPT_ADD_SYMBOLS
;
169 tv
[i
].tv_u
.tv_add_symbols
= add_symbols
;
172 tv
[i
].tv_tag
= LDPT_GET_INPUT_FILE
;
173 tv
[i
].tv_u
.tv_get_input_file
= get_input_file
;
176 tv
[i
].tv_tag
= LDPT_RELEASE_INPUT_FILE
;
177 tv
[i
].tv_u
.tv_release_input_file
= release_input_file
;
180 tv
[i
].tv_tag
= LDPT_GET_SYMBOLS
;
181 tv
[i
].tv_u
.tv_get_symbols
= get_symbols
;
184 tv
[i
].tv_tag
= LDPT_ADD_INPUT_FILE
;
185 tv
[i
].tv_u
.tv_add_input_file
= add_input_file
;
188 tv
[i
].tv_tag
= LDPT_NULL
;
189 tv
[i
].tv_u
.tv_val
= 0;
191 gold_assert(i
== tv_size
- 1);
193 // Call the onload entry point.
197 #endif // ENABLE_PLUGINS
200 // Call the plugin claim-file handler.
203 Plugin::claim_file(struct ld_plugin_input_file
*plugin_input_file
)
207 if (this->claim_file_handler_
!= NULL
)
209 (*this->claim_file_handler_
)(plugin_input_file
, &claimed
);
216 // Call the all-symbols-read handler.
219 Plugin::all_symbols_read()
221 if (this->all_symbols_read_handler_
!= NULL
)
222 (*this->all_symbols_read_handler_
)();
225 // Call the cleanup handler.
230 if (this->cleanup_handler_
!= NULL
)
231 (*this->cleanup_handler_
)();
234 // Plugin_manager methods.
236 Plugin_manager::~Plugin_manager()
238 for (Plugin_list::iterator p
= this->plugins_
.begin();
239 p
!= this->plugins_
.end();
242 this->plugins_
.clear();
243 for (Object_list::iterator obj
= this->objects_
.begin();
244 obj
!= this->objects_
.end();
247 this->objects_
.clear();
250 // Load all plugin libraries.
253 Plugin_manager::load_plugins()
255 for (this->current_
= this->plugins_
.begin();
256 this->current_
!= this->plugins_
.end();
258 (*this->current_
)->load();
261 // Call the plugin claim-file handlers in turn to see if any claim the file.
264 Plugin_manager::claim_file(Input_file
* input_file
, off_t offset
,
267 if (this->in_replacement_phase_
)
270 unsigned int handle
= this->objects_
.size();
271 this->input_file_
= input_file
;
272 this->plugin_input_file_
.name
= input_file
->filename().c_str();
273 this->plugin_input_file_
.fd
= input_file
->file().descriptor();
274 this->plugin_input_file_
.offset
= offset
;
275 this->plugin_input_file_
.filesize
= filesize
;
276 this->plugin_input_file_
.handle
= reinterpret_cast<void*>(handle
);
278 for (this->current_
= this->plugins_
.begin();
279 this->current_
!= this->plugins_
.end();
282 if ((*this->current_
)->claim_file(&this->plugin_input_file_
))
284 if (this->objects_
.size() > handle
)
285 return this->objects_
[handle
];
287 // If the plugin claimed the file but did not call the
288 // add_symbols callback, we need to create the Pluginobj now.
289 Pluginobj
* obj
= this->make_plugin_object(handle
);
297 // Call the all-symbols-read handlers.
300 Plugin_manager::all_symbols_read(Workqueue
* workqueue
, Task
* task
,
301 Input_objects
* input_objects
,
302 Symbol_table
* symtab
, Layout
* layout
,
303 Dirsearch
* dirpath
, Mapfile
* mapfile
,
304 Task_token
** last_blocker
)
306 this->in_replacement_phase_
= true;
307 this->workqueue_
= workqueue
;
309 this->input_objects_
= input_objects
;
310 this->symtab_
= symtab
;
311 this->layout_
= layout
;
312 this->dirpath_
= dirpath
;
313 this->mapfile_
= mapfile
;
314 this->this_blocker_
= NULL
;
316 for (this->current_
= this->plugins_
.begin();
317 this->current_
!= this->plugins_
.end();
319 (*this->current_
)->all_symbols_read();
321 *last_blocker
= this->this_blocker_
;
324 // Layout deferred objects.
327 Plugin_manager::layout_deferred_objects()
329 Deferred_layout_list::iterator obj
;
331 for (obj
= this->deferred_layout_objects_
.begin();
332 obj
!= this->deferred_layout_objects_
.end();
334 (*obj
)->layout_deferred_sections(this->layout_
);
337 // Call the cleanup handlers.
340 Plugin_manager::cleanup()
342 if (this->cleanup_done_
)
344 for (this->current_
= this->plugins_
.begin();
345 this->current_
!= this->plugins_
.end();
347 (*this->current_
)->cleanup();
348 this->cleanup_done_
= true;
351 // Make a new Pluginobj object. This is called when the plugin calls
352 // the add_symbols API.
355 Plugin_manager::make_plugin_object(unsigned int handle
)
357 // Make sure we aren't asked to make an object for the same handle twice.
358 if (this->objects_
.size() != handle
)
361 Pluginobj
* obj
= make_sized_plugin_object(this->input_file_
,
362 this->plugin_input_file_
.offset
,
363 this->plugin_input_file_
.filesize
);
364 this->objects_
.push_back(obj
);
368 // Get the input file information with an open (possibly re-opened)
372 Plugin_manager::get_input_file(unsigned int handle
,
373 struct ld_plugin_input_file
*file
)
375 Pluginobj
* obj
= this->object(handle
);
377 return LDPS_BAD_HANDLE
;
379 obj
->lock(this->task_
);
380 file
->name
= obj
->filename().c_str();
381 file
->fd
= obj
->descriptor();
382 file
->offset
= obj
->offset();
383 file
->filesize
= obj
->filesize();
384 file
->handle
= reinterpret_cast<void*>(handle
);
388 // Release the input file.
391 Plugin_manager::release_input_file(unsigned int handle
)
393 Pluginobj
* obj
= this->object(handle
);
395 return LDPS_BAD_HANDLE
;
397 obj
->unlock(this->task_
);
401 // Add a new input file.
404 Plugin_manager::add_input_file(char *pathname
)
406 Input_file_argument
file(pathname
, false, "", false, this->options_
);
407 Input_argument
* input_argument
= new Input_argument(file
);
408 Task_token
* next_blocker
= new Task_token(true);
409 next_blocker
->add_blocker();
410 this->workqueue_
->queue_soon(new Read_symbols(this->options_
,
411 this->input_objects_
,
420 this->this_blocker_
= next_blocker
;
426 Pluginobj::Pluginobj(const std::string
& name
, Input_file
* input_file
,
427 off_t offset
, off_t filesize
)
428 : Object(name
, input_file
, false, offset
),
429 nsyms_(0), syms_(NULL
), symbols_(), filesize_(filesize
), comdat_map_()
433 // Return TRUE if a defined symbol might be reachable from outside the
434 // universe of claimed objects.
437 is_visible_from_outside(Symbol
* lsym
)
439 if (lsym
->in_real_elf())
441 if (parameters
->options().relocatable())
443 if (parameters
->options().export_dynamic() || parameters
->options().shared())
444 return lsym
->is_externally_visible();
448 // Get symbol resolution info.
451 Pluginobj::get_symbol_resolution_info(int nsyms
, ld_plugin_symbol
* syms
) const
453 if (nsyms
> this->nsyms_
)
455 for (int i
= 0; i
< nsyms
; i
++)
457 ld_plugin_symbol
* isym
= &syms
[i
];
458 Symbol
* lsym
= this->symbols_
[i
];
459 ld_plugin_symbol_resolution res
= LDPR_UNKNOWN
;
461 if (lsym
->is_undefined())
462 // The symbol remains undefined.
464 else if (isym
->def
== LDPK_UNDEF
465 || isym
->def
== LDPK_WEAKUNDEF
466 || isym
->def
== LDPK_COMMON
)
468 // The original symbol was undefined or common.
469 if (lsym
->source() != Symbol::FROM_OBJECT
)
470 res
= LDPR_RESOLVED_EXEC
;
471 else if (lsym
->object()->pluginobj() != NULL
)
472 res
= LDPR_RESOLVED_IR
;
473 else if (lsym
->object()->is_dynamic())
474 res
= LDPR_RESOLVED_DYN
;
476 res
= LDPR_RESOLVED_EXEC
;
480 // The original symbol was a definition.
481 if (lsym
->source() != Symbol::FROM_OBJECT
)
482 res
= LDPR_PREEMPTED_REG
;
483 else if (lsym
->object() == static_cast<const Object
*>(this))
484 res
= (is_visible_from_outside(lsym
)
485 ? LDPR_PREVAILING_DEF
486 : LDPR_PREVAILING_DEF_IRONLY
);
488 res
= (lsym
->object()->pluginobj() != NULL
490 : LDPR_PREEMPTED_REG
);
492 isym
->resolution
= res
;
497 // Return TRUE if the comdat group with key COMDAT_KEY from this object
501 Pluginobj::include_comdat_group(std::string comdat_key
, Layout
* layout
)
503 std::pair
<Comdat_map::iterator
, bool> ins
=
504 this->comdat_map_
.insert(std::make_pair(comdat_key
, false));
506 // If this is the first time we've seen this comdat key, ask the
507 // layout object whether it should be included.
509 ins
.first
->second
= layout
->add_comdat(NULL
, 1, comdat_key
, true);
511 return ins
.first
->second
;
514 // Class Sized_pluginobj.
516 template<int size
, bool big_endian
>
517 Sized_pluginobj
<size
, big_endian
>::Sized_pluginobj(
518 const std::string
& name
,
519 Input_file
* input_file
,
522 : Pluginobj(name
, input_file
, offset
, filesize
)
526 // Read the symbols. Not used for plugin objects.
528 template<int size
, bool big_endian
>
530 Sized_pluginobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
535 // Lay out the input sections. Not used for plugin objects.
537 template<int size
, bool big_endian
>
539 Sized_pluginobj
<size
, big_endian
>::do_layout(Symbol_table
*, Layout
*,
545 // Add the symbols to the symbol table.
547 template<int size
, bool big_endian
>
549 Sized_pluginobj
<size
, big_endian
>::do_add_symbols(Symbol_table
*,
555 template<int size
, bool big_endian
>
557 Sized_pluginobj
<size
, big_endian
>::do_add_symbols(Symbol_table
* symtab
,
560 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
561 unsigned char symbuf
[sym_size
];
562 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
563 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
565 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
567 this->symbols_
.resize(this->nsyms_
);
569 for (int i
= 0; i
< this->nsyms_
; ++i
)
571 const struct ld_plugin_symbol
*isym
= &this->syms_
[i
];
572 const char* name
= isym
->name
;
573 const char* ver
= isym
->version
;
574 elfcpp::Elf_Half shndx
;
578 if (name
!= NULL
&& name
[0] == '\0')
580 if (ver
!= NULL
&& ver
[0] == '\0')
587 bind
= elfcpp::STB_WEAK
;
593 bind
= elfcpp::STB_GLOBAL
;
601 shndx
= elfcpp::SHN_ABS
;
604 shndx
= elfcpp::SHN_COMMON
;
609 shndx
= elfcpp::SHN_UNDEF
;
613 switch (isym
->visibility
)
616 vis
= elfcpp::STV_DEFAULT
;
619 vis
= elfcpp::STV_DEFAULT
;
622 vis
= elfcpp::STV_DEFAULT
;
626 vis
= elfcpp::STV_DEFAULT
;
630 if (isym
->comdat_key
!= NULL
631 && isym
->comdat_key
[0] != '\0'
632 && !this->include_comdat_group(isym
->comdat_key
, layout
))
633 shndx
= elfcpp::SHN_UNDEF
;
636 osym
.put_st_value(0);
637 osym
.put_st_size(static_cast<Elf_size_type
>(isym
->size
));
638 osym
.put_st_info(bind
, elfcpp::STT_NOTYPE
);
639 osym
.put_st_other(vis
, 0);
640 osym
.put_st_shndx(shndx
);
643 symtab
->add_from_pluginobj
<size
, big_endian
>(this, name
, ver
, &sym
);
647 // Get the size of a section. Not used for plugin objects.
649 template<int size
, bool big_endian
>
651 Sized_pluginobj
<size
, big_endian
>::do_section_size(unsigned int)
657 // Get the name of a section. Not used for plugin objects.
659 template<int size
, bool big_endian
>
661 Sized_pluginobj
<size
, big_endian
>::do_section_name(unsigned int)
664 return std::string();
667 // Return a view of the contents of a section. Not used for plugin objects.
669 template<int size
, bool big_endian
>
671 Sized_pluginobj
<size
, big_endian
>::do_section_contents(unsigned int)
679 // Return section flags. Not used for plugin objects.
681 template<int size
, bool big_endian
>
683 Sized_pluginobj
<size
, big_endian
>::do_section_flags(unsigned int)
689 // Return section address. Not used for plugin objects.
691 template<int size
, bool big_endian
>
693 Sized_pluginobj
<size
, big_endian
>::do_section_address(unsigned int)
699 // Return section type. Not used for plugin objects.
701 template<int size
, bool big_endian
>
703 Sized_pluginobj
<size
, big_endian
>::do_section_type(unsigned int)
709 // Return the section link field. Not used for plugin objects.
711 template<int size
, bool big_endian
>
713 Sized_pluginobj
<size
, big_endian
>::do_section_link(unsigned int)
719 // Return the section link field. Not used for plugin objects.
721 template<int size
, bool big_endian
>
723 Sized_pluginobj
<size
, big_endian
>::do_section_info(unsigned int)
729 // Return the section alignment. Not used for plugin objects.
731 template<int size
, bool big_endian
>
733 Sized_pluginobj
<size
, big_endian
>::do_section_addralign(unsigned int)
739 // Return the Xindex structure to use. Not used for plugin objects.
741 template<int size
, bool big_endian
>
743 Sized_pluginobj
<size
, big_endian
>::do_initialize_xindex()
749 // Get symbol counts. Not used for plugin objects.
751 template<int size
, bool big_endian
>
753 Sized_pluginobj
<size
, big_endian
>::do_get_global_symbol_counts(const Symbol_table
*,
754 size_t*, size_t*) const
759 // Class Add_plugin_symbols.
761 Add_plugin_symbols::~Add_plugin_symbols()
763 if (this->this_blocker_
!= NULL
)
764 delete this->this_blocker_
;
765 // next_blocker_ is deleted by the task associated with the next
769 // We are blocked by this_blocker_. We block next_blocker_. We also
773 Add_plugin_symbols::is_runnable()
775 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
776 return this->this_blocker_
;
777 if (this->obj_
->is_locked())
778 return this->obj_
->token();
783 Add_plugin_symbols::locks(Task_locker
* tl
)
785 tl
->add(this, this->next_blocker_
);
786 tl
->add(this, this->obj_
->token());
789 // Add the symbols in the object to the symbol table.
792 Add_plugin_symbols::run(Workqueue
*)
794 this->obj_
->add_symbols(this->symtab_
, this->layout_
);
797 // Class Plugin_finish. This task runs after all replacement files have
798 // been added. It calls Layout::layout for any deferred sections and
799 // calls each plugin's cleanup handler.
801 class Plugin_finish
: public Task
804 Plugin_finish(Task_token
* this_blocker
, Task_token
* next_blocker
)
805 : this_blocker_(this_blocker
), next_blocker_(next_blocker
)
810 if (this->this_blocker_
!= NULL
)
811 delete this->this_blocker_
;
817 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
818 return this->this_blocker_
;
823 locks(Task_locker
* tl
)
824 { tl
->add(this, this->next_blocker_
); }
829 Plugin_manager
* plugins
= parameters
->options().plugins();
830 gold_assert(plugins
!= NULL
);
831 plugins
->layout_deferred_objects();
837 { return "Plugin_finish"; }
840 Task_token
* this_blocker_
;
841 Task_token
* next_blocker_
;
844 // Class Plugin_hook.
846 Plugin_hook::~Plugin_hook()
850 // Return whether a Plugin_hook task is runnable.
853 Plugin_hook::is_runnable()
855 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
856 return this->this_blocker_
;
860 // Return a Task_locker for a Plugin_hook task. We don't need any
864 Plugin_hook::locks(Task_locker
*)
868 // Run the "all symbols read" plugin hook.
871 Plugin_hook::run(Workqueue
* workqueue
)
873 gold_assert(this->options_
.has_plugins());
874 this->options_
.plugins()->all_symbols_read(workqueue
,
876 this->input_objects_
,
881 &this->this_blocker_
);
882 workqueue
->queue_soon(new Plugin_finish(this->this_blocker_
,
883 this->next_blocker_
));
886 // The C interface routines called by the plugins.
888 #ifdef ENABLE_PLUGINS
890 // Register a claim-file handler.
892 static enum ld_plugin_status
893 register_claim_file(ld_plugin_claim_file_handler handler
)
895 gold_assert(parameters
->options().has_plugins());
896 parameters
->options().plugins()->set_claim_file_handler(handler
);
900 // Register an all-symbols-read handler.
902 static enum ld_plugin_status
903 register_all_symbols_read(ld_plugin_all_symbols_read_handler handler
)
905 gold_assert(parameters
->options().has_plugins());
906 parameters
->options().plugins()->set_all_symbols_read_handler(handler
);
910 // Register a cleanup handler.
912 static enum ld_plugin_status
913 register_cleanup(ld_plugin_cleanup_handler handler
)
915 gold_assert(parameters
->options().has_plugins());
916 parameters
->options().plugins()->set_cleanup_handler(handler
);
920 // Add symbols from a plugin-claimed input file.
922 static enum ld_plugin_status
923 add_symbols(void* handle
, int nsyms
, const ld_plugin_symbol
*syms
)
925 gold_assert(parameters
->options().has_plugins());
926 Pluginobj
* obj
= parameters
->options().plugins()->make_plugin_object(
927 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
)));
930 obj
->store_incoming_symbols(nsyms
, syms
);
934 // Get the input file information with an open (possibly re-opened)
937 static enum ld_plugin_status
938 get_input_file(const void *handle
, struct ld_plugin_input_file
*file
)
940 gold_assert(parameters
->options().has_plugins());
941 unsigned int obj_index
=
942 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
));
943 return parameters
->options().plugins()->get_input_file(obj_index
, file
);
946 // Release the input file.
948 static enum ld_plugin_status
949 release_input_file(const void *handle
)
951 gold_assert(parameters
->options().has_plugins());
952 unsigned int obj_index
=
953 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
));
954 return parameters
->options().plugins()->release_input_file(obj_index
);
957 // Get the symbol resolution info for a plugin-claimed input file.
959 static enum ld_plugin_status
960 get_symbols(const void * handle
, int nsyms
, ld_plugin_symbol
* syms
)
962 gold_assert(parameters
->options().has_plugins());
963 Pluginobj
* obj
= parameters
->options().plugins()->object(
964 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle
)));
967 return obj
->get_symbol_resolution_info(nsyms
, syms
);
970 // Add a new (real) input file generated by a plugin.
972 static enum ld_plugin_status
973 add_input_file(char *pathname
)
975 gold_assert(parameters
->options().has_plugins());
976 return parameters
->options().plugins()->add_input_file(pathname
);
979 // Issue a diagnostic message from a plugin.
981 static enum ld_plugin_status
982 message(int level
, const char * format
, ...)
985 va_start(args
, format
);
990 parameters
->errors()->info(format
, args
);
993 parameters
->errors()->warning(format
, args
);
997 parameters
->errors()->error(format
, args
);
1000 parameters
->errors()->fatal(format
, args
);
1008 #endif // ENABLE_PLUGINS
1010 // Allocate a Pluginobj object of the appropriate size and endianness.
1013 make_sized_plugin_object(Input_file
* input_file
, off_t offset
, off_t filesize
)
1016 Pluginobj
* obj
= NULL
;
1018 if (parameters
->target_valid())
1019 target
= const_cast<Target
*>(¶meters
->target());
1021 target
= const_cast<Target
*>(¶meters
->default_target());
1023 if (target
->get_size() == 32)
1025 if (target
->is_big_endian())
1026 #ifdef HAVE_TARGET_32_BIG
1027 obj
= new Sized_pluginobj
<32, true>(input_file
->filename(),
1028 input_file
, offset
, filesize
);
1030 gold_error(_("%s: not configured to support "
1031 "32-bit big-endian object"),
1032 input_file
->filename().c_str());
1035 #ifdef HAVE_TARGET_32_LITTLE
1036 obj
= new Sized_pluginobj
<32, false>(input_file
->filename(),
1037 input_file
, offset
, filesize
);
1039 gold_error(_("%s: not configured to support "
1040 "32-bit little-endian object"),
1041 input_file
->filename().c_str());
1044 else if (target
->get_size() == 64)
1046 if (target
->is_big_endian())
1047 #ifdef HAVE_TARGET_64_BIG
1048 obj
= new Sized_pluginobj
<64, true>(input_file
->filename(),
1049 input_file
, offset
, filesize
);
1051 gold_error(_("%s: not configured to support "
1052 "64-bit big-endian object"),
1053 input_file
->filename().c_str());
1056 #ifdef HAVE_TARGET_64_LITTLE
1057 obj
= new Sized_pluginobj
<64, false>(input_file
->filename(),
1058 input_file
, offset
, filesize
);
1060 gold_error(_("%s: not configured to support "
1061 "64-bit little-endian object"),
1062 input_file
->filename().c_str());
1066 gold_assert(obj
!= NULL
);
1067 obj
->set_target(target
);
1071 } // End namespace gold.