Don't pass around the target in order to define symbols; get it from
[external/binutils.git] / gold / script-sections.h
1 // script-sections.h -- linker script SECTIONS for gold   -*- C++ -*-
2
3 // Copyright 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@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 // This is for the support of the SECTIONS clause in linker scripts.
24
25 #ifndef GOLD_SCRIPT_SECTIONS_H
26 #define GOLD_SCRIPT_SECTIONS_H
27
28 #include <cstdio>
29 #include <vector>
30
31 namespace gold
32 {
33
34 struct Parser_output_section_header;
35 struct Parser_output_section_trailer;
36 struct Input_section_spec;
37 class Expression;
38 class Sections_element;
39 class Output_section_definition;
40
41 class Script_sections
42 {
43  public:
44   Script_sections();
45
46   // Start a SECTIONS clause.
47   void
48   start_sections();
49
50   // Finish a SECTIONS clause.
51   void
52   finish_sections();
53
54   // Return whether we ever saw a SECTIONS clause.  If we did, then
55   // all section layout needs to go through this class.
56   bool
57   saw_sections_clause() const
58   { return this->saw_sections_clause_; }
59
60   // Return whether we are currently processing a SECTIONS clause.
61   bool
62   in_sections_clause() const
63   { return this->in_sections_clause_; }
64
65   // Start processing entries for an output section.
66   void
67   start_output_section(const char* name, size_t namelen,
68                        const Parser_output_section_header*);
69
70   // Finish processing entries for an output section.
71   void
72   finish_output_section(const Parser_output_section_trailer*);
73
74   // Add a data item to the current output section.
75   void
76   add_data(int size, bool is_signed, Expression* val);
77
78   // Add a symbol to be defined.
79   void
80   add_symbol_assignment(const char* name, size_t length, Expression* value,
81                         bool provide, bool hidden);
82   // Add an assertion.
83   void
84   add_assertion(Expression* check, const char* message, size_t messagelen);
85
86   // Add a setting for the fill value.
87   void
88   add_fill(Expression* val);
89
90   // Add an input section specification.
91   void
92   add_input_section(const Input_section_spec* spec, bool keep);
93
94   // Print the contents to the FILE.  This is for debugging.
95   void
96   print(FILE*) const;
97
98  private:
99   typedef std::vector<Sections_element*> Sections_elements;
100
101   // True if we ever saw a SECTIONS clause.
102   bool saw_sections_clause_;
103   // True if we are currently processing a SECTIONS clause.
104   bool in_sections_clause_;
105   // The list of elements in the SECTIONS clause.
106   Sections_elements* sections_elements_;
107   // The current output section, if there is one.
108   Output_section_definition* output_section_;
109 };
110
111 } // End namespace gold.
112
113 #endif // !defined(GOLD_SCRIPT_SECTIONS_H