Initial CVS checkin of gold
[deliverable/binutils-gdb.git] / gold / readsyms.cc
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"
10 #include "readsyms.h"
11
12 namespace gold
13 {
14
15 // Class read_symbols.
16
17 Read_symbols::~Read_symbols()
18 {
19 // The this_blocker_ and next_blocker_ pointers are passed on to the
20 // Add_symbols task.
21 }
22
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.
27
28 Task::Is_runnable_type
29 Read_symbols::is_runnable(Workqueue*)
30 {
31 if (this->input_.is_lib() && this->dirpath_.token().is_blocked())
32 return IS_BLOCKED;
33
34 return IS_RUNNABLE;
35 }
36
37 // Return a Task_locker for a Read_symbols task. We don't need any
38 // locks here.
39
40 Task_locker*
41 Read_symbols::locks(Workqueue*)
42 {
43 return NULL;
44 }
45
46 // Run a Read_symbols task. This is where we actually read the
47 // symbols and relocations.
48
49 void
50 Read_symbols::run(Workqueue* workqueue)
51 {
52 // We don't keep track of Input_file objects, so this is a memory
53 // leak.
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);
74
75 Read_symbols_data sd = obj->read_symbols();
76 workqueue->queue(new Add_symbols(obj, sd, this->this_blocker_,
77 this->next_blocker_));
78
79 // Opening the file locked it, so now we need to unlock it.
80 input_file->file().unlock();
81
82 return;
83 }
84 }
85
86 // Here we have to handle archives and any other input file
87 // types we need.
88 gold_fatal("only objects are currently supported", false);
89 }
90
91 // Class Add_symbols.
92
93 Add_symbols::~Add_symbols()
94 {
95 if (this->this_blocker_ != NULL)
96 delete this->this_blocker_;
97 // next_blocker_ is deleted by the task associated with the next
98 // input file.
99 }
100
101 // We are blocked by this_blocker_. We block next_blocker_.
102
103 Task::Is_runnable_type
104 Add_symbols::is_runnable(Workqueue*)
105 {
106 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
107 return IS_BLOCKED;
108 return IS_RUNNABLE;
109 }
110
111 Task_locker*
112 Add_symbols::locks(Workqueue* workqueue)
113 {
114 return new Task_locker_block(*this->next_blocker_, workqueue);
115 }
116
117 void
118 Add_symbols::run(Workqueue*)
119 {
120 this->object_->add_symbols(this->sd_);
121 }
122
123 } // End namespace gold.
This page took 0.052022 seconds and 5 git commands to generate.