*** empty log message ***
[platform/upstream/binutils.git] / ld / ldlang.h
1 /* ldlang.h -
2
3    Copyright (C) 1991 Free Software Foundation, Inc.
4
5    This file is part of GLD, the Gnu Linker.
6
7    GLD is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 1, or (at your option)
10    any later version.
11
12    GLD is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GLD; see the file COPYING.  If not, write to
19    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21
22 typedef enum {
23   lang_input_file_is_l_enum,
24   lang_input_file_is_symbols_only_enum,
25   lang_input_file_is_marker_enum,
26   lang_input_file_is_fake_enum,
27 lang_input_file_is_search_file_enum,
28   lang_input_file_is_file_enum } lang_input_file_enum_type;
29
30 typedef unsigned short fill_type;
31 typedef struct statement_list {
32   union lang_statement_union *head;
33   union lang_statement_union **tail;
34 } lang_statement_list_type;
35
36
37 typedef struct {
38   boolean flag_read;
39   boolean flag_write;
40   boolean flag_executable;
41   boolean flag_loadable;
42 } lang_section_flags_type;
43
44 typedef struct memory_region_struct {
45   char *name;
46   struct memory_region_struct *next;
47   bfd_vma origin;
48   bfd_offset length;
49   bfd_vma current;
50   lang_section_flags_type flags;
51 } lang_memory_region_type ;
52
53 typedef struct lang_statement_header_struct 
54 {
55 union  lang_statement_union  *next;
56   enum statement_enum {
57     lang_output_section_statement_enum,
58     lang_assignment_statement_enum,
59     lang_input_statement_enum,
60     lang_address_statement_enum,
61     lang_wild_statement_enum,
62     lang_input_section_enum,
63     lang_object_symbols_statement_enum,
64     lang_fill_statement_enum,
65     lang_data_statement_enum,
66     lang_target_statement_enum,
67     lang_output_statement_enum,
68     lang_padding_statement_enum,
69
70     lang_afile_asection_pair_statement_enum
71   } type;
72
73 } lang_statement_header_type;
74
75
76 typedef struct 
77 {
78   lang_statement_header_type header;
79   union etree_union *exp;
80 }  lang_assignment_statement_type;
81
82
83 typedef struct lang_target_statement_struct {
84   lang_statement_header_type header;
85   CONST char *target;
86 } lang_target_statement_type;
87
88
89 typedef struct lang_output_statement_struct {
90   lang_statement_header_type header;
91   CONST char *name;
92 } lang_output_statement_type;
93
94
95 typedef struct lang_output_section_statement_struct 
96 {
97   lang_statement_header_type header;
98   union etree_union *addr_tree;
99   lang_statement_list_type children;
100   CONST char *memspec;
101   union lang_statement_union *next;
102   CONST char *name;
103   unsigned long subsection_alignment;
104   boolean processed;
105
106   asection *bfd_section;
107   lang_section_flags_type flags;
108   struct memory_region_struct *region;
109   size_t block_value;
110   fill_type fill;
111 } lang_output_section_statement_type;
112
113
114 typedef struct {
115   lang_statement_header_type header;
116 } lang_common_statement_type;
117
118 typedef struct {
119   lang_statement_header_type header;
120 } lang_object_symbols_statement_type;
121
122 typedef struct {
123   lang_statement_header_type header;
124   fill_type fill;
125 } lang_fill_statement_type;
126
127 typedef struct {
128   lang_statement_header_type header;
129   unsigned int type;
130   union  etree_union *exp;
131   bfd_vma value;
132   asection *output_section;
133   bfd_vma output_vma;
134 } lang_data_statement_type;
135
136
137
138
139 typedef struct lang_input_statement_struct
140   {
141     lang_statement_header_type header;
142     /* Name of this file.  */
143     CONST char *filename;
144     /* Name to use for the symbol giving address of text start */
145     /* Usually the same as filename, but for a file spec'd with -l
146        this is the -l switch itself rather than the filename.  */
147     CONST char *local_sym_name;
148
149     /* Describe the layout of the contents of the file */
150
151     /* The file's a.out header.  */
152     /*  struct exec header;*/
153     /* Offset in file of GDB symbol segment, or 0 if there is none.  */
154     int symseg_offset;
155
156     /* Describe data from the file loaded into core */
157
158     bfd *the_bfd;
159
160     boolean closed;
161     file_ptr passive_position;
162
163     /* Symbol table of the file.  */
164     asymbol **asymbols;
165     unsigned int symbol_count;
166
167     /* For library members only */
168
169     /* For a library, points to chain of entries for the library members.  */
170     struct lang_input_statement_struct *subfiles;
171     /* For a library member, offset of the member within the archive.
172        Zero for files that are not library members.  */
173     /*  int starting_offset;*/
174     /* Size of contents of this file, if library member.  */
175     int total_size;
176     /* For library member, points to the library's own entry.  */
177     struct lang_input_statement_struct *superfile;
178     /* For library member, points to next entry for next member.  */
179     struct lang_input_statement_struct *chain;
180     /* Point to the next file - whatever it is, wanders up and down
181        archives */
182
183     union lang_statement_union  *next;
184     /* Point to the next file, but skips archive contents */
185     union  lang_statement_union  *next_real_file;
186
187     boolean is_archive;
188
189     /* 1 means search a set of directories for this file.  */
190     boolean search_dirs_flag;
191
192     /* 1 means this is base file of incremental load.
193        Do not load this file's text or data.
194        Also default text_start to after this file's bss. */
195
196     boolean just_syms_flag;
197
198     boolean loaded;
199
200
201     /*    unsigned int globals_in_this_file;*/
202     CONST char *target;
203     boolean real;
204
205     asection *common_section;
206     asection *common_output_section;
207   } lang_input_statement_type;
208
209 typedef struct {
210   lang_statement_header_type header;
211   asection *section;
212   lang_input_statement_type *ifile;
213
214 } lang_input_section_type;
215
216
217 typedef struct {
218   lang_statement_header_type header;
219   asection *section;
220   union lang_statement_union *file;
221 } lang_afile_asection_pair_statement_type;
222
223 typedef struct lang_wild_statement_struct {
224   lang_statement_header_type header;
225 CONST char *section_name;
226 CONST char *filename;
227   lang_statement_list_type children;
228 } lang_wild_statement_type;
229
230 typedef struct lang_address_statement_struct {
231   lang_statement_header_type header;
232   CONST  char *section_name;
233   union  etree_union *address;
234 } lang_address_statement_type;
235
236 typedef struct {
237   lang_statement_header_type header;
238   bfd_vma output_offset;
239   size_t size;
240   asection *output_section;
241   fill_type fill;
242 } lang_padding_statement_type;
243
244 typedef union lang_statement_union 
245 {
246   lang_statement_header_type header;
247   union lang_statement_union *next;
248   lang_wild_statement_type wild_statement;
249   lang_data_statement_type data_statement;
250   lang_address_statement_type address_statement;
251   lang_output_section_statement_type output_section_statement;
252   lang_afile_asection_pair_statement_type afile_asection_pair_statement;
253   lang_assignment_statement_type assignment_statement;
254   lang_input_statement_type input_statement;
255   lang_target_statement_type target_statement;
256   lang_output_statement_type output_statement;
257   lang_input_section_type input_section;
258   lang_common_statement_type common_statement;
259   lang_object_symbols_statement_type object_symbols_statement;
260   lang_fill_statement_type fill_statement;
261   lang_padding_statement_type padding_statement;
262 } lang_statement_union_type;
263
264
265
266 PROTO(void,lang_init,(void));
267 PROTO(struct memory_region_struct ,
268       *lang_memory_region_lookup,(CONST
269                                   char *CONST));
270
271
272 PROTO(void ,lang_map,(FILE *));
273 PROTO(void,lang_set_flags,(lang_section_flags_type *, CONST char *));
274 PROTO(void,lang_add_output,(CONST char *));
275
276 PROTO(void,lang_final,(void));
277 PROTO(struct symbol_cache_entry *,create_symbol,(CONST char *, unsigned int, struct sec_struct *));
278 PROTO(void ,lang_process,(void));
279 PROTO(void ,lang_section_start,(CONST char *, union etree_union *));
280 PROTO(void,lang_add_entry,(CONST char *));
281 PROTO(void,lang_add_target,(CONST char *));
282 PROTO(void,lang_add_wild,(CONST char *CONST , CONST char *CONST));
283 PROTO(void,lang_add_map,(CONST char *));
284 PROTO(void,lang_add_fill,(int));
285 PROTO(void,lang_add_assignment,(union etree_union *));
286 PROTO(void,lang_add_attribute,(enum statement_enum));
287 PROTO(void,lang_startup,(CONST char *));
288 PROTO(void,lang_float,(enum boolean));
289 PROTO(void,lang_leave_output_section_statement,(bfd_vma, CONST char *));
290 PROTO(void,lang_abs_symbol_at_end_of,(CONST char *, CONST char *));
291 PROTO(void,lang_abs_symbol_at_beginning_of,(CONST char *, CONST char *));
292 PROTO(void,lang_statement_append,(struct statement_list *, union lang_statement_union *, union lang_statement_union **));
293 PROTO(void, lang_for_each_file,(void (*dothis)(lang_input_statement_type *)));
294
295      
296 #define LANG_FOR_EACH_INPUT_STATEMENT(statement)               \
297   extern lang_statement_list_type file_chain;                   \
298   lang_input_statement_type *statement;                         \
299   for (statement = (lang_input_statement_type *)file_chain.head;\
300        statement != (lang_input_statement_type *)NULL;          \
301        statement = (lang_input_statement_type *)statement->next)\
302
303 #define LANG_FOR_EACH_INPUT_SECTION(statement, abfd, section, x) \
304 { extern lang_statement_list_type file_chain;                   \
305   lang_input_statement_type *statement;                         \
306   for (statement = (lang_input_statement_type *)file_chain.head;\
307        statement != (lang_input_statement_type *)NULL;          \
308        statement = (lang_input_statement_type *)statement->next)\
309     {                                                           \
310       asection *section;                                        \
311       bfd *abfd = statement->the_bfd;                           \
312       for (section = abfd->sections;                            \
313            section != (asection *)NULL;                         \
314            section = section->next) {                           \
315         x;                                                      \
316       }                                                         \
317     }                                                           \
318  }              
319
320 #define LANG_FOR_EACH_OUTPUT_SECTION(section, x)                \
321  { extern bfd *output_bfd;                                      \
322    asection *section;                                           \
323    for (section = output_bfd->sections;                         \
324         section != (asection *)NULL;                            \
325         section = section->next)                                \
326         { x; }                                                  \
327  }
328                                         
329
330 PROTO(void, lang_process,(void));
331 PROTO(void, ldlang_add_file,(lang_input_statement_type *));
332
333 PROTO(lang_output_section_statement_type
334       *,lang_output_section_find,(CONST char * CONST));
335
336 PROTO(lang_input_statement_type *,
337        lang_add_input_file,(char *name,
338                             lang_input_file_enum_type file_type,
339                             char *target));
340 PROTO(lang_output_section_statement_type *,
341 lang_output_section_statement_lookup,(CONST char * CONST name));
342
343 PROTO(void, ldlang_add_undef,(CONST char *CONST name));
344 PROTO(void, lang_add_output_format,(CONST char *));