* lexsup.c (parse_args): Recognize --no-whole-archive.
[platform/upstream/binutils.git] / ld / ldlang.h
1 /* ldlang.h - linker command language support
2    Copyright 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3    
4    This file is part of GLD, the Gnu Linker.
5    
6    GLD is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 1, or (at your option)
9    any later version.
10    
11    GLD is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with GLD; see the file COPYING.  If not, write to
18    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 #ifndef LDLANG_H
21 #define LDLANG_H
22
23 typedef enum
24 {
25   lang_input_file_is_l_enum,
26   lang_input_file_is_symbols_only_enum,
27   lang_input_file_is_marker_enum,
28   lang_input_file_is_fake_enum,
29   lang_input_file_is_search_file_enum,
30   lang_input_file_is_file_enum
31 } lang_input_file_enum_type;
32
33 typedef unsigned int fill_type;
34 typedef struct statement_list
35 {
36   union lang_statement_union *head;
37   union lang_statement_union **tail;
38 } lang_statement_list_type;
39
40
41 typedef struct memory_region_struct
42 {
43   char *name;
44   struct memory_region_struct *next;
45   bfd_vma origin;
46   bfd_size_type length;
47   bfd_vma current;
48   bfd_size_type old_length;
49   int flags;
50   boolean had_full_message;
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     {
58       lang_output_section_statement_enum,
59       lang_assignment_statement_enum,
60       lang_input_statement_enum,
61       lang_address_statement_enum,
62       lang_wild_statement_enum,
63       lang_input_section_enum,
64       lang_object_symbols_statement_enum,
65       lang_fill_statement_enum,
66       lang_data_statement_enum,
67       lang_reloc_statement_enum,
68       lang_target_statement_enum,
69       lang_output_statement_enum,
70       lang_padding_statement_enum,
71       lang_group_statement_enum,
72
73       lang_afile_asection_pair_statement_enum,
74       lang_constructors_statement_enum
75     } type;
76 } lang_statement_header_type;
77
78
79 typedef struct 
80 {
81   lang_statement_header_type header;
82   union etree_union *exp;
83 } lang_assignment_statement_type;
84
85
86 typedef struct lang_target_statement_struct
87 {
88   lang_statement_header_type header;
89   const char *target;
90 } lang_target_statement_type;
91
92
93 typedef struct lang_output_statement_struct
94 {
95   lang_statement_header_type header;
96   const char *name;
97 } lang_output_statement_type;
98
99
100 /* This structure holds a list of program headers describing segments
101    in which this section should be placed.  */
102
103 struct lang_output_section_phdr_list
104 {
105   struct lang_output_section_phdr_list *next;
106   const char *name;
107   boolean used;
108 };
109
110 typedef struct lang_output_section_statement_struct 
111 {
112   lang_statement_header_type header;
113   union etree_union *addr_tree;
114   lang_statement_list_type children;
115   const char *memspec;
116   union lang_statement_union *next;
117   const char *name;
118
119   boolean processed;
120     
121   asection *bfd_section;
122   int flags;                    /* Or together of all input sections */
123   int loadable;                 /* set from NOLOAD flag in script */
124   struct memory_region_struct *region;
125   size_t block_value;
126   fill_type fill;
127
128   int subsection_alignment;  /* alignment of components */
129   int section_alignment;  /* alignment of start of section */
130
131   union etree_union *load_base;
132
133   struct lang_output_section_phdr_list *phdrs;
134 } lang_output_section_statement_type;
135
136
137 typedef struct
138 {
139   lang_statement_header_type header;
140 } lang_common_statement_type;
141
142 typedef struct
143 {
144   lang_statement_header_type header;
145 } lang_object_symbols_statement_type;
146
147 typedef struct
148 {
149   lang_statement_header_type header;
150   fill_type fill;
151   int size;
152   asection *output_section;
153 } lang_fill_statement_type;
154
155 typedef struct
156 {
157   lang_statement_header_type header;
158   unsigned int type;
159   union  etree_union *exp;
160   bfd_vma value;
161   asection *output_section;
162   bfd_vma output_vma;
163 } lang_data_statement_type;
164
165 /* Generate a reloc in the output file.  */
166
167 typedef struct
168 {
169   lang_statement_header_type header;
170
171   /* Reloc to generate.  */
172   bfd_reloc_code_real_type reloc;
173
174   /* Reloc howto structure.  */
175   reloc_howto_type *howto;
176
177   /* Section to generate reloc against.  Exactly one of section and
178      name must be NULL.  */
179   asection *section;
180
181   /* Name of symbol to generate reloc against.  Exactly one of section
182      and name must be NULL.  */
183   const char *name;
184
185   /* Expression for addend.  */
186   union etree_union *addend_exp;
187
188   /* Resolved addend.  */
189   bfd_vma addend_value;
190
191   /* Output section where reloc should be performed.  */
192   asection *output_section;
193
194   /* VMA within output section.  */
195   bfd_vma output_vma;
196 } lang_reloc_statement_type;
197
198 typedef struct lang_input_statement_struct
199 {
200   lang_statement_header_type header;
201   /* Name of this file.  */
202   const char *filename;
203   /* Name to use for the symbol giving address of text start */
204   /* Usually the same as filename, but for a file spec'd with -l
205      this is the -l switch itself rather than the filename.  */
206   const char *local_sym_name;
207     
208   bfd *the_bfd;
209     
210   boolean closed;
211   file_ptr passive_position;
212     
213   /* Symbol table of the file.  */
214   asymbol **asymbols;
215   unsigned int symbol_count;
216     
217   /* Point to the next file - whatever it is, wanders up and down
218      archives */
219     
220   union lang_statement_union  *next;
221   /* Point to the next file, but skips archive contents */
222   union  lang_statement_union  *next_real_file;
223     
224   boolean is_archive;
225     
226   /* 1 means search a set of directories for this file.  */
227   boolean search_dirs_flag;
228     
229   /* 1 means this is base file of incremental load.
230      Do not load this file's text or data.
231      Also default text_start to after this file's bss. */
232     
233   boolean just_syms_flag;
234
235   /* Whether to search for this entry as a dynamic archive.  */
236   boolean dynamic;
237
238   /* Whether to include the entire contents of an archive.  */
239   boolean whole_archive;
240
241   boolean loaded;
242     
243   /*    unsigned int globals_in_this_file;*/
244   const char *target;
245   boolean real;
246   asection *common_section;
247   asection *common_output_section;
248   boolean complained;
249 } lang_input_statement_type;
250
251 typedef struct
252 {
253   lang_statement_header_type header;
254   asection *section;
255   lang_input_statement_type *ifile;
256   
257 } lang_input_section_type;
258
259
260 typedef struct
261 {
262   lang_statement_header_type header;
263   asection *section;
264   union lang_statement_union *file;
265 } lang_afile_asection_pair_statement_type;
266
267 typedef struct lang_wild_statement_struct
268 {
269   lang_statement_header_type header;
270   const char *section_name;
271   const char *filename;
272   lang_statement_list_type children;
273 } lang_wild_statement_type;
274
275 typedef struct lang_address_statement_struct
276 {
277   lang_statement_header_type header;
278   const  char *section_name;
279   union  etree_union *address;
280 } lang_address_statement_type;
281
282 typedef struct
283 {
284   lang_statement_header_type header;
285   bfd_vma output_offset;
286   size_t size;
287   asection *output_section;
288   fill_type fill;
289 } lang_padding_statement_type;
290
291 /* A group statement collects a set of libraries together.  The
292    libraries are searched multiple times, until no new undefined
293    symbols are found.  The effect is to search a group of libraries as
294    though they were a single library.  */
295
296 typedef struct
297 {
298   lang_statement_header_type header;
299   lang_statement_list_type children;
300 } lang_group_statement_type;
301
302 typedef union lang_statement_union 
303 {
304   lang_statement_header_type header;
305   union lang_statement_union *next;
306   lang_wild_statement_type wild_statement;
307   lang_data_statement_type data_statement;
308   lang_reloc_statement_type reloc_statement;
309   lang_address_statement_type address_statement;
310   lang_output_section_statement_type output_section_statement;
311   lang_afile_asection_pair_statement_type afile_asection_pair_statement;
312   lang_assignment_statement_type assignment_statement;
313   lang_input_statement_type input_statement;
314   lang_target_statement_type target_statement;
315   lang_output_statement_type output_statement;
316   lang_input_section_type input_section;
317   lang_common_statement_type common_statement;
318   lang_object_symbols_statement_type object_symbols_statement;
319   lang_fill_statement_type fill_statement;
320   lang_padding_statement_type padding_statement;
321   lang_group_statement_type group_statement;
322 } lang_statement_union_type;
323
324 /* This structure holds information about a program header, from the
325    PHDRS command in the linker script.  */
326
327 struct lang_phdr
328 {
329   struct lang_phdr *next;
330   const char *name;
331   unsigned long type;
332   boolean filehdr;
333   boolean phdrs;
334   etree_type *at;
335   etree_type *flags;
336 };
337
338 extern lang_output_section_statement_type *abs_output_section;
339 extern boolean lang_has_input_file;
340 extern etree_type *base;
341 extern lang_statement_list_type *stat_ptr;
342 extern boolean delete_output_file_on_failure;
343
344 extern const char *entry_symbol;
345 extern boolean entry_from_cmdline;
346
347 extern void lang_init PARAMS ((void));
348 extern struct memory_region_struct *lang_memory_region_lookup
349   PARAMS ((const char *const));
350 extern void lang_map PARAMS ((void));
351 extern void lang_set_flags PARAMS ((int *, const char *));
352 extern void lang_add_output PARAMS ((const char *, int from_script));
353 extern void lang_enter_output_section_statement
354   PARAMS ((const char *output_section_statement_name,
355            etree_type * address_exp,
356            int flags,
357            bfd_vma block_value,
358            etree_type *align,
359            etree_type *subalign,
360            etree_type *));
361 extern void lang_final PARAMS ((void));
362 extern void lang_process PARAMS ((void));
363 extern void lang_section_start PARAMS ((const char *, union etree_union *));
364 extern void lang_add_entry PARAMS ((const char *, boolean));
365 extern void lang_add_target PARAMS ((const char *));
366 extern void lang_add_wild PARAMS ((const char *const , const char *const));
367 extern void lang_add_map PARAMS ((const char *));
368 extern void lang_add_fill PARAMS ((int));
369 extern void lang_add_assignment PARAMS ((union etree_union *));
370 extern void lang_add_attribute PARAMS ((enum statement_enum));
371 extern void lang_startup PARAMS ((const char *));
372 extern void lang_float PARAMS ((enum bfd_boolean));
373 extern void lang_leave_output_section_statement PARAMS ((bfd_vma,
374                                                          const char *));
375 extern void lang_abs_symbol_at_end_of PARAMS ((const char *, const char *));
376 extern void lang_abs_symbol_at_beginning_of PARAMS ((const char *,
377                                                      const char *));
378 extern void lang_statement_append PARAMS ((struct statement_list *,
379                                            union lang_statement_union *,
380                                            union lang_statement_union **));
381 extern void lang_for_each_input_file
382   PARAMS ((void (*dothis) (lang_input_statement_type *)));
383 extern void lang_for_each_file
384   PARAMS ((void (*dothis) (lang_input_statement_type *)));
385 extern bfd_vma lang_do_assignments
386   PARAMS ((lang_statement_union_type * s,
387            lang_output_section_statement_type *output_section_statement,
388            fill_type fill,
389            bfd_vma dot));
390
391 #define LANG_FOR_EACH_INPUT_STATEMENT(statement)                \
392   extern lang_statement_list_type file_chain;                   \
393   lang_input_statement_type *statement;                         \
394   for (statement = (lang_input_statement_type *)file_chain.head;\
395        statement != (lang_input_statement_type *)NULL;          \
396        statement = (lang_input_statement_type *)statement->next)\
397   
398 extern void lang_process PARAMS ((void));
399 extern void ldlang_add_file PARAMS ((lang_input_statement_type *));
400 extern lang_output_section_statement_type *lang_output_section_find
401   PARAMS ((const char * const));
402 extern lang_input_statement_type *lang_add_input_file
403   PARAMS ((const char *name, lang_input_file_enum_type file_type,
404            const char *target));
405 extern void lang_add_keepsyms_file PARAMS ((const char *filename));
406 extern lang_output_section_statement_type *
407   lang_output_section_statement_lookup PARAMS ((const char * const name));
408 extern void ldlang_add_undef PARAMS ((const char *const name));
409 extern void lang_add_output_format PARAMS ((const char *, const char *,
410                                             const char *, int from_script));
411 extern void lang_list_init PARAMS ((lang_statement_list_type*));
412 extern void lang_add_data PARAMS ((int type, union etree_union *));
413 extern void lang_add_reloc
414   PARAMS ((bfd_reloc_code_real_type reloc, reloc_howto_type *howto,
415            asection *section, const char *name, union etree_union *addend));
416 extern void lang_for_each_statement
417   PARAMS ((void (*func) (lang_statement_union_type *)));
418 extern PTR stat_alloc PARAMS ((size_t size));
419 extern bfd_vma lang_size_sections
420   PARAMS ((lang_statement_union_type *s,
421            lang_output_section_statement_type *output_section_statement,
422            lang_statement_union_type **prev, fill_type fill,
423            bfd_vma dot, boolean relax));
424 extern void lang_enter_group PARAMS ((void));
425 extern void lang_leave_group PARAMS ((void));
426 extern void wild_doit
427   PARAMS ((lang_statement_list_type *ptr, asection *section,
428            lang_output_section_statement_type *output,
429            lang_input_statement_type *file));
430 extern void lang_new_phdr
431   PARAMS ((const char *, etree_type *, boolean, boolean, etree_type *,
432            etree_type *));
433 extern void lang_section_in_phdr PARAMS ((const char *));
434
435 #endif