Back to index

cell-binutils  2.17cvs20070401
ldlang.h
Go to the documentation of this file.
00001 /* ldlang.h - linker command language support
00002    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
00003    2001, 2002, 2003, 2004, 2005, 2006
00004    Free Software Foundation, Inc.
00005 
00006    This file is part of GLD, the Gnu Linker.
00007 
00008    GLD is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2, or (at your option)
00011    any later version.
00012 
00013    GLD is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with GLD; see the file COPYING.  If not, write to the Free
00020    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00021    02110-1301, USA.  */
00022 
00023 #ifndef LDLANG_H
00024 #define LDLANG_H
00025 
00026 #define DEFAULT_MEMORY_REGION   "*default*"
00027 
00028 typedef enum
00029 {
00030   lang_input_file_is_l_enum,
00031   lang_input_file_is_symbols_only_enum,
00032   lang_input_file_is_marker_enum,
00033   lang_input_file_is_fake_enum,
00034   lang_input_file_is_search_file_enum,
00035   lang_input_file_is_file_enum
00036 } lang_input_file_enum_type;
00037 
00038 struct _fill_type
00039 {
00040   size_t size;
00041   unsigned char data[1];
00042 };
00043 
00044 typedef struct statement_list
00045 {
00046   union lang_statement_union *head;
00047   union lang_statement_union **tail;
00048 } lang_statement_list_type;
00049 
00050 typedef struct memory_region_struct
00051 {
00052   char *name;
00053   struct memory_region_struct *next;
00054   bfd_vma origin;
00055   bfd_size_type length;
00056   bfd_vma current;
00057   union lang_statement_union *last_os;
00058   flagword flags;
00059   flagword not_flags;
00060   bfd_boolean had_full_message;
00061 } lang_memory_region_type;
00062 
00063 typedef struct lang_statement_header_struct
00064 {
00065   union lang_statement_union *next;
00066   enum statement_enum
00067   {
00068     lang_output_section_statement_enum,
00069     lang_assignment_statement_enum,
00070     lang_input_statement_enum,
00071     lang_address_statement_enum,
00072     lang_wild_statement_enum,
00073     lang_input_section_enum,
00074     lang_object_symbols_statement_enum,
00075     lang_fill_statement_enum,
00076     lang_data_statement_enum,
00077     lang_reloc_statement_enum,
00078     lang_target_statement_enum,
00079     lang_output_statement_enum,
00080     lang_padding_statement_enum,
00081     lang_group_statement_enum,
00082 
00083     lang_afile_asection_pair_statement_enum,
00084     lang_constructors_statement_enum
00085   } type;
00086 } lang_statement_header_type;
00087 
00088 typedef struct
00089 {
00090   lang_statement_header_type header;
00091   union etree_union *exp;
00092 } lang_assignment_statement_type;
00093 
00094 typedef struct lang_target_statement_struct
00095 {
00096   lang_statement_header_type header;
00097   const char *target;
00098 } lang_target_statement_type;
00099 
00100 typedef struct lang_output_statement_struct
00101 {
00102   lang_statement_header_type header;
00103   const char *name;
00104 } lang_output_statement_type;
00105 
00106 /* Section types specified in a linker script.  */
00107 
00108 enum section_type
00109 {
00110   normal_section,
00111   noload_section,
00112   noalloc_section
00113 };
00114 
00115 /* This structure holds a list of program headers describing
00116    segments in which this section should be placed.  */
00117 
00118 typedef struct lang_output_section_phdr_list
00119 {
00120   struct lang_output_section_phdr_list *next;
00121   const char *name;
00122   bfd_boolean used;
00123 } lang_output_section_phdr_list;
00124 
00125 typedef struct lang_output_section_statement_struct
00126 {
00127   lang_statement_header_type header;
00128   lang_statement_list_type children;
00129   struct lang_output_section_statement_struct *next;
00130   struct lang_output_section_statement_struct *prev;
00131   const char *name;
00132   asection *bfd_section;
00133   lang_memory_region_type *region;
00134   lang_memory_region_type *lma_region;
00135   fill_type *fill;
00136   union etree_union *addr_tree;
00137   union etree_union *load_base;
00138 
00139   /* If non-null, an expression to evaluate after setting the section's
00140      size.  The expression is evaluated inside REGION (above) with '.'
00141      set to the end of the section.  Used in the last overlay section
00142      to move '.' past all the overlaid sections.  */
00143   union etree_union *update_dot_tree;
00144 
00145   lang_output_section_phdr_list *phdrs;
00146 
00147   unsigned int block_value;
00148   int subsection_alignment; /* Alignment of components.  */
00149   int section_alignment;    /* Alignment of start of section.  */
00150   int constraint;
00151   flagword flags;
00152   enum section_type sectype;
00153   unsigned int processed_vma : 1;
00154   unsigned int processed_lma : 1;
00155   unsigned int all_input_readonly : 1;
00156   /* If this section should be ignored.  */
00157   unsigned int ignored : 1; 
00158   /* If there is a symbol relative to this section.  */
00159   unsigned int section_relative_symbol : 1; 
00160 } lang_output_section_statement_type;
00161 
00162 typedef struct
00163 {
00164   lang_statement_header_type header;
00165 } lang_common_statement_type;
00166 
00167 typedef struct
00168 {
00169   lang_statement_header_type header;
00170 } lang_object_symbols_statement_type;
00171 
00172 typedef struct
00173 {
00174   lang_statement_header_type header;
00175   fill_type *fill;
00176   int size;
00177   asection *output_section;
00178 } lang_fill_statement_type;
00179 
00180 typedef struct
00181 {
00182   lang_statement_header_type header;
00183   unsigned int type;
00184   union etree_union *exp;
00185   bfd_vma value;
00186   asection *output_section;
00187   bfd_vma output_offset;
00188 } lang_data_statement_type;
00189 
00190 /* Generate a reloc in the output file.  */
00191 
00192 typedef struct
00193 {
00194   lang_statement_header_type header;
00195 
00196   /* Reloc to generate.  */
00197   bfd_reloc_code_real_type reloc;
00198 
00199   /* Reloc howto structure.  */
00200   reloc_howto_type *howto;
00201 
00202   /* Section to generate reloc against.
00203      Exactly one of section and name must be NULL.  */
00204   asection *section;
00205 
00206   /* Name of symbol to generate reloc against.
00207      Exactly one of section and name must be NULL.  */
00208   const char *name;
00209 
00210   /* Expression for addend.  */
00211   union etree_union *addend_exp;
00212 
00213   /* Resolved addend.  */
00214   bfd_vma addend_value;
00215 
00216   /* Output section where reloc should be performed.  */
00217   asection *output_section;
00218 
00219   /* Offset within output section.  */
00220   bfd_vma output_offset;
00221 } lang_reloc_statement_type;
00222 
00223 typedef struct lang_input_statement_struct
00224 {
00225   lang_statement_header_type header;
00226   /* Name of this file.  */
00227   const char *filename;
00228   /* Name to use for the symbol giving address of text start.
00229      Usually the same as filename, but for a file spec'd with
00230      -l this is the -l switch itself rather than the filename.  */
00231   const char *local_sym_name;
00232 
00233   bfd *the_bfd;
00234 
00235   file_ptr passive_position;
00236 
00237   /* Symbol table of the file.  */
00238   asymbol **asymbols;
00239   unsigned int symbol_count;
00240 
00241   /* Point to the next file - whatever it is, wanders up and down
00242      archives */
00243   union lang_statement_union *next;
00244 
00245   /* Point to the next file, but skips archive contents.  */
00246   union lang_statement_union *next_real_file;
00247 
00248   const char *target;
00249 
00250   unsigned int closed : 1;
00251   unsigned int is_archive : 1;
00252 
00253   /* 1 means search a set of directories for this file.  */
00254   unsigned int search_dirs_flag : 1;
00255 
00256   /* 1 means this was found in a search directory marked as sysrooted,
00257      if search_dirs_flag is false, otherwise, that it should be
00258      searched in ld_sysroot before any other location, as long as it
00259      starts with a slash.  */
00260   unsigned int sysrooted : 1;
00261 
00262   /* 1 means this is base file of incremental load.
00263      Do not load this file's text or data.
00264      Also default text_start to after this file's bss.  */
00265   unsigned int just_syms_flag : 1;
00266 
00267   /* Whether to search for this entry as a dynamic archive.  */
00268   unsigned int dynamic : 1;
00269 
00270   /* Whether DT_NEEDED tags should be added for dynamic libraries in
00271      DT_NEEDED tags from this entry.  */
00272   unsigned int add_needed : 1;
00273 
00274   /* Whether this entry should cause a DT_NEEDED tag only when
00275      satisfying references from regular files, or always.  */
00276   unsigned int as_needed : 1;
00277 
00278   /* Whether to include the entire contents of an archive.  */
00279   unsigned int whole_archive : 1;
00280 
00281   unsigned int loaded : 1;
00282 
00283   unsigned int real : 1;
00284 } lang_input_statement_type;
00285 
00286 typedef struct
00287 {
00288   lang_statement_header_type header;
00289   asection *section;
00290 } lang_input_section_type;
00291 
00292 typedef struct
00293 {
00294   lang_statement_header_type header;
00295   asection *section;
00296   union lang_statement_union *file;
00297 } lang_afile_asection_pair_statement_type;
00298 
00299 typedef struct lang_wild_statement_struct lang_wild_statement_type;
00300 
00301 typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
00302                          asection *, lang_input_statement_type *, void *);
00303 
00304 typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *,
00305                                         lang_input_statement_type *,
00306                                         callback_t callback,
00307                                         void *data);
00308 
00309 typedef bfd_boolean (*lang_match_sec_type_func) (bfd *, const asection *,
00310                                            bfd *, const asection *);
00311 
00312 /* Binary search tree structure to efficiently sort sections by
00313    name.  */
00314 typedef struct lang_section_bst
00315 {
00316   asection *section;
00317   struct lang_section_bst *left;
00318   struct lang_section_bst *right;
00319 } lang_section_bst_type;
00320 
00321 struct lang_wild_statement_struct
00322 {
00323   lang_statement_header_type header;
00324   const char *filename;
00325   bfd_boolean filenames_sorted;
00326   struct wildcard_list *section_list;
00327   bfd_boolean keep_sections;
00328   lang_statement_list_type children;
00329 
00330   walk_wild_section_handler_t walk_wild_section_handler;
00331   struct wildcard_list *handler_data[4];
00332   lang_section_bst_type *tree;
00333 };
00334 
00335 typedef struct lang_address_statement_struct
00336 {
00337   lang_statement_header_type header;
00338   const char *section_name;
00339   union etree_union *address;
00340   const segment_type *segment;
00341 } lang_address_statement_type;
00342 
00343 typedef struct
00344 {
00345   lang_statement_header_type header;
00346   bfd_vma output_offset;
00347   size_t size;
00348   asection *output_section;
00349   fill_type *fill;
00350 } lang_padding_statement_type;
00351 
00352 /* A group statement collects a set of libraries together.  The
00353    libraries are searched multiple times, until no new undefined
00354    symbols are found.  The effect is to search a group of libraries as
00355    though they were a single library.  */
00356 
00357 typedef struct
00358 {
00359   lang_statement_header_type header;
00360   lang_statement_list_type children;
00361 } lang_group_statement_type;
00362 
00363 typedef union lang_statement_union
00364 {
00365   lang_statement_header_type header;
00366   lang_wild_statement_type wild_statement;
00367   lang_data_statement_type data_statement;
00368   lang_reloc_statement_type reloc_statement;
00369   lang_address_statement_type address_statement;
00370   lang_output_section_statement_type output_section_statement;
00371   lang_afile_asection_pair_statement_type afile_asection_pair_statement;
00372   lang_assignment_statement_type assignment_statement;
00373   lang_input_statement_type input_statement;
00374   lang_target_statement_type target_statement;
00375   lang_output_statement_type output_statement;
00376   lang_input_section_type input_section;
00377   lang_common_statement_type common_statement;
00378   lang_object_symbols_statement_type object_symbols_statement;
00379   lang_fill_statement_type fill_statement;
00380   lang_padding_statement_type padding_statement;
00381   lang_group_statement_type group_statement;
00382 } lang_statement_union_type;
00383 
00384 /* This structure holds information about a program header, from the
00385    PHDRS command in the linker script.  */
00386 
00387 struct lang_phdr
00388 {
00389   struct lang_phdr *next;
00390   const char *name;
00391   unsigned long type;
00392   bfd_boolean filehdr;
00393   bfd_boolean phdrs;
00394   etree_type *at;
00395   etree_type *flags;
00396 };
00397 
00398 extern struct lang_phdr *lang_phdr_list;
00399 
00400 /* This structure is used to hold a list of sections which may not
00401    cross reference each other.  */
00402 
00403 typedef struct lang_nocrossref
00404 {
00405   struct lang_nocrossref *next;
00406   const char *name;
00407 } lang_nocrossref_type;
00408 
00409 /* The list of nocrossref lists.  */
00410 
00411 struct lang_nocrossrefs
00412 {
00413   struct lang_nocrossrefs *next;
00414   lang_nocrossref_type *list;
00415 };
00416 
00417 extern struct lang_nocrossrefs *nocrossref_list;
00418 
00419 /* This structure is used to hold a list of input section names which
00420    will not match an output section in the linker script.  */
00421 
00422 struct unique_sections
00423 {
00424   struct unique_sections *next;
00425   const char *name;
00426 };
00427 
00428 /* This structure records symbols for which we need to keep track of
00429    definedness for use in the DEFINED () test.  */
00430 
00431 struct lang_definedness_hash_entry
00432 {
00433   struct bfd_hash_entry root;
00434   int iteration;
00435 };
00436 
00437 /* Used by place_orphan to keep track of orphan sections and statements.  */
00438 
00439 struct orphan_save {
00440   const char *name;
00441   flagword flags;
00442   lang_output_section_statement_type *os;
00443   asection **section;
00444   lang_statement_union_type **stmt;
00445   lang_output_section_statement_type **os_tail;
00446 };
00447 
00448 extern lang_output_section_statement_type *abs_output_section;
00449 extern lang_statement_list_type lang_output_section_statement;
00450 extern bfd_boolean lang_has_input_file;
00451 extern etree_type *base;
00452 extern lang_statement_list_type *stat_ptr;
00453 extern bfd_boolean delete_output_file_on_failure;
00454 
00455 extern struct bfd_sym_chain entry_symbol;
00456 extern const char *entry_section;
00457 extern bfd_boolean entry_from_cmdline;
00458 extern lang_statement_list_type file_chain;
00459 extern lang_statement_list_type input_file_chain;
00460 
00461 extern int lang_statement_iteration;
00462 
00463 extern void lang_init
00464   (void);
00465 extern void lang_finish
00466   (void);
00467 extern lang_memory_region_type *lang_memory_region_lookup
00468   (const char *const, bfd_boolean);
00469 extern lang_memory_region_type *lang_memory_region_default
00470   (asection *);
00471 extern void lang_map
00472   (void);
00473 extern void lang_set_flags
00474   (lang_memory_region_type *, const char *, int);
00475 extern void lang_add_output
00476   (const char *, int from_script);
00477 extern lang_output_section_statement_type *lang_enter_output_section_statement
00478   (const char *output_section_statement_name,
00479    etree_type *address_exp,
00480    enum section_type sectype,
00481    etree_type *align,
00482    etree_type *subalign,
00483    etree_type *, int);
00484 extern void lang_final
00485   (void);
00486 extern void lang_process
00487   (void);
00488 extern void lang_section_start
00489   (const char *, union etree_union *, const segment_type *);
00490 extern void lang_add_entry
00491   (const char *, bfd_boolean);
00492 extern void lang_default_entry
00493   (const char *);
00494 extern void lang_add_target
00495   (const char *);
00496 extern void lang_add_wild
00497   (struct wildcard_spec *, struct wildcard_list *, bfd_boolean);
00498 extern void lang_add_map
00499   (const char *);
00500 extern void lang_add_fill
00501   (fill_type *);
00502 extern lang_assignment_statement_type *lang_add_assignment
00503   (union etree_union *);
00504 extern void lang_add_attribute
00505   (enum statement_enum);
00506 extern void lang_startup
00507   (const char *);
00508 extern void lang_float
00509   (bfd_boolean);
00510 extern void lang_leave_output_section_statement
00511   (fill_type *, const char *, lang_output_section_phdr_list *,
00512    const char *);
00513 extern void lang_abs_symbol_at_end_of
00514   (const char *, const char *);
00515 extern void lang_abs_symbol_at_beginning_of
00516   (const char *, const char *);
00517 extern void lang_statement_append
00518   (lang_statement_list_type *, lang_statement_union_type *,
00519    lang_statement_union_type **);
00520 extern void lang_for_each_input_file
00521   (void (*dothis) (lang_input_statement_type *));
00522 extern void lang_for_each_file
00523   (void (*dothis) (lang_input_statement_type *));
00524 extern void lang_reset_memory_regions
00525   (void);
00526 extern void lang_do_assignments
00527   (void);
00528 
00529 #define LANG_FOR_EACH_INPUT_STATEMENT(statement)               \
00530   lang_input_statement_type *statement;                               \
00531   for (statement = (lang_input_statement_type *) file_chain.head;     \
00532        statement != (lang_input_statement_type *) NULL;               \
00533        statement = (lang_input_statement_type *) statement->next)     \
00534 
00535 extern void lang_process
00536   (void);
00537 extern void ldlang_add_file
00538   (lang_input_statement_type *);
00539 extern lang_output_section_statement_type *lang_output_section_find
00540   (const char * const);
00541 extern lang_output_section_statement_type *lang_output_section_find_by_flags
00542   (const asection *, lang_output_section_statement_type **,
00543    lang_match_sec_type_func);
00544 extern lang_output_section_statement_type *lang_insert_orphan
00545   (asection *, const char *, lang_output_section_statement_type *,
00546    struct orphan_save *, etree_type *, lang_statement_list_type *);
00547 extern lang_input_statement_type *lang_add_input_file
00548   (const char *, lang_input_file_enum_type, const char *);
00549 extern void lang_add_keepsyms_file
00550   (const char *);
00551 extern lang_output_section_statement_type *
00552   lang_output_section_statement_lookup
00553   (const char *const);
00554 extern void ldlang_add_undef
00555   (const char *const);
00556 extern void lang_add_output_format
00557   (const char *, const char *, const char *, int);
00558 extern void lang_list_init
00559   (lang_statement_list_type *);
00560 extern void lang_add_data
00561   (int type, union etree_union *);
00562 extern void lang_add_reloc
00563   (bfd_reloc_code_real_type, reloc_howto_type *, asection *, const char *,
00564    union etree_union *);
00565 extern void lang_for_each_statement
00566   (void (*) (lang_statement_union_type *));
00567 extern void *stat_alloc
00568   (size_t);
00569 extern void strip_excluded_output_sections
00570   (void);
00571 extern void dprint_statement
00572   (lang_statement_union_type *, int);
00573 extern void lang_size_sections
00574   (bfd_boolean *, bfd_boolean);
00575 extern void one_lang_size_sections_pass
00576   (bfd_boolean *, bfd_boolean);
00577 extern void lang_enter_group
00578   (void);
00579 extern void lang_leave_group
00580   (void);
00581 extern void lang_add_section
00582   (lang_statement_list_type *, asection *,
00583    lang_output_section_statement_type *);
00584 extern void lang_new_phdr
00585   (const char *, etree_type *, bfd_boolean, bfd_boolean, etree_type *,
00586    etree_type *);
00587 extern void lang_add_nocrossref
00588   (lang_nocrossref_type *);
00589 extern void lang_enter_overlay
00590   (etree_type *, etree_type *);
00591 extern void lang_enter_overlay_section
00592   (const char *);
00593 extern void lang_leave_overlay_section
00594   (fill_type *, lang_output_section_phdr_list *);
00595 extern void lang_leave_overlay
00596   (etree_type *, int, fill_type *, const char *,
00597    lang_output_section_phdr_list *, const char *);
00598 
00599 extern struct bfd_elf_version_tree *lang_elf_version_info;
00600 
00601 extern struct bfd_elf_version_expr *lang_new_vers_pattern
00602   (struct bfd_elf_version_expr *, const char *, const char *, bfd_boolean);
00603 extern struct bfd_elf_version_tree *lang_new_vers_node
00604   (struct bfd_elf_version_expr *, struct bfd_elf_version_expr *);
00605 extern struct bfd_elf_version_deps *lang_add_vers_depend
00606   (struct bfd_elf_version_deps *, const char *);
00607 extern void lang_register_vers_node
00608   (const char *, struct bfd_elf_version_tree *, struct bfd_elf_version_deps *);
00609 extern void lang_append_dynamic_list (struct bfd_elf_version_expr *);
00610 extern void lang_append_dynamic_list_cpp_typeinfo (void);
00611 extern void lang_append_dynamic_list_cpp_new (void);
00612 bfd_boolean unique_section_p
00613   (const asection *);
00614 extern void lang_add_unique
00615   (const char *);
00616 extern const char *lang_get_output_target
00617   (void);
00618 extern void lang_track_definedness (const char *);
00619 extern int lang_symbol_definition_iteration (const char *);
00620 extern void lang_update_definedness
00621   (const char *, struct bfd_link_hash_entry *);
00622 
00623 extern void add_excluded_libs (const char *);
00624 extern bfd_boolean load_symbols
00625   (lang_input_statement_type *, lang_statement_list_type *);
00626 
00627 extern bfd_boolean
00628 ldlang_override_segment_assignment
00629   (struct bfd_link_info *, bfd *, asection *, asection *, bfd_boolean);
00630 
00631 #endif