bfd/
[binutils.git] / gold / incremental.h
blob9650993303259ed1f1a1dec01113517f95152114
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
26 #include <map>
27 #include <vector>
29 #include "stringpool.h"
30 #include "workqueue.h"
31 #include "fileread.h"
33 namespace gold
36 class Archive;
37 class Input_argument;
38 class Incremental_inputs_checker;
39 class Object;
40 class Output_section_data;
42 // Incremental input type as stored in .gnu_incremental_inputs.
44 enum Incremental_input_type
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
53 // Code invoked early during an incremental link that checks what files need
54 // to be relinked.
55 class Incremental_checker
57 public:
58 Incremental_checker(const char* output_name)
59 : output_name_(output_name)
60 { }
62 // Analyzes the output file to check if incremental linking is possible and
63 // what files needs to be relinked.
64 bool
65 can_incrementally_link_output_file();
67 private:
68 const char* output_name_;
71 // This class contains the information needed during an incremental
72 // build about the inputs necessary to build the .gnu_incremental_inputs.
73 class Incremental_inputs
75 public:
76 Incremental_inputs()
77 : lock_(new Lock()), inputs_(NULL), command_line_key_(0),
78 strtab_(new Stringpool())
79 { }
80 ~Incremental_inputs() { delete this->strtab_; }
82 // Record the command line.
83 void
84 report_command_line(int argc, const char* const* argv);
86 // Record the input arguments obtained from parsing the command line.
87 void
88 report_inputs(const Input_arguments& inputs)
89 { this->inputs_ = &inputs; }
91 // Record that the input argument INPUT is an archive ARCHIVE.
92 void
93 report_archive(const Input_argument* input, Archive* archive);
95 // Record that the input argument INPUT is to an object OBJ.
96 void
97 report_object(const Input_argument* input, Object* obj);
99 // Record that the input argument INPUT is to an script SCRIPT.
100 void
101 report_script(const Input_argument* input, Timespec mtime,
102 Script_info* script);
104 // Prepare for layout. Called from Layout::finalize.
105 void
106 finalize();
108 // Create the content of the .gnu_incremental_inputs section.
109 Output_section_data*
110 create_incremental_inputs_section_data();
112 // Return the .gnu_incremental_strtab stringpool.
113 Stringpool*
114 get_stringpool()
115 { return this->strtab_; }
117 private:
118 // Code for each of the four possible variants of create_inputs_section_data.
119 template<int size, bool big_endian>
120 Output_section_data*
121 sized_create_inputs_section_data();
123 // Compute indexes in the order in which the inputs should appear in
124 // .gnu_incremental_inputs and put file names to the stringtable.
125 // This needs to be done after all the scripts are parsed.
127 void
128 finalize_inputs(Input_argument_list::const_iterator begin,
129 Input_argument_list::const_iterator end,
130 unsigned int* index);
132 // Additional data about an input needed for an incremental link.
133 // None of these pointers is owned by the structure.
134 struct Input_info
136 Input_info()
137 : type(INCREMENTAL_INPUT_INVALID), archive(NULL), filename_key(0),
138 index(0)
141 // Type of the file pointed by this argument.
142 Incremental_input_type type;
144 union
146 // Present if type == INCREMENTAL_INPUT_ARCHIVE.
147 Archive* archive;
149 // Present if type == INCREMENTAL_INPUT_OBJECT or
150 // INCREMENTAL_INPUT_SHARED_LIBRARY.
151 Object* object;
153 // Present if type == INCREMENTAL_INPUT_SCRIPT.
154 Script_info* script;
157 // Key of the filename string in the section stringtable.
158 Stringpool::Key filename_key;
160 // Position of the entry information in the output section.
161 unsigned int index;
163 // Last modification time of the file.
164 Timespec mtime;
167 typedef std::map<const Input_argument*, Input_info> Inputs_info_map;
169 // A lock guarding access to inputs_ during the first phase of linking, when
170 // report_ function may be called from multiple threads.
171 Lock* lock_;
173 // The list of input arguments obtained from parsing the command line.
174 const Input_arguments* inputs_;
176 // A map containing additional information about the input elements.
177 Inputs_info_map inputs_map_;
179 // The key of the command line string in the string pool.
180 Stringpool::Key command_line_key_;
181 // The .gnu_incremental_strtab string pool associated with the
182 // .gnu_incremental_inputs.
183 Stringpool* strtab_;
186 } // End namespace gold.
188 #endif // !defined(GOLD_INCREMENTAL_H)