1 // script.h -- handle linker scripts for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@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 // We implement a subset of the original GNU ld linker script language
24 // for compatibility. The goal is not to implement the entire
25 // language. It is merely to implement enough to handle common uses.
26 // In particular we need to handle /usr/lib/libc.so on a typical
27 // GNU/Linux system, and we want to handle linker scripts used by the
28 // Linux kernel build.
38 class General_options
;
50 // This class represents an expression in a linker script.
55 // These should only be created by child classes.
63 // Return the value of the expression.
65 eval(const Symbol_table
*, const Layout
*);
68 struct Expression_eval_info
;
71 // Compute the value of the expression (implemented by child class).
72 // This is public rather than protected because it is called
73 // directly by children of Expression on other Expression objects.
75 value(const Expression_eval_info
*) = 0;
79 Expression(const Expression
&);
80 Expression
& operator=(const Expression
&);
83 // We can read a linker script in two different contexts: when
84 // initially parsing the command line, and when we find an input file
85 // which is actually a linker script. Also some of the data which can
86 // be set by a linker script can also be set via command line options
87 // like -e and --defsym. This means that we have a type of data which
88 // can be set both during command line option parsing and while
89 // reading input files. We store that data in an instance of this
90 // object. We will keep pointers to that instance in both the
91 // Command_line and Layout objects.
101 { return this->entry_
.empty() ? NULL
: this->entry_
.c_str(); }
103 // Set the entry address.
105 set_entry(const char* entry
, size_t length
)
106 { this->entry_
.assign(entry
, length
); }
108 // Add a symbol to be defined. These are for symbol definitions
109 // which appear outside of a SECTIONS clause.
111 add_symbol_assignment(const char* name
, size_t length
, Expression
* value
,
112 bool provided
, bool hidden
)
114 this->symbol_assignments_
.push_back(Symbol_assignment(name
, length
, value
,
118 // Define a symbol from the command line.
120 define_symbol(const char* definition
);
122 // Add all symbol definitions to the symbol table.
124 add_symbols_to_table(Symbol_table
*, const Target
*);
126 // Finalize the symbol values.
128 finalize_symbols(Symbol_table
*, const Layout
*);
131 // We keep a list of symbol assignments.
132 struct Symbol_assignment
136 // Expression to assign to symbol.
138 // Whether the assignment should be provided (only set if there is
139 // an undefined reference to the symbol.
141 // Whether the assignment should be hidden.
143 // The entry in the symbol table.
146 Symbol_assignment(const char* namea
, size_t lengtha
, Expression
* valuea
,
147 bool providea
, bool hiddena
)
148 : name(namea
, lengtha
), value(valuea
), provide(providea
),
149 hidden(hiddena
), sym(NULL
)
153 typedef std::vector
<Symbol_assignment
> Symbol_assignments
;
157 sized_finalize_symbols(Symbol_table
*, const Layout
*);
159 // The entry address. This will be empty if not set.
162 Symbol_assignments symbol_assignments_
;
165 // FILE was found as an argument on the command line, but was not
166 // recognized as an ELF file. Try to read it as a script. We've
167 // already read BYTES of data into P. Return true if the file was
168 // handled. This has to handle /usr/lib/libc.so on a GNU/Linux
172 read_input_script(Workqueue
*, const General_options
&, Symbol_table
*, Layout
*,
173 Dirsearch
*, Input_objects
*, Input_group
*,
174 const Input_argument
*, Input_file
*, const unsigned char* p
,
175 off_t bytes
, Task_token
* this_blocker
,
176 Task_token
* next_blocker
);
178 // FILE was found as an argument to --script (-T).
179 // Read it as a script, and execute its contents immediately.
182 read_commandline_script(const char* filename
, Command_line
*);
184 } // End namespace gold.
186 #endif // !defined(GOLD_SCRIPT_H)