Replace sh_size/sh_entsize with NUM_SHDR_ENTRIES
[binutils-gdb.git] / bfd / elf-bfd.h
index b17f7c6cda0a926e6455cd4898290c12868eccc9..f5b74e93dc944e595e5b00a8b094b74e1f209e70 100644 (file)
@@ -1,6 +1,6 @@
 /* BFD back-end data structures for ELF files.
-   Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000 Free Software
-   Foundation, Inc.
+   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -27,6 +27,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "elf/external.h"
 #include "bfdlink.h"
 
+/* The number of entries in a section is its size divided by the size
+   of a single entry.  This is normally only applicaable to reloc and
+   symbol table sections.  */
+#define NUM_SHDR_ENTRIES(shdr) ((shdr)->sh_size / (shdr)->sh_entsize)
+
 /* If size isn't specified as 64 or 32, NAME macro should fail.  */
 #ifndef NAME
 #if ARCH_SIZE==64
@@ -208,7 +213,7 @@ struct elf_link_local_dynamic_entry
 
   /* The index in the outgoing dynamic symbol table.  */
   long dynindx;
-  
+
   /* A copy of the input symbol.  */
   Elf_Internal_Sym isym;
 };
@@ -241,8 +246,13 @@ struct elf_link_hash_table
   struct elf_link_hash_entry *hgot;
   /* A pointer to information used to link stabs in sections.  */
   PTR stab_info;
+  /* A pointer to information used to merge SEC_MERGE sections.  */
+  PTR merge_info;
   /* A linked list of local symbols to be added to .dynsym.  */
   struct elf_link_local_dynamic_entry *dynlocal;
+  /* A linked list of DT_RPATH/DT_RUNPATH names found in dynamic
+     objects included in the link.  */
+  struct bfd_link_needed_list *runpath;
 };
 
 /* Look up an entry in an ELF linker hash table.  */
@@ -372,9 +382,9 @@ struct elf_backend_data
                                                          unsigned int));
 
    /* A function to set the type of the info field.  Processor-specific
-     types should be handled here. */
-  int (*elf_backend_get_symbol_type) PARAMS (( Elf_Internal_Sym *, int)); 
+     types should be handled here.  */
+  int (*elf_backend_get_symbol_type) PARAMS (( Elf_Internal_Sym *, int));
+
   /* A function to do additional processing on the ELF section header
      just before writing it out.  This is used to set the flags and
      type fields for some sections, or to actually write out data for
@@ -388,8 +398,13 @@ struct elf_backend_data
                                                    Elf32_Internal_Shdr *,
                                                    char *));
 
+  /* A function to convert machine dependent section header flags to
+     BFD internal section header flags.  */
+  boolean (*elf_backend_section_flags) PARAMS ((flagword *,
+                                               Elf32_Internal_Shdr *));
+
   /* A function to handle unusual program segment types when creating BFD
-     sections from ELF program segments. */
+     sections from ELF program segments.  */
   boolean (*elf_backend_section_from_phdr) PARAMS ((bfd *,
                                                    Elf32_Internal_Phdr *,
                                                    int));
@@ -638,7 +653,7 @@ struct elf_backend_data
      both REL and RELA relocations, and this flag is set for those
      backends.)  */
   unsigned may_use_rel_p : 1;
-    
+
   /* Whether the backend may use RELA relocations.  (Some backends use
      both REL and RELA relocations, and this flag is set for those
      backends.)  */
@@ -647,8 +662,8 @@ struct elf_backend_data
   /* Whether the default relocation type is RELA.  If a backend with
      this flag set wants REL relocations for a particular section,
      it must note that explicitly.  Similarly, if this flag is clear,
-     and the backend wants RELA relocations for a particular 
-     section.  */   
+     and the backend wants RELA relocations for a particular
+     section.  */
   unsigned default_use_rela_p : 1;
 
   /* True if addresses "naturally" sign extend.  This is used when
@@ -704,6 +719,8 @@ struct bfd_elf_section_data
   long dynindx;
   /* A pointer used for .stab linking optimizations.  */
   PTR stab_info;
+  /* A pointer used for SEC_MERGE optimizations.  */
+  PTR merge_info;
   /* A pointer available for the processor specific ELF backend.  */
   PTR tdata;
   /* Nonzero if this section uses RELA relocations, rather than REL.  */
@@ -788,14 +805,14 @@ struct elf_obj_tdata
   file_ptr next_file_pos;
 #if 0
   /* we don't need these inside bfd anymore, and I think
-     these weren't used outside bfd. */
+     these weren't used outside bfd.  */
   void *prstatus;                      /* The raw /proc prstatus structure */
   void *prpsinfo;                      /* The raw /proc prpsinfo structure */
 #endif
   bfd_vma gp;                          /* The gp value (MIPS only, for now) */
   unsigned int gp_size;                        /* The gp size (MIPS only, for now) */
 
-  /* Information grabbed from an elf core file. */
+  /* Information grabbed from an elf core file.  */
   int core_signal;
   int core_pid;
   int core_lwpid;
@@ -817,7 +834,7 @@ struct elf_obj_tdata
      document the intent of any particular piece of code.  The field
      should be used as a count until size_dynamic_sections, at which
      point the contents of the .got is fixed.  Afterward, if an entry
-     is -1, then the symbol does not require a global offset table entry. */
+     is -1, then the symbol does not require a global offset table entry.  */
   union
     {
       bfd_signed_vma *refcounts;
@@ -838,6 +855,14 @@ struct elf_obj_tdata
      one.  */
   const char *dt_name;
 
+  /* When a reference in a regular object is resolved by a shared
+     object is loaded into via the DT_NEEDED entries by the linker
+     ELF emulation code, we need to add the shared object to the
+     DT_NEEDED list of the resulting binary to indicate the dependency
+     as if the -l option is passed to the linker. This field holds the
+     name of the loaded shared object.  */
+  const char *dt_soname;
+
   /* Irix 5 often screws up the symbol table, sorting local symbols
      after global symbols.  This flag is set if the symbol table in
      this BFD appears to be screwed up.  If it is, we ignore the
@@ -857,11 +882,11 @@ struct elf_obj_tdata
      find_nearest_line.  */
   struct mips_elf_find_line *find_line_info;
 
-  /* A place to stash dwarf1 info for this bfd. */
+  /* A place to stash dwarf1 info for this bfd.  */
   struct dwarf1_debug *dwarf1_find_line_info;
 
-  /* A place to stash dwarf2 info for this bfd. */
-  struct dwarf2_debug *dwarf2_find_line_info;
+  /* A place to stash dwarf2 info for this bfd.  */
+  PTR dwarf2_find_line_info;
 
   /* An array of stub sections indexed by symbol number, used by the
      MIPS ELF linker.  FIXME: We should figure out some way to only
@@ -885,6 +910,13 @@ struct elf_obj_tdata
 
   /* Linker sections that we are interested in.  */
   struct elf_linker_section *linker_section[ (int)LINKER_SECTION_MAX ];
+
+  /* The Irix 5 support uses two virtual sections, which represent
+     text/data symbols defined in dynamic objects.  */
+  asymbol *elf_data_symbol;
+  asymbol *elf_text_symbol;
+  asection *elf_data_section;
+  asection *elf_text_section;
 };
 
 #define elf_tdata(bfd)         ((bfd) -> tdata.elf_obj_data)
@@ -908,6 +940,7 @@ struct elf_obj_tdata
 #define elf_local_got_offsets(bfd) (elf_tdata(bfd) -> local_got.offsets)
 #define elf_local_ptr_offsets(bfd) (elf_tdata(bfd) -> linker_section_pointers)
 #define elf_dt_name(bfd)       (elf_tdata(bfd) -> dt_name)
+#define elf_dt_soname(bfd)     (elf_tdata(bfd) -> dt_soname)
 #define elf_bad_symtab(bfd)    (elf_tdata(bfd) -> bad_symtab)
 #define elf_flags_init(bfd)    (elf_tdata(bfd) -> flags_init)
 #define elf_linker_section(bfd,n) (elf_tdata(bfd) -> linker_section[(int)n])
@@ -978,6 +1011,9 @@ extern boolean _bfd_elf_link_hash_table_init
                                       const char *)));
 extern boolean _bfd_elf_slurp_version_tables PARAMS ((bfd *));
 
+extern boolean _bfd_elf_merge_sections
+  PARAMS ((bfd *, struct bfd_link_info *));
+
 extern boolean _bfd_elf_copy_private_symbol_data
   PARAMS ((bfd *, asymbol *, bfd *, asymbol *));
 extern boolean _bfd_elf_copy_private_section_data
@@ -1006,14 +1042,14 @@ extern boolean _bfd_elf_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
                                                unsigned long));
 extern boolean _bfd_elf_find_nearest_line PARAMS ((bfd *, asection *,
                                                    asymbol **,
-                                                   bfd_vma, CONST char **,
-                                                   CONST char **,
+                                                   bfd_vma, const char **,
+                                                   const char **,
                                                    unsigned int *));
 #define _bfd_elf_read_minisymbols _bfd_generic_read_minisymbols
 #define _bfd_elf_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
 extern int _bfd_elf_sizeof_headers PARAMS ((bfd *, boolean));
 extern boolean _bfd_elf_new_section_hook PARAMS ((bfd *, asection *));
-extern boolean _bfd_elf_init_reloc_shdr 
+extern boolean _bfd_elf_init_reloc_shdr
   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *, boolean));
 
 /* If the target doesn't have reloc handling written yet:  */
@@ -1282,11 +1318,11 @@ extern boolean _bfd_mips_elf_finish_dynamic_symbol
           Elf_Internal_Sym *));
 extern boolean _bfd_mips_elf_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
-extern asection * _bfd_mips_elf_gc_mark_hook 
+extern asection * _bfd_mips_elf_gc_mark_hook
   PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
           struct elf_link_hash_entry *, Elf_Internal_Sym *));
-extern boolean _bfd_mips_elf_gc_sweep_hook 
-  PARAMS ((bfd *, struct bfd_link_info *, asection *, 
+extern boolean _bfd_mips_elf_gc_sweep_hook
+  PARAMS ((bfd *, struct bfd_link_info *, asection *,
           const Elf_Internal_Rela *));
 extern boolean _bfd_mips_elf_always_size_sections
   PARAMS ((bfd *, struct bfd_link_info *));
@@ -1297,7 +1333,7 @@ extern boolean _bfd_mips_elf_check_relocs
           const Elf_Internal_Rela *));
 extern struct bfd_link_hash_table *_bfd_mips_elf_link_hash_table_create
   PARAMS ((bfd *));
-extern boolean _bfd_mips_elf_print_private_bfd_data 
+extern boolean _bfd_mips_elf_print_private_bfd_data
   PARAMS ((bfd *, PTR));
 extern boolean _bfd_mips_elf_link_output_symbol_hook
   PARAMS ((bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,