1 // plugin.cc -- plugin manager for gold -*- C++ -*-
3 // Copyright (C) 2008-2017 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.
34 #elif defined (HAVE_WINDOWS_H)
37 #error Unknown how to handle dynamic-load-libraries.
40 #if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
42 #define RTLD_NOW 0 /* Dummy value. */
44 dlopen(const char *file, int mode ATTRIBUTE_UNUSED)
46 return LoadLibrary(file);
50 dlsym(void *handle, const char *name)
52 return reinterpret_cast<void *>(
53 GetProcAddress(static_cast<HMODULE>(handle),name));
59 return "unable to load dll";
62 #endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H) */
63 #endif /* ENABLE_PLUGINS */
65 #include "parameters.h"
74 #include "descriptors.h"
82 // The linker's exported interfaces.
87 static enum ld_plugin_status
88 register_claim_file(ld_plugin_claim_file_handler handler);
90 static enum ld_plugin_status
91 register_all_symbols_read(ld_plugin_all_symbols_read_handler handler);
93 static enum ld_plugin_status
94 register_cleanup(ld_plugin_cleanup_handler handler);
96 static enum ld_plugin_status
97 add_symbols(void *handle, int nsyms, const struct ld_plugin_symbol *syms);
99 static enum ld_plugin_status
100 get_input_file(const void *handle, struct ld_plugin_input_file *file);
102 static enum ld_plugin_status
103 get_view(const void *handle, const void **viewp);
105 static enum ld_plugin_status
106 release_input_file(const void *handle);
108 static enum ld_plugin_status
109 get_symbols(const void *handle, int nsyms, struct ld_plugin_symbol *syms);
111 static enum ld_plugin_status
112 get_symbols_v2(const void *handle, int nsyms, struct ld_plugin_symbol *syms);
114 static enum ld_plugin_status
115 get_symbols_v3(const void *handle, int nsyms, struct ld_plugin_symbol *syms);
117 static enum ld_plugin_status
118 add_input_file(const char *pathname);
120 static enum ld_plugin_status
121 add_input_library(const char *pathname);
123 static enum ld_plugin_status
124 set_extra_library_path(const char *path);
126 static enum ld_plugin_status
127 message(int level, const char *format, ...);
129 static enum ld_plugin_status
130 get_input_section_count(const void* handle, unsigned int* count);
132 static enum ld_plugin_status
133 get_input_section_type(const struct ld_plugin_section section,
136 static enum ld_plugin_status
137 get_input_section_name(const struct ld_plugin_section section,
138 char** section_name_ptr);
140 static enum ld_plugin_status
141 get_input_section_contents(const struct ld_plugin_section section,
142 const unsigned char** section_contents,
145 static enum ld_plugin_status
146 update_section_order(const struct ld_plugin_section *section_list,
147 unsigned int num_sections);
149 static enum ld_plugin_status
150 allow_section_ordering();
152 static enum ld_plugin_status
153 allow_unique_segment_for_sections();
155 static enum ld_plugin_status
156 unique_segment_for_sections(const char* segment_name,
159 const struct ld_plugin_section *section_list,
160 unsigned int num_sections);
162 static enum ld_plugin_status
163 get_input_section_alignment(const struct ld_plugin_section section,
164 unsigned int* addralign);
166 static enum ld_plugin_status
167 get_input_section_size(const struct ld_plugin_section section,
170 static enum ld_plugin_status
171 register_new_input(ld_plugin_new_input_handler handler);
175 #endif // ENABLE_PLUGINS
177 static Pluginobj* make_sized_plugin_object(Input_file* input_file,
178 off_t offset, off_t filesize);
182 // Load one plugin library.
187 #ifdef ENABLE_PLUGINS
188 // Load the plugin library.
189 // FIXME: Look for the library in standard locations.
190 this->handle_ = dlopen(this->filename_.c_str(), RTLD_NOW);
191 if (this->handle_ == NULL)
193 gold_error(_("%s: could not load plugin library: %s"),
194 this->filename_.c_str(), dlerror());
198 // Find the plugin's onload entry point.
199 void* ptr = dlsym(this->handle_, "onload");
202 gold_error(_("%s: could not find onload entry point"),
203 this->filename_.c_str());
206 ld_plugin_onload onload;
207 gold_assert(sizeof(onload) == sizeof(ptr));
208 memcpy(&onload, &ptr, sizeof(ptr));
210 // Get the linker's version number.
211 const char* ver = get_version_string();
214 sscanf(ver, "%d.%d", &major, &minor);
216 // Allocate and populate a transfer vector.
217 const int tv_fixed_size = 30;
219 int tv_size = this->args_.size() + tv_fixed_size;
220 ld_plugin_tv* tv = new ld_plugin_tv[tv_size];
222 // Put LDPT_MESSAGE at the front of the list so the plugin can use it
223 // while processing subsequent entries.
225 tv[i].tv_tag = LDPT_MESSAGE;
226 tv[i].tv_u.tv_message = message;
229 tv[i].tv_tag = LDPT_API_VERSION;
230 tv[i].tv_u.tv_val = LD_PLUGIN_API_VERSION;
233 tv[i].tv_tag = LDPT_GOLD_VERSION;
234 tv[i].tv_u.tv_val = major * 100 + minor;
237 tv[i].tv_tag = LDPT_LINKER_OUTPUT;
238 if (parameters->options().relocatable())
239 tv[i].tv_u.tv_val = LDPO_REL;
240 else if (parameters->options().shared())
241 tv[i].tv_u.tv_val = LDPO_DYN;
242 else if (parameters->options().pie())
243 tv[i].tv_u.tv_val = LDPO_PIE;
245 tv[i].tv_u.tv_val = LDPO_EXEC;
248 tv[i].tv_tag = LDPT_OUTPUT_NAME;
249 tv[i].tv_u.tv_string = parameters->options().output();
251 for (unsigned int j = 0; j < this->args_.size(); ++j)
254 tv[i].tv_tag = LDPT_OPTION;
255 tv[i].tv_u.tv_string = this->args_[j].c_str();
259 tv[i].tv_tag = LDPT_REGISTER_CLAIM_FILE_HOOK;
260 tv[i].tv_u.tv_register_claim_file = register_claim_file;
263 tv[i].tv_tag = LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK;
264 tv[i].tv_u.tv_register_all_symbols_read = register_all_symbols_read;
267 tv[i].tv_tag = LDPT_REGISTER_CLEANUP_HOOK;
268 tv[i].tv_u.tv_register_cleanup = register_cleanup;
271 tv[i].tv_tag = LDPT_ADD_SYMBOLS;
272 tv[i].tv_u.tv_add_symbols = add_symbols;
275 tv[i].tv_tag = LDPT_GET_INPUT_FILE;
276 tv[i].tv_u.tv_get_input_file = get_input_file;
279 tv[i].tv_tag = LDPT_GET_VIEW;
280 tv[i].tv_u.tv_get_view = get_view;
283 tv[i].tv_tag = LDPT_RELEASE_INPUT_FILE;
284 tv[i].tv_u.tv_release_input_file = release_input_file;
287 tv[i].tv_tag = LDPT_GET_SYMBOLS;
288 tv[i].tv_u.tv_get_symbols = get_symbols;
291 tv[i].tv_tag = LDPT_GET_SYMBOLS_V2;
292 tv[i].tv_u.tv_get_symbols = get_symbols_v2;
295 tv[i].tv_tag = LDPT_GET_SYMBOLS_V3;
296 tv[i].tv_u.tv_get_symbols = get_symbols_v3;
299 tv[i].tv_tag = LDPT_ADD_INPUT_FILE;
300 tv[i].tv_u.tv_add_input_file = add_input_file;
303 tv[i].tv_tag = LDPT_ADD_INPUT_LIBRARY;
304 tv[i].tv_u.tv_add_input_library = add_input_library;
307 tv[i].tv_tag = LDPT_SET_EXTRA_LIBRARY_PATH;
308 tv[i].tv_u.tv_set_extra_library_path = set_extra_library_path;
311 tv[i].tv_tag = LDPT_GET_INPUT_SECTION_COUNT;
312 tv[i].tv_u.tv_get_input_section_count = get_input_section_count;
315 tv[i].tv_tag = LDPT_GET_INPUT_SECTION_TYPE;
316 tv[i].tv_u.tv_get_input_section_type = get_input_section_type;
319 tv[i].tv_tag = LDPT_GET_INPUT_SECTION_NAME;
320 tv[i].tv_u.tv_get_input_section_name = get_input_section_name;
323 tv[i].tv_tag = LDPT_GET_INPUT_SECTION_CONTENTS;
324 tv[i].tv_u.tv_get_input_section_contents = get_input_section_contents;
327 tv[i].tv_tag = LDPT_UPDATE_SECTION_ORDER;
328 tv[i].tv_u.tv_update_section_order = update_section_order;
331 tv[i].tv_tag = LDPT_ALLOW_SECTION_ORDERING;
332 tv[i].tv_u.tv_allow_section_ordering = allow_section_ordering;
335 tv[i].tv_tag = LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS;
336 tv[i].tv_u.tv_allow_unique_segment_for_sections
337 = allow_unique_segment_for_sections;
340 tv[i].tv_tag = LDPT_UNIQUE_SEGMENT_FOR_SECTIONS;
341 tv[i].tv_u.tv_unique_segment_for_sections = unique_segment_for_sections;
344 tv[i].tv_tag = LDPT_GET_INPUT_SECTION_ALIGNMENT;
345 tv[i].tv_u.tv_get_input_section_alignment = get_input_section_alignment;
348 tv[i].tv_tag = LDPT_GET_INPUT_SECTION_SIZE;
349 tv[i].tv_u.tv_get_input_section_size = get_input_section_size;
352 tv[i].tv_tag = LDPT_REGISTER_NEW_INPUT_HOOK;
353 tv[i].tv_u.tv_register_new_input = register_new_input;
356 tv[i].tv_tag = LDPT_NULL;
357 tv[i].tv_u.tv_val = 0;
359 gold_assert(i == tv_size - 1);
361 // Call the onload entry point.
365 #endif // ENABLE_PLUGINS
368 // Call the plugin claim-file handler.
371 Plugin::claim_file(struct ld_plugin_input_file* plugin_input_file)
375 if (this->claim_file_handler_ != NULL)
377 (*this->claim_file_handler_)(plugin_input_file, &claimed);
384 // Call the all-symbols-read handler.
387 Plugin::all_symbols_read()
389 if (this->all_symbols_read_handler_ != NULL)
390 (*this->all_symbols_read_handler_)();
393 // Call the new_input handler.
396 Plugin::new_input(struct ld_plugin_input_file* plugin_input_file)
398 if (this->new_input_handler_ != NULL)
399 (*this->new_input_handler_)(plugin_input_file);
402 // Call the cleanup handler.
407 if (this->cleanup_handler_ != NULL && !this->cleanup_done_)
409 // Set this flag before calling to prevent a recursive plunge
410 // in the event that a plugin's cleanup handler issues a
412 this->cleanup_done_ = true;
413 (*this->cleanup_handler_)();
417 // This task is used to rescan archives as needed.
419 class Plugin_rescan : public Task
422 Plugin_rescan(Task_token* this_blocker, Task_token* next_blocker)
423 : this_blocker_(this_blocker), next_blocker_(next_blocker)
428 delete this->this_blocker_;
434 if (this->this_blocker_->is_blocked())
435 return this->this_blocker_;
440 locks(Task_locker* tl)
441 { tl->add(this, this->next_blocker_); }
445 { parameters->options().plugins()->rescan(this); }
449 { return "Plugin_rescan"; }
452 Task_token* this_blocker_;
453 Task_token* next_blocker_;
456 // Plugin_manager methods.
458 Plugin_manager::~Plugin_manager()
460 for (Plugin_list::iterator p = this->plugins_.begin();
461 p != this->plugins_.end();
464 this->plugins_.clear();
465 for (Object_list::iterator obj = this->objects_.begin();
466 obj != this->objects_.end();
469 this->objects_.clear();
473 // Load all plugin libraries.
476 Plugin_manager::load_plugins(Layout* layout)
478 this->layout_ = layout;
479 for (this->current_ = this->plugins_.begin();
480 this->current_ != this->plugins_.end();
482 (*this->current_)->load();
485 // Call the plugin claim-file handlers in turn to see if any claim the file.
488 Plugin_manager::claim_file(Input_file* input_file, off_t offset,
489 off_t filesize, Object* elf_object)
491 bool lock_initialized = this->initialize_lock_.initialize();
493 gold_assert(lock_initialized);
494 Hold_lock hl(*this->lock_);
496 unsigned int handle = this->objects_.size();
497 this->input_file_ = input_file;
498 this->plugin_input_file_.name = input_file->filename().c_str();
499 this->plugin_input_file_.fd = input_file->file().descriptor();
500 this->plugin_input_file_.offset = offset;
501 this->plugin_input_file_.filesize = filesize;
502 this->plugin_input_file_.handle = reinterpret_cast<void*>(handle);
503 if (elf_object != NULL)
504 this->objects_.push_back(elf_object);
505 this->in_claim_file_handler_ = true;
507 for (this->current_ = this->plugins_.begin();
508 this->current_ != this->plugins_.end();
511 // If we aren't yet in replacement phase, allow plugins to claim input
512 // files, otherwise notify the plugin of the new input file, if needed.
513 if (!this->in_replacement_phase_)
515 if ((*this->current_)->claim_file(&this->plugin_input_file_))
517 this->any_claimed_ = true;
518 this->in_claim_file_handler_ = false;
520 if (this->objects_.size() > handle
521 && this->objects_[handle]->pluginobj() != NULL)
522 return this->objects_[handle]->pluginobj();
524 // If the plugin claimed the file but did not call the
525 // add_symbols callback, we need to create the Pluginobj now.
526 Pluginobj* obj = this->make_plugin_object(handle);
532 (*this->current_)->new_input(&this->plugin_input_file_);
536 this->in_claim_file_handler_ = false;
540 // Save an archive. This is used so that a plugin can add a file
541 // which refers to a symbol which was not previously referenced. In
542 // that case we want to pretend that the symbol was referenced before,
543 // and pull in the archive object.
546 Plugin_manager::save_archive(Archive* archive)
548 if (this->in_replacement_phase_ || !this->any_claimed_)
551 this->rescannable_.push_back(Rescannable(archive));
554 // Save an Input_group. This is like save_archive.
557 Plugin_manager::save_input_group(Input_group* input_group)
559 if (this->in_replacement_phase_ || !this->any_claimed_)
562 this->rescannable_.push_back(Rescannable(input_group));
565 // Call the all-symbols-read handlers.
568 Plugin_manager::all_symbols_read(Workqueue* workqueue, Task* task,
569 Input_objects* input_objects,
570 Symbol_table* symtab,
571 Dirsearch* dirpath, Mapfile* mapfile,
572 Task_token** last_blocker)
574 this->in_replacement_phase_ = true;
575 this->workqueue_ = workqueue;
577 this->input_objects_ = input_objects;
578 this->symtab_ = symtab;
579 this->dirpath_ = dirpath;
580 this->mapfile_ = mapfile;
581 this->this_blocker_ = NULL;
583 for (this->current_ = this->plugins_.begin();
584 this->current_ != this->plugins_.end();
586 (*this->current_)->all_symbols_read();
588 if (this->any_added_)
590 Task_token* next_blocker = new Task_token(true);
591 next_blocker->add_blocker();
592 workqueue->queue(new Plugin_rescan(this->this_blocker_, next_blocker));
593 this->this_blocker_ = next_blocker;
596 *last_blocker = this->this_blocker_;
599 // This is called when we see a new undefined symbol. If we are in
600 // the replacement phase, this means that we may need to rescan some
601 // archives we have previously seen.
604 Plugin_manager::new_undefined_symbol(Symbol* sym)
606 if (this->in_replacement_phase_)
607 this->undefined_symbols_.push_back(sym);
610 // Rescan archives as needed. This handles the case where a new
611 // object file added by a plugin has an undefined reference to some
612 // symbol defined in an archive.
615 Plugin_manager::rescan(Task* task)
617 size_t rescan_pos = 0;
618 size_t rescan_size = this->rescannable_.size();
619 while (!this->undefined_symbols_.empty())
621 if (rescan_pos >= rescan_size)
623 this->undefined_symbols_.clear();
627 Undefined_symbol_list undefs;
628 undefs.reserve(this->undefined_symbols_.size());
629 this->undefined_symbols_.swap(undefs);
631 size_t min_rescan_pos = rescan_size;
633 for (Undefined_symbol_list::const_iterator p = undefs.begin();
637 if (!(*p)->is_undefined())
640 this->undefined_symbols_.push_back(*p);
642 // Find the first rescan archive which defines this symbol,
643 // starting at the current rescan position. The rescan position
644 // exists so that given -la -lb -lc we don't look for undefined
645 // symbols in -lb back in -la, but instead get the definition
646 // from -lc. Don't bother to look past the current minimum
648 for (size_t i = rescan_pos; i < min_rescan_pos; ++i)
650 if (this->rescannable_defines(i, *p))
658 if (min_rescan_pos >= rescan_size)
660 // We didn't find any rescannable archives which define any
661 // undefined symbols.
665 const Rescannable& r(this->rescannable_[min_rescan_pos]);
668 Task_lock_obj<Archive> tl(task, r.u.archive);
669 r.u.archive->add_symbols(this->symtab_, this->layout_,
670 this->input_objects_, this->mapfile_);
674 size_t next_saw_undefined = this->symtab_->saw_undefined();
675 size_t saw_undefined;
678 saw_undefined = next_saw_undefined;
680 for (Input_group::const_iterator p = r.u.input_group->begin();
681 p != r.u.input_group->end();
684 Task_lock_obj<Archive> tl(task, *p);
686 (*p)->add_symbols(this->symtab_, this->layout_,
687 this->input_objects_, this->mapfile_);
690 next_saw_undefined = this->symtab_->saw_undefined();
692 while (saw_undefined != next_saw_undefined);
695 for (size_t i = rescan_pos; i < min_rescan_pos + 1; ++i)
697 if (this->rescannable_[i].is_archive)
698 delete this->rescannable_[i].u.archive;
700 delete this->rescannable_[i].u.input_group;
703 rescan_pos = min_rescan_pos + 1;
707 // Return whether the rescannable at index I defines SYM.
710 Plugin_manager::rescannable_defines(size_t i, Symbol* sym)
712 const Rescannable& r(this->rescannable_[i]);
714 return r.u.archive->defines_symbol(sym);
717 for (Input_group::const_iterator p = r.u.input_group->begin();
718 p != r.u.input_group->end();
721 if ((*p)->defines_symbol(sym))
728 // Layout deferred objects.
731 Plugin_manager::layout_deferred_objects()
733 Deferred_layout_list::iterator obj;
735 for (obj = this->deferred_layout_objects_.begin();
736 obj != this->deferred_layout_objects_.end();
739 // Lock the object so we can read from it. This is only called
740 // single-threaded from queue_middle_tasks, so it is OK to lock.
741 // Unfortunately we have no way to pass in a Task token.
742 const Task* dummy_task = reinterpret_cast<const Task*>(-1);
743 Task_lock_obj<Object> tl(dummy_task, *obj);
744 (*obj)->layout_deferred_sections(this->layout_);
748 // Call the cleanup handlers.
751 Plugin_manager::cleanup()
753 if (this->any_added_)
755 // If any input files were added, close all the input files.
756 // This is because the plugin may want to remove them, and on
757 // Windows you are not allowed to remove an open file.
758 close_all_descriptors();
761 for (this->current_ = this->plugins_.begin();
762 this->current_ != this->plugins_.end();
764 (*this->current_)->cleanup();
767 // Make a new Pluginobj object. This is called when the plugin calls
768 // the add_symbols API.
771 Plugin_manager::make_plugin_object(unsigned int handle)
773 // Make sure we aren't asked to make an object for the same handle twice.
774 if (this->objects_.size() != handle
775 && this->objects_[handle]->pluginobj() != NULL)
778 Pluginobj* obj = make_sized_plugin_object(this->input_file_,
779 this->plugin_input_file_.offset,
780 this->plugin_input_file_.filesize);
783 // If the elf object for this file was pushed into the objects_ vector, delete
784 // it to make room for the Pluginobj as this file is claimed.
785 if (this->objects_.size() != handle)
786 this->objects_.pop_back();
788 this->objects_.push_back(obj);
792 // Get the input file information with an open (possibly re-opened)
796 Plugin_manager::get_input_file(unsigned int handle,
797 struct ld_plugin_input_file* file)
799 Pluginobj* obj = this->object(handle)->pluginobj();
801 return LDPS_BAD_HANDLE;
803 obj->lock(this->task_);
804 file->name = obj->filename().c_str();
805 file->fd = obj->descriptor();
806 file->offset = obj->offset();
807 file->filesize = obj->filesize();
808 file->handle = reinterpret_cast<void*>(handle);
812 // Release the input file.
815 Plugin_manager::release_input_file(unsigned int handle)
817 if (this->object(handle) == NULL)
818 return LDPS_BAD_HANDLE;
820 Pluginobj* obj = this->object(handle)->pluginobj();
823 return LDPS_BAD_HANDLE;
825 obj->unlock(this->task_);
829 // Get the elf object corresponding to the handle. Return NULL if we
830 // found a Pluginobj instead.
833 Plugin_manager::get_elf_object(const void* handle)
835 Object* obj = this->object(
836 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
838 // The object should not be a Pluginobj.
840 || obj->pluginobj() != NULL)
847 Plugin_manager::get_view(unsigned int handle, const void **viewp)
851 Input_file *input_file;
852 if (this->in_claim_file_handler_)
854 // We are being called from the claim_file hook.
855 const struct ld_plugin_input_file &f = this->plugin_input_file_;
857 filesize = f.filesize;
858 input_file = this->input_file_;
862 // An already claimed file.
863 if (this->object(handle) == NULL)
864 return LDPS_BAD_HANDLE;
865 Pluginobj* obj = this->object(handle)->pluginobj();
867 return LDPS_BAD_HANDLE;
868 offset = obj->offset();
869 filesize = obj->filesize();
870 input_file = obj->input_file();
872 *viewp = (void*) input_file->file().get_view(offset, 0, filesize, false,
877 // Add a new library path.
880 Plugin_manager::set_extra_library_path(const char* path)
882 this->extra_search_path_ = std::string(path);
886 // Add a new input file.
889 Plugin_manager::add_input_file(const char* pathname, bool is_lib)
891 Input_file_argument file(pathname,
893 ? Input_file_argument::INPUT_FILE_TYPE_LIBRARY
894 : Input_file_argument::INPUT_FILE_TYPE_FILE),
896 ? this->extra_search_path_.c_str()
900 Input_argument* input_argument = new Input_argument(file);
901 Task_token* next_blocker = new Task_token(true);
902 next_blocker->add_blocker();
903 if (parameters->incremental())
904 gold_error(_("input files added by plug-ins in --incremental mode not "
906 this->workqueue_->queue_soon(new Read_symbols(this->input_objects_,
917 this->this_blocker_ = next_blocker;
918 this->any_added_ = true;
924 Pluginobj::Pluginobj(const std::string& name, Input_file* input_file,
925 off_t offset, off_t filesize)
926 : Object(name, input_file, false, offset),
927 nsyms_(0), syms_(NULL), symbols_(), filesize_(filesize), comdat_map_()
931 // Return TRUE if a defined symbol is referenced from outside the
932 // universe of claimed objects. Only references from relocatable,
933 // non-IR (unclaimed) objects count as a reference. References from
934 // dynamic objects count only as "visible".
937 is_referenced_from_outside(Symbol* lsym)
939 if (lsym->in_real_elf())
941 if (parameters->options().relocatable())
943 if (parameters->options().is_undefined(lsym->name()))
948 // Return TRUE if a defined symbol might be reachable from outside the
952 is_visible_from_outside(Symbol* lsym)
956 if (parameters->options().export_dynamic() || parameters->options().shared()
957 || parameters->options().in_dynamic_list(lsym->name())
958 || parameters->options().is_export_dynamic_symbol(lsym->name()))
959 return lsym->is_externally_visible();
963 // Get symbol resolution info.
966 Pluginobj::get_symbol_resolution_info(Symbol_table* symtab,
968 ld_plugin_symbol* syms,
971 // For version 1 of this interface, we cannot use
972 // LDPR_PREVAILING_DEF_IRONLY_EXP, so we return LDPR_PREVAILING_DEF
974 const ld_plugin_symbol_resolution ldpr_prevailing_def_ironly_exp
976 ? LDPR_PREVAILING_DEF_IRONLY_EXP
977 : LDPR_PREVAILING_DEF);
979 if (nsyms > this->nsyms_)
982 if (static_cast<size_t>(nsyms) > this->symbols_.size())
984 // We never decided to include this object. We mark all symbols as
986 gold_assert(this->symbols_.size() == 0);
987 for (int i = 0; i < nsyms; i++)
988 syms[i].resolution = LDPR_PREEMPTED_REG;
989 return version > 2 ? LDPS_NO_SYMS : LDPS_OK;
992 for (int i = 0; i < nsyms; i++)
994 ld_plugin_symbol* isym = &syms[i];
995 Symbol* lsym = this->symbols_[i];
996 if (lsym->is_forwarder())
997 lsym = symtab->resolve_forwards(lsym);
998 ld_plugin_symbol_resolution res = LDPR_UNKNOWN;
1000 if (lsym->is_undefined())
1001 // The symbol remains undefined.
1003 else if (isym->def == LDPK_UNDEF
1004 || isym->def == LDPK_WEAKUNDEF
1005 || isym->def == LDPK_COMMON)
1007 // The original symbol was undefined or common.
1008 if (lsym->source() != Symbol::FROM_OBJECT)
1009 res = LDPR_RESOLVED_EXEC;
1010 else if (lsym->object()->pluginobj() == this)
1012 if (is_referenced_from_outside(lsym))
1013 res = LDPR_PREVAILING_DEF;
1014 else if (is_visible_from_outside(lsym))
1015 res = ldpr_prevailing_def_ironly_exp;
1017 res = LDPR_PREVAILING_DEF_IRONLY;
1019 else if (lsym->object()->pluginobj() != NULL)
1020 res = LDPR_RESOLVED_IR;
1021 else if (lsym->object()->is_dynamic())
1022 res = LDPR_RESOLVED_DYN;
1024 res = LDPR_RESOLVED_EXEC;
1028 // The original symbol was a definition.
1029 if (lsym->source() != Symbol::FROM_OBJECT)
1030 res = LDPR_PREEMPTED_REG;
1031 else if (lsym->object() == static_cast<const Object*>(this))
1033 if (is_referenced_from_outside(lsym))
1034 res = LDPR_PREVAILING_DEF;
1035 else if (is_visible_from_outside(lsym))
1036 res = ldpr_prevailing_def_ironly_exp;
1038 res = LDPR_PREVAILING_DEF_IRONLY;
1041 res = (lsym->object()->pluginobj() != NULL
1043 : LDPR_PREEMPTED_REG);
1045 isym->resolution = res;
1050 // Return TRUE if the comdat group with key COMDAT_KEY from this object
1054 Pluginobj::include_comdat_group(std::string comdat_key, Layout* layout)
1056 std::pair<Comdat_map::iterator, bool> ins =
1057 this->comdat_map_.insert(std::make_pair(comdat_key, false));
1059 // If this is the first time we've seen this comdat key, ask the
1060 // layout object whether it should be included.
1062 ins.first->second = layout->find_or_add_kept_section(comdat_key,
1066 return ins.first->second;
1069 // Class Sized_pluginobj.
1071 template<int size, bool big_endian>
1072 Sized_pluginobj<size, big_endian>::Sized_pluginobj(
1073 const std::string& name,
1074 Input_file* input_file,
1077 : Pluginobj(name, input_file, offset, filesize)
1081 // Read the symbols. Not used for plugin objects.
1083 template<int size, bool big_endian>
1085 Sized_pluginobj<size, big_endian>::do_read_symbols(Read_symbols_data*)
1090 // Lay out the input sections. Not used for plugin objects.
1092 template<int size, bool big_endian>
1094 Sized_pluginobj<size, big_endian>::do_layout(Symbol_table*, Layout*,
1100 // Add the symbols to the symbol table.
1102 template<int size, bool big_endian>
1104 Sized_pluginobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
1108 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1109 unsigned char symbuf[sym_size];
1110 elfcpp::Sym<size, big_endian> sym(symbuf);
1111 elfcpp::Sym_write<size, big_endian> osym(symbuf);
1113 this->symbols_.resize(this->nsyms_);
1115 for (int i = 0; i < this->nsyms_; ++i)
1117 const struct ld_plugin_symbol* isym = &this->syms_[i];
1118 const char* name = isym->name;
1119 const char* ver = isym->version;
1120 elfcpp::Elf_Half shndx;
1124 if (name != NULL && name[0] == '\0')
1126 if (ver != NULL && ver[0] == '\0')
1132 case LDPK_WEAKUNDEF:
1133 bind = elfcpp::STB_WEAK;
1139 bind = elfcpp::STB_GLOBAL;
1147 shndx = elfcpp::SHN_ABS;
1150 shndx = elfcpp::SHN_COMMON;
1153 case LDPK_WEAKUNDEF:
1155 shndx = elfcpp::SHN_UNDEF;
1159 switch (isym->visibility)
1161 case LDPV_PROTECTED:
1162 vis = elfcpp::STV_PROTECTED;
1165 vis = elfcpp::STV_INTERNAL;
1168 vis = elfcpp::STV_HIDDEN;
1172 vis = elfcpp::STV_DEFAULT;
1176 if (isym->comdat_key != NULL
1177 && isym->comdat_key[0] != '\0'
1178 && !this->include_comdat_group(isym->comdat_key, layout))
1179 shndx = elfcpp::SHN_UNDEF;
1181 osym.put_st_name(0);
1182 osym.put_st_value(0);
1183 osym.put_st_size(0);
1184 osym.put_st_info(bind, elfcpp::STT_NOTYPE);
1185 osym.put_st_other(vis, 0);
1186 osym.put_st_shndx(shndx);
1189 symtab->add_from_pluginobj<size, big_endian>(this, name, ver, &sym);
1193 template<int size, bool big_endian>
1194 Archive::Should_include
1195 Sized_pluginobj<size, big_endian>::do_should_include_member(
1196 Symbol_table* symtab,
1201 char* tmpbuf = NULL;
1202 size_t tmpbuflen = 0;
1204 for (int i = 0; i < this->nsyms_; ++i)
1206 const struct ld_plugin_symbol& sym = this->syms_[i];
1207 if (sym.def == LDPK_UNDEF || sym.def == LDPK_WEAKUNDEF)
1209 const char* name = sym.name;
1211 Archive::Should_include t = Archive::should_include_member(symtab,
1217 if (t == Archive::SHOULD_INCLUDE_YES)
1226 return Archive::SHOULD_INCLUDE_UNKNOWN;
1229 // Iterate over global symbols, calling a visitor class V for each.
1231 template<int size, bool big_endian>
1233 Sized_pluginobj<size, big_endian>::do_for_all_global_symbols(
1235 Library_base::Symbol_visitor_base* v)
1237 for (int i = 0; i < this->nsyms_; ++i)
1239 const struct ld_plugin_symbol& sym = this->syms_[i];
1240 if (sym.def != LDPK_UNDEF)
1245 // Iterate over local symbols, calling a visitor class V for each GOT offset
1246 // associated with a local symbol.
1247 template<int size, bool big_endian>
1249 Sized_pluginobj<size, big_endian>::do_for_all_local_got_entries(
1250 Got_offset_list::Visitor*) const
1255 // Get the size of a section. Not used for plugin objects.
1257 template<int size, bool big_endian>
1259 Sized_pluginobj<size, big_endian>::do_section_size(unsigned int)
1265 // Get the name of a section. Not used for plugin objects.
1267 template<int size, bool big_endian>
1269 Sized_pluginobj<size, big_endian>::do_section_name(unsigned int) const
1272 return std::string();
1275 // Return a view of the contents of a section. Not used for plugin objects.
1277 template<int size, bool big_endian>
1278 const unsigned char*
1279 Sized_pluginobj<size, big_endian>::do_section_contents(
1288 // Return section flags. Not used for plugin objects.
1290 template<int size, bool big_endian>
1292 Sized_pluginobj<size, big_endian>::do_section_flags(unsigned int)
1298 // Return section entsize. Not used for plugin objects.
1300 template<int size, bool big_endian>
1302 Sized_pluginobj<size, big_endian>::do_section_entsize(unsigned int)
1308 // Return section address. Not used for plugin objects.
1310 template<int size, bool big_endian>
1312 Sized_pluginobj<size, big_endian>::do_section_address(unsigned int)
1318 // Return section type. Not used for plugin objects.
1320 template<int size, bool big_endian>
1322 Sized_pluginobj<size, big_endian>::do_section_type(unsigned int)
1328 // Return the section link field. Not used for plugin objects.
1330 template<int size, bool big_endian>
1332 Sized_pluginobj<size, big_endian>::do_section_link(unsigned int)
1338 // Return the section link field. Not used for plugin objects.
1340 template<int size, bool big_endian>
1342 Sized_pluginobj<size, big_endian>::do_section_info(unsigned int)
1348 // Return the section alignment. Not used for plugin objects.
1350 template<int size, bool big_endian>
1352 Sized_pluginobj<size, big_endian>::do_section_addralign(unsigned int)
1358 // Return the Xindex structure to use. Not used for plugin objects.
1360 template<int size, bool big_endian>
1362 Sized_pluginobj<size, big_endian>::do_initialize_xindex()
1368 // Get symbol counts. Don't count plugin objects; the replacement
1369 // files will provide the counts.
1371 template<int size, bool big_endian>
1373 Sized_pluginobj<size, big_endian>::do_get_global_symbol_counts(
1374 const Symbol_table*,
1382 // Get symbols. Not used for plugin objects.
1384 template<int size, bool big_endian>
1385 const Object::Symbols*
1386 Sized_pluginobj<size, big_endian>::do_get_global_symbols() const
1391 // Class Plugin_finish. This task runs after all replacement files have
1392 // been added. For now, it's a placeholder for a possible plugin API
1393 // to allow the plugin to release most of its resources. The cleanup
1394 // handlers must be called later, because they can remove the temporary
1395 // object files that are needed until the end of the link.
1397 class Plugin_finish : public Task
1400 Plugin_finish(Task_token* this_blocker, Task_token* next_blocker)
1401 : this_blocker_(this_blocker), next_blocker_(next_blocker)
1406 if (this->this_blocker_ != NULL)
1407 delete this->this_blocker_;
1413 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
1414 return this->this_blocker_;
1419 locks(Task_locker* tl)
1420 { tl->add(this, this->next_blocker_); }
1425 // We could call early cleanup handlers here.
1430 { return "Plugin_finish"; }
1433 Task_token* this_blocker_;
1434 Task_token* next_blocker_;
1437 // Class Plugin_hook.
1439 Plugin_hook::~Plugin_hook()
1443 // Return whether a Plugin_hook task is runnable.
1446 Plugin_hook::is_runnable()
1448 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
1449 return this->this_blocker_;
1453 // Return a Task_locker for a Plugin_hook task. We don't need any
1457 Plugin_hook::locks(Task_locker*)
1461 // Run the "all symbols read" plugin hook.
1464 Plugin_hook::run(Workqueue* workqueue)
1466 gold_assert(this->options_.has_plugins());
1467 Symbol* start_sym = this->symtab_->lookup(parameters->entry());
1468 if (start_sym != NULL)
1469 start_sym->set_in_real_elf();
1471 this->options_.plugins()->all_symbols_read(workqueue,
1473 this->input_objects_,
1477 &this->this_blocker_);
1478 workqueue->queue_soon(new Plugin_finish(this->this_blocker_,
1479 this->next_blocker_));
1482 // The C interface routines called by the plugins.
1484 #ifdef ENABLE_PLUGINS
1486 // Register a claim-file handler.
1488 static enum ld_plugin_status
1489 register_claim_file(ld_plugin_claim_file_handler handler)
1491 gold_assert(parameters->options().has_plugins());
1492 parameters->options().plugins()->set_claim_file_handler(handler);
1496 // Register an all-symbols-read handler.
1498 static enum ld_plugin_status
1499 register_all_symbols_read(ld_plugin_all_symbols_read_handler handler)
1501 gold_assert(parameters->options().has_plugins());
1502 parameters->options().plugins()->set_all_symbols_read_handler(handler);
1506 // Register a cleanup handler.
1508 static enum ld_plugin_status
1509 register_cleanup(ld_plugin_cleanup_handler handler)
1511 gold_assert(parameters->options().has_plugins());
1512 parameters->options().plugins()->set_cleanup_handler(handler);
1516 // Add symbols from a plugin-claimed input file.
1518 static enum ld_plugin_status
1519 add_symbols(void* handle, int nsyms, const ld_plugin_symbol* syms)
1521 gold_assert(parameters->options().has_plugins());
1522 Pluginobj* obj = parameters->options().plugins()->make_plugin_object(
1523 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
1526 obj->store_incoming_symbols(nsyms, syms);
1530 // Get the input file information with an open (possibly re-opened)
1533 static enum ld_plugin_status
1534 get_input_file(const void* handle, struct ld_plugin_input_file* file)
1536 gold_assert(parameters->options().has_plugins());
1537 unsigned int obj_index =
1538 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle));
1539 return parameters->options().plugins()->get_input_file(obj_index, file);
1542 // Release the input file.
1544 static enum ld_plugin_status
1545 release_input_file(const void* handle)
1547 gold_assert(parameters->options().has_plugins());
1548 unsigned int obj_index =
1549 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle));
1550 return parameters->options().plugins()->release_input_file(obj_index);
1553 static enum ld_plugin_status
1554 get_view(const void *handle, const void **viewp)
1556 gold_assert(parameters->options().has_plugins());
1557 unsigned int obj_index =
1558 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle));
1559 return parameters->options().plugins()->get_view(obj_index, viewp);
1562 // Get the symbol resolution info for a plugin-claimed input file.
1564 static enum ld_plugin_status
1565 get_symbols(const void* handle, int nsyms, ld_plugin_symbol* syms)
1567 gold_assert(parameters->options().has_plugins());
1568 Plugin_manager* plugins = parameters->options().plugins();
1569 Object* obj = plugins->object(
1570 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
1573 Pluginobj* plugin_obj = obj->pluginobj();
1574 if (plugin_obj == NULL)
1576 Symbol_table* symtab = plugins->symtab();
1577 return plugin_obj->get_symbol_resolution_info(symtab, nsyms, syms, 1);
1580 // Version 2 of the above. The only difference is that this version
1581 // is allowed to return the resolution code LDPR_PREVAILING_DEF_IRONLY_EXP.
1583 static enum ld_plugin_status
1584 get_symbols_v2(const void* handle, int nsyms, ld_plugin_symbol* syms)
1586 gold_assert(parameters->options().has_plugins());
1587 Plugin_manager* plugins = parameters->options().plugins();
1588 Object* obj = plugins->object(
1589 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
1592 Pluginobj* plugin_obj = obj->pluginobj();
1593 if (plugin_obj == NULL)
1595 Symbol_table* symtab = plugins->symtab();
1596 return plugin_obj->get_symbol_resolution_info(symtab, nsyms, syms, 2);
1599 // Version 3 of the above. The only difference from v2 is that it
1600 // returns LDPS_NO_SYMS instead of LDPS_OK for the objects we never
1601 // decided to include.
1603 static enum ld_plugin_status
1604 get_symbols_v3(const void* handle, int nsyms, ld_plugin_symbol* syms)
1606 gold_assert(parameters->options().has_plugins());
1607 Plugin_manager* plugins = parameters->options().plugins();
1608 Object* obj = plugins->object(
1609 static_cast<unsigned int>(reinterpret_cast<intptr_t>(handle)));
1612 Pluginobj* plugin_obj = obj->pluginobj();
1613 if (plugin_obj == NULL)
1615 Symbol_table* symtab = plugins->symtab();
1616 return plugin_obj->get_symbol_resolution_info(symtab, nsyms, syms, 3);
1619 // Add a new (real) input file generated by a plugin.
1621 static enum ld_plugin_status
1622 add_input_file(const char* pathname)
1624 gold_assert(parameters->options().has_plugins());
1625 return parameters->options().plugins()->add_input_file(pathname, false);
1628 // Add a new (real) library required by a plugin.
1630 static enum ld_plugin_status
1631 add_input_library(const char* pathname)
1633 gold_assert(parameters->options().has_plugins());
1634 return parameters->options().plugins()->add_input_file(pathname, true);
1637 // Set the extra library path to be used by libraries added via
1638 // add_input_library
1640 static enum ld_plugin_status
1641 set_extra_library_path(const char* path)
1643 gold_assert(parameters->options().has_plugins());
1644 return parameters->options().plugins()->set_extra_library_path(path);
1647 // Issue a diagnostic message from a plugin.
1649 static enum ld_plugin_status
1650 message(int level, const char* format, ...)
1653 va_start(args, format);
1658 parameters->errors()->info(format, args);
1661 parameters->errors()->warning(format, args);
1665 parameters->errors()->error(format, args);
1668 parameters->errors()->fatal(format, args);
1676 // Get the section count of the object corresponding to the handle. This
1677 // plugin interface can only be called in the claim_file handler of the plugin.
1679 static enum ld_plugin_status
1680 get_input_section_count(const void* handle, unsigned int* count)
1682 gold_assert(parameters->options().has_plugins());
1684 if (!parameters->options().plugins()->in_claim_file_handler())
1687 Object* obj = parameters->options().plugins()->get_elf_object(handle);
1692 *count = obj->shnum();
1696 // Get the type of the specified section in the object corresponding
1697 // to the handle. This plugin interface can only be called in the
1698 // claim_file handler of the plugin.
1700 static enum ld_plugin_status
1701 get_input_section_type(const struct ld_plugin_section section,
1704 gold_assert(parameters->options().has_plugins());
1706 if (!parameters->options().plugins()->in_claim_file_handler())
1710 = parameters->options().plugins()->get_elf_object(section.handle);
1713 return LDPS_BAD_HANDLE;
1715 *type = obj->section_type(section.shndx);
1719 // Get the name of the specified section in the object corresponding
1720 // to the handle. This plugin interface can only be called in the
1721 // claim_file handler of the plugin.
1723 static enum ld_plugin_status
1724 get_input_section_name(const struct ld_plugin_section section,
1725 char** section_name_ptr)
1727 gold_assert(parameters->options().has_plugins());
1729 if (!parameters->options().plugins()->in_claim_file_handler())
1733 = parameters->options().plugins()->get_elf_object(section.handle);
1736 return LDPS_BAD_HANDLE;
1738 // Check if the object is locked before getting the section name.
1739 gold_assert(obj->is_locked());
1741 const std::string section_name = obj->section_name(section.shndx);
1742 *section_name_ptr = static_cast<char*>(malloc(section_name.length() + 1));
1743 memcpy(*section_name_ptr, section_name.c_str(), section_name.length() + 1);
1747 // Get the contents of the specified section in the object corresponding
1748 // to the handle. This plugin interface can only be called in the
1749 // claim_file handler of the plugin.
1751 static enum ld_plugin_status
1752 get_input_section_contents(const struct ld_plugin_section section,
1753 const unsigned char** section_contents_ptr,
1756 gold_assert(parameters->options().has_plugins());
1758 if (!parameters->options().plugins()->in_claim_file_handler())
1762 = parameters->options().plugins()->get_elf_object(section.handle);
1765 return LDPS_BAD_HANDLE;
1767 // Check if the object is locked before getting the section contents.
1768 gold_assert(obj->is_locked());
1770 section_size_type plen;
1771 *section_contents_ptr
1772 = obj->section_contents(section.shndx, &plen, false);
1777 // Get the alignment of the specified section in the object corresponding
1778 // to the handle. This plugin interface can only be called in the
1779 // claim_file handler of the plugin.
1781 static enum ld_plugin_status
1782 get_input_section_alignment(const struct ld_plugin_section section,
1783 unsigned int* addralign)
1785 gold_assert(parameters->options().has_plugins());
1787 if (!parameters->options().plugins()->in_claim_file_handler())
1791 = parameters->options().plugins()->get_elf_object(section.handle);
1794 return LDPS_BAD_HANDLE;
1796 *addralign = obj->section_addralign(section.shndx);
1800 // Get the size of the specified section in the object corresponding
1801 // to the handle. This plugin interface can only be called in the
1802 // claim_file handler of the plugin.
1804 static enum ld_plugin_status
1805 get_input_section_size(const struct ld_plugin_section section,
1808 gold_assert(parameters->options().has_plugins());
1810 if (!parameters->options().plugins()->in_claim_file_handler())
1814 = parameters->options().plugins()->get_elf_object(section.handle);
1817 return LDPS_BAD_HANDLE;
1819 *secsize = obj->section_size(section.shndx);
1824 // Specify the ordering of sections in the final layout. The sections are
1825 // specified as (handle,shndx) pairs in the two arrays in the order in
1826 // which they should appear in the final layout.
1828 static enum ld_plugin_status
1829 update_section_order(const struct ld_plugin_section* section_list,
1830 unsigned int num_sections)
1832 gold_assert(parameters->options().has_plugins());
1834 if (num_sections == 0)
1837 if (section_list == NULL)
1840 Layout* layout = parameters->options().plugins()->layout();
1841 gold_assert (layout != NULL);
1843 std::map<Section_id, unsigned int>* order_map
1844 = layout->get_section_order_map();
1846 /* Store the mapping from Section_id to section position in layout's
1847 order_map to consult after output sections are added. */
1848 for (unsigned int i = 0; i < num_sections; ++i)
1850 Object* obj = parameters->options().plugins()->get_elf_object(
1851 section_list[i].handle);
1852 if (obj == NULL || obj->is_dynamic())
1853 return LDPS_BAD_HANDLE;
1854 unsigned int shndx = section_list[i].shndx;
1855 Section_id secn_id(static_cast<Relobj*>(obj), shndx);
1856 (*order_map)[secn_id] = i + 1;
1862 // Let the linker know that the sections could be reordered.
1864 static enum ld_plugin_status
1865 allow_section_ordering()
1867 gold_assert(parameters->options().has_plugins());
1868 Layout* layout = parameters->options().plugins()->layout();
1869 layout->set_section_ordering_specified();
1873 // Let the linker know that a subset of sections could be mapped
1874 // to a unique segment.
1876 static enum ld_plugin_status
1877 allow_unique_segment_for_sections()
1879 gold_assert(parameters->options().has_plugins());
1880 Layout* layout = parameters->options().plugins()->layout();
1881 layout->set_unique_segment_for_sections_specified();
1885 // This function should map the list of sections specified in the
1886 // SECTION_LIST to a unique segment. ELF segments do not have names
1887 // and the NAME is used to identify Output Section which should contain
1888 // the list of sections. This Output Section will then be mapped to
1889 // a unique segment. FLAGS is used to specify if any additional segment
1890 // flags need to be set. For instance, a specific segment flag can be
1891 // set to identify this segment. Unsetting segment flags is not possible.
1892 // ALIGN specifies the alignment of the segment.
1894 static enum ld_plugin_status
1895 unique_segment_for_sections(const char* segment_name,
1898 const struct ld_plugin_section* section_list,
1899 unsigned int num_sections)
1901 gold_assert(parameters->options().has_plugins());
1903 if (num_sections == 0)
1906 if (section_list == NULL)
1909 Layout* layout = parameters->options().plugins()->layout();
1910 gold_assert (layout != NULL);
1912 Layout::Unique_segment_info* s = new Layout::Unique_segment_info;
1913 s->name = segment_name;
1917 for (unsigned int i = 0; i < num_sections; ++i)
1919 Object* obj = parameters->options().plugins()->get_elf_object(
1920 section_list[i].handle);
1921 if (obj == NULL || obj->is_dynamic())
1922 return LDPS_BAD_HANDLE;
1923 unsigned int shndx = section_list[i].shndx;
1924 Const_section_id secn_id(static_cast<Relobj*>(obj), shndx);
1925 layout->insert_section_segment_map(secn_id, s);
1931 // Register a new_input handler.
1933 static enum ld_plugin_status
1934 register_new_input(ld_plugin_new_input_handler handler)
1936 gold_assert(parameters->options().has_plugins());
1937 parameters->options().plugins()->set_new_input_handler(handler);
1941 #endif // ENABLE_PLUGINS
1943 // Allocate a Pluginobj object of the appropriate size and endianness.
1946 make_sized_plugin_object(Input_file* input_file, off_t offset, off_t filesize)
1948 Pluginobj* obj = NULL;
1950 parameters_force_valid_target();
1951 const Target& target(parameters->target());
1953 if (target.get_size() == 32)
1955 if (target.is_big_endian())
1956 #ifdef HAVE_TARGET_32_BIG
1957 obj = new Sized_pluginobj<32, true>(input_file->filename(),
1958 input_file, offset, filesize);
1960 gold_error(_("%s: not configured to support "
1961 "32-bit big-endian object"),
1962 input_file->filename().c_str());
1965 #ifdef HAVE_TARGET_32_LITTLE
1966 obj = new Sized_pluginobj<32, false>(input_file->filename(),
1967 input_file, offset, filesize);
1969 gold_error(_("%s: not configured to support "
1970 "32-bit little-endian object"),
1971 input_file->filename().c_str());
1974 else if (target.get_size() == 64)
1976 if (target.is_big_endian())
1977 #ifdef HAVE_TARGET_64_BIG
1978 obj = new Sized_pluginobj<64, true>(input_file->filename(),
1979 input_file, offset, filesize);
1981 gold_error(_("%s: not configured to support "
1982 "64-bit big-endian object"),
1983 input_file->filename().c_str());
1986 #ifdef HAVE_TARGET_64_LITTLE
1987 obj = new Sized_pluginobj<64, false>(input_file->filename(),
1988 input_file, offset, filesize);
1990 gold_error(_("%s: not configured to support "
1991 "64-bit little-endian object"),
1992 input_file->filename().c_str());
1996 gold_assert(obj != NULL);
2000 } // End namespace gold.