merge from gcc
[deliverable/binutils-gdb.git] / gold / incremental.h
CommitLineData
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
33namespace gold
34{
35
36class Archive;
37class Input_argument;
38class Incremental_inputs_checker;
39class Object;
40class Output_section_data;
41
072fe7ce
ILT
42// Incremental input type as stored in .gnu_incremental_inputs.
43
44enum 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
44453f85
ILT
53// Code invoked early during an incremental link that checks what files need
54// to be relinked.
55class Incremental_checker
56{
57 public:
58 Incremental_checker(const char* output_name)
59 : output_name_(output_name)
60 { }
61
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();
66
67 private:
68 const char* output_name_;
69};
70
3ce2c28e
ILT
71// This class contains the information needed during an incremental
72// build about the inputs necessary to build the .gnu_incremental_inputs.
73class Incremental_inputs
74{
75 public:
76 Incremental_inputs()
072fe7ce
ILT
77 : lock_(new Lock()), inputs_(NULL), command_line_key_(0),
78 strtab_(new Stringpool())
3ce2c28e
ILT
79 { }
80 ~Incremental_inputs() { delete this->strtab_; }
81
82 // Record the command line.
83 void
84 report_command_line(int argc, const char* const* argv);
072fe7ce
ILT
85
86 // Record the input arguments obtained from parsing the command line.
87 void
88 report_inputs(const Input_arguments& inputs)
89 { this->inputs_ = &inputs; }
90
91 // Record that the input argument INPUT is an archive ARCHIVE.
92 void
93 report_archive(const Input_argument* input, Archive* archive);
94
95 // Record that the input argument INPUT is to an object OBJ.
96 void
97 report_object(const Input_argument* input, Object* obj);
98
99 // Record that the input argument INPUT is to an script SCRIPT.
100 void
98fa85cb
ILT
101 report_script(const Input_argument* input, Timespec mtime,
102 Script_info* script);
072fe7ce 103
3ce2c28e
ILT
104 // Prepare for layout. Called from Layout::finalize.
105 void
106 finalize();
107
108 // Create the content of the .gnu_incremental_inputs section.
109 Output_section_data*
110 create_incremental_inputs_section_data();
072fe7ce
ILT
111
112 // Return the .gnu_incremental_strtab stringpool.
3ce2c28e
ILT
113 Stringpool*
114 get_stringpool()
115 { return this->strtab_; }
116
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*
072fe7ce
ILT
121 sized_create_inputs_section_data();
122
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.
126
127 void
128 finalize_inputs(Input_argument_list::const_iterator begin,
129 Input_argument_list::const_iterator end,
130 unsigned int* index);
131
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
135 {
136 Input_info()
98fa85cb
ILT
137 : type(INCREMENTAL_INPUT_INVALID), archive(NULL), filename_key(0),
138 index(0)
072fe7ce
ILT
139 { }
140
141 // Type of the file pointed by this argument.
142 Incremental_input_type type;
143
98fa85cb
ILT
144 union
145 {
146 // Present if type == INCREMENTAL_INPUT_ARCHIVE.
147 Archive* archive;
44453f85 148
98fa85cb
ILT
149 // Present if type == INCREMENTAL_INPUT_OBJECT or
150 // INCREMENTAL_INPUT_SHARED_LIBRARY.
151 Object* object;
44453f85 152
98fa85cb
ILT
153 // Present if type == INCREMENTAL_INPUT_SCRIPT.
154 Script_info* script;
155 };
072fe7ce
ILT
156
157 // Key of the filename string in the section stringtable.
158 Stringpool::Key filename_key;
159
160 // Position of the entry information in the output section.
161 unsigned int index;
44453f85 162
98fa85cb
ILT
163 // Last modification time of the file.
164 Timespec mtime;
072fe7ce
ILT
165 };
166
167 typedef std::map<const Input_argument*, Input_info> Inputs_info_map;
168
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_;
44453f85 172
072fe7ce
ILT
173 // The list of input arguments obtained from parsing the command line.
174 const Input_arguments* inputs_;
175
176 // A map containing additional information about the input elements.
177 Inputs_info_map inputs_map_;
3ce2c28e
ILT
178
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_;
184};
185
186} // End namespace gold.
187
188#endif // !defined(GOLD_INCREMENTAL_H)
This page took 0.05166 seconds and 4 git commands to generate.