1 // readsyms.cc -- read input file symbols for gold
16 // Class read_symbols.
18 Read_symbols::~Read_symbols()
20 // The this_blocker_ and next_blocker_ pointers are passed on to the
24 // Return whether a Read_symbols task is runnable. We need write
25 // access to the symbol table. We can read an ordinary input file
26 // immediately. For an archive specified using -l, we have to wait
27 // until the search path is complete.
29 Task::Is_runnable_type
30 Read_symbols::is_runnable(Workqueue
*)
32 if (this->input_
.is_lib() && this->dirpath_
.token().is_blocked())
38 // Return a Task_locker for a Read_symbols task. We don't need any
42 Read_symbols::locks(Workqueue
*)
47 // Run a Read_symbols task. This is where we actually read the
48 // symbols and relocations.
51 Read_symbols::run(Workqueue
* workqueue
)
53 Input_file
* input_file
= new Input_file(this->input_
);
54 input_file
->open(this->options_
, this->dirpath_
);
56 // Read enough of the file to pick up the entire ELF header.
58 int ehdr_size
= elfcpp::Elf_sizes
<64>::ehdr_size
;
60 const unsigned char* p
= input_file
->file().get_view(0, ehdr_size
, &bytes
);
63 static unsigned char elfmagic
[4] =
65 elfcpp::ELFMAG0
, elfcpp::ELFMAG1
,
66 elfcpp::ELFMAG2
, elfcpp::ELFMAG3
68 if (memcmp(p
, elfmagic
, 4) == 0)
70 // This is an ELF object.
71 Object
* obj
= make_elf_object(this->input_
.name(), input_file
, 0,
74 this->input_objects_
->push_back(obj
);
76 Read_symbols_data sd
= obj
->read_symbols();
77 workqueue
->queue(new Add_symbols(this->symtab_
, obj
, sd
,
79 this->next_blocker_
));
81 // Opening the file locked it, so now we need to unlock it.
82 input_file
->file().unlock();
88 // Here we have to handle archives and any other input file
90 gold_fatal("only objects are currently supported", false);
95 Add_symbols::~Add_symbols()
97 if (this->this_blocker_
!= NULL
)
98 delete this->this_blocker_
;
99 // next_blocker_ is deleted by the task associated with the next
103 // We are blocked by this_blocker_. We block next_blocker_. We also
106 Task::Is_runnable_type
107 Add_symbols::is_runnable(Workqueue
*)
109 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
111 if (this->object_
->is_locked())
116 class Add_symbols::Add_symbols_locker
: public Task_locker
119 Add_symbols_locker(Task_token
& token
, Workqueue
* workqueue
,
121 : blocker_(token
, workqueue
), objlock_(*object
)
125 Task_locker_block blocker_
;
126 Task_locker_obj
<Object
> objlock_
;
130 Add_symbols::locks(Workqueue
* workqueue
)
132 return new Add_symbols_locker(*this->next_blocker_
, workqueue
,
137 Add_symbols::run(Workqueue
*)
139 this->object_
->add_symbols(this->symtab_
, this->sd_
);
142 } // End namespace gold.