1 // readsyms.cc -- read input file symbols for gold
15 // Class read_symbols.
17 Read_symbols::~Read_symbols()
19 // The this_blocker_ and next_blocker_ pointers are passed on to the
23 // Return whether a Read_symbols task is runnable. We need write
24 // access to the symbol table. We can read an ordinary input file
25 // immediately. For an archive specified using -l, we have to wait
26 // until the search path is complete.
28 Task::Is_runnable_type
29 Read_symbols::is_runnable(Workqueue
*)
31 if (this->input_
.is_lib() && this->dirpath_
.token().is_blocked())
37 // Return a Task_locker for a Read_symbols task. We don't need any
41 Read_symbols::locks(Workqueue
*)
46 // Run a Read_symbols task. This is where we actually read the
47 // symbols and relocations.
50 Read_symbols::run(Workqueue
* workqueue
)
52 // We don't keep track of Input_file objects, so this is a memory
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 Read_symbols_data sd
= obj
->read_symbols();
76 workqueue
->queue(new Add_symbols(obj
, sd
, this->this_blocker_
,
77 this->next_blocker_
));
79 // Opening the file locked it, so now we need to unlock it.
80 input_file
->file().unlock();
86 // Here we have to handle archives and any other input file
88 gold_fatal("only objects are currently supported", false);
93 Add_symbols::~Add_symbols()
95 if (this->this_blocker_
!= NULL
)
96 delete this->this_blocker_
;
97 // next_blocker_ is deleted by the task associated with the next
101 // We are blocked by this_blocker_. We block next_blocker_.
103 Task::Is_runnable_type
104 Add_symbols::is_runnable(Workqueue
*)
106 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
112 Add_symbols::locks(Workqueue
* workqueue
)
114 return new Task_locker_block(*this->next_blocker_
, workqueue
);
118 Add_symbols::run(Workqueue
*)
120 this->object_
->add_symbols(this->sd_
);
123 } // End namespace gold.