Handle R_X86_64_64 properly for x32
[deliverable/binutils-gdb.git] / bfd / mach-o.h
index f0c2f6fe5ce14657878fc74006c1d97a2de4c20c..7f54961c7f3ae9d1f8a90508fa634def08947969 100644 (file)
@@ -1,5 +1,6 @@
 /* Mach-O support for BFD.
 /* Mach-O support for BFD.
-   Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009
+   Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2011,
+   2012
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -41,14 +42,26 @@ typedef struct bfd_mach_o_header
 }
 bfd_mach_o_header;
 
 }
 bfd_mach_o_header;
 
-#define BFD_MACH_O_HEADER_SIZE 28
-#define BFD_MACH_O_HEADER_64_SIZE 32
+typedef struct bfd_mach_o_asymbol
+{
+  /* The actual symbol which the rest of BFD works with.  */
+  asymbol symbol;
+
+  /* Mach-O symbol fields.  */
+  unsigned char n_type;
+  unsigned char n_sect;
+  unsigned short n_desc;
+}
+bfd_mach_o_asymbol;
+
+#define BFD_MACH_O_SEGNAME_SIZE 16
+#define BFD_MACH_O_SECTNAME_SIZE 16
 
 typedef struct bfd_mach_o_section
 {
 
 typedef struct bfd_mach_o_section
 {
-  asection *bfdsection;
-  char sectname[16 + 1];
-  char segname[16 + 1];
+  /* Fields present in the file.  */
+  char sectname[BFD_MACH_O_SECTNAME_SIZE + 1]; /* Always NUL padded.  */
+  char segname[BFD_MACH_O_SEGNAME_SIZE + 1];
   bfd_vma addr;
   bfd_vma size;
   bfd_vma offset;
   bfd_vma addr;
   bfd_vma size;
   bfd_vma offset;
@@ -59,14 +72,24 @@ typedef struct bfd_mach_o_section
   unsigned long reserved1;
   unsigned long reserved2;
   unsigned long reserved3;
   unsigned long reserved1;
   unsigned long reserved2;
   unsigned long reserved3;
+
+  /* Corresponding bfd section.  */
+  asection *bfdsection;
+
+  /* An array holding the indirect symbols for this section.
+     NULL values indicate local symbols.
+     The number of symbols is determined from the section size and type.  */
+
+  bfd_mach_o_asymbol **indirect_syms;
+
+  /* Simply linked list.  */
+  struct bfd_mach_o_section *next;
 }
 bfd_mach_o_section;
 }
 bfd_mach_o_section;
-#define BFD_MACH_O_SECTION_SIZE 68
-#define BFD_MACH_O_SECTION_64_SIZE 80
 
 typedef struct bfd_mach_o_segment_command
 {
 
 typedef struct bfd_mach_o_segment_command
 {
-  char segname[16 + 1];
+  char segname[BFD_MACH_O_SEGNAME_SIZE + 1];
   bfd_vma vmaddr;
   bfd_vma vmsize;
   bfd_vma fileoff;
   bfd_vma vmaddr;
   bfd_vma vmsize;
   bfd_vma fileoff;
@@ -75,58 +98,18 @@ typedef struct bfd_mach_o_segment_command
   unsigned long initprot;      /* Initial protection.  */
   unsigned long nsects;
   unsigned long flags;
   unsigned long initprot;      /* Initial protection.  */
   unsigned long nsects;
   unsigned long flags;
-  bfd_mach_o_section *sections;
+
+  /* Linked list of sections.  */
+  bfd_mach_o_section *sect_head;
+  bfd_mach_o_section *sect_tail;
 }
 bfd_mach_o_segment_command;
 }
 bfd_mach_o_segment_command;
-#define BFD_MACH_O_LC_SEGMENT_SIZE 56
-#define BFD_MACH_O_LC_SEGMENT_64_SIZE 72
 
 /* Protection flags.  */
 #define BFD_MACH_O_PROT_READ    0x01
 #define BFD_MACH_O_PROT_WRITE   0x02
 #define BFD_MACH_O_PROT_EXECUTE 0x04
 
 
 /* Protection flags.  */
 #define BFD_MACH_O_PROT_READ    0x01
 #define BFD_MACH_O_PROT_WRITE   0x02
 #define BFD_MACH_O_PROT_EXECUTE 0x04
 
-/* Generic relocation types (used by i386).  */
-#define BFD_MACH_O_GENERIC_RELOC_VANILLA       0
-#define BFD_MACH_O_GENERIC_RELOC_PAIR          1
-#define BFD_MACH_O_GENERIC_RELOC_SECTDIFF      2
-#define BFD_MACH_O_GENERIC_RELOC_PB_LA_PTR     3
-#define BFD_MACH_O_GENERIC_RELOC_LOCAL_SECTDIFF        4
-
-/* X86-64 relocations.  */
-#define BFD_MACH_O_X86_64_RELOC_UNSIGNED   0 /* Absolute addresses.  */
-#define BFD_MACH_O_X86_64_RELOC_SIGNED     1 /* 32-bit disp.  */
-#define BFD_MACH_O_X86_64_RELOC_BRANCH     2 /* 32-bit pcrel disp.  */
-#define BFD_MACH_O_X86_64_RELOC_GOT_LOAD   3 /* Movq load of a GOT entry.  */
-#define BFD_MACH_O_X86_64_RELOC_GOT        4 /* GOT reference.  */
-#define BFD_MACH_O_X86_64_RELOC_SUBTRACTOR 5 /* Symbol difference.  */
-#define BFD_MACH_O_X86_64_RELOC_SIGNED_1   6 /* 32-bit signed disp -1.  */
-#define BFD_MACH_O_X86_64_RELOC_SIGNED_2   7 /* 32-bit signed disp -2.  */
-#define BFD_MACH_O_X86_64_RELOC_SIGNED_4   8 /* 32-bit signed disp -4.  */
-
-/* Size of a relocation entry.  */
-#define BFD_MACH_O_RELENT_SIZE 8
-
-/* Fields for a normal (non-scattered) entry.  */
-#define BFD_MACH_O_R_PCREL             0x01000000
-#define BFD_MACH_O_GET_R_LENGTH(s)     (((s) >> 25) & 0x3)
-#define BFD_MACH_O_R_EXTERN            0x08000000
-#define BFD_MACH_O_GET_R_TYPE(s)       (((s) >> 28) & 0x0f)
-#define BFD_MACH_O_GET_R_SYMBOLNUM(s)  ((s) & 0x00ffffff)
-#define BFD_MACH_O_SET_R_LENGTH(l)     (((l) & 0x3) << 25)
-#define BFD_MACH_O_SET_R_TYPE(t)       (((t) & 0xf) << 28)
-#define BFD_MACH_O_SET_R_SYMBOLNUM(s)  ((s) & 0x00ffffff)
-
-/* Fields for a scattered entry.  */
-#define BFD_MACH_O_SR_SCATTERED                0x80000000
-#define BFD_MACH_O_SR_PCREL            0x40000000
-#define BFD_MACH_O_GET_SR_LENGTH(s)    (((s) >> 28) & 0x3)
-#define BFD_MACH_O_GET_SR_TYPE(s)      (((s) >> 24) & 0x0f)
-#define BFD_MACH_O_GET_SR_ADDRESS(s)   ((s) & 0x00ffffff)
-#define BFD_MACH_O_SET_SR_LENGTH(l)    (((l) & 0x3) << 28)
-#define BFD_MACH_O_SET_SR_TYPE(t)      (((t) & 0xf) << 24)
-#define BFD_MACH_O_SET_SR_ADDRESS(s)   ((s) & 0x00ffffff)
-
 /* Expanded internal representation of a relocation entry.  */
 typedef struct bfd_mach_o_reloc_info
 {
 /* Expanded internal representation of a relocation entry.  */
 typedef struct bfd_mach_o_reloc_info
 {
@@ -140,19 +123,14 @@ typedef struct bfd_mach_o_reloc_info
 }
 bfd_mach_o_reloc_info;
 
 }
 bfd_mach_o_reloc_info;
 
-typedef struct bfd_mach_o_asymbol
-{
-  /* The actual symbol which the rest of BFD works with.  */
-  asymbol symbol;
-
-  /* Fields from Mach-O symbol.  */
-  unsigned char n_type;
-  unsigned char n_sect;
-  unsigned short n_desc;
-}
-bfd_mach_o_asymbol;
-#define BFD_MACH_O_NLIST_SIZE 12
-#define BFD_MACH_O_NLIST_64_SIZE 16
+/* The symbol table is sorted like this:
+ (1) local.
+       (otherwise in order of generation)
+ (2) external defined
+       (sorted by name)
+ (3) external undefined / common
+       (sorted by name)
+*/
 
 typedef struct bfd_mach_o_symtab_command
 {
 
 typedef struct bfd_mach_o_symtab_command
 {
@@ -259,8 +237,6 @@ typedef struct bfd_mach_o_dylib_module
   bfd_vma objc_module_info_addr;
 }
 bfd_mach_o_dylib_module;
   bfd_vma objc_module_info_addr;
 }
 bfd_mach_o_dylib_module;
-#define BFD_MACH_O_DYLIB_MODULE_SIZE 52
-#define BFD_MACH_O_DYLIB_MODULE_64_SIZE 56
 
 typedef struct bfd_mach_o_dylib_table_of_content
 {
 
 typedef struct bfd_mach_o_dylib_table_of_content
 {
@@ -271,7 +247,6 @@ typedef struct bfd_mach_o_dylib_table_of_content
   unsigned long module_index;
 }
 bfd_mach_o_dylib_table_of_content;
   unsigned long module_index;
 }
 bfd_mach_o_dylib_table_of_content;
-#define BFD_MACH_O_TABLE_OF_CONTENT_SIZE 8
 
 typedef struct bfd_mach_o_dylib_reference
 {
 
 typedef struct bfd_mach_o_dylib_reference
 {
@@ -479,6 +454,16 @@ typedef struct bfd_mach_o_str_command
 }
 bfd_mach_o_str_command;
 
 }
 bfd_mach_o_str_command;
 
+typedef struct bfd_mach_o_fvmlib_command
+{
+  unsigned int name_offset;
+  unsigned int name_len;
+  char *name_str;
+  unsigned int minor_version;
+  unsigned int header_addr;
+}
+bfd_mach_o_fvmlib_command;
+
 typedef struct bfd_mach_o_dyld_info_command
 {
   /* File offset and size to rebase info.  */
 typedef struct bfd_mach_o_dyld_info_command
 {
   /* File offset and size to rebase info.  */
@@ -503,6 +488,23 @@ typedef struct bfd_mach_o_dyld_info_command
 }
 bfd_mach_o_dyld_info_command;
 
 }
 bfd_mach_o_dyld_info_command;
 
+typedef struct bfd_mach_o_version_min_command
+{
+  unsigned char rel;
+  unsigned char maj;
+  unsigned char min;
+  unsigned int reserved;
+}
+bfd_mach_o_version_min_command;
+
+typedef struct bfd_mach_o_encryption_info_command
+{
+  unsigned int cryptoff;
+  unsigned int cryptsize;
+  unsigned int cryptid;
+}
+bfd_mach_o_encryption_info_command;
+
 typedef struct bfd_mach_o_load_command
 {
   bfd_mach_o_load_command_type type;
 typedef struct bfd_mach_o_load_command
 {
   bfd_mach_o_load_command_type type;
@@ -522,6 +524,9 @@ typedef struct bfd_mach_o_load_command
     bfd_mach_o_linkedit_command linkedit;
     bfd_mach_o_str_command str;
     bfd_mach_o_dyld_info_command dyld_info;
     bfd_mach_o_linkedit_command linkedit;
     bfd_mach_o_str_command str;
     bfd_mach_o_dyld_info_command dyld_info;
+    bfd_mach_o_version_min_command version_min;
+    bfd_mach_o_encryption_info_command encryption_info;
+    bfd_mach_o_fvmlib_command fvmlib;
   }
   command;
 }
   }
   command;
 }
@@ -538,37 +543,45 @@ typedef struct mach_o_data_struct
   unsigned long nsects;
   bfd_mach_o_section **sections;
 
   unsigned long nsects;
   bfd_mach_o_section **sections;
 
-  /* Used while writting: current length of the output file.  This is used
+  /* Used while writing: current length of the output file.  This is used
      to allocate space in the file.  */
   ufile_ptr filelen;
 
   /* As symtab is referenced by other load command, it is handy to have
      to allocate space in the file.  */
   ufile_ptr filelen;
 
   /* As symtab is referenced by other load command, it is handy to have
-     a direct access to it.  Also it is not clearly stated, only one symtab
+     a direct access to it.  Although it is not clearly stated, only one symtab
      is expected.  */
   bfd_mach_o_symtab_command *symtab;
   bfd_mach_o_dysymtab_command *dysymtab;
      is expected.  */
   bfd_mach_o_symtab_command *symtab;
   bfd_mach_o_dysymtab_command *dysymtab;
+
+  /* A place to stash dwarf2 info for this bfd.  */
+  void *dwarf2_find_line_info;
+
+  /* BFD of .dSYM file. */
+  bfd *dsym_bfd;
+
+  /* Cache of dynamic relocs. */
+  arelent *dyn_reloc_cache;
 }
 bfd_mach_o_data_struct;
 
 }
 bfd_mach_o_data_struct;
 
-/* Target specific routines.  */
-typedef struct bfd_mach_o_backend_data
+typedef struct bfd_mach_o_xlat_name
 {
 {
-  enum bfd_architecture arch;
-  bfd_boolean (*_bfd_mach_o_swap_reloc_in)(arelent *, bfd_mach_o_reloc_info *);
-  bfd_boolean (*_bfd_mach_o_swap_reloc_out)(arelent *, bfd_mach_o_reloc_info *);
-  bfd_boolean (*_bfd_mach_o_print_thread)(bfd *, bfd_mach_o_thread_flavour *,
-                                          void *, char *);
+  const char *name;
+  unsigned long val;
 }
 }
-bfd_mach_o_backend_data;
+bfd_mach_o_xlat_name;
+
+/* Target specific routines.  */
 
 #define bfd_mach_o_get_data(abfd) ((abfd)->tdata.mach_o_data)
 #define bfd_mach_o_get_backend_data(abfd) \
   ((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
 
 
 #define bfd_mach_o_get_data(abfd) ((abfd)->tdata.mach_o_data)
 #define bfd_mach_o_get_backend_data(abfd) \
   ((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
 
+/* Get the Mach-O header for section SEC.  */
+#define bfd_mach_o_get_mach_o_section(sec) \
+  ((bfd_mach_o_section *)(sec)->used_by_bfd)
+
 bfd_boolean bfd_mach_o_valid (bfd *);
 bfd_boolean bfd_mach_o_valid (bfd *);
-int bfd_mach_o_read_dysymtab_symbol (bfd *, bfd_mach_o_dysymtab_command *, bfd_mach_o_symtab_command *, bfd_mach_o_asymbol *, unsigned long);
-int bfd_mach_o_scan_start_address (bfd *);
-int bfd_mach_o_scan (bfd *, bfd_mach_o_header *, bfd_mach_o_data_struct *);
 bfd_boolean bfd_mach_o_mkobject_init (bfd *);
 const bfd_target *bfd_mach_o_object_p (bfd *);
 const bfd_target *bfd_mach_o_core_p (bfd *);
 bfd_boolean bfd_mach_o_mkobject_init (bfd *);
 const bfd_target *bfd_mach_o_object_p (bfd *);
 const bfd_target *bfd_mach_o_core_p (bfd *);
@@ -576,14 +589,15 @@ const bfd_target *bfd_mach_o_archive_p (bfd *);
 bfd *bfd_mach_o_openr_next_archived_file (bfd *, bfd *);
 bfd_boolean bfd_mach_o_set_arch_mach (bfd *, enum bfd_architecture,
                                       unsigned long);
 bfd *bfd_mach_o_openr_next_archived_file (bfd *, bfd *);
 bfd_boolean bfd_mach_o_set_arch_mach (bfd *, enum bfd_architecture,
                                       unsigned long);
-int bfd_mach_o_lookup_section (bfd *, asection *, bfd_mach_o_load_command **, bfd_mach_o_section **);
 int bfd_mach_o_lookup_command (bfd *, bfd_mach_o_load_command_type, bfd_mach_o_load_command **);
 int bfd_mach_o_lookup_command (bfd *, bfd_mach_o_load_command_type, bfd_mach_o_load_command **);
+bfd_boolean bfd_mach_o_new_section_hook (bfd *, asection *);
 bfd_boolean bfd_mach_o_write_contents (bfd *);
 bfd_boolean bfd_mach_o_bfd_copy_private_symbol_data (bfd *, asymbol *,
                                                      bfd *, asymbol *);
 bfd_boolean bfd_mach_o_bfd_copy_private_section_data (bfd *, asection *,
                                                       bfd *, asection *);
 bfd_boolean bfd_mach_o_bfd_copy_private_bfd_data (bfd *, bfd *);
 bfd_boolean bfd_mach_o_write_contents (bfd *);
 bfd_boolean bfd_mach_o_bfd_copy_private_symbol_data (bfd *, asymbol *,
                                                      bfd *, asymbol *);
 bfd_boolean bfd_mach_o_bfd_copy_private_section_data (bfd *, asection *,
                                                       bfd *, asection *);
 bfd_boolean bfd_mach_o_bfd_copy_private_bfd_data (bfd *, bfd *);
+bfd_boolean bfd_mach_o_bfd_set_private_flags (bfd *, flagword);
 long bfd_mach_o_get_symtab_upper_bound (bfd *);
 long bfd_mach_o_canonicalize_symtab (bfd *, asymbol **);
 long bfd_mach_o_get_synthetic_symtab (bfd *, long, asymbol **, long, 
 long bfd_mach_o_get_symtab_upper_bound (bfd *);
 long bfd_mach_o_canonicalize_symtab (bfd *, asymbol **);
 long bfd_mach_o_get_synthetic_symtab (bfd *, long, asymbol **, long, 
@@ -595,7 +609,6 @@ long bfd_mach_o_canonicalize_dynamic_reloc (bfd *, arelent **, asymbol **);
 asymbol *bfd_mach_o_make_empty_symbol (bfd *);
 void bfd_mach_o_get_symbol_info (bfd *, asymbol *, symbol_info *);
 void bfd_mach_o_print_symbol (bfd *, PTR, asymbol *, bfd_print_symbol_type);
 asymbol *bfd_mach_o_make_empty_symbol (bfd *);
 void bfd_mach_o_get_symbol_info (bfd *, asymbol *, symbol_info *);
 void bfd_mach_o_print_symbol (bfd *, PTR, asymbol *, bfd_print_symbol_type);
-bfd_boolean bfd_mach_o_bfd_print_private_bfd_data (bfd *, PTR);
 int bfd_mach_o_sizeof_headers (bfd *, struct bfd_link_info *);
 unsigned long bfd_mach_o_stack_addr (enum bfd_mach_o_cpu_type);
 int bfd_mach_o_core_fetch_environment (bfd *, unsigned char **, unsigned int *);
 int bfd_mach_o_sizeof_headers (bfd *, struct bfd_link_info *);
 unsigned long bfd_mach_o_stack_addr (enum bfd_mach_o_cpu_type);
 int bfd_mach_o_core_fetch_environment (bfd *, unsigned char **, unsigned int *);
@@ -610,6 +623,70 @@ bfd_boolean bfd_mach_o_set_section_contents (bfd *, asection *, const void *,
                                              file_ptr, bfd_size_type);
 unsigned int bfd_mach_o_version (bfd *);
 
                                              file_ptr, bfd_size_type);
 unsigned int bfd_mach_o_version (bfd *);
 
+unsigned int bfd_mach_o_get_section_type_from_name (bfd *, const char *);
+unsigned int bfd_mach_o_get_section_attribute_from_name (const char *);
+
+void bfd_mach_o_convert_section_name_to_bfd (bfd *, const char *, const char *,
+                                            const char **, flagword *);
+bfd_boolean bfd_mach_o_find_nearest_line (bfd *, asection *, asymbol **,
+                                          bfd_vma, const char **,
+                                          const char **, unsigned int *);
+bfd_boolean bfd_mach_o_close_and_cleanup (bfd *);
+bfd_boolean bfd_mach_o_free_cached_info (bfd *);
+
+unsigned int bfd_mach_o_section_get_nbr_indirect (bfd *, bfd_mach_o_section *);
+unsigned int bfd_mach_o_section_get_entry_size (bfd *, bfd_mach_o_section *);
+bfd_boolean bfd_mach_o_read_symtab_symbols (bfd *);
+bfd_boolean bfd_mach_o_read_symtab_strtab (bfd *abfd);
+
+/* A placeholder in case we need to suppress emitting the dysymtab for some
+   reason (e.g. compatibility with older system versions).  */
+#define bfd_mach_o_should_emit_dysymtab(x) TRUE
+
+extern const bfd_mach_o_xlat_name bfd_mach_o_section_attribute_name[];
+extern const bfd_mach_o_xlat_name bfd_mach_o_section_type_name[];
+
 extern const bfd_target mach_o_fat_vec;
 
 extern const bfd_target mach_o_fat_vec;
 
+/* Interfaces between BFD names and Mach-O names.  */
+
+typedef struct mach_o_section_name_xlat
+{
+  const char *bfd_name;
+  const char *mach_o_name;
+  flagword bfd_flags;
+  unsigned int macho_sectype;
+  unsigned int macho_secattr;
+  unsigned int sectalign;
+} mach_o_section_name_xlat;
+
+typedef struct mach_o_segment_name_xlat
+{
+  const char *segname;
+  const mach_o_section_name_xlat *sections;
+} mach_o_segment_name_xlat;
+
+const mach_o_section_name_xlat *
+bfd_mach_o_section_data_for_mach_sect (bfd *, const char *, const char *);
+const mach_o_section_name_xlat *
+bfd_mach_o_section_data_for_bfd_name (bfd *, const char *, const char **);
+
+typedef struct bfd_mach_o_backend_data
+{
+  enum bfd_architecture arch;
+  bfd_boolean (*_bfd_mach_o_swap_reloc_in)(arelent *, bfd_mach_o_reloc_info *);
+  bfd_boolean (*_bfd_mach_o_swap_reloc_out)(arelent *, bfd_mach_o_reloc_info *);
+  bfd_boolean (*_bfd_mach_o_print_thread)(bfd *, bfd_mach_o_thread_flavour *,
+                                          void *, char *);
+  const mach_o_segment_name_xlat *segsec_names_xlat;
+  bfd_boolean (*bfd_mach_o_section_type_valid_for_target) (unsigned long);
+}
+bfd_mach_o_backend_data;
+
+/* Values used in symbol.udata.i, to signal that the mach-o-specific data in the
+   symbol are not yet set, or need validation (where this is possible).  */
+
+#define SYM_MACHO_FIELDS_UNSET ((bfd_vma) -1)
+#define SYM_MACHO_FIELDS_NOT_VALIDATED ((bfd_vma) -2)
+
 #endif /* _BFD_MACH_O_H_ */
 #endif /* _BFD_MACH_O_H_ */
This page took 0.029544 seconds and 4 git commands to generate.