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(const char *pathname);
80 static enum ld_plugin_status
81 add_input_library(const char *pathname);
83 static enum ld_plugin_status
84 set_extra_library_path(const char *path);
86 static enum ld_plugin_status
87 message(int level, const char *format, ...);
91 #endif // ENABLE_PLUGINS
93 static Pluginobj* make_sized_plugin_object(Input_file* input_file,
94 off_t offset, off_t filesize);
98 // Load one plugin library.
103 #ifdef ENABLE_PLUGINS
104 // Load the plugin library.
105 // FIXME: Look for the library in standard locations.
106 this->handle_ = dlopen(this->filename_.c_str(), RTLD_NOW);
107 if (this->handle_ == NULL)
109 gold_error(_("%s: could not load plugin library: %s"),
110 this->filename_.c_str(), dlerror());
114 // Find the plugin's onload entry point.
115 void* ptr = dlsym(this->handle_, "onload");
118 gold_error(_("%s: could not find onload entry point"),
119 this->filename_.c_str());
122 ld_plugin_onload onload;
123 gold_assert(sizeof(onload) == sizeof(ptr));
124 memcpy(&onload, &ptr, sizeof(ptr));
126 // Get the linker's version number.
127 const char* ver = get_version_string();
130 sscanf(ver, "%d.%d", &major, &minor);
132 // Allocate and populate a transfer vector.
133 const int tv_fixed_size = 16;
134 int tv_size = this->args_.size() + tv_fixed_size;
135 ld_plugin_tv* tv = new ld_plugin_tv[tv_size];
137 // Put LDPT_MESSAGE at the front of the list so the plugin can use it
138 // while processing subsequent entries.
140 tv[i].tv_tag = LDPT_MESSAGE;
141 tv[i].tv_u.tv_message = message;
144 tv[i].tv_tag = LDPT_API_VERSION;
145 tv[i].tv_u.tv_val = LD_PLUGIN_API_VERSION;
148 tv[i].tv_tag = LDPT_GOLD_VERSION;
149 tv[i].tv_u.tv_val = major * 100 + minor;
152 tv[i].tv_tag = LDPT_LINKER_OUTPUT;
153 if (parameters->options().relocatable())
154 tv[i].tv_u.tv_val = LDPO_REL;
155 else if (parameters->options().shared())
156 tv[i].tv_u.tv_val = LDPO_DYN;
158 tv[i].tv_u.tv_val = LDPO_EXEC;
161 tv[i].tv_tag = LDPT_OUTPUT_NAME;
162 tv[i].tv_u.tv_string = parameters->options().output();
164 for (unsigned int j = 0; j < this->args_.size(); ++j)
167 tv[i].tv_tag = LDPT_OPTION;
168 tv[i].tv_u.tv_string = this->args_[j].c_str();
172 tv[i].tv_tag = LDPT_REGISTER_CLAIM_FILE_HOOK;
173 tv[i].tv_u.tv_register_claim_file = register_claim_file;
176 tv[i].tv_tag = LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK;
177 tv[i].tv_u.tv_register_all_symbols_read = register_all_symbols_read;
180 tv[i].tv_tag = LDPT_REGISTER_CLEANUP_HOOK;
181 tv[i].tv_u.tv_register_cleanup = register_cleanup;
184 tv[i].tv_tag = LDPT_ADD_SYMBOLS;
185 tv[i].tv_u.tv_add_symbols = add_symbols;
188 tv[i].tv_tag = LDPT_GET_INPUT_FILE;
189 tv[i].tv_u.tv_get_input_file = get_input_file;
192 tv[i].tv_tag = LDPT_RELEASE_INPUT_FILE;
193 tv[i].tv_u.tv_release_input_file = release_input_file;
196 tv[i].tv_tag = LDPT_GET_SYMBOLS;
197 tv[i].tv_u.tv_get_symbols = get_symbols;
200 tv[i].tv_tag = LDPT_ADD_INPUT_FILE;
201 tv[i].tv_u.tv_add_input_file = add_input_file;
204 tv[i].tv_tag = LDPT_ADD_INPUT_LIBRARY;
205 tv[i].tv_u.tv_add_input_library = add_input_library;
208 tv[i].tv_tag = LDPT_SET_EXTRA_LIBRARY_PATH;
209 tv[i].tv_u.tv_set_extra_library_path = set_extra_library_path;
212 tv[i].tv_tag = LDPT_NULL;
213 tv[i].tv_u.tv_val = 0;
215 gold_assert(i == tv_size - 1);
217 // Call the onload entry point.
221 #endif // ENABLE_PLUGINS
224 // Call the plugin claim-file handler.
227 Plugin::claim_file(struct ld_plugin_input_file* plugin_input_file)
231 if (this->claim_file_handler_ != NULL)
233 (*this->claim_file_handler_)(plugin_input_file, &claimed);
240 // Call the all-symbols-read handler.
243 Plugin::all_symbols_read()
245 if (this->all_symbols_read_handler_ != NULL)
246 (*this->all_symbols_read_handler_)();
249 // Call the cleanup handler.
254 if (this->cleanup_handler_ != NULL && !this->cleanup_done_)
256 // Set this flag before calling to prevent a recursive plunge
257 // in the event that a plugin's cleanup handler issues a
259 this->cleanup_done_ = true;
260 (*this->cleanup_handler_)();
264 // Plugin_manager methods.
266 Plugin_manager::~Plugin_manager()
268 for (Plugin_list::iterator p = this->plugins_.begin();
269 p != this->plugins_.end();
272 this->plugins_.clear();
273 for (Object_list::iterator obj = this->objects_.begin();
274 obj != this->objects_.end();
277 this->objects_.clear();
280 // Load all plugin libraries.
283 Plugin_manager::load_plugins()
285 for (this->current_ = this->plugins_.begin();
286 this->current_ != this->plugins_.end();
288 (*this->current_)->load();
291 // Call the plugin claim-file handlers in turn to see if any claim the file.
294 Plugin_manager::claim_file(Input_file* input_file, off_t offset,
297 if (this->in_replacement_phase_)
300 unsigned int handle = this->objects_.size();
301 this->input_file_ = input_file;
302 this->plugin_input_file_.name = input_file->filename().c_str();
303 this->plugin_input_file_.fd = input_file->file().descriptor();
304 this->plugin_input_file_.offset = offset;
305 this->plugin_input_file_.filesize = filesize;
306 this->plugin_input_file_.handle = reinterpret_cast<void*>(handle);
308 for (this->current_ = this->plugins_.begin();
309 this->current_ != this->plugins_.end();
312 if ((*this->current_)->claim_file(&this->plugin_input_file_))
314 if (this->objects_.size() > handle)
315 return this->objects_[handle];
317 // If the plugin claimed the file but did not call the
318 // add_symbols callback, we need to create the Pluginobj now.
319 Pluginobj* obj = this->make_plugin_object(handle);
327 // Call the all-symbols-read handlers.
330 Plugin_manager::all_symbols_read(Workqueue* workqueue, Task* task,
331 Input_objects* input_objects,
332 Symbol_table* symtab, Layout* layout,
333 Dirsearch* dirpath, Mapfile* mapfile,
334 Task_token** last_blocker)
336 this->in_replacement_phase_ = true;
337 this->workqueue_ = workqueue;
339 this->input_objects_ = input_objects;
340 this->symtab_ = symtab;
341 this->layout_ = layout;
342 this->dirpath_ = dirpath;
343 this->mapfile_ = mapfile;
344 this->this_blocker_ = NULL;
346 for (this->current_ = this->plugins_.begin();
347 this->current_ != this->plugins_.end();
349 (*this->current_)->all_symbols_read();
351 *last_blocker = this->this_blocker_;
354 // Layout deferred objects.
357 Plugin_manager::layout_deferred_objects()
359 Deferred_layout_list::iterator obj;
361 for (obj = this->deferred_layout_objects_.begin();
362 obj != this->deferred_layout_objects_.end();
365 // Lock the object so we can read from it. This is only called
366 // single-threaded from queue_middle_tasks, so it is OK to lock.
367 // Unfortunately we have no way to pass in a Task token.
368 const Task* dummy_task = reinterpret_cast<const Task*>(-1);
369 Task_lock_obj<Object> tl(dummy_task, *obj);
370 (*obj)->layout_deferred_sections(this->layout_);
374 // Call the cleanup handlers.
377 Plugin_manager::cleanup()
379 for (this->current_ = this->plugins_.begin();
380 this->current_ != this->plugins_.end();
382 (*this->current_)->cleanup();
385 // Make a new Pluginobj object. This is called when the plugin calls
386 // the add_symbols API.
389 Plugin_manager::make_plugin_object(unsigned int handle)
391 // Make sure we aren't asked to make an object for the same handle twice.
392 if (this->objects_.size() != handle)
395 Pluginobj* obj = make_sized_plugin_object(this->input_file_,
396 this->plugin_input_file_.offset,
397 this->plugin_input_file_.filesize);
398 this->objects_.push_back(obj);
402 // Get the input file information with an open (possibly re-opened)
406 Plugin_manager::get_input_file(unsigned int handle,
407 struct ld_plugin_input_file* file)
409 Pluginobj* obj = this->object(handle);
411 return LDPS_BAD_HANDLE;
413 obj->lock(this->task_);
414 file->name = obj->filename().c_str();
415 file->fd = obj->descriptor();
416 file->offset = obj->offset();
417 file->filesize = obj->filesize();
418 file->handle = reinterpret_cast<void*>(handle);
422 // Release the input file.
425 Plugin_manager::release_input_file(unsigned int handle)
427 Pluginobj* obj = this->object(handle);
429 return LDPS_BAD_HANDLE;
431 obj->unlock(this->task_);
435 // Add a new library path.
438 Plugin_manager::set_extra_library_path(const char* path)
440 this->extra_search_path_ = std::string(path);
444 // Add a new input file.
447 Plugin_manager::add_input_file(const char* pathname, bool is_lib)
449 Input_file_argument file(pathname,
451 ? Input_file_argument::INPUT_FILE_TYPE_LIBRARY
452 : Input_file_argument::INPUT_FILE_TYPE_FILE),
454 ? this->extra_search_path_.c_str()
458 Input_argument* input_argument = new Input_argument(file);
459 Task_token* next_blocker = new Task_token(true);
460 next_blocker->add_blocker();
461 if (parameters->incremental())
462 gold_error(_("input files added by plug-ins in --incremental mode not "
464 this->workqueue_->queue_soon(new Read_symbols(this->input_objects_,
475 this->this_blocker_ = next_blocker;
481 Pluginobj::Pluginobj(const std::string& name, Input_file* input_file,
482 off_t offset, off_t filesize)
483 : Object(name, input_file, false, offset),
484 nsyms_(0), syms_(NULL), symbols_(), filesize_(filesize), comdat_map_()
488 // Return TRUE if a defined symbol might be reachable from outside the
489 // universe of claimed objects.
492 is_visible_from_outside(Symbol* lsym)
494 if (lsym->in_real_elf())
496 if (parameters->options().relocatable())
498 if (parameters->options().export_dynamic() || parameters->options().shared())
499 return lsym->is_externally_visible();
503 // Get symbol resolution info.
506 Pluginobj::get_symbol_resolution_info(int nsyms, ld_plugin_symbol* syms) const
508 if (nsyms > this->nsyms_)
511 if (static_cast<size_t>(nsyms) > this->symbols_.size())
513 // We never decided to include this object. We mark all symbols as
515 gold_assert(this->symbols_.size() == 0);
516 for (int i = 0; i < nsyms; i++)
517 syms[i].resolution = LDPR_PREEMPTED_REG;
521 for (int i = 0; i < nsyms; i++)
523 ld_plugin_symbol* isym = &syms[i];
524 Symbol* lsym = this->symbols_[i];
525 ld_plugin_symbol_resolution res = LDPR_UNKNOWN;
527 if (lsym->is_undefined())
528 // The symbol remains undefined.
530 else if (isym->def == LDPK_UNDEF
531 || isym->def == LDPK_WEAKUNDEF
532 || isym->def == LDPK_COMMON)
534 // The original symbol was undefined or common.
535 if (lsym->source() != Symbol::FROM_OBJECT)
536 res = LDPR_RESOLVED_EXEC;
537 else if (lsym->object()->pluginobj() == this)
538 res = (is_visible_from_outside(lsym)
539 ? LDPR_PREVAILING_DEF
540 : LDPR_PREVAILING_DEF_IRONLY);
541 else if (lsym->object()->pluginobj() != NULL)
542 res = LDPR_RESOLVED_IR;
543 else if (lsym->object()->is_dynamic())
544 res = LDPR_RESOLVED_DYN;
546 res = LDPR_RESOLVED_EXEC;
550 // The original symbol was a definition.
551 if (lsym->source() != Symbol::FROM_OBJECT)
552 res = LDPR_PREEMPTED_REG;
553 else if (lsym->object() == static_cast<const Object*>(this))
554 res = (is_visible_from_outside(lsym)
555 ? LDPR_PREVAILING_DEF
556 : LDPR_PREVAILING_DEF_IRONLY);
558 res = (lsym->object()->pluginobj() != NULL
560 : LDPR_PREEMPTED_REG);
562 isym->resolution = res;
567 // Return TRUE if the comdat group with key COMDAT_KEY from this object
571 Pluginobj::include_comdat_group(std::string comdat_key, Layout* layout)
573 std::pair<Comdat_map::iterator, bool> ins =
574 this->comdat_map_.insert(std::make_pair(comdat_key, false));
576 // If this is the first time we've seen this comdat key, ask the
577 // layout object whether it should be included.
579 ins.first->second = layout->find_or_add_kept_section(comdat_key,
583 return ins.first->second;
586 // Class Sized_pluginobj.
588 template<int size, bool big_endian>
589 Sized_pluginobj<size, big_endian>::Sized_pluginobj(
590 const std::string& name,
591 Input_file* input_file,
594 : Pluginobj(name, input_file, offset, filesize)
598 // Read the symbols. Not used for plugin objects.
600 template<int size, bool big_endian>
602 Sized_pluginobj<size, big_endian>::do_read_symbols(Read_symbols_data*)
607 // Lay out the input sections. Not used for plugin objects.
609 template<int size, bool big_endian>
611 Sized_pluginobj<size, big_endian>::do_layout(Symbol_table*, Layout*,
617 // Add the symbols to the symbol table.
619 template<int size, bool big_endian>
621 Sized_pluginobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
625 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
626 unsigned char symbuf[sym_size];
627 elfcpp::Sym<size, big_endian> sym(symbuf);
628 elfcpp::Sym_write<size, big_endian> osym(symbuf);
630 typedef typename elfcpp::Elf_types<size>::Elf_WXword Elf_size_type;
632 this->symbols_.resize(this->nsyms_);
634 for (int i = 0; i < this->nsyms_; ++i)
636 const struct ld_plugin_symbol* isym = &this->syms_[i];
637 const char* name = isym->name;
638 const char* ver = isym->version;
639 elfcpp::Elf_Half shndx;
643 if (name != NULL && name[0] == '\0')
645 if (ver != NULL && ver[0] == '\0')
652 bind = elfcpp::STB_WEAK;
658 bind = elfcpp::STB_GLOBAL;
666 shndx = elfcpp::SHN_ABS;
669 shndx = elfcpp::SHN_COMMON;
674 shndx = elfcpp::SHN_UNDEF;
678 switch (isym->visibility)
681 vis = elfcpp::STV_PROTECTED;
684 vis = elfcpp::STV_INTERNAL;
687 vis = elfcpp::STV_HIDDEN;
691 vis = elfcpp::STV_DEFAULT;
695 if (isym->comdat_key != NULL
696 && isym->comdat_key[0] != '\0'
697 && !this->include_comdat_group(isym->comdat_key, layout))
698 shndx = elfcpp::SHN_UNDEF;
701 osym.put_st_value(0);
702 osym.put_st_size(static_cast<Elf_size_type>(isym->size));
703 osym.put_st_info(bind, elfcpp::STT_NOTYPE);
704 osym.put_st_other(vis, 0);
705 osym.put_st_shndx(shndx);
708 symtab->add_from_pluginobj<size, big_endian>(this, name, ver, &sym);
712 template<int size, bool big_endian>
713 Archive::Should_include
714 Sized_pluginobj<size, big_endian>::do_should_include_member(
715 Symbol_table* symtab,
721 size_t tmpbuflen = 0;
723 for (int i = 0; i < this->nsyms_; ++i)
725 const struct ld_plugin_symbol& sym = this->syms_[i];
726 const char* name = sym.name;
728 Archive::Should_include t = Archive::should_include_member(symtab,
734 if (t == Archive::SHOULD_INCLUDE_YES)
743 return Archive::SHOULD_INCLUDE_UNKNOWN;
746 // Get the size of a section. Not used for plugin objects.
748 template<int size, bool big_endian>
750 Sized_pluginobj<size, big_endian>::do_section_size(unsigned int)
756 // Get the name of a section. Not used for plugin objects.
758 template<int size, bool big_endian>
760 Sized_pluginobj<size, big_endian>::do_section_name(unsigned int)
763 return std::string();
766 // Return a view of the contents of a section. Not used for plugin objects.
768 template<int size, bool big_endian>
770 Sized_pluginobj<size, big_endian>::do_section_contents(unsigned int)
778 // Return section flags. Not used for plugin objects.
780 template<int size, bool big_endian>
782 Sized_pluginobj<size, big_endian>::do_section_flags(unsigned int)
788 // Return section entsize. Not used for plugin objects.
790 template<int size, bool big_endian>
792 Sized_pluginobj<size, big_endian>::do_section_entsize(unsigned int)
798 // Return section address. Not used for plugin objects.
800 template<int size, bool big_endian>
802 Sized_pluginobj<size, big_endian>::do_section_address(unsigned int)
808 // Return section type. Not used for plugin objects.
810 template<int size, bool big_endian>
812 Sized_pluginobj<size, big_endian>::do_section_type(unsigned int)
818 // Return the section link field. Not used for plugin objects.
820 template<int size, bool big_endian>
822 Sized_pluginobj<size, big_endian>::do_section_link(unsigned int)
828 // Return the section link field. Not used for plugin objects.
830 template<int size, bool big_endian>
832 Sized_pluginobj<size, big_endian>::do_section_info(unsigned int)
838 // Return the section alignment. Not used for plugin objects.
840 template<int size, bool big_endian>
842 Sized_pluginobj<size, big_endian>::do_section_addralign(unsigned int)
848 // Return the Xindex structure to use. Not used for plugin objects.
850 template<int size, bool big_endian>
852 Sized_pluginobj<size, big_endian>::do_initialize_xindex()
858 // Get symbol counts. Not used for plugin objects.
860 template<int size, bool big_endian>
862 Sized_pluginobj<size, big_endian>::do_get_global_symbol_counts(const Symbol_table*,
863 size_t*, size_t*) const
868 // Get symbols. Not used for plugin objects.
870 template<int size, bool big_endian>
871 const Object::Symbols*
872 Sized_pluginobj<size, big_endian>::do_get_global_symbols() const
877 // Class Plugin_finish. This task runs after all replacement files have
878 // been added. For now, it's a placeholder for a possible plugin API
879 // to allow the plugin to release most of its resources. The cleanup
880 // handlers must be called later, because they can remove the temporary
881 // object files that are needed until the end of the link.
883 class Plugin_finish : public Task
886 Plugin_finish(Task_token* this_blocker, Task_token* next_blocker)
887 : this_blocker_(this_blocker), next_blocker_(next_blocker)
892 if (this->this_blocker_ != NULL)
893 delete this->this_blocker_;
899 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
900 return this->this_blocker_;
905 locks(Task_locker* tl)
906 { tl->add(this, this->next_blocker_); }
911 // We could call early cleanup handlers here.
916 { return "Plugin_finish"; }
919 Task_token* this_blocker_;
920 Task_token* next_blocker_;
923 // Class Plugin_hook.
925 Plugin_hook::~Plugin_hook()
929 // Return whether a Plugin_hook task is runnable.
932 Plugin_hook::is_runnable()
934 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
935 return this->this_blocker_;
939 // Return a Task_locker for a Plugin_hook task. We don't need any
943 Plugin_hook::locks(Task_locker*)
947 // Run the "all symbols read" plugin hook.
950 Plugin_hook::run(Workqueue* workqueue)
952 gold_assert(this->options_.has_plugins());
954 if (parameters->options().entry())
955 start_sym = this->symtab_->lookup(parameters->options().entry());
957 start_sym = this->symtab_->lookup("_start");
958 if (start_sym != NULL)
959 start_sym->set_in_real_elf();
961 this->options_.plugins()->all_symbols_read(workqueue,
963 this->input_objects_,
968 &this->this_blocker_);
969 workqueue->queue_soon(new Plugin_finish(this->this_blocker_,
970 this->next_blocker_));
973 // The C interface routines called by the plugins.
975 #ifdef ENABLE_PLUGINS
977 // Register a claim-file handler.
979 static enum ld_plugin_status
980 register_claim_file(ld_plugin_claim_file_handler handler)
982 gold_assert(parameters->options().has_plugins());
983 parameters->options().plugins()->set_claim_file_handler(handler);
987 // Register an all-symbols-read handler.
989 static enum ld_plugin_status
990 register_all_symbols_read(ld_plugin_all_symbols_read_handler handler)
992 gold_assert(parameters->options().has_plugins());
993 parameters->options().plugins()->set_all_symbols_read_handler(handler);
997 // Register a cleanup handler.
999 static enum ld_plugin_status
1000 register_cleanup(ld_plugin_cleanup_handler handler)
1002 gold_assert(parameters->options().has_plugins());
1003 parameters->options().plugins()->set_cleanup_handler(handler);
1007 // Add symbols from a plugin-claimed input file.
1009 static enum ld_plugin_status
1010 add_symbols(void* handle, int nsyms, const ld_plugin_symbol* syms)
1012 gold_assert(parameters->options().has_plugins());
1013 Pluginobj* obj = parameters->options().plugins()->make_plugin_object(
1014 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
1017 obj->store_incoming_symbols(nsyms, syms);
1021 // Get the input file information with an open (possibly re-opened)
1024 static enum ld_plugin_status
1025 get_input_file(const void* handle, struct ld_plugin_input_file* file)
1027 gold_assert(parameters->options().has_plugins());
1028 unsigned int obj_index =
1029 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle));
1030 return parameters->options().plugins()->get_input_file(obj_index, file);
1033 // Release the input file.
1035 static enum ld_plugin_status
1036 release_input_file(const void* handle)
1038 gold_assert(parameters->options().has_plugins());
1039 unsigned int obj_index =
1040 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle));
1041 return parameters->options().plugins()->release_input_file(obj_index);
1044 // Get the symbol resolution info for a plugin-claimed input file.
1046 static enum ld_plugin_status
1047 get_symbols(const void* handle, int nsyms, ld_plugin_symbol* syms)
1049 gold_assert(parameters->options().has_plugins());
1050 Pluginobj* obj = parameters->options().plugins()->object(
1051 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
1054 return obj->get_symbol_resolution_info(nsyms, syms);
1057 // Add a new (real) input file generated by a plugin.
1059 static enum ld_plugin_status
1060 add_input_file(const char* pathname)
1062 gold_assert(parameters->options().has_plugins());
1063 return parameters->options().plugins()->add_input_file(pathname, false);
1066 // Add a new (real) library required by a plugin.
1068 static enum ld_plugin_status
1069 add_input_library(const char* pathname)
1071 gold_assert(parameters->options().has_plugins());
1072 return parameters->options().plugins()->add_input_file(pathname, true);
1075 // Set the extra library path to be used by libraries added via
1076 // add_input_library
1078 static enum ld_plugin_status
1079 set_extra_library_path(const char* path)
1081 gold_assert(parameters->options().has_plugins());
1082 return parameters->options().plugins()->set_extra_library_path(path);
1085 // Issue a diagnostic message from a plugin.
1087 static enum ld_plugin_status
1088 message(int level, const char* format, ...)
1091 va_start(args, format);
1096 parameters->errors()->info(format, args);
1099 parameters->errors()->warning(format, args);
1103 parameters->errors()->error(format, args);
1106 parameters->errors()->fatal(format, args);
1114 #endif // ENABLE_PLUGINS
1116 // Allocate a Pluginobj object of the appropriate size and endianness.
1119 make_sized_plugin_object(Input_file* input_file, off_t offset, off_t filesize)
1121 Pluginobj* obj = NULL;
1123 parameters_force_valid_target();
1124 const Target& target(parameters->target());
1126 if (target.get_size() == 32)
1128 if (target.is_big_endian())
1129 #ifdef HAVE_TARGET_32_BIG
1130 obj = new Sized_pluginobj<32, true>(input_file->filename(),
1131 input_file, offset, filesize);
1133 gold_error(_("%s: not configured to support "
1134 "32-bit big-endian object"),
1135 input_file->filename().c_str());
1138 #ifdef HAVE_TARGET_32_LITTLE
1139 obj = new Sized_pluginobj<32, false>(input_file->filename(),
1140 input_file, offset, filesize);
1142 gold_error(_("%s: not configured to support "
1143 "32-bit little-endian object"),
1144 input_file->filename().c_str());
1147 else if (target.get_size() == 64)
1149 if (target.is_big_endian())
1150 #ifdef HAVE_TARGET_64_BIG
1151 obj = new Sized_pluginobj<64, true>(input_file->filename(),
1152 input_file, offset, filesize);
1154 gold_error(_("%s: not configured to support "
1155 "64-bit big-endian object"),
1156 input_file->filename().c_str());
1159 #ifdef HAVE_TARGET_64_LITTLE
1160 obj = new Sized_pluginobj<64, false>(input_file->filename(),
1161 input_file, offset, filesize);
1163 gold_error(_("%s: not configured to support "
1164 "64-bit little-endian object"),
1165 input_file->filename().c_str());
1169 gold_assert(obj != NULL);
1173 } // End namespace gold.