2009-06-25 Kai Tietz <kai.tietz@onevision.com>
[binutils.git] / gold / incremental.h
blobed074ae946a9155e0ce1be59ecff9f774f17498f
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"
32 namespace gold
35 class Archive;
36 class Input_argument;
37 class Incremental_inputs_checker;
38 class Object;
39 class Output_section_data;
41 // Incremental input type as stored in .gnu_incremental_inputs.
43 enum Incremental_input_type
45 INCREMENTAL_INPUT_INVALID = 0,
46 INCREMENTAL_INPUT_OBJECT = 1,
47 INCREMENTAL_INPUT_ARCHIVE = 2,
48 INCREMENTAL_INPUT_SHARED_LIBRARY = 3,
49 INCREMENTAL_INPUT_SCRIPT = 4
52 // This class contains the information needed during an incremental
53 // build about the inputs necessary to build the .gnu_incremental_inputs.
54 class Incremental_inputs
56 public:
57 Incremental_inputs()
58 : lock_(new Lock()), inputs_(NULL), command_line_key_(0),
59 strtab_(new Stringpool())
60 { }
61 ~Incremental_inputs() { delete this->strtab_; }
63 // Record the command line.
64 void
65 report_command_line(int argc, const char* const* argv);
67 // Record the input arguments obtained from parsing the command line.
68 void
69 report_inputs(const Input_arguments& inputs)
70 { this->inputs_ = &inputs; }
72 // Record that the input argument INPUT is an archive ARCHIVE.
73 void
74 report_archive(const Input_argument* input, Archive* archive);
76 // Record that the input argument INPUT is to an object OBJ.
77 void
78 report_object(const Input_argument* input, Object* obj);
80 // Record that the input argument INPUT is to an script SCRIPT.
81 void
82 report_script(const Input_argument* input, Script_info* script);
84 // Prepare for layout. Called from Layout::finalize.
85 void
86 finalize();
88 // Create the content of the .gnu_incremental_inputs section.
89 Output_section_data*
90 create_incremental_inputs_section_data();
92 // Return the .gnu_incremental_strtab stringpool.
93 Stringpool*
94 get_stringpool()
95 { return this->strtab_; }
97 private:
98 // Code for each of the four possible variants of create_inputs_section_data.
99 template<int size, bool big_endian>
100 Output_section_data*
101 sized_create_inputs_section_data();
103 // Compute indexes in the order in which the inputs should appear in
104 // .gnu_incremental_inputs and put file names to the stringtable.
105 // This needs to be done after all the scripts are parsed.
107 void
108 finalize_inputs(Input_argument_list::const_iterator begin,
109 Input_argument_list::const_iterator end,
110 unsigned int* index);
112 // Additional data about an input needed for an incremental link.
113 // None of these pointers is owned by the structure.
114 struct Input_info
116 Input_info()
117 : type(INCREMENTAL_INPUT_INVALID), archive(NULL), object(NULL),
118 script(NULL), filename_key(0), index(0)
121 // Type of the file pointed by this argument.
122 Incremental_input_type type;
124 // Present if type == INCREMENTAL_INPUT_ARCHIVE.
125 Archive* archive;
127 // Present if type == INCREMENTAL_INPUT_OBJECT or
128 // INCREMENTAL_INPUT_SHARED_LIBRARY.
129 Object* object;
131 // Present if type == INCREMENTAL_INPUT_SCRIPT.
132 Script_info* script;
134 // Key of the filename string in the section stringtable.
135 Stringpool::Key filename_key;
137 // Position of the entry information in the output section.
138 unsigned int index;
141 typedef std::map<const Input_argument*, Input_info> Inputs_info_map;
143 // A lock guarding access to inputs_ during the first phase of linking, when
144 // report_ function may be called from multiple threads.
145 Lock* lock_;
147 // The list of input arguments obtained from parsing the command line.
148 const Input_arguments* inputs_;
150 // A map containing additional information about the input elements.
151 Inputs_info_map inputs_map_;
153 // The key of the command line string in the string pool.
154 Stringpool::Key command_line_key_;
155 // The .gnu_incremental_strtab string pool associated with the
156 // .gnu_incremental_inputs.
157 Stringpool* strtab_;
160 } // End namespace gold.
162 #endif // !defined(GOLD_INCREMENTAL_H)