Commit | Line | Data |
---|---|---|
61ba1cf9 ILT |
1 | // archive.h -- archive support for gold -*- C++ -*- |
2 | ||
3 | #ifndef GOLD_ARCHIVE_H | |
4 | #define GOLD_ARCHIVE_H | |
5 | ||
6 | #include <string> | |
7 | #include <vector> | |
8 | ||
9 | #include "workqueue.h" | |
10 | ||
11 | namespace gold | |
12 | { | |
13 | ||
14 | class Input_file; | |
15 | class Input_objects; | |
12e14209 | 16 | class Layout; |
61ba1cf9 ILT |
17 | class Symbol_table; |
18 | ||
19 | // This class represents an archive--generally a libNAME.a file. | |
20 | // Archives have a symbol table and a list of objects. | |
21 | ||
22 | class Archive | |
23 | { | |
24 | public: | |
25 | Archive(const std::string& name, Input_file* input_file) | |
26 | : name_(name), input_file_(input_file), armap_(), extended_names_() | |
27 | { } | |
28 | ||
29 | // The length of the magic string at the start of an archive. | |
30 | static const int sarmag = 8; | |
31 | ||
32 | // The magic string at the start of an archive. | |
33 | static const char armag[sarmag]; | |
34 | ||
35 | // The string expected at the end of an archive member header. | |
36 | static const char arfmag[2]; | |
37 | ||
38 | // The name of the object. | |
39 | const std::string& | |
40 | name() const | |
41 | { return this->name_; } | |
42 | ||
43 | // Set up the archive: read the symbol map. | |
44 | void | |
45 | setup(); | |
46 | ||
47 | // Lock the underlying file. | |
48 | void | |
49 | lock() | |
50 | { this->input_file_->file().lock(); } | |
51 | ||
52 | // Unlock the underlying file. | |
53 | void | |
54 | unlock() | |
55 | { this->input_file_->file().unlock(); } | |
56 | ||
57 | // Return whether the underlying file is locked. | |
58 | bool | |
59 | is_locked() const | |
60 | { return this->input_file_->file().is_locked(); } | |
61 | ||
62 | // Select members from the archive as needed and add them to the | |
63 | // link. | |
64 | void | |
12e14209 | 65 | add_symbols(Symbol_table*, Layout*, Input_objects*); |
61ba1cf9 ILT |
66 | |
67 | private: | |
68 | Archive(const Archive&); | |
69 | Archive& operator=(const Archive&); | |
70 | ||
71 | struct Archive_header; | |
72 | class Add_archive_symbols_locker; | |
73 | ||
74 | // Get a view into the underlying file. | |
75 | const unsigned char* | |
76 | get_view(off_t start, off_t size); | |
77 | ||
78 | // Read an archive member header at OFF. Return the size of the | |
79 | // member, and set *PNAME to the name. | |
80 | off_t | |
81 | read_header(off_t off, std::string* pname); | |
82 | ||
83 | // Include an archive member in the link. | |
84 | void | |
12e14209 | 85 | include_member(Symbol_table*, Layout*, Input_objects*, off_t off); |
61ba1cf9 ILT |
86 | |
87 | // An entry in the archive map of symbols to object files. | |
88 | struct Armap_entry | |
89 | { | |
90 | // The symbol name. | |
91 | const char* name; | |
92 | // The offset to the file. | |
93 | off_t offset; | |
94 | }; | |
95 | ||
96 | // Name of object as printed to user. | |
97 | std::string name_; | |
98 | // For reading the file. | |
99 | Input_file* input_file_; | |
100 | // The archive map. | |
101 | std::vector<Armap_entry> armap_; | |
102 | // The extended name table. | |
103 | std::string extended_names_; | |
104 | }; | |
105 | ||
106 | // This class is used to read an archive and pick out the desired | |
107 | // elements and add them to the link. | |
108 | ||
109 | class Add_archive_symbols : public Task | |
110 | { | |
111 | public: | |
12e14209 ILT |
112 | Add_archive_symbols(Symbol_table* symtab, Layout* layout, |
113 | Input_objects* input_objects, | |
61ba1cf9 ILT |
114 | Archive* archive, Task_token* this_blocker, |
115 | Task_token* next_blocker) | |
12e14209 ILT |
116 | : symtab_(symtab), layout_(layout), input_objects_(input_objects), |
117 | archive_(archive), this_blocker_(this_blocker), | |
118 | next_blocker_(next_blocker) | |
61ba1cf9 ILT |
119 | { } |
120 | ||
121 | ~Add_archive_symbols(); | |
122 | ||
123 | // The standard Task methods. | |
124 | ||
125 | Is_runnable_type | |
126 | is_runnable(Workqueue*); | |
127 | ||
128 | Task_locker* | |
129 | locks(Workqueue*); | |
130 | ||
131 | void | |
132 | run(Workqueue*); | |
133 | ||
134 | private: | |
135 | class Add_archive_symbols_locker; | |
136 | ||
137 | Symbol_table* symtab_; | |
12e14209 | 138 | Layout* layout_; |
61ba1cf9 ILT |
139 | Input_objects* input_objects_; |
140 | Archive* archive_; | |
141 | Task_token* this_blocker_; | |
142 | Task_token* next_blocker_; | |
143 | }; | |
144 | ||
145 | } // End namespace gold. | |
146 | ||
147 | #endif // !defined(GOLD_ARCHIVE_H) |