Commit | Line | Data |
---|---|---|
3ce2c28e ILT |
1 | // inremental.h -- incremental linking support for gold -*- C++ -*- |
2 | ||
3 | // Copyright 2009 Free Software Foundation, Inc. | |
4 | // Written by Mikolaj Zalewski <mikolajz@google.com>. | |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
23 | #ifndef GOLD_INCREMENTAL_H | |
24 | #define GOLD_INCREMENTAL_H | |
25 | ||
072fe7ce | 26 | #include <map> |
3ce2c28e ILT |
27 | #include <vector> |
28 | ||
29 | #include "stringpool.h" | |
30 | #include "workqueue.h" | |
98fa85cb | 31 | #include "fileread.h" |
3ce2c28e ILT |
32 | |
33 | namespace gold | |
34 | { | |
35 | ||
36 | class Archive; | |
37 | class Input_argument; | |
38 | class Incremental_inputs_checker; | |
39 | class Object; | |
40 | class Output_section_data; | |
41 | ||
072fe7ce ILT |
42 | // Incremental input type as stored in .gnu_incremental_inputs. |
43 | ||
44 | enum Incremental_input_type | |
45 | { | |
46 | INCREMENTAL_INPUT_INVALID = 0, | |
47 | INCREMENTAL_INPUT_OBJECT = 1, | |
48 | INCREMENTAL_INPUT_ARCHIVE = 2, | |
49 | INCREMENTAL_INPUT_SHARED_LIBRARY = 3, | |
50 | INCREMENTAL_INPUT_SCRIPT = 4 | |
51 | }; | |
52 | ||
3ce2c28e ILT |
53 | // This class contains the information needed during an incremental |
54 | // build about the inputs necessary to build the .gnu_incremental_inputs. | |
55 | class Incremental_inputs | |
56 | { | |
57 | public: | |
58 | Incremental_inputs() | |
072fe7ce ILT |
59 | : lock_(new Lock()), inputs_(NULL), command_line_key_(0), |
60 | strtab_(new Stringpool()) | |
3ce2c28e ILT |
61 | { } |
62 | ~Incremental_inputs() { delete this->strtab_; } | |
63 | ||
64 | // Record the command line. | |
65 | void | |
66 | report_command_line(int argc, const char* const* argv); | |
072fe7ce ILT |
67 | |
68 | // Record the input arguments obtained from parsing the command line. | |
69 | void | |
70 | report_inputs(const Input_arguments& inputs) | |
71 | { this->inputs_ = &inputs; } | |
72 | ||
73 | // Record that the input argument INPUT is an archive ARCHIVE. | |
74 | void | |
75 | report_archive(const Input_argument* input, Archive* archive); | |
76 | ||
77 | // Record that the input argument INPUT is to an object OBJ. | |
78 | void | |
79 | report_object(const Input_argument* input, Object* obj); | |
80 | ||
81 | // Record that the input argument INPUT is to an script SCRIPT. | |
82 | void | |
98fa85cb ILT |
83 | report_script(const Input_argument* input, Timespec mtime, |
84 | Script_info* script); | |
072fe7ce | 85 | |
3ce2c28e ILT |
86 | // Prepare for layout. Called from Layout::finalize. |
87 | void | |
88 | finalize(); | |
89 | ||
90 | // Create the content of the .gnu_incremental_inputs section. | |
91 | Output_section_data* | |
92 | create_incremental_inputs_section_data(); | |
072fe7ce ILT |
93 | |
94 | // Return the .gnu_incremental_strtab stringpool. | |
3ce2c28e ILT |
95 | Stringpool* |
96 | get_stringpool() | |
97 | { return this->strtab_; } | |
98 | ||
99 | private: | |
100 | // Code for each of the four possible variants of create_inputs_section_data. | |
101 | template<int size, bool big_endian> | |
102 | Output_section_data* | |
072fe7ce ILT |
103 | sized_create_inputs_section_data(); |
104 | ||
105 | // Compute indexes in the order in which the inputs should appear in | |
106 | // .gnu_incremental_inputs and put file names to the stringtable. | |
107 | // This needs to be done after all the scripts are parsed. | |
108 | ||
109 | void | |
110 | finalize_inputs(Input_argument_list::const_iterator begin, | |
111 | Input_argument_list::const_iterator end, | |
112 | unsigned int* index); | |
113 | ||
114 | // Additional data about an input needed for an incremental link. | |
115 | // None of these pointers is owned by the structure. | |
116 | struct Input_info | |
117 | { | |
118 | Input_info() | |
98fa85cb ILT |
119 | : type(INCREMENTAL_INPUT_INVALID), archive(NULL), filename_key(0), |
120 | index(0) | |
072fe7ce ILT |
121 | { } |
122 | ||
123 | // Type of the file pointed by this argument. | |
124 | Incremental_input_type type; | |
125 | ||
98fa85cb ILT |
126 | union |
127 | { | |
128 | // Present if type == INCREMENTAL_INPUT_ARCHIVE. | |
129 | Archive* archive; | |
130 | ||
131 | // Present if type == INCREMENTAL_INPUT_OBJECT or | |
132 | // INCREMENTAL_INPUT_SHARED_LIBRARY. | |
133 | Object* object; | |
134 | ||
135 | // Present if type == INCREMENTAL_INPUT_SCRIPT. | |
136 | Script_info* script; | |
137 | }; | |
072fe7ce ILT |
138 | |
139 | // Key of the filename string in the section stringtable. | |
140 | Stringpool::Key filename_key; | |
141 | ||
142 | // Position of the entry information in the output section. | |
143 | unsigned int index; | |
98fa85cb ILT |
144 | |
145 | // Last modification time of the file. | |
146 | Timespec mtime; | |
072fe7ce ILT |
147 | }; |
148 | ||
149 | typedef std::map<const Input_argument*, Input_info> Inputs_info_map; | |
150 | ||
151 | // A lock guarding access to inputs_ during the first phase of linking, when | |
152 | // report_ function may be called from multiple threads. | |
153 | Lock* lock_; | |
154 | ||
155 | // The list of input arguments obtained from parsing the command line. | |
156 | const Input_arguments* inputs_; | |
157 | ||
158 | // A map containing additional information about the input elements. | |
159 | Inputs_info_map inputs_map_; | |
3ce2c28e ILT |
160 | |
161 | // The key of the command line string in the string pool. | |
162 | Stringpool::Key command_line_key_; | |
163 | // The .gnu_incremental_strtab string pool associated with the | |
164 | // .gnu_incremental_inputs. | |
165 | Stringpool* strtab_; | |
166 | }; | |
167 | ||
168 | } // End namespace gold. | |
169 | ||
170 | #endif // !defined(GOLD_INCREMENTAL_H) |