summaryrefslogtreecommitdiff
path: root/bfd/mach-o.h
diff options
context:
space:
mode:
authorTristan Gingold <gingold@adacore.com>2009-06-12 09:15:45 +0000
committerTristan Gingold <gingold@adacore.com>2009-06-12 09:15:45 +0000
commitc4ad487cb16d25add8ac9c0d38367ca5ed3a8794 (patch)
tree9aa2a0a799bf79188e2cb7a5f37ffe3bf51a1a03 /bfd/mach-o.h
parent670f24233bbc15fb62dee9c2267c0f22cd03fa71 (diff)
downloadgdb-c4ad487cb16d25add8ac9c0d38367ca5ed3a8794.tar.gz
2009-06-12 Tristan Gingold <gingold@adacore.com>
* reloc.c: Add BFD_RELOC_MACH_O_SECTDIFF and BFD_RELOC_MACH_O_PAIR. * bfd-in2.h: Regenerated. * libbfd.h: Regenerated. * mach-o.c (FILE_ALIGN): New macro. (bfd_mach_o_canonicalize_symtab): Adjust for bfd_mach_o_asymbol. (bfd_mach_o_print_symbol): Ditto. (bfd_mach_o_scan_write_thread): Adjust type of variable offset. (bfd_mach_o_get_reloc_upper_bound): New function. (bfd_mach_o_canonicalize_reloc): Ditto. (bfd_mach_o_scan_write_relocs): Ditto. (bfd_mach_o_scan_write_section_32): Remove offset argument. (bfd_mach_o_scan_write_section_64): Ditto. (bfd_mach_o_scan_write_segment_32): Write relocs. Fix size of data written for load command. Do not compute section file offset. (bfd_mach_o_scan_write_segment_64): Ditto. (bfd_mach_o_scan_write_symtab): Compute file offset first. Adjust for bfd_mach_o_asymbol. Move code to convert from BFD to Mach-O to ... (bfd_mach_o_mangle_symbols): ... this new function. (bfd_mach_o_write_contents): Be sure to habe load commands built. Call bfd_mach_o_mangle_symbols. (bfd_mach_o_build_commands): Adjust for filelen field. Use FILE_ALIGN macro. Clear section file offset if section is empty. Do not set symtab file offset anymore here. (bfd_mach_o_make_empty_symbol): Allocate a bfd_mach_o_asymbol. (bfd_mach_o_make_bfd_section): Set SEC_RELOC if has reloc. Set reloc_count and rel_filepos section fields. (bfd_mach_o_scan_read_section_32): Type of argument offset is now unsigned int. (bfd_mach_o_scan_read_section_64): Ditto. (bfd_mach_o_scan_read_section): Ditto. (bfd_mach_o_scan_read_symtab_symbol): Typr of argument s is now bfd_mach_o_asymbol. Use unsigned int for file offset type. (bfd_mach_o_scan_read_symtab_symbol): Adjust for bfd_mach_o_asymbol. Handle weak-ref symbols. (bfd_mach_o_scan_read_symtab_symbols): Adjust for bfd_mach_o_asymbol. (bfd_mach_o_scan_read_dysymtab_symbol): Ditto. (bfd_mach_o_scan): Remove assignment to removed field. (bfd_mach_o_mkobject_init): Ditto. (bfd_mach_o_bfd_print_private_bfd_data): Adjust printf formatter. (bfd_mach_o_bfd_reloc_type_lookup): New macro. (bfd_mach_o_bfd_reloc_name_lookup): Ditto. (bfd_mach_o_swap_reloc_in): Ditto. (bfd_mach_o_swap_reloc_out): Ditto. * mach-o.h (BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_NON_LAZY) (BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_LAZY) (BFD_MACH_O_REFERENCE_FLAG_DEFINED) (BFD_MACH_O_REFERENCE_FLAG_PRIVATE_DEFINED) (BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY) (BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY) (BFD_MACH_O_REFERENCED_DYNAMICALLY, BFD_MACH_O_N_DESC_DISCARDED) (BFD_MACH_O_N_NO_DEAD_STRIP, BFD_MACH_O_N_WEAK_REF) (BFD_MACH_O_N_WEAK_DEF): New macros. Add comments. (bfd_mach_o_section_type): Add new enumeration values. (BFD_MACH_O_S_SELF_MODIFYING_CODE) (BFD_MACH_O_S_ATTR_LIVE_SUPPORT) (BFD_MACH_O_S_ATTR_NO_DEAD_STRIP) (BFD_MACH_O_S_ATTR_STRIP_STATIC_SYMS, BFD_MACH_O_S_ATTR_NO_TOC): New macros. (BFD_MACH_O_GENERIC_RELOC_VANILLA) (BFD_MACH_O_GENERIC_RELOC_PAIR) (BFD_MACH_O_GENERIC_RELOC_SECTDIFF) (BFD_MACH_O_GENERIC_RELOC_PB_LA_PTR) (BFD_MACH_O_GENERIC_RELOC_LOCAL_SECTDIFF): Ditto. (BFD_MACH_O_RELENT_SIZE): Ditto. (BFD_MACH_O_R_PCREL, BFD_MACH_O_GET_R_LENGTH) (BFD_MACH_O_R_EXTERN, BFD_MACH_O_GET_R_TYPE) (BFD_MACH_O_GET_R_SYMBOLNUM, BFD_MACH_O_SET_R_LENGTH) (BFD_MACH_O_SET_R_TYPE, BFD_MACH_O_SET_R_SYMBOLNUM): Ditto. (BFD_MACH_O_SR_SCATTERED, BFD_MACH_O_SR_PCREL) (BFD_MACH_O_GET_SR_LENGTH, BFD_MACH_O_GET_SR_TYPE) (BFD_MACH_O_GET_SR_ADDRESS, BFD_MACH_O_SET_SR_LENGTH) (BFD_MACH_O_SET_SR_TYPE, BFD_MACH_O_SET_SR_ADDRESS): Ditto. (bfd_mach_o_reloc_info): New struct. (bfd_mach_o_asymbol): New struct. (bfd_mach_o_symtab_command): The symbols field is now of type bfd_mach_o_asymbol. (bfd_mach_o_load_command): The offset and len fields are now of type unsigned int. (mach_o_data_struct): Remove symbols, nsymbols and ibfd fields. Add a filelen field. Add comments. (bfd_mach_o_backend_data): New struct. (bfd_mach_o_get_backend_data): New macro. (bfd_mach_o_scan_read_symtab_symbol): Parameter symbol now of type bfd_mach_o_asymbol. (bfd_mach_o_scan_read_dysymtab_symbol): Ditto. (bfd_mach_o_get_reloc_upper_bound): New prototype. (bfd_mach_o_canonicalize_reloc): Ditto. * mach-o-target.c (bfd_mach_o_bfd_is_local_label_name): Remove duplicated macro. Now defined to _bfd_generic_is_local_label. (TARGET_NAME_BACKEND): New macro... (TARGET_NAME_BACKEND): ... used to name a new variable. (TARGET_NAME): Define relocs table using bfd_mach_o, reference Mach-O backend data. * mach-o-i386.c (i386_howto_table): New variable. (bfd_mach_o_i386_swap_reloc_in): New function. (bfd_mach_o_i386_swap_reloc_out): Ditto. (bfd_mach_o_i386_bfd_reloc_type_lookup): Ditto. (bfd_mach_o_i386_bfd_reloc_name_lookup): Ditto. (bfd_mach_o_swap_reloc_in, bfd_mach_o_swap_reloc_out): New macros. (bfd_mach_o_bfd_reloc_type_lookup) (bfd_mach_o_bfd_reloc_name_lookup): Ditto.
Diffstat (limited to 'bfd/mach-o.h')
-rw-r--r--bfd/mach-o.h167
1 files changed, 145 insertions, 22 deletions
diff --git a/bfd/mach-o.h b/bfd/mach-o.h
index 5401587765d..766a68a70b5 100644
--- a/bfd/mach-o.h
+++ b/bfd/mach-o.h
@@ -24,6 +24,7 @@
#include "bfd.h"
+/* Symbol n_type values. */
#define BFD_MACH_O_N_STAB 0xe0 /* If any of these bits set, a symbolic debugging entry. */
#define BFD_MACH_O_N_PEXT 0x10 /* Private external symbol bit. */
#define BFD_MACH_O_N_TYPE 0x0e /* Mask for the type bits. */
@@ -34,11 +35,20 @@
#define BFD_MACH_O_N_PBUD 0x0c /* Prebound undefined (defined in a dylib). */
#define BFD_MACH_O_N_SECT 0x0e /* Defined in section number n_sect. */
-#define BFD_MACH_O_NO_SECT 0
-
-#define BFD_MACH_O_SYM_NTYPE(SYM) (((SYM)->udata.i >> 24) & 0xff)
-#define BFD_MACH_O_SYM_NSECT(SYM) (((SYM)->udata.i >> 16) & 0xff)
-#define BFD_MACH_O_SYM_NDESC(SYM) ((SYM)->udata.i & 0xffff)
+#define BFD_MACH_O_NO_SECT 0 /* Symbol not in any section of the image. */
+
+/* Symbol n_desc flags. */
+#define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_NON_LAZY 0x00
+#define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_LAZY 0x01
+#define BFD_MACH_O_REFERENCE_FLAG_DEFINED 0x02
+#define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_DEFINED 0x03
+#define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 0x04
+#define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 0x05
+#define BFD_MACH_O_REFERENCED_DYNAMICALLY 0x10
+#define BFD_MACH_O_N_DESC_DISCARDED 0x20
+#define BFD_MACH_O_N_NO_DEAD_STRIP 0x20
+#define BFD_MACH_O_N_WEAK_REF 0x40
+#define BFD_MACH_O_N_WEAK_DEF 0x80
typedef enum bfd_mach_o_mach_header_magic
{
@@ -203,11 +213,33 @@ typedef enum bfd_mach_o_section_type
/* Section with only lazy symbol pointers. */
BFD_MACH_O_S_LAZY_SYMBOL_POINTERS = 0x7,
- /* Section with only symbol stubs, byte size of stub in the reserved2 field. */
+ /* Section with only symbol stubs, byte size of stub in the reserved2
+ field. */
BFD_MACH_O_S_SYMBOL_STUBS = 0x8,
/* Section with only function pointers for initialization. */
- BFD_MACH_O_S_MOD_INIT_FUNC_POINTERS = 0x9
+ BFD_MACH_O_S_MOD_INIT_FUNC_POINTERS = 0x9,
+
+ /* Section with only function pointers for termination. */
+ BFD_MACH_O_S_MOD_FINI_FUNC_POINTERS = 0xa,
+
+ /* Section contains symbols that are coalesced by the linkers. */
+ BFD_MACH_O_S_COALESCED = 0xb,
+
+ /* Zero fill on demand section (possibly larger than 4 GB). */
+ BFD_MACH_O_S_GB_ZEROFILL = 0xc,
+
+ /* Section with only pairs of function pointers for interposing. */
+ BFD_MACH_O_S_INTERPOSING = 0xd,
+
+ /* Section with only 16 byte literals. */
+ BFD_MACH_O_S_16BYTE_LITERALS = 0xe,
+
+ /* Section contains DTrace Object Format. */
+ BFD_MACH_O_S_DTRACE_DOF = 0xf,
+
+ /* Section with only lazy symbol pointers to lazy loaded dylibs. */
+ BFD_MACH_O_S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10
}
bfd_mach_o_section_type;
@@ -233,10 +265,27 @@ bfd_mach_o_section_type;
#define BFD_MACH_O_S_ATTR_EXT_RELOC 0x00000200
/* Section contains some machine instructions. */
-#define BFD_MACH_O_S_ATTR_SOME_INSTRUCTIONS 0x00004000
+#define BFD_MACH_O_S_ATTR_SOME_INSTRUCTIONS 0x00000400
+/* A debug section. */
#define BFD_MACH_O_S_ATTR_DEBUG 0x02000000
+/* Used with i386 stubs. */
+#define BFD_MACH_O_S_SELF_MODIFYING_CODE 0x04000000
+
+/* Blocks are live if they reference live blocks. */
+#define BFD_MACH_O_S_ATTR_LIVE_SUPPORT 0x08000000
+
+/* No dead stripping. */
+#define BFD_MACH_O_S_ATTR_NO_DEAD_STRIP 0x10000000
+
+/* Section symbols can be stripped in files with MH_DYLDLINK flag. */
+#define BFD_MACH_O_S_ATTR_STRIP_STATIC_SYMS 0x20000000
+
+/* Section contains coalesced symbols that are not to be in the TOC of an
+ archive. */
+#define BFD_MACH_O_S_ATTR_NO_TOC 0x40000000
+
/* Section contains only true machine instructions. */
#define BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS 0x80000000
@@ -302,13 +351,68 @@ bfd_mach_o_segment_command;
#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
+
+/* 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
+{
+ bfd_vma r_address;
+ bfd_vma r_value;
+ unsigned int r_scattered : 1;
+ unsigned int r_type : 4;
+ unsigned int r_pcrel : 1;
+ unsigned int r_length : 2;
+ unsigned int r_extern : 1;
+}
+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;
+
typedef struct bfd_mach_o_symtab_command
{
- unsigned long symoff;
- unsigned long nsyms;
- unsigned long stroff;
- unsigned long strsize;
- asymbol *symbols;
+ unsigned int symoff;
+ unsigned int nsyms;
+ unsigned int stroff;
+ unsigned int strsize;
+ bfd_mach_o_asymbol *symbols;
char *strtab;
}
bfd_mach_o_symtab_command;
@@ -525,8 +629,8 @@ typedef struct bfd_mach_o_load_command
{
bfd_mach_o_load_command_type type;
bfd_boolean type_required;
- bfd_vma offset;
- bfd_vma len;
+ unsigned int offset;
+ unsigned int len;
union
{
bfd_mach_o_segment_command segment;
@@ -544,25 +648,40 @@ bfd_mach_o_load_command;
typedef struct mach_o_data_struct
{
+ /* Mach-O header. */
bfd_mach_o_header header;
+ /* Array of load commands (length is given by header.ncmds). */
bfd_mach_o_load_command *commands;
- unsigned long nsymbols;
- asymbol *symbols;
+
+ /* Flatten array of sections. The array is 0-based. */
unsigned long nsects;
bfd_mach_o_section **sections;
- bfd *ibfd;
+
+ /* Used while writting: current length of the output file. This is used
+ to allocate space in the file. */
+ ufile_ptr filelen;
}
mach_o_data_struct;
+typedef struct mach_o_data_struct bfd_mach_o_data_struct;
-#define bfd_get_mach_o_data(abfd) ((abfd)->tdata.mach_o_data)
+/* Target specific routines. */
+typedef struct bfd_mach_o_backend_data
+{
+ 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_mach_o_backend_data;
-typedef struct mach_o_data_struct bfd_mach_o_data_struct;
+#define bfd_get_mach_o_data(abfd) ((abfd)->tdata.mach_o_data)
+#define bfd_mach_o_get_backend_data(abfd) \
+ ((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
bfd_boolean bfd_mach_o_valid (bfd *);
-int bfd_mach_o_scan_read_symtab_symbol (bfd *, bfd_mach_o_symtab_command *, asymbol *, unsigned long);
+int bfd_mach_o_scan_read_symtab_symbol (bfd *, bfd_mach_o_symtab_command *,
+ bfd_mach_o_asymbol *, unsigned long);
int bfd_mach_o_scan_read_symtab_strtab (bfd *, bfd_mach_o_symtab_command *);
int bfd_mach_o_scan_read_symtab_symbols (bfd *, bfd_mach_o_symtab_command *);
-int bfd_mach_o_scan_read_dysymtab_symbol (bfd *, bfd_mach_o_dysymtab_command *, bfd_mach_o_symtab_command *, asymbol *, unsigned long);
+int bfd_mach_o_scan_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 *);
@@ -580,6 +699,10 @@ bfd_boolean bfd_mach_o_bfd_copy_private_section_data (bfd *, asection *,
bfd_boolean bfd_mach_o_bfd_copy_private_bfd_data (bfd *, bfd *);
long bfd_mach_o_get_symtab_upper_bound (bfd *);
long bfd_mach_o_canonicalize_symtab (bfd *, asymbol **);
+long bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *asect);
+long bfd_mach_o_canonicalize_reloc (bfd *abfd, asection *asect,
+ arelent **rels, asymbol **syms);
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);