Fix typo in comment.
[deliverable/binutils-gdb.git] / gold / readsyms.cc
CommitLineData
bae7f79e
ILT
1// readsyms.cc -- read input file symbols for gold
2
3#include "gold.h"
4
5#include <cstring>
6
7#include "elfcpp.h"
8#include "options.h"
9#include "dirsearch.h"
a2fb1b05 10#include "object.h"
61ba1cf9
ILT
11#include "archive.h"
12#include "readsyms.h"
bae7f79e
ILT
13
14namespace gold
15{
16
17// Class read_symbols.
18
19Read_symbols::~Read_symbols()
20{
21 // The this_blocker_ and next_blocker_ pointers are passed on to the
22 // Add_symbols task.
23}
24
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.
29
30Task::Is_runnable_type
31Read_symbols::is_runnable(Workqueue*)
32{
33 if (this->input_.is_lib() && this->dirpath_.token().is_blocked())
34 return IS_BLOCKED;
35
36 return IS_RUNNABLE;
37}
38
39// Return a Task_locker for a Read_symbols task. We don't need any
40// locks here.
41
42Task_locker*
43Read_symbols::locks(Workqueue*)
44{
45 return NULL;
46}
47
48// Run a Read_symbols task. This is where we actually read the
49// symbols and relocations.
50
51void
52Read_symbols::run(Workqueue* workqueue)
53{
bae7f79e
ILT
54 Input_file* input_file = new Input_file(this->input_);
55 input_file->open(this->options_, this->dirpath_);
56
57 // Read enough of the file to pick up the entire ELF header.
58
59 int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
60 off_t bytes;
61 const unsigned char* p = input_file->file().get_view(0, ehdr_size, &bytes);
62 if (bytes >= 4)
63 {
64 static unsigned char elfmagic[4] =
65 {
66 elfcpp::ELFMAG0, elfcpp::ELFMAG1,
67 elfcpp::ELFMAG2, elfcpp::ELFMAG3
68 };
69 if (memcmp(p, elfmagic, 4) == 0)
70 {
71 // This is an ELF object.
72 Object* obj = make_elf_object(this->input_.name(), input_file, 0,
73 p, bytes);
a2fb1b05 74
54dc6425 75 this->input_objects_->add_object(obj);
a2fb1b05 76
12e14209
ILT
77 Read_symbols_data* sd = new Read_symbols_data;
78 obj->read_symbols(sd);
92e059d8
ILT
79 workqueue->queue_front(new Add_symbols(this->symtab_, this->layout_,
80 obj, sd,
81 this->this_blocker_,
82 this->next_blocker_));
bae7f79e
ILT
83
84 // Opening the file locked it, so now we need to unlock it.
85 input_file->file().unlock();
86
87 return;
88 }
89 }
90
61ba1cf9
ILT
91 if (bytes >= Archive::sarmag)
92 {
93 if (memcmp(p, Archive::armag, Archive::sarmag) == 0)
94 {
95 // This is an archive.
96 Archive* arch = new Archive(this->input_.name(), input_file);
97 arch->setup();
98 workqueue->queue(new Add_archive_symbols(this->symtab_,
12e14209 99 this->layout_,
61ba1cf9
ILT
100 this->input_objects_,
101 arch,
102 this->this_blocker_,
103 this->next_blocker_));
104 return;
105 }
106 }
107
92e059d8 108 // Here we have to handle any other input file types we need.
61ba1cf9
ILT
109 fprintf(stderr, _("%s: %s: not an object or archive\n"),
110 program_name, input_file->file().filename().c_str());
111 gold_exit(false);
bae7f79e
ILT
112}
113
114// Class Add_symbols.
115
116Add_symbols::~Add_symbols()
117{
118 if (this->this_blocker_ != NULL)
119 delete this->this_blocker_;
120 // next_blocker_ is deleted by the task associated with the next
121 // input file.
122}
123
a2fb1b05
ILT
124// We are blocked by this_blocker_. We block next_blocker_. We also
125// lock the file.
bae7f79e
ILT
126
127Task::Is_runnable_type
128Add_symbols::is_runnable(Workqueue*)
129{
130 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
131 return IS_BLOCKED;
a2fb1b05
ILT
132 if (this->object_->is_locked())
133 return IS_LOCKED;
bae7f79e
ILT
134 return IS_RUNNABLE;
135}
136
a2fb1b05
ILT
137class Add_symbols::Add_symbols_locker : public Task_locker
138{
139 public:
140 Add_symbols_locker(Task_token& token, Workqueue* workqueue,
141 Object* object)
142 : blocker_(token, workqueue), objlock_(*object)
143 { }
144
145 private:
146 Task_locker_block blocker_;
147 Task_locker_obj<Object> objlock_;
148};
149
bae7f79e
ILT
150Task_locker*
151Add_symbols::locks(Workqueue* workqueue)
152{
a2fb1b05
ILT
153 return new Add_symbols_locker(*this->next_blocker_, workqueue,
154 this->object_);
bae7f79e
ILT
155}
156
157void
158Add_symbols::run(Workqueue*)
159{
12e14209 160 this->object_->layout(this->layout_, this->sd_);
14bfc3f5 161 this->object_->add_symbols(this->symtab_, this->sd_);
12e14209
ILT
162 delete this->sd_;
163 this->sd_ = NULL;
bae7f79e
ILT
164}
165
166} // End namespace gold.
This page took 0.036262 seconds and 4 git commands to generate.