[ gas/ChangeLog ]
[binutils.git] / gold / readsyms.cc
blob30b341c1b6907f8da0be58cf0d9513c1437f601f
1 // readsyms.cc -- read input file symbols for gold
3 #include "gold.h"
5 #include <cstring>
7 #include "elfcpp.h"
8 #include "options.h"
9 #include "dirsearch.h"
10 #include "readsyms.h"
12 namespace gold
15 // Class read_symbols.
17 Read_symbols::~Read_symbols()
19 // The this_blocker_ and next_blocker_ pointers are passed on to the
20 // Add_symbols task.
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())
32 return IS_BLOCKED;
34 return IS_RUNNABLE;
37 // Return a Task_locker for a Read_symbols task. We don't need any
38 // locks here.
40 Task_locker*
41 Read_symbols::locks(Workqueue*)
43 return NULL;
46 // Run a Read_symbols task. This is where we actually read the
47 // symbols and relocations.
49 void
50 Read_symbols::run(Workqueue* workqueue)
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_);
57 // Read enough of the file to pick up the entire ELF header.
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)
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,
73 p, bytes);
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();
82 return;
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);
91 // Class Add_symbols.
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
98 // input file.
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())
107 return IS_BLOCKED;
108 return IS_RUNNABLE;
111 Task_locker*
112 Add_symbols::locks(Workqueue* workqueue)
114 return new Task_locker_block(*this->next_blocker_, workqueue);
117 void
118 Add_symbols::run(Workqueue*)
120 this->object_->add_symbols(this->sd_);
123 } // End namespace gold.