home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / include / bfdlink.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-20  |  16.0 KB  |  412 lines

  1. /* bfdlink.h -- header file for BFD link routines
  2.    Copyright 1993 Free Software Foundation, Inc.
  3.    Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program 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 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program 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 this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #ifndef BFDLINK_H
  22. #define BFDLINK_H
  23.  
  24. /* Which symbols to strip during a link.  */
  25. enum bfd_link_strip
  26. {
  27.   strip_none,        /* Don't strip any symbols.  */
  28.   strip_debugger,    /* Strip debugging symbols.  */
  29.   strip_some,        /* keep_hash is the list of symbols to keep.  */
  30.   strip_all        /* Strip all symbols.  */
  31. };
  32.  
  33. /* Which local symbols to discard during a link.  This is irrelevant
  34.    if strip_all is used.  */
  35. enum bfd_link_discard
  36. {
  37.   discard_none,        /* Don't discard any locals.  */
  38.   discard_l,        /* Discard locals with a certain prefix.  */
  39.   discard_all        /* Discard all locals.  */
  40. };
  41.  
  42. /* These are the possible types of an entry in the BFD link hash
  43.    table.  */
  44.  
  45. enum bfd_link_hash_type
  46. {
  47.   bfd_link_hash_new,        /* Symbol is new.  */
  48.   bfd_link_hash_undefined,    /* Symbol seen before, but undefined.  */
  49.   bfd_link_hash_weak,        /* Symbol is weak and undefined.  */
  50.   bfd_link_hash_defined,    /* Symbol is defined.  */
  51.   bfd_link_hash_common,        /* Symbol is common.  */
  52.   bfd_link_hash_indirect,    /* Symbol is an indirect link.  */
  53.   bfd_link_hash_warning        /* Like indirect, but warn if referenced.  */
  54. };
  55.  
  56. /* The linking routines use a hash table which uses this structure for
  57.    its elements.  */
  58.  
  59. struct bfd_link_hash_entry
  60. {
  61.   /* Base hash table entry structure.  */
  62.   struct bfd_hash_entry root;
  63.   /* Type of this entry.  */
  64.   enum bfd_link_hash_type type;
  65.  
  66.   /* Undefined and common symbols are kept in a linked list through
  67.      this field.  This field is not in the union because that would
  68.      force us to remove entries from the list when we changed their
  69.      type, which would force the list to be doubly linked, which would
  70.      waste more memory.  When an undefined or common symbol is
  71.      created, it should be added to this list, the head of which is in
  72.      the link hash table itself.  As symbols are defined, they need
  73.      not be removed from the list; anything which reads the list must
  74.      doublecheck the symbol type.
  75.  
  76.      Weak symbols are not kept on this list.
  77.  
  78.      Defined symbols use this field as a reference marker.  If the
  79.      field is not NULL, or this structure is the tail of the undefined
  80.      symbol list, the symbol has been referenced.  If the symbol is
  81.      undefined and becomes defined, this field will automatically be
  82.      non-NULL since the symbol will have been on the undefined symbol
  83.      list.  */
  84.   struct bfd_link_hash_entry *next;
  85.   /* A union of information depending upon the type.  */
  86.   union
  87.     {
  88.       /* Nothing is kept for bfd_hash_new.  */
  89.       /* bfd_link_hash_undefined, bfd_link_hash_weak.  */
  90.       struct
  91.     {
  92.       bfd *abfd;        /* BFD symbol was found in.  */
  93.     } undef;
  94.       /* bfd_link_hash_defined.  */
  95.       struct
  96.     {
  97.       bfd_vma value;    /* Symbol value.  */
  98.       asection *section;    /* Symbol section.  */
  99.     } def;
  100.       /* bfd_link_hash_indirect, bfd_link_hash_warning.  */
  101.       struct
  102.     {
  103.       struct bfd_link_hash_entry *link;    /* Real symbol.  */
  104.       const char *warning;    /* Warning (bfd_link_hash_warning only).  */
  105.     } i;
  106.       /* bfd_link_hash_common.  */
  107.       struct
  108.     {
  109.       bfd_vma size;        /* Common symbol size.  */
  110.       asection *section;    /* Symbol section.  */
  111.     } c;
  112.     } u;
  113. };
  114.  
  115. /* This is the link hash table.  It is a derived class of
  116.    bfd_hash_table.  */
  117.  
  118. struct bfd_link_hash_table
  119. {
  120.   /* The hash table itself.  */
  121.   struct bfd_hash_table table;
  122.   /* The back end which created this hash table.  This indicates the
  123.      type of the entries in the hash table, which is sometimes
  124.      important information when linking object files of different
  125.      types together.  */
  126.   const bfd_target *creator;
  127.   /* A linked list of undefined and common symbols, linked through the
  128.      next field in the bfd_link_hash_entry structure.  */
  129.   struct bfd_link_hash_entry *undefs;
  130.   /* Entries are added to the tail of the undefs list.  */
  131.   struct bfd_link_hash_entry *undefs_tail;
  132. };
  133.  
  134. /* Look up an entry in a link hash table.  If FOLLOW is true, this
  135.    follows bfd_link_hash_indirect and bfd_link_hash_warning links to
  136.    the real symbol.  */
  137. extern struct bfd_link_hash_entry *bfd_link_hash_lookup
  138.   PARAMS ((struct bfd_link_hash_table *, const char *, boolean create,
  139.        boolean copy, boolean follow));
  140.  
  141. /* Traverse a link hash table.  */
  142. extern void bfd_link_hash_traverse
  143.   PARAMS ((struct bfd_link_hash_table *,
  144.        boolean (*) (struct bfd_link_hash_entry *, PTR),
  145.        PTR));
  146.  
  147. /* Add an entry to the undefs list.  */
  148. extern void bfd_link_add_undef
  149.   PARAMS ((struct bfd_link_hash_table *, struct bfd_link_hash_entry *));
  150.  
  151. /* This structure holds all the information needed to communicate
  152.    between BFD and the linker when doing a link.  */
  153.  
  154. struct bfd_link_info
  155. {
  156.   /* Function callbacks.  */
  157.   const struct bfd_link_callbacks *callbacks;
  158.   /* true if BFD should generate a relocateable object file.  */
  159.   boolean relocateable;
  160.   /* true if BFD should generate a shared object.  */
  161.   boolean shared;
  162.   /* Which symbols to strip.  */
  163.   enum bfd_link_strip strip;
  164.   /* Which local symbols to discard.  */
  165.   enum bfd_link_discard discard;
  166.   /* The local symbol prefix to discard if using discard_l.  */
  167.   unsigned int lprefix_len;
  168.   const char *lprefix;
  169.   /* true if symbols should be retained in memory, false if they
  170.      should be freed and reread.  */
  171.   boolean keep_memory;
  172.   /* The list of input BFD's involved in the link.  These are chained
  173.      together via the link_next field.  */
  174.   bfd *input_bfds;
  175.   /* If a symbol should be created for each input BFD, this is section
  176.      where those symbols should be placed.  It must be a section in
  177.      the output BFD.  It may be NULL, in which case no such symbols
  178.      will be created.  This is to support CREATE_OBJECT_SYMBOLS in the
  179.      linker command language.  */
  180.   asection *create_object_symbols_section;
  181.   /* Hash table handled by BFD.  */
  182.   struct bfd_link_hash_table *hash;
  183.   /* Hash table of symbols to keep.  This is NULL unless strip is
  184.      strip_some.  */
  185.   struct bfd_hash_table *keep_hash;
  186.   /* Hash table of symbols to report back via notice_callback.  If
  187.      this is NULL no symbols are reported back.  */
  188.   struct bfd_hash_table *notice_hash;
  189. };
  190.  
  191. /* This structures holds a set of callback functions.  These are
  192.    called by the BFD linker routines.  The first argument to each
  193.    callback function is the bfd_link_info structure being used.  Each
  194.    function returns a boolean value.  If the function returns false,
  195.    then the BFD function which called it will return with a failure
  196.    indication.  */
  197.  
  198. struct bfd_link_callbacks
  199. {
  200.   /* A function which is called when an object is added from an
  201.      archive.  ABFD is the archive element being added.  NAME is the
  202.      name of the symbol which caused the archive element to be pulled
  203.      in.  */
  204.   boolean (*add_archive_element) PARAMS ((struct bfd_link_info *,
  205.                       bfd *abfd,
  206.                       const char *name));
  207.   /* A function which is called when a symbol is found with multiple
  208.      definitions.  NAME is the symbol which is defined multiple times.
  209.      OBFD is the old BFD, OSEC is the old section, OVAL is the old
  210.      value, NBFD is the new BFD, NSEC is the new section, and NVAL is
  211.      the new value.  OBFD may be NULL.  OSEC and NSEC may be
  212.      bfd_com_section or bfd_ind_section.  */
  213.   boolean (*multiple_definition) PARAMS ((struct bfd_link_info *,
  214.                       const char *name,
  215.                       bfd *obfd,
  216.                       asection *osec,
  217.                       bfd_vma oval,
  218.                       bfd *nbfd,
  219.                       asection *nsec,
  220.                       bfd_vma nval));
  221.   /* A function which is called when a common symbol is defined
  222.      multiple times.  NAME is the symbol appearing multiple times.
  223.      OBFD is the BFD of the existing symbol.  OTYPE is the type of the
  224.      existing symbol, either bfd_link_hash_defined or
  225.      bfd_link_hash_common.  If OTYPE is bfd_link_hash_common, OSIZE is
  226.      the size of the existing symbol.  NBFD is the BFD of the new
  227.      symbol.  NTYPE is the type of the new symbol, either
  228.      bfd_link_hash_defined or bfd_link_hash_common.  If NTYPE is
  229.      bfd_link_hash_common, NSIZE is the size of the new symbol.  */
  230.   boolean (*multiple_common) PARAMS ((struct bfd_link_info *,
  231.                       const char *name,
  232.                       bfd *obfd,
  233.                       enum bfd_link_hash_type otype,
  234.                       bfd_vma osize,
  235.                       bfd *nbfd,
  236.                       enum bfd_link_hash_type ntype,
  237.                       bfd_vma nsize));
  238.   /* A function which is called to add a symbol to a set.  ENTRY is
  239.      the link hash table entry for the set itself (e.g.,
  240.      __CTOR_LIST__).  RELOC is the relocation to use for an entry in
  241.      the set when generating a relocateable file, and is also used to
  242.      get the size of the entry when generating an executable file.
  243.      ABFD, SEC and VALUE identify the value to add to the set.  */
  244.   boolean (*add_to_set) PARAMS ((struct bfd_link_info *,
  245.                  struct bfd_link_hash_entry *entry,
  246.                  bfd_reloc_code_real_type reloc,
  247.                  bfd *abfd, asection *sec, bfd_vma value));
  248.   /* A function which is called when the name of a g++ constructor or
  249.      destructor is found.  This is only called by some object file
  250.      formats.  CONSTRUCTOR is true for a constructor, false for a
  251.      destructor.  This will use BFD_RELOC_CTOR when generating a
  252.      relocateable file.  NAME is the name of the symbol found.  ABFD,
  253.      SECTION and VALUE are the value of the symbol.  */
  254.   boolean (*constructor) PARAMS ((struct bfd_link_info *,
  255.                   boolean constructor,
  256.                   const char *name, bfd *abfd, asection *sec,
  257.                   bfd_vma value));
  258.   /* A function which is called when there is a reference to a warning
  259.      symbol.  WARNING is the warning to be issued.  */
  260.   boolean (*warning) PARAMS ((struct bfd_link_info *,
  261.                   const char *warning));
  262.   /* A function which is called when a relocation is attempted against
  263.      an undefined symbol.  NAME is the symbol which is undefined.
  264.      ABFD, SECTION and ADDRESS identify the location from which the
  265.      reference is made.  */
  266.   boolean (*undefined_symbol) PARAMS ((struct bfd_link_info *,
  267.                        const char *name, bfd *abfd,
  268.                        asection *section, bfd_vma address));
  269.   /* A function which is called when a reloc overflow occurs.  NAME is
  270.      the name of the symbol or section the reloc is against,
  271.      RELOC_NAME is the name of the relocation, and ADDEND is any
  272.      addend that is used.  ABFD, SECTION and ADDRESS identify the
  273.      location at which the overflow occurs; if this is the result of a
  274.      bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
  275.      ABFD will be NULL.  */
  276.   boolean (*reloc_overflow) PARAMS ((struct bfd_link_info *,
  277.                      const char *name,
  278.                      const char *reloc_name, bfd_vma addend,
  279.                      bfd *abfd, asection *section,
  280.                      bfd_vma address));
  281.   /* A function which is called when a dangerous reloc is performed.
  282.      The canonical example is an a29k IHCONST reloc which does not
  283.      follow an IHIHALF reloc.  MESSAGE is an appropriate message.
  284.      ABFD, SECTION and ADDRESS identify the location at which the
  285.      problem occurred; if this is the result of a
  286.      bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
  287.      ABFD will be NULL.  */
  288.   boolean (*reloc_dangerous) PARAMS ((struct bfd_link_info *,
  289.                       const char *message,
  290.                       bfd *abfd, asection *section,
  291.                       bfd_vma address));
  292.   /* A function which is called when a reloc is found to be attached
  293.      to a symbol which is not being written out.  NAME is the name of
  294.      the symbol.  ABFD, SECTION and ADDRESS identify the location of
  295.      the reloc; if this is the result of a
  296.      bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
  297.      ABFD will be NULL.  */
  298.   boolean (*unattached_reloc) PARAMS ((struct bfd_link_info *,
  299.                        const char *name,
  300.                        bfd *abfd, asection *section,
  301.                        bfd_vma address));
  302.   /* A function which is called when a symbol in notice_hash is
  303.      defined or referenced.  NAME is the symbol.  ABFD, SECTION and
  304.      ADDRESS are the value of the symbol.  If SECTION is
  305.      bfd_und_section, this is a reference.  */
  306.   boolean (*notice) PARAMS ((struct bfd_link_info *, const char *name,
  307.                  bfd *abfd, asection *section, bfd_vma address));
  308. };
  309.  
  310. /* The linker builds link_order structures which tell the code how to
  311.    include input data in the output file.  */
  312.  
  313. /* These are the types of link_order structures.  */
  314.  
  315. enum bfd_link_order_type
  316. {
  317.   bfd_undefined_link_order,    /* Undefined.  */
  318.   bfd_indirect_link_order,    /* Built from a section.  */
  319.   bfd_fill_link_order,        /* Fill with a 16 bit constant.  */
  320.   bfd_data_link_order,        /* Set to explicit data.  */
  321.   bfd_section_reloc_link_order,    /* Relocate against a section.  */
  322.   bfd_symbol_reloc_link_order    /* Relocate against a symbol.  */
  323. };
  324.  
  325. /* This is the link_order structure itself.  These form a chain
  326.    attached to the section whose contents they are describing.  */
  327.  
  328. struct bfd_link_order 
  329. {
  330.   /* Next link_order in chain.  */
  331.   struct bfd_link_order *next;
  332.   /* Type of link_order.  */
  333.   enum bfd_link_order_type type;
  334.   /* Offset within output section.  */
  335.   bfd_vma offset;  
  336.   /* Size within output section.  */
  337.   bfd_size_type size;
  338.   /* Type specific information.  */
  339.   union 
  340.     {
  341.       struct 
  342.     {
  343.       /* Section to include.  If this is used, then
  344.          section->output_section must be the section the
  345.          link_order is attached to, section->output_offset must
  346.          equal the link_order offset field, and section->_raw_size
  347.          must equal the link_order size field.  Maybe these
  348.          restrictions should be relaxed someday.  */
  349.       asection *section;
  350.     } indirect;
  351.       struct
  352.     {
  353.       /* Value to fill with.  */
  354.       unsigned int value;
  355.     } fill;
  356.       struct
  357.     {
  358.       /* Data to put into file.  The size field gives the number
  359.          of bytes which this field points to.  */
  360.       bfd_byte *contents;
  361.     } data;
  362.       struct
  363.     {
  364.       /* Description of reloc to generate.  Used for
  365.          bfd_section_reloc_link_order and
  366.          bfd_symbol_reloc_link_order.  */
  367.       struct bfd_link_order_reloc *p;
  368.     } reloc;
  369.     } u;
  370. };
  371.  
  372. /* A linker order of type bfd_section_reloc_link_order or
  373.    bfd_symbol_reloc_link_order means to create a reloc against a
  374.    section or symbol, respectively.  This is used to implement -Ur to
  375.    generate relocs for the constructor tables.  The
  376.    bfd_link_order_reloc structure describes the reloc that BFD should
  377.    create.  It is similar to a arelent, but I didn't use arelent
  378.    because the linker does not know anything about most symbols, and
  379.    any asymbol structure it creates will be partially meaningless.
  380.    This information could logically be in the bfd_link_order struct,
  381.    but I didn't want to waste the space since these types of relocs
  382.    are relatively rare.  */
  383.  
  384. struct bfd_link_order_reloc
  385. {
  386.   /* Reloc type.  */
  387.   bfd_reloc_code_real_type reloc;
  388.  
  389.   union
  390.     {
  391.       /* For type bfd_section_reloc_link_order, this is the section
  392.      the reloc should be against.  This must be a section in the
  393.      output BFD, not any of the input BFDs.  */
  394.       asection *section;
  395.       /* For type bfd_symbol_reloc_link_order, this is the name of the
  396.      symbol the reloc should be against.  */
  397.       const char *name;
  398.     } u;
  399.  
  400.   /* Addend to use.  The object file should contain zero.  The BFD
  401.      backend is responsible for filling in the contents of the object
  402.      file correctly.  For some object file formats (e.g., COFF) the
  403.      addend must be stored into in the object file, and for some
  404.      (e.g., SPARC a.out) it is kept in the reloc.  */
  405.   bfd_vma addend;
  406. };
  407.  
  408. /* Allocate a new link_order for a section.  */
  409. extern struct bfd_link_order *bfd_new_link_order PARAMS ((bfd *, asection *));
  410.  
  411. #endif
  412.