1 // readsyms.cc -- read input file symbols for gold
17 // Class read_symbols.
19 Read_symbols::~Read_symbols()
21 // The this_blocker_ and next_blocker_ pointers are passed on to the
25 // Return whether a Read_symbols task is runnable. We need write
26 // access to the symbol table. We can read an ordinary input file
27 // immediately. For an archive specified using -l, we have to wait
28 // until the search path is complete.
30 Task::Is_runnable_type
31 Read_symbols::is_runnable(Workqueue*)
33 if (this->input_.is_lib() && this->dirpath_.token().is_blocked())
39 // Return a Task_locker for a Read_symbols task. We don't need any
43 Read_symbols::locks(Workqueue*)
48 // Run a Read_symbols task. This is where we actually read the
49 // symbols and relocations.
52 Read_symbols::run(Workqueue* workqueue)
54 Input_file* input_file = new Input_file(this->input_);
55 input_file->open(this->options_, this->dirpath_);
57 // Read enough of the file to pick up the entire ELF header.
59 int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
61 const unsigned char* p = input_file->file().get_view(0, ehdr_size, &bytes);
64 static unsigned char elfmagic[4] =
66 elfcpp::ELFMAG0, elfcpp::ELFMAG1,
67 elfcpp::ELFMAG2, elfcpp::ELFMAG3
69 if (memcmp(p, elfmagic, 4) == 0)
71 // This is an ELF object.
72 Object* obj = make_elf_object(this->input_.name(), input_file, 0,
75 this->input_objects_->add_object(obj);
77 Read_symbols_data* sd = new Read_symbols_data;
78 obj->read_symbols(sd);
79 workqueue->queue(new Add_symbols(this->symtab_, this->layout_,
82 this->next_blocker_));
84 // Opening the file locked it, so now we need to unlock it.
85 input_file->file().unlock();
91 if (bytes >= Archive::sarmag)
93 if (memcmp(p, Archive::armag, Archive::sarmag) == 0)
95 // This is an archive.
96 Archive* arch = new Archive(this->input_.name(), input_file);
98 workqueue->queue(new Add_archive_symbols(this->symtab_,
100 this->input_objects_,
103 this->next_blocker_));
108 // Here we have to handle archives and any other input file
110 fprintf(stderr, _("%s: %s: not an object or archive\n"),
111 program_name, input_file->file().filename().c_str());
115 // Class Add_symbols.
117 Add_symbols::~Add_symbols()
119 if (this->this_blocker_ != NULL)
120 delete this->this_blocker_;
121 // next_blocker_ is deleted by the task associated with the next
125 // We are blocked by this_blocker_. We block next_blocker_. We also
128 Task::Is_runnable_type
129 Add_symbols::is_runnable(Workqueue*)
131 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
133 if (this->object_->is_locked())
138 class Add_symbols::Add_symbols_locker : public Task_locker
141 Add_symbols_locker(Task_token& token, Workqueue* workqueue,
143 : blocker_(token, workqueue), objlock_(*object)
147 Task_locker_block blocker_;
148 Task_locker_obj<Object> objlock_;
152 Add_symbols::locks(Workqueue* workqueue)
154 return new Add_symbols_locker(*this->next_blocker_, workqueue,
159 Add_symbols::run(Workqueue*)
161 this->object_->layout(this->layout_, this->sd_);
162 this->object_->add_symbols(this->symtab_, this->sd_);
167 } // End namespace gold.