1 // inremental.h -- incremental linking support for gold -*- C++ -*-
3 // Copyright 2009 Free Software Foundation, Inc.
4 // Written by Mikolaj Zalewski <mikolajz@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #ifndef GOLD_INCREMENTAL_H
24 #define GOLD_INCREMENTAL_H
29 #include "elfcpp_file.h"
30 #include "stringpool.h"
31 #include "workqueue.h"
40 class Incremental_inputs_checker
;
42 class Output_section_data
;
44 // Incremental input type as stored in .gnu_incremental_inputs.
46 enum Incremental_input_type
48 INCREMENTAL_INPUT_INVALID
= 0,
49 INCREMENTAL_INPUT_OBJECT
= 1,
50 INCREMENTAL_INPUT_ARCHIVE
= 2,
51 INCREMENTAL_INPUT_SHARED_LIBRARY
= 3,
52 INCREMENTAL_INPUT_SCRIPT
= 4
55 // An object representing the ELF file we edit during an incremental build.
56 // Similar to Object or Dynobj, but operates on Output_file and contains
57 // method specific to file edition (TBD). This is the abstract parent class
58 // implemented in Sized_incremental_binary<size, big_endian> for a specific
59 // endianness and size.
61 class Incremental_binary
64 Incremental_binary(Output_file
* output
, Target
* target
)
65 : output_(output
), target_(target
)
72 // Functions and types for the elfcpp::Elf_file interface. This
73 // permit us to use Incremental_binary as the File template parameter for
76 // The View class is returned by view. It must support a single
77 // method, data(). This is trivial, because Output_file::get_output_view
82 View(const unsigned char* p
)
91 const unsigned char* p_
;
96 view(off_t file_offset
, section_size_type data_size
)
97 { return View(this->output_
->get_input_view(file_offset
, data_size
)); }
99 // A location in the file.
105 Location(off_t fo
, section_size_type ds
)
106 : file_offset(fo
), data_size(ds
)
110 : file_offset(0), data_size(0)
114 // Get a View given a Location.
115 View
view(Location loc
)
116 { return View(this->view(loc
.file_offset
, loc
.data_size
)); }
120 error(const char* format
, ...) const ATTRIBUTE_PRINTF_2
;
123 // Find the .gnu_incremental_inputs section. It selects the first section
124 // of type SHT_GNU_INCREMENTAL_INPUTS. Returns false if such a section
127 find_incremental_inputs_section(Location
* location
)
128 { return do_find_incremental_inputs_section(location
); }
131 // Find incremental inputs section.
133 do_find_incremental_inputs_section(Location
* location
) = 0;
136 // Edited output file object.
137 Output_file
* output_
;
138 // Target of the output file.
142 template<int size
, bool big_endian
>
143 class Sized_incremental_binary
: public Incremental_binary
146 Sized_incremental_binary(Output_file
* output
,
147 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
,
149 : Incremental_binary(output
, target
), elf_file_(this, ehdr
)
154 do_find_incremental_inputs_section(Location
* location
);
157 // Output as an ELF file.
158 elfcpp::Elf_file
<size
, big_endian
, Incremental_binary
> elf_file_
;
161 // Create an Incremental_binary object for FILE. Returns NULL is this is not
162 // possible, e.g. FILE is not an ELF file or has an unsupported target.
164 open_incremental_binary(Output_file
* file
);
166 // Code invoked early during an incremental link that checks what files need
168 class Incremental_checker
171 Incremental_checker(const char* output_name
)
172 : output_name_(output_name
)
175 // Analyzes the output file to check if incremental linking is possible and
176 // what files needs to be relinked.
178 can_incrementally_link_output_file();
181 const char* output_name_
;
184 // This class contains the information needed during an incremental
185 // build about the inputs necessary to build the .gnu_incremental_inputs.
186 class Incremental_inputs
190 : lock_(new Lock()), inputs_(NULL
), command_line_key_(0),
191 strtab_(new Stringpool())
193 ~Incremental_inputs() { delete this->strtab_
; }
195 // Record the command line.
197 report_command_line(int argc
, const char* const* argv
);
199 // Record the input arguments obtained from parsing the command line.
201 report_inputs(const Input_arguments
& inputs
)
202 { this->inputs_
= &inputs
; }
204 // Record that the input argument INPUT is an archive ARCHIVE.
206 report_archive(const Input_argument
* input
, Archive
* archive
);
208 // Record that the input argument INPUT is to an object OBJ.
210 report_object(const Input_argument
* input
, Object
* obj
);
212 // Record that the input argument INPUT is to an script SCRIPT.
214 report_script(const Input_argument
* input
, Timespec mtime
,
215 Script_info
* script
);
217 // Prepare for layout. Called from Layout::finalize.
221 // Create the content of the .gnu_incremental_inputs section.
223 create_incremental_inputs_section_data();
225 // Return the .gnu_incremental_strtab stringpool.
228 { return this->strtab_
; }
231 // Code for each of the four possible variants of create_inputs_section_data.
232 template<int size
, bool big_endian
>
234 sized_create_inputs_section_data();
236 // Compute indexes in the order in which the inputs should appear in
237 // .gnu_incremental_inputs and put file names to the stringtable.
238 // This needs to be done after all the scripts are parsed.
241 finalize_inputs(Input_argument_list::const_iterator begin
,
242 Input_argument_list::const_iterator end
,
243 unsigned int* index
);
245 // Additional data about an input needed for an incremental link.
246 // None of these pointers is owned by the structure.
250 : type(INCREMENTAL_INPUT_INVALID
), archive(NULL
), filename_key(0),
254 // Type of the file pointed by this argument.
255 Incremental_input_type type
;
259 // Present if type == INCREMENTAL_INPUT_ARCHIVE.
262 // Present if type == INCREMENTAL_INPUT_OBJECT or
263 // INCREMENTAL_INPUT_SHARED_LIBRARY.
266 // Present if type == INCREMENTAL_INPUT_SCRIPT.
270 // Key of the filename string in the section stringtable.
271 Stringpool::Key filename_key
;
273 // Position of the entry information in the output section.
276 // Last modification time of the file.
280 typedef std::map
<const Input_argument
*, Input_info
> Inputs_info_map
;
282 // A lock guarding access to inputs_ during the first phase of linking, when
283 // report_ function may be called from multiple threads.
286 // The list of input arguments obtained from parsing the command line.
287 const Input_arguments
* inputs_
;
289 // A map containing additional information about the input elements.
290 Inputs_info_map inputs_map_
;
292 // The key of the command line string in the string pool.
293 Stringpool::Key command_line_key_
;
294 // The .gnu_incremental_strtab string pool associated with the
295 // .gnu_incremental_inputs.
299 } // End namespace gold.
301 #endif // !defined(GOLD_INCREMENTAL_H)