This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Committed - Mach-O]: Handle reloc
- From: Tristan Gingold <gingold at adacore dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Fri, 12 Jun 2009 11:20:56 +0200
- Subject: [Committed - Mach-O]: Handle reloc
Hi,
here is what I have just committed to bfd. This patch adds reloc
handling (currently only for i386) to
the Mach-O back-end. With this patch (and a little bit of work), I
was able to run the gas testsuite with
only 1 regression (which looks to be a baseline error).
Tristan.
bfd/
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.
Index: mach-o-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o-i386.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -c -p -r1.2 -r1.3
*** mach-o-i386.c 9 Jun 2009 07:37:19 -0000 1.2
--- mach-o-i386.c 12 Jun 2009 09:15:45 -0000 1.3
*************** bfd_mach_o_i386_mkobject (bfd *abfd)
*** 60,68 ****
return TRUE;
}
#define TARGET_NAME mach_o_i386_vec
#define TARGET_STRING "mach-o-i386"
#define TARGET_BIG_ENDIAN 0
#define TARGET_ARCHIVE 0
-
#include "mach-o-target.c"
--- 60,230 ----
return TRUE;
}
+ static reloc_howto_type i386_howto_table[]=
+ {
+ HOWTO(BFD_RELOC_32, 0, 2, 32, FALSE, 0,
+ complain_overflow_bitfield,
+ NULL, "32",
+ FALSE, 0xffffffff, 0xffffffff, FALSE),
+ HOWTO(BFD_RELOC_16, 0, 1, 16, FALSE, 0,
+ complain_overflow_bitfield,
+ NULL, "16",
+ FALSE, 0xffff, 0xffff, FALSE),
+ HOWTO(BFD_RELOC_8, 0, 0, 8, FALSE, 0,
+ complain_overflow_bitfield,
+ NULL, "8",
+ FALSE, 0xff, 0xff, FALSE),
+ HOWTO(BFD_RELOC_32_PCREL, 0, 2, 32, TRUE, 0,
+ complain_overflow_bitfield,
+ NULL, "DISP32",
+ FALSE, 0xffffffff, 0xffffffff, TRUE),
+ HOWTO(BFD_RELOC_16_PCREL, 0, 1, 16, TRUE, 0,
+ complain_overflow_bitfield,
+ NULL, "DISP16",
+ FALSE, 0xffff, 0xffff, TRUE),
+ HOWTO(BFD_RELOC_MACH_O_SECTDIFF, 0, 2, 32, FALSE, 0,
+ complain_overflow_bitfield,
+ NULL, "SECTDIFF_32",
+ FALSE, 0xffffffff, 0xffffffff, FALSE),
+ HOWTO(BFD_RELOC_MACH_O_PAIR, 0, 2, 32, FALSE, 0,
+ complain_overflow_bitfield,
+ NULL, "PAIR_32",
+ FALSE, 0xffffffff, 0xffffffff, FALSE),
+ };
+
+ static bfd_boolean
+ bfd_mach_o_i386_swap_reloc_in (arelent *res, bfd_mach_o_reloc_info
*reloc)
+ {
+ if (reloc->r_scattered)
+ {
+ switch (reloc->r_type)
+ {
+ case BFD_MACH_O_GENERIC_RELOC_PAIR:
+ if (reloc->r_length != 2)
+ return FALSE;
+ res->howto = &i386_howto_table[3];
+ res->address = res[-1].address;
+ return TRUE;
+ case BFD_MACH_O_GENERIC_RELOC_SECTDIFF:
+ case BFD_MACH_O_GENERIC_RELOC_LOCAL_SECTDIFF:
+ if (reloc->r_length != 2)
+ return FALSE;
+ res->howto = &i386_howto_table[2];
+ return TRUE;
+ default:
+ return FALSE;
+ }
+ }
+ else
+ {
+ switch (reloc->r_type)
+ {
+ case BFD_MACH_O_GENERIC_RELOC_VANILLA:
+ switch ((reloc->r_length << 1) | reloc->r_pcrel)
+ {
+ case 0: /* len = 0, pcrel = 0 */
+ res->howto = &i386_howto_table[2];
+ return TRUE;
+ case 2: /* len = 1, pcrel = 0 */
+ res->howto = &i386_howto_table[1];
+ return TRUE;
+ case 3: /* len = 1, pcrel = 1 */
+ res->howto = &i386_howto_table[4];
+ return TRUE;
+ case 4: /* len = 2, pcrel = 0 */
+ res->howto = &i386_howto_table[0];
+ return TRUE;
+ case 5: /* len = 2, pcrel = 1 */
+ res->howto = &i386_howto_table[3];
+ return TRUE;
+ default:
+ return FALSE;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+ }
+ }
+
+ static bfd_boolean
+ bfd_mach_o_i386_swap_reloc_out (arelent *rel, bfd_mach_o_reloc_info
*rinfo)
+ {
+ rinfo->r_address = rel->address;
+ switch (rel->howto->type)
+ {
+ case BFD_RELOC_32:
+ case BFD_RELOC_32_PCREL:
+ case BFD_RELOC_16:
+ case BFD_RELOC_16_PCREL:
+ case BFD_RELOC_8:
+ rinfo->r_scattered = 0;
+ rinfo->r_type = BFD_MACH_O_GENERIC_RELOC_VANILLA;
+ rinfo->r_pcrel = rel->howto->pc_relative;
+ rinfo->r_length = rel->howto->size; /* Correct in practice. */
+ if ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
+ {
+ rinfo->r_extern = 0;
+ rinfo->r_value = (*rel->sym_ptr_ptr)->section->target_index;
+ }
+ else
+ {
+ rinfo->r_extern = 1;
+ rinfo->r_value = (*rel->sym_ptr_ptr)->udata.i;
+ }
+ break;
+ case BFD_RELOC_MACH_O_SECTDIFF:
+ rinfo->r_scattered = 1;
+ rinfo->r_type = BFD_MACH_O_GENERIC_RELOC_SECTDIFF;
+ rinfo->r_pcrel = 0;
+ rinfo->r_length = 2;
+ rinfo->r_extern = 0;
+ rinfo->r_value = (*rel->sym_ptr_ptr)->value
+ + (*rel->sym_ptr_ptr)->section->vma;
+ break;
+ case BFD_RELOC_MACH_O_PAIR:
+ rinfo->r_address = 0;
+ rinfo->r_scattered = 1;
+ rinfo->r_type = BFD_MACH_O_GENERIC_RELOC_PAIR;
+ rinfo->r_pcrel = 0;
+ rinfo->r_length = 2;
+ rinfo->r_extern = 0;
+ rinfo->r_value = (*rel->sym_ptr_ptr)->value
+ + (*rel->sym_ptr_ptr)->section->vma;
+ break;
+ default:
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ static reloc_howto_type *
+ bfd_mach_o_i386_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+ bfd_reloc_code_real_type code)
+ {
+ unsigned int i;
+
+ for (i = 0; i < sizeof (i386_howto_table) / sizeof
(*i386_howto_table); i++)
+ if (code == i386_howto_table[i].type)
+ return &i386_howto_table[i];
+ return NULL;
+ }
+
+ static reloc_howto_type *
+ bfd_mach_o_i386_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+ const char *name
ATTRIBUTE_UNUSED)
+ {
+ return NULL;
+ }
+
+ #define bfd_mach_o_swap_reloc_in bfd_mach_o_i386_swap_reloc_in
+ #define bfd_mach_o_swap_reloc_out bfd_mach_o_i386_swap_reloc_out
+
+ #define bfd_mach_o_bfd_reloc_type_lookup
bfd_mach_o_i386_bfd_reloc_type_lookup
+ #define bfd_mach_o_bfd_reloc_name_lookup
bfd_mach_o_i386_bfd_reloc_name_lookup
+
#define TARGET_NAME mach_o_i386_vec
#define TARGET_STRING "mach-o-i386"
#define TARGET_BIG_ENDIAN 0
#define TARGET_ARCHIVE 0
#include "mach-o-target.c"
Index: mach-o-target.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o-target.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -c -p -r1.7 -r1.8
*** mach-o-target.c 5 Jun 2009 09:19:44 -0000 1.7
--- mach-o-target.c 12 Jun 2009 09:15:45 -0000 1.8
***************
*** 39,47 ****
#define bfd_mach_o_bfd_free_cached_info
_bfd_generic_bfd_free_cached_info
#define bfd_mach_o_new_section_hook
_bfd_generic_new_section_hook
#define bfd_mach_o_get_section_contents_in_window
_bfd_generic_get_section_contents_in_window
- #define bfd_mach_o_bfd_is_local_label_name
_bfd_nosymbols_bfd_is_local_label_name
#define bfd_mach_o_bfd_is_target_special_symbol ((bfd_boolean
(*) (bfd *, asymbol *)) bfd_false)
! #define bfd_mach_o_bfd_is_local_label_name
_bfd_nosymbols_bfd_is_local_label_name
#define bfd_mach_o_get_lineno
_bfd_nosymbols_get_lineno
#define bfd_mach_o_find_nearest_line
_bfd_nosymbols_find_nearest_line
#define bfd_mach_o_find_inliner_info
_bfd_nosymbols_find_inliner_info
--- 39,46 ----
#define bfd_mach_o_bfd_free_cached_info
_bfd_generic_bfd_free_cached_info
#define bfd_mach_o_new_section_hook
_bfd_generic_new_section_hook
#define bfd_mach_o_get_section_contents_in_window
_bfd_generic_get_section_contents_in_window
#define bfd_mach_o_bfd_is_target_special_symbol ((bfd_boolean
(*) (bfd *, asymbol *)) bfd_false)
! #define bfd_mach_o_bfd_is_local_label_name
bfd_generic_is_local_label_name
#define bfd_mach_o_get_lineno
_bfd_nosymbols_get_lineno
#define bfd_mach_o_find_nearest_line
_bfd_nosymbols_find_nearest_line
#define bfd_mach_o_find_inliner_info
_bfd_nosymbols_find_inliner_info
***************
*** 69,74 ****
--- 68,75 ----
#define bfd_mach_o_bfd_copy_private_header_data
_bfd_generic_bfd_copy_private_header_data
#define bfd_mach_o_core_file_matches_executable_p
generic_core_file_matches_executable_p
+ #define TARGET_NAME_BACKEND XCONCAT2(TARGET_NAME,_backend)
+
#endif /* MACH_O_TARGET_COMMON_DEFINED */
#ifndef TARGET_NAME
***************
*** 91,96 ****
--- 92,103 ----
#error Mach-O fat files must always be big-endian.
#endif /* ((TARGET_ARCHIVE) && (! TARGET_BIG_ENDIAN)) */
+ static const bfd_mach_o_backend_data TARGET_NAME_BACKEND =
+ {
+ bfd_mach_o_swap_reloc_in,
+ bfd_mach_o_swap_reloc_out
+ };
+
const bfd_target TARGET_NAME =
{
TARGET_STRING, /* Name. */
*************** const bfd_target TARGET_NAME =
*** 162,174 ****
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
#endif
BFD_JUMP_TABLE_SYMBOLS (bfd_mach_o),
! BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
BFD_JUMP_TABLE_WRITE (bfd_mach_o),
BFD_JUMP_TABLE_LINK (bfd_mach_o),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
NULL,
! NULL
};
--- 169,183 ----
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
#endif
BFD_JUMP_TABLE_SYMBOLS (bfd_mach_o),
! BFD_JUMP_TABLE_RELOCS (bfd_mach_o),
BFD_JUMP_TABLE_WRITE (bfd_mach_o),
BFD_JUMP_TABLE_LINK (bfd_mach_o),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
+ /* Alternative endian target. */
NULL,
! /* Back-end data. */
! &TARGET_NAME_BACKEND
};
Index: mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -c -p -r1.35 -r1.36
*** mach-o.c 9 Jun 2009 07:37:19 -0000 1.35
--- mach-o.c 12 Jun 2009 09:15:46 -0000 1.36
***************
*** 31,36 ****
--- 31,39 ----
#define bfd_mach_o_core_p bfd_mach_o_gen_core_p
#define bfd_mach_o_mkobject bfd_false
+ #define FILE_ALIGN(off, algn) \
+ (((off) + ((file_ptr) 1 << (algn)) - 1) & ((file_ptr) -1 << (algn)))
+
unsigned int
bfd_mach_o_version (bfd *abfd)
{
*************** bfd_mach_o_canonicalize_symtab (bfd *abf
*** 351,357 ****
for (j = 0; j < sym->nsyms; j++)
{
BFD_ASSERT (csym < (alocation + nsyms));
! *csym++ = &sym->symbols[j];
}
}
}
--- 354,360 ----
for (j = 0; j < sym->nsyms; j++)
{
BFD_ASSERT (csym < (alocation + nsyms));
! *csym++ = &sym->symbols[j].symbol;
}
}
}
*************** bfd_mach_o_print_symbol (bfd *abfd,
*** 376,385 ****
bfd_print_symbol_type how)
{
FILE *file = (FILE *) afile;
- unsigned char ntype;
- unsigned char nsect;
- unsigned int ndesc;
const char *name;
switch (how)
{
--- 379,386 ----
bfd_print_symbol_type how)
{
FILE *file = (FILE *) afile;
const char *name;
+ bfd_mach_o_asymbol *asym = (bfd_mach_o_asymbol *)symbol;
switch (how)
{
*************** bfd_mach_o_print_symbol (bfd *abfd,
*** 388,400 ****
break;
default:
bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
! ntype = BFD_MACH_O_SYM_NTYPE (symbol);
! nsect = BFD_MACH_O_SYM_NSECT (symbol);
! ndesc = BFD_MACH_O_SYM_NDESC (symbol);
! if (ntype & BFD_MACH_O_N_STAB)
! name = bfd_get_stab_name (ntype);
else
! switch (ntype & BFD_MACH_O_N_TYPE)
{
case BFD_MACH_O_N_UNDF:
name = "UND";
--- 389,398 ----
break;
default:
bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
! if (asym->n_type & BFD_MACH_O_N_STAB)
! name = bfd_get_stab_name (asym->n_type);
else
! switch (asym->n_type & BFD_MACH_O_N_TYPE)
{
case BFD_MACH_O_N_UNDF:
name = "UND";
*************** bfd_mach_o_print_symbol (bfd *abfd,
*** 417,425 ****
}
if (name == NULL)
name = "";
! fprintf (file, " %02x %-6s %02x %04x", ntype, name, nsect,
ndesc);
! if ((ntype & BFD_MACH_O_N_STAB) == 0
! && (ntype & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_SECT)
fprintf (file, " %-5s", symbol->section->name);
fprintf (file, " %s", symbol->name);
}
--- 415,424 ----
}
if (name == NULL)
name = "";
! fprintf (file, " %02x %-6s %02x %04x",
! asym->n_type, name, asym->n_sect, asym->n_desc);
! if ((asym->n_type & BFD_MACH_O_N_STAB) == 0
! && (asym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_SECT)
fprintf (file, " %-5s", symbol->section->name);
fprintf (file, " %s", symbol->name);
}
*************** bfd_mach_o_scan_write_thread (bfd *abfd,
*** 503,509 ****
bfd_mach_o_thread_command *cmd = &command->command.thread;
unsigned int i;
unsigned char buf[8];
! bfd_vma offset;
unsigned int nflavours;
BFD_ASSERT ((command->type == BFD_MACH_O_LC_THREAD)
--- 502,508 ----
bfd_mach_o_thread_command *cmd = &command->command.thread;
unsigned int i;
unsigned char buf[8];
! unsigned int offset;
unsigned int nflavours;
BFD_ASSERT ((command->type == BFD_MACH_O_LC_THREAD)
*************** bfd_mach_o_scan_write_thread (bfd *abfd,
*** 529,538 ****
return 0;
}
static int
! bfd_mach_o_scan_write_section_32 (bfd *abfd,
! bfd_mach_o_section *section,
! bfd_vma offset)
{
unsigned char buf[BFD_MACH_O_SECTION_SIZE];
--- 528,719 ----
return 0;
}
+ long
+ bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *asect)
+ {
+ return (asect->reloc_count + 1) * sizeof (arelent *);
+ }
+
+ long
+ bfd_mach_o_canonicalize_reloc (bfd *abfd, asection *asect,
+ arelent **rels, asymbol **syms)
+ {
+ bfd_mach_o_data_struct *mdata = abfd->tdata.mach_o_data;
+ bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+ unsigned long i;
+ arelent *res;
+ char *native_relocs;
+ bfd_size_type native_size;
+
+ if (asect->reloc_count == 0)
+ return 0;
+
+ /* No need to go further if we don't know how to read relocs. */
+ if (bed->_bfd_mach_o_swap_reloc_in == NULL)
+ return 0;
+
+ /* Allocate and read relocs. */
+ native_size = asect->reloc_count * BFD_MACH_O_RELENT_SIZE;
+ native_relocs = bfd_malloc (native_size);
+ if (native_relocs == NULL)
+ return -1;
+
+ if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0
+ || bfd_bread (native_relocs, native_size, abfd) != native_size)
+ {
+ free (native_relocs);
+ return -1;
+ }
+
+ res = bfd_malloc (asect->reloc_count * sizeof (arelent));
+ if (res == NULL)
+ {
+ free (native_relocs);
+ return -1;
+ }
+
+ for (i = 0; i < asect->reloc_count; i++)
+ {
+ char *buf = native_relocs + BFD_MACH_O_RELENT_SIZE * i;
+ bfd_mach_o_reloc_info reloc;
+ bfd_vma addr;
+ bfd_vma symnum;
+ asymbol **sym;
+
+ addr = bfd_get_32 (abfd, buf + 0);
+ symnum = bfd_get_32 (abfd, buf + 4);
+
+ if (addr & BFD_MACH_O_SR_SCATTERED)
+ {
+ unsigned int j;
+
+ /* Scattered relocation.
+ Extract section and offset from r_value. */
+ res[i].sym_ptr_ptr = NULL;
+ res[i].addend = 0;
+ for (j = 0; j < mdata->nsects; j++)
+ {
+ bfd_mach_o_section *sect = mdata->sections[j];
+ if (symnum >= sect->addr && symnum < sect->addr + sect-
>size)
+ {
+ res[i].sym_ptr_ptr = sect->bfdsection-
>symbol_ptr_ptr;
+ res[i].addend = symnum - sect->addr;
+ break;
+ }
+ }
+ res[i].address = BFD_MACH_O_GET_SR_ADDRESS (addr);
+ reloc.r_type = BFD_MACH_O_GET_SR_TYPE (addr);
+ reloc.r_length = BFD_MACH_O_GET_SR_LENGTH (addr);
+ reloc.r_pcrel = addr & BFD_MACH_O_SR_PCREL;
+ reloc.r_scattered = 1;
+ }
+ else
+ {
+ unsigned int num = BFD_MACH_O_GET_R_SYMBOLNUM (symnum);
+ res[i].addend = 0;
+ res[i].address = addr;
+ if (symnum & BFD_MACH_O_R_EXTERN)
+ sym = syms + num;
+ else
+ {
+ BFD_ASSERT (num != 0);
+ BFD_ASSERT (num <= mdata->nsects);
+ sym = mdata->sections[num - 1]->bfdsection-
>symbol_ptr_ptr;
+ }
+ res[i].sym_ptr_ptr = sym;
+ reloc.r_type = BFD_MACH_O_GET_R_TYPE (symnum);
+ reloc.r_length = BFD_MACH_O_GET_R_LENGTH (symnum);
+ reloc.r_pcrel = (symnum & BFD_MACH_O_R_PCREL) ? 1 : 0;
+ reloc.r_scattered = 0;
+ }
+
+ if (!(*bed->_bfd_mach_o_swap_reloc_in)(&res[i], &reloc))
+ {
+ free (res);
+ free (native_relocs);
+ return -1;
+ }
+ rels[i] = &res[i];
+ }
+ asect->relocation = res;
+ free (native_relocs);
+ return i;
+ }
+
+ static bfd_boolean
+ bfd_mach_o_scan_write_relocs (bfd *abfd, bfd_mach_o_section *section)
+ {
+ bfd_mach_o_data_struct *mdata = bfd_get_mach_o_data (abfd);
+ unsigned int i;
+ arelent **entries;
+ asection *sec;
+ bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+
+ sec = section->bfdsection;
+ if (sec->reloc_count == 0)
+ return TRUE;
+
+ if (bed->_bfd_mach_o_swap_reloc_out == NULL)
+ return TRUE;
+
+ /* Allocate relocation room. */
+ mdata->filelen = FILE_ALIGN(mdata->filelen, 2);
+ section->nreloc = sec->reloc_count;
+ sec->rel_filepos = mdata->filelen;
+ section->reloff = sec->rel_filepos;
+ mdata->filelen += sec->reloc_count * BFD_MACH_O_RELENT_SIZE;
+
+ if (bfd_seek (abfd, section->reloff, SEEK_SET) != 0)
+ return FALSE;
+
+ /* Convert and write. */
+ entries = section->bfdsection->orelocation;
+ for (i = 0; i < section->nreloc; i++)
+ {
+ arelent *rel = entries[i];
+ char buf[8];
+ bfd_mach_o_reloc_info info, *pinfo = &info;
+
+ /* Convert relocation to an intermediate representation. */
+ if (!(*bed->_bfd_mach_o_swap_reloc_out) (rel, pinfo))
+ return FALSE;
+
+ /* Lower the relocation info. */
+ if (pinfo->r_scattered)
+ {
+ unsigned long v;
+
+ v = BFD_MACH_O_SR_SCATTERED
+ | (pinfo->r_pcrel ? BFD_MACH_O_SR_PCREL : 0)
+ | BFD_MACH_O_SET_SR_LENGTH(pinfo->r_length)
+ | BFD_MACH_O_SET_SR_TYPE(pinfo->r_type)
+ | BFD_MACH_O_SET_SR_ADDRESS(pinfo->r_address);
+ bfd_put_32 (abfd, v, buf);
+ bfd_put_32 (abfd, pinfo->r_value, buf + 4);
+ }
+ else
+ {
+ unsigned long v;
+
+ bfd_put_32 (abfd, pinfo->r_address, buf);
+ v = BFD_MACH_O_SET_R_SYMBOLNUM (pinfo->r_value)
+ | (pinfo->r_pcrel ? BFD_MACH_O_R_PCREL : 0)
+ | BFD_MACH_O_SET_R_LENGTH (pinfo->r_length)
+ | (pinfo->r_extern ? BFD_MACH_O_R_EXTERN : 0)
+ | BFD_MACH_O_SET_R_TYPE (pinfo->r_type);
+ bfd_put_32 (abfd, v, buf + 4);
+ }
+
+ if (bfd_bwrite ((PTR) buf, BFD_MACH_O_RELENT_SIZE, abfd)
+ != BFD_MACH_O_RELENT_SIZE)
+ return FALSE;
+ }
+ return TRUE;
+ }
+
static int
! bfd_mach_o_scan_write_section_32 (bfd *abfd, bfd_mach_o_section
*section)
{
unsigned char buf[BFD_MACH_O_SECTION_SIZE];
*************** bfd_mach_o_scan_write_section_32 (bfd *a
*** 548,565 ****
bfd_h_put_32 (abfd, section->reserved1, buf + 60);
bfd_h_put_32 (abfd, section->reserved2, buf + 64);
! if (bfd_seek (abfd, offset, SEEK_SET) != 0
! || (bfd_bwrite ((PTR) buf, BFD_MACH_O_SECTION_SIZE, abfd)
! != BFD_MACH_O_SECTION_SIZE))
return -1;
return 0;
}
static int
! bfd_mach_o_scan_write_section_64 (bfd *abfd,
! bfd_mach_o_section *section,
! bfd_vma offset)
{
unsigned char buf[BFD_MACH_O_SECTION_64_SIZE];
--- 729,743 ----
bfd_h_put_32 (abfd, section->reserved1, buf + 60);
bfd_h_put_32 (abfd, section->reserved2, buf + 64);
! if (bfd_bwrite ((PTR) buf, BFD_MACH_O_SECTION_SIZE, abfd)
! != BFD_MACH_O_SECTION_SIZE)
return -1;
return 0;
}
static int
! bfd_mach_o_scan_write_section_64 (bfd *abfd, bfd_mach_o_section
*section)
{
unsigned char buf[BFD_MACH_O_SECTION_64_SIZE];
*************** bfd_mach_o_scan_write_section_64 (bfd *a
*** 576,584 ****
bfd_h_put_32 (abfd, section->reserved2, buf + 72);
bfd_h_put_32 (abfd, section->reserved3, buf + 76);
! if (bfd_seek (abfd, offset, SEEK_SET) != 0
! || (bfd_bwrite ((PTR) buf, BFD_MACH_O_SECTION_64_SIZE, abfd)
! != BFD_MACH_O_SECTION_64_SIZE))
return -1;
return 0;
--- 754,761 ----
bfd_h_put_32 (abfd, section->reserved2, buf + 72);
bfd_h_put_32 (abfd, section->reserved3, buf + 76);
! if (bfd_bwrite ((PTR) buf, BFD_MACH_O_SECTION_64_SIZE, abfd)
! != BFD_MACH_O_SECTION_64_SIZE)
return -1;
return 0;
*************** bfd_mach_o_scan_write_segment_32 (bfd *a
*** 593,600 ****
BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT);
! memcpy (buf, seg->segname, 16);
bfd_h_put_32 (abfd, seg->vmaddr, buf + 16);
bfd_h_put_32 (abfd, seg->vmsize, buf + 20);
bfd_h_put_32 (abfd, seg->fileoff, buf + 24);
--- 770,780 ----
BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT);
! for (i = 0; i < seg->nsects; i++)
! if (!bfd_mach_o_scan_write_relocs (abfd, &seg->sections[i]))
! return -1;
+ memcpy (buf, seg->segname, 16);
bfd_h_put_32 (abfd, seg->vmaddr, buf + 16);
bfd_h_put_32 (abfd, seg->vmsize, buf + 20);
bfd_h_put_32 (abfd, seg->fileoff, buf + 24);
*************** bfd_mach_o_scan_write_segment_32 (bfd *a
*** 605,622 ****
bfd_h_put_32 (abfd, seg->flags, buf + 44);
if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
! || (bfd_bwrite ((PTR) buf, BFD_MACH_O_LC_SEGMENT_SIZE, abfd)
! != BFD_MACH_O_LC_SEGMENT_SIZE))
return -1;
for (i = 0; i < seg->nsects; i++)
! {
! bfd_vma segoff = command->offset + BFD_MACH_O_LC_SEGMENT_SIZE
! + (i * BFD_MACH_O_SECTION_SIZE);
- if (bfd_mach_o_scan_write_section_32 (abfd, &seg->sections[i],
segoff))
- return -1;
- }
return 0;
}
--- 785,798 ----
bfd_h_put_32 (abfd, seg->flags, buf + 44);
if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
! || (bfd_bwrite ((PTR) buf, BFD_MACH_O_LC_SEGMENT_SIZE - 8, abfd)
! != BFD_MACH_O_LC_SEGMENT_SIZE - 8))
return -1;
for (i = 0; i < seg->nsects; i++)
! if (bfd_mach_o_scan_write_section_32 (abfd, &seg->sections[i]))
! return -1;
return 0;
}
*************** bfd_mach_o_scan_write_segment_64 (bfd *a
*** 629,636 ****
BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT_64);
! memcpy (buf, seg->segname, 16);
bfd_h_put_64 (abfd, seg->vmaddr, buf + 16);
bfd_h_put_64 (abfd, seg->vmsize, buf + 24);
bfd_h_put_64 (abfd, seg->fileoff, buf + 32);
--- 805,815 ----
BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT_64);
! for (i = 0; i < seg->nsects; i++)
! if (!bfd_mach_o_scan_write_relocs (abfd, &seg->sections[i]))
! return -1;
+ memcpy (buf, seg->segname, 16);
bfd_h_put_64 (abfd, seg->vmaddr, buf + 16);
bfd_h_put_64 (abfd, seg->vmsize, buf + 24);
bfd_h_put_64 (abfd, seg->fileoff, buf + 32);
*************** bfd_mach_o_scan_write_segment_64 (bfd *a
*** 641,664 ****
bfd_h_put_32 (abfd, seg->flags, buf + 60);
if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
! || (bfd_bwrite ((PTR) buf, BFD_MACH_O_LC_SEGMENT_64_SIZE, abfd)
! != BFD_MACH_O_LC_SEGMENT_64_SIZE))
return -1;
for (i = 0; i < seg->nsects; i++)
! {
! bfd_vma segoff = command->offset + BFD_MACH_O_LC_SEGMENT_64_SIZE
! + (i * BFD_MACH_O_SECTION_64_SIZE);
- if (bfd_mach_o_scan_write_section_64 (abfd, &seg->sections[i],
segoff))
- return -1;
- }
return 0;
}
static bfd_boolean
bfd_mach_o_scan_write_symtab (bfd *abfd, bfd_mach_o_load_command
*command)
{
bfd_mach_o_symtab_command *sym = &command->command.symtab;
unsigned char buf[16];
unsigned long i;
--- 820,840 ----
bfd_h_put_32 (abfd, seg->flags, buf + 60);
if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
! || (bfd_bwrite ((PTR) buf, BFD_MACH_O_LC_SEGMENT_64_SIZE - 8,
abfd)
! != BFD_MACH_O_LC_SEGMENT_64_SIZE - 8))
return -1;
for (i = 0; i < seg->nsects; i++)
! if (bfd_mach_o_scan_write_section_64 (abfd, &seg->sections[i]))
! return -1;
return 0;
}
static bfd_boolean
bfd_mach_o_scan_write_symtab (bfd *abfd, bfd_mach_o_load_command
*command)
{
+ bfd_mach_o_data_struct *mdata = bfd_get_mach_o_data (abfd);
bfd_mach_o_symtab_command *sym = &command->command.symtab;
unsigned char buf[16];
unsigned long i;
*************** bfd_mach_o_scan_write_symtab (bfd *abfd,
*** 670,679 ****
--- 846,858 ----
BFD_ASSERT (command->type == BFD_MACH_O_LC_SYMTAB);
/* Write the symbols first. */
+ mdata->filelen = FILE_ALIGN(mdata->filelen, wide ? 3 : 2);
+ sym->symoff = mdata->filelen;
if (bfd_seek (abfd, sym->symoff, SEEK_SET) != 0)
return FALSE;
sym->nsyms = bfd_get_symcount (abfd);
+ mdata->filelen += sym->nsyms * symlen;
strtab = _bfd_stringtab_init ();
if (strtab == NULL)
*************** bfd_mach_o_scan_write_symtab (bfd *abfd,
*** 682,749 ****
for (i = 0; i < sym->nsyms; i++)
{
unsigned char buf[16];
- unsigned char ntype;
- unsigned char nsect;
- short ndesc;
bfd_size_type index;
! asymbol *s = symbols[i];
! /* Compute index. */
/* An index of 0 always means the empty string. */
! if (s->name == 0 || s->name[0] == '\0')
index = 0;
else
{
! index = _bfd_stringtab_add (strtab, s->name, TRUE, FALSE);
if (index == (bfd_size_type) -1)
goto err;
}
-
- /* Get back-end specific values. */
- ntype = BFD_MACH_O_SYM_NTYPE (s);
- nsect = BFD_MACH_O_SYM_NSECT (s);
- ndesc = BFD_MACH_O_SYM_NDESC (s);
-
- if (ntype == BFD_MACH_O_N_UNDF && !(s->flags & BSF_DEBUGGING))
- {
- /* As genuine Mach-O symbols type shouldn't be N_UNDF
(undefined
- symbols should be N_UNDEF | N_EXT), we suppose the back-
end
- values haven't been set. */
- if (s->flags & (BSF_LOCAL | BSF_GLOBAL))
- {
- if (s->section == bfd_abs_section_ptr)
- ntype = BFD_MACH_O_N_ABS;
- else if (s->section == bfd_und_section_ptr)
- ntype = BFD_MACH_O_N_UNDF;
- else if (s->section == bfd_com_section_ptr)
- ntype = BFD_MACH_O_N_UNDF | BFD_MACH_O_N_EXT;
- else
- ntype = BFD_MACH_O_N_SECT;
-
- ntype |= (s->flags & BSF_GLOBAL) ? BFD_MACH_O_N_EXT : 0;
- }
- }
-
- /* Compute section index. */
- if (s->section != bfd_abs_section_ptr
- && s->section != bfd_und_section_ptr
- && s->section != bfd_com_section_ptr)
- nsect = s->section->target_index;
-
bfd_h_put_32 (abfd, index, buf);
! bfd_h_put_8 (abfd, ntype, buf + 4);
! bfd_h_put_8 (abfd, nsect, buf + 5);
! bfd_h_put_16 (abfd, ndesc, buf + 6);
if (wide)
! bfd_h_put_64 (abfd, s->section->vma + s->value, buf + 8);
else
! bfd_h_put_32 (abfd, s->section->vma + s->value, buf + 8);
if (bfd_bwrite ((PTR) buf, symlen, abfd) != symlen)
goto err;
}
sym->strsize = _bfd_stringtab_size (strtab);
! sym->stroff = sym->symoff + sym->nsyms * symlen;
if (_bfd_stringtab_emit (abfd, strtab) != TRUE)
goto err;
--- 861,894 ----
for (i = 0; i < sym->nsyms; i++)
{
unsigned char buf[16];
bfd_size_type index;
! bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *)symbols[i];
! /* Compute name index. */
/* An index of 0 always means the empty string. */
! if (s->symbol.name == 0 || s->symbol.name[0] == '\0')
index = 0;
else
{
! index = _bfd_stringtab_add (strtab, s->symbol.name, TRUE,
FALSE);
if (index == (bfd_size_type) -1)
goto err;
}
bfd_h_put_32 (abfd, index, buf);
! bfd_h_put_8 (abfd, s->n_type, buf + 4);
! bfd_h_put_8 (abfd, s->n_sect, buf + 5);
! bfd_h_put_16 (abfd, s->n_desc, buf + 6);
if (wide)
! bfd_h_put_64 (abfd, s->symbol.section->vma + s-
>symbol.value, buf + 8);
else
! bfd_h_put_32 (abfd, s->symbol.section->vma + s-
>symbol.value, buf + 8);
if (bfd_bwrite ((PTR) buf, symlen, abfd) != symlen)
goto err;
}
sym->strsize = _bfd_stringtab_size (strtab);
! sym->stroff = mdata->filelen;
! mdata->filelen += sym->strsize;
if (_bfd_stringtab_emit (abfd, strtab) != TRUE)
goto err;
*************** bfd_mach_o_scan_write_symtab (bfd *abfd,
*** 766,777 ****
--- 911,973 ----
return FALSE;
}
+ /* Process the symbols and generate Mach-O specific fields.
+ Number them. */
+
+ static bfd_boolean
+ bfd_mach_o_mangle_symbols (bfd *abfd)
+ {
+ unsigned long i;
+ asymbol **symbols = bfd_get_outsymbols (abfd);
+
+ for (i = 0; i < bfd_get_symcount (abfd); i++)
+ {
+ bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *)symbols[i];
+
+ if (s->n_type == BFD_MACH_O_N_UNDF && !(s->symbol.flags &
BSF_DEBUGGING))
+ {
+ /* As genuine Mach-O symbols type shouldn't be N_UNDF
(undefined
+ symbols should be N_UNDEF | N_EXT), we suppose the back-
end
+ values haven't been set. */
+ if (s->symbol.section == bfd_abs_section_ptr)
+ s->n_type = BFD_MACH_O_N_ABS;
+ else if (s->symbol.section == bfd_und_section_ptr)
+ {
+ s->n_type = BFD_MACH_O_N_UNDF;
+ if (s->symbol.flags & BSF_WEAK)
+ s->n_desc |= BFD_MACH_O_N_WEAK_REF;
+ }
+ else if (s->symbol.section == bfd_com_section_ptr)
+ s->n_type = BFD_MACH_O_N_UNDF | BFD_MACH_O_N_EXT;
+ else
+ s->n_type = BFD_MACH_O_N_SECT;
+
+ if (s->symbol.flags & BSF_GLOBAL)
+ s->n_type |= BFD_MACH_O_N_EXT;
+ }
+
+ /* Compute section index. */
+ if (s->symbol.section != bfd_abs_section_ptr
+ && s->symbol.section != bfd_und_section_ptr
+ && s->symbol.section != bfd_com_section_ptr)
+ s->n_sect = s->symbol.section->target_index;
+
+ /* Number symbols. */
+ s->symbol.udata.i = i;
+ }
+ return TRUE;
+ }
+
bfd_boolean
bfd_mach_o_write_contents (bfd *abfd)
{
unsigned int i;
bfd_mach_o_data_struct *mdata = abfd->tdata.mach_o_data;
+ if (mdata->header.ncmds == 0)
+ if (!bfd_mach_o_build_commands (abfd))
+ return FALSE;
+
/* Now write header information. */
if (mdata->header.filetype == 0)
{
*************** bfd_mach_o_write_contents (bfd *abfd)
*** 785,790 ****
--- 981,990 ----
if (!bfd_mach_o_write_header (abfd, &mdata->header))
return FALSE;
+ /* Assign a number to each symbols. */
+ if (!bfd_mach_o_mangle_symbols (abfd))
+ return FALSE;
+
for (i = 0; i < mdata->header.ncmds; i++)
{
unsigned char buf[8];
*************** bfd_mach_o_build_commands (bfd *abfd)
*** 857,863 ****
bfd_mach_o_segment_command *seg;
bfd_mach_o_section *sections;
asection *sec;
- file_ptr filepos;
bfd_mach_o_load_command *cmd;
bfd_mach_o_load_command *symtab_cmd;
int target_index;
--- 1057,1062 ----
*************** bfd_mach_o_build_commands (bfd *abfd)
*** 898,904 ****
}
cmd->type_required = FALSE;
mdata->header.sizeofcmds = cmd->len;
! filepos = cmd->offset + cmd->len;
/* Set symtab command. */
symtab_cmd = &mdata->commands[1];
--- 1097,1103 ----
}
cmd->type_required = FALSE;
mdata->header.sizeofcmds = cmd->len;
! mdata->filelen = cmd->offset + cmd->len;
/* Set symtab command. */
symtab_cmd = &mdata->commands[1];
*************** bfd_mach_o_build_commands (bfd *abfd)
*** 909,920 ****
symtab_cmd->type_required = FALSE;
mdata->header.sizeofcmds += symtab_cmd->len;
! filepos += symtab_cmd->len;
/* Fill segment command. */
memset (seg->segname, 0, sizeof (seg->segname));
seg->vmaddr = 0;
! seg->fileoff = filepos;
seg->filesize = 0;
seg->maxprot = BFD_MACH_O_PROT_READ | BFD_MACH_O_PROT_WRITE
| BFD_MACH_O_PROT_EXECUTE;
--- 1108,1119 ----
symtab_cmd->type_required = FALSE;
mdata->header.sizeofcmds += symtab_cmd->len;
! mdata->filelen += symtab_cmd->len;
/* Fill segment command. */
memset (seg->segname, 0, sizeof (seg->segname));
seg->vmaddr = 0;
! seg->fileoff = mdata->filelen;
seg->filesize = 0;
seg->maxprot = BFD_MACH_O_PROT_READ | BFD_MACH_O_PROT_WRITE
| BFD_MACH_O_PROT_EXECUTE;
*************** bfd_mach_o_build_commands (bfd *abfd)
*** 931,960 ****
sections->size = bfd_get_section_size (sec);
sections->align = bfd_get_section_alignment (abfd, sec);
! filepos = (filepos + ((file_ptr) 1 << sections->align) - 1)
! & ((file_ptr) -1 << sections->align);
! sections->offset = filepos;
sections->reloff = 0;
sections->nreloc = 0;
sections->reserved1 = 0;
sections->reserved2 = 0;
sections->reserved3 = 0;
! sec->filepos = filepos;
sec->target_index = ++target_index;
! filepos += sections->size;
sections++;
}
! seg->filesize = filepos - seg->fileoff;
seg->vmsize = seg->filesize;
- /* Fill symtab command.
- Note: we don't know the number of symbols.
- Also, symtab is at the end since the length of the symbol table
(and
- string table) is not known. */
- symtab_cmd->command.symtab.symoff = filepos;
-
return TRUE;
}
--- 1130,1157 ----
sections->size = bfd_get_section_size (sec);
sections->align = bfd_get_section_alignment (abfd, sec);
! if (sections->size != 0)
! {
! mdata->filelen = FILE_ALIGN (mdata->filelen, sections-
>align);
! sections->offset = mdata->filelen;
! }
! else
! sections->offset = 0;
sections->reloff = 0;
sections->nreloc = 0;
sections->reserved1 = 0;
sections->reserved2 = 0;
sections->reserved3 = 0;
! sec->filepos = sections->offset;
sec->target_index = ++target_index;
! mdata->filelen += sections->size;
sections++;
}
! seg->filesize = mdata->filelen - seg->fileoff;
seg->vmsize = seg->filesize;
return TRUE;
}
*************** bfd_mach_o_make_empty_symbol (bfd *abfd)
*** 1000,1009 ****
{
asymbol *new;
! new = bfd_zalloc (abfd, sizeof (* new));
if (new == NULL)
return new;
new->the_bfd = abfd;
return new;
}
--- 1197,1207 ----
{
asymbol *new;
! new = bfd_zalloc (abfd, sizeof (bfd_mach_o_asymbol));
if (new == NULL)
return new;
new->the_bfd = abfd;
+ new->udata.i = 0;
return new;
}
*************** bfd_mach_o_make_bfd_section (bfd *abfd,
*** 1103,1108 ****
--- 1301,1309 ----
flags |= SEC_READONLY;
}
}
+ if (section->nreloc != 0)
+ flags |= SEC_RELOC;
+
bfdsec = bfd_make_section_anyway_with_flags (abfd, sname, flags);
if (bfdsec == NULL)
return NULL;
*************** bfd_mach_o_make_bfd_section (bfd *abfd,
*** 1113,1118 ****
--- 1314,1321 ----
bfdsec->filepos = section->offset;
bfdsec->alignment_power = section->align;
bfdsec->segment_mark = 0;
+ bfdsec->reloc_count = section->nreloc;
+ bfdsec->rel_filepos = section->reloff;
return bfdsec;
}
*************** bfd_mach_o_make_bfd_section (bfd *abfd,
*** 1120,1126 ****
static int
bfd_mach_o_scan_read_section_32 (bfd *abfd,
bfd_mach_o_section *section,
! bfd_vma offset,
unsigned long prot)
{
unsigned char buf[BFD_MACH_O_SECTION_SIZE];
--- 1323,1329 ----
static int
bfd_mach_o_scan_read_section_32 (bfd *abfd,
bfd_mach_o_section *section,
! unsigned int offset,
unsigned long prot)
{
unsigned char buf[BFD_MACH_O_SECTION_SIZE];
*************** bfd_mach_o_scan_read_section_32 (bfd *ab
*** 1155,1161 ****
static int
bfd_mach_o_scan_read_section_64 (bfd *abfd,
bfd_mach_o_section *section,
! bfd_vma offset,
unsigned long prot)
{
unsigned char buf[BFD_MACH_O_SECTION_64_SIZE];
--- 1358,1364 ----
static int
bfd_mach_o_scan_read_section_64 (bfd *abfd,
bfd_mach_o_section *section,
! unsigned int offset,
unsigned long prot)
{
unsigned char buf[BFD_MACH_O_SECTION_64_SIZE];
*************** bfd_mach_o_scan_read_section_64 (bfd *ab
*** 1190,1196 ****
static int
bfd_mach_o_scan_read_section (bfd *abfd,
bfd_mach_o_section *section,
! bfd_vma offset,
unsigned long prot,
unsigned int wide)
{
--- 1393,1399 ----
static int
bfd_mach_o_scan_read_section (bfd *abfd,
bfd_mach_o_section *section,
! unsigned int offset,
unsigned long prot,
unsigned int wide)
{
*************** bfd_mach_o_scan_read_section (bfd *abfd,
*** 1203,1215 ****
int
bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
bfd_mach_o_symtab_command *sym,
! asymbol *s,
unsigned long i)
{
bfd_mach_o_data_struct *mdata = abfd->tdata.mach_o_data;
unsigned int wide = mach_o_wide_p (&mdata->header);
unsigned int symwidth = wide ? 16 : 12;
! bfd_vma symoff = sym->symoff + (i * symwidth);
unsigned char buf[16];
unsigned char type = -1;
unsigned char section = -1;
--- 1406,1418 ----
int
bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
bfd_mach_o_symtab_command *sym,
! bfd_mach_o_asymbol *s,
unsigned long i)
{
bfd_mach_o_data_struct *mdata = abfd->tdata.mach_o_data;
unsigned int wide = mach_o_wide_p (&mdata->header);
unsigned int symwidth = wide ? 16 : 12;
! unsigned int symoff = sym->symoff + (i * symwidth);
unsigned char buf[16];
unsigned char type = -1;
unsigned char section = -1;
*************** bfd_mach_o_scan_read_symtab_symbol (bfd
*** 1245,1260 ****
return -1;
}
! s->the_bfd = abfd;
! s->name = sym->strtab + stroff;
! s->value = value;
! s->udata.i = (type << 24) | (section << 16) | desc;
! s->flags = 0x0;
if (type & BFD_MACH_O_N_STAB)
{
! s->flags |= BSF_DEBUGGING;
! s->section = bfd_und_section_ptr;
switch (type)
{
case N_FUN:
--- 1448,1466 ----
return -1;
}
! s->symbol.the_bfd = abfd;
! s->symbol.name = sym->strtab + stroff;
! s->symbol.value = value;
! s->symbol.flags = 0x0;
! s->symbol.udata.i = 0;
! s->n_type = type;
! s->n_sect = section;
! s->n_desc = desc;
if (type & BFD_MACH_O_N_STAB)
{
! s->symbol.flags |= BSF_DEBUGGING;
! s->symbol.section = bfd_und_section_ptr;
switch (type)
{
case N_FUN:
*************** bfd_mach_o_scan_read_symtab_symbol (bfd
*** 1268,1275 ****
case N_GSYM:
if ((section > 0) && (section <= mdata->nsects))
{
! s->section = mdata->sections[section - 1]->bfdsection;
! s->value = s->value - mdata->sections[section - 1]->addr;
}
break;
}
--- 1474,1482 ----
case N_GSYM:
if ((section > 0) && (section <= mdata->nsects))
{
! s->symbol.section = mdata->sections[section - 1]->bfdsection;
! s->symbol.value =
! s->symbol.value - mdata->sections[section - 1]->addr;
}
break;
}
*************** bfd_mach_o_scan_read_symtab_symbol (bfd
*** 1277,1314 ****
else
{
if (type & BFD_MACH_O_N_PEXT)
! s->flags |= BSF_GLOBAL;
if (type & BFD_MACH_O_N_EXT)
! s->flags |= BSF_GLOBAL;
if (!(type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT)))
! s->flags |= BSF_LOCAL;
switch (symtype)
{
case BFD_MACH_O_N_UNDF:
if (type == (BFD_MACH_O_N_UNDF | BFD_MACH_O_N_EXT)
! && s->value != 0)
{
/* A common symbol. */
! s->section = bfd_com_section_ptr;
! s->flags = BSF_NO_FLAGS;
}
else
! s->section = bfd_und_section_ptr;
break;
case BFD_MACH_O_N_PBUD:
! s->section = bfd_und_section_ptr;
break;
case BFD_MACH_O_N_ABS:
! s->section = bfd_abs_section_ptr;
break;
case BFD_MACH_O_N_SECT:
if ((section > 0) && (section <= mdata->nsects))
{
! s->section = mdata->sections[section - 1]->bfdsection;
! s->value = s->value - mdata->sections[section - 1]->addr;
}
else
{
--- 1484,1526 ----
else
{
if (type & BFD_MACH_O_N_PEXT)
! s->symbol.flags |= BSF_GLOBAL;
if (type & BFD_MACH_O_N_EXT)
! s->symbol.flags |= BSF_GLOBAL;
if (!(type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT)))
! s->symbol.flags |= BSF_LOCAL;
switch (symtype)
{
case BFD_MACH_O_N_UNDF:
if (type == (BFD_MACH_O_N_UNDF | BFD_MACH_O_N_EXT)
! && s->symbol.value != 0)
{
/* A common symbol. */
! s->symbol.section = bfd_com_section_ptr;
! s->symbol.flags = BSF_NO_FLAGS;
}
else
! {
! s->symbol.section = bfd_und_section_ptr;
! if (s->n_desc & BFD_MACH_O_N_WEAK_REF)
! s->symbol.flags |= BSF_WEAK;
! }
break;
case BFD_MACH_O_N_PBUD:
! s->symbol.section = bfd_und_section_ptr;
break;
case BFD_MACH_O_N_ABS:
! s->symbol.section = bfd_abs_section_ptr;
break;
case BFD_MACH_O_N_SECT:
if ((section > 0) && (section <= mdata->nsects))
{
! s->symbol.section = mdata->sections[section - 1]->bfdsection;
! s->symbol.value =
! s->symbol.value - mdata->sections[section - 1]->addr;
}
else
{
*************** bfd_mach_o_scan_read_symtab_symbol (bfd
*** 1317,1338 ****
{
fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
"symbol \"%s\" specified invalid section %d (max %lu):
setting to undefined\n",
! s->name, section, mdata->nsects);
}
! s->section = bfd_und_section_ptr;
}
break;
case BFD_MACH_O_N_INDR:
fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
"symbol \"%s\" is unsupported 'indirect' reference: setting to
undefined\n",
! s->name);
! s->section = bfd_und_section_ptr;
break;
default:
fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
"symbol \"%s\" specified invalid type field 0x%x: setting to
undefined\n",
! s->name, symtype);
! s->section = bfd_und_section_ptr;
break;
}
}
--- 1529,1550 ----
{
fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
"symbol \"%s\" specified invalid section %d (max %lu):
setting to undefined\n",
! s->symbol.name, section, mdata->nsects);
}
! s->symbol.section = bfd_und_section_ptr;
}
break;
case BFD_MACH_O_N_INDR:
fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
"symbol \"%s\" is unsupported 'indirect' reference: setting to
undefined\n",
! s->symbol.name);
! s->symbol.section = bfd_und_section_ptr;
break;
default:
fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
"symbol \"%s\" specified invalid type field 0x%x: setting to
undefined\n",
! s->symbol.name, symtype);
! s->symbol.section = bfd_und_section_ptr;
break;
}
}
*************** bfd_mach_o_scan_read_symtab_strtab (bfd
*** 1368,1375 ****
if (bfd_seek (abfd, sym->stroff, SEEK_SET) != 0
|| bfd_bread ((PTR) sym->strtab, sym->strsize, abfd) != sym-
>strsize)
{
! fprintf (stderr, "bfd_mach_o_scan_read_symtab_strtab: unable
to read %lu bytes at %lu\n",
! sym->strsize, sym->stroff);
return -1;
}
--- 1580,1586 ----
if (bfd_seek (abfd, sym->stroff, SEEK_SET) != 0
|| bfd_bread ((PTR) sym->strtab, sym->strsize, abfd) != sym-
>strsize)
{
! bfd_set_error (bfd_error_file_truncated);
return -1;
}
*************** bfd_mach_o_scan_read_symtab_symbols (bfd
*** 1384,1390 ****
int ret;
BFD_ASSERT (sym->symbols == NULL);
! sym->symbols = bfd_alloc (abfd, sym->nsyms * sizeof (asymbol));
if (sym->symbols == NULL)
{
--- 1595,1601 ----
int ret;
BFD_ASSERT (sym->symbols == NULL);
! sym->symbols = bfd_alloc (abfd, sym->nsyms * sizeof
(bfd_mach_o_asymbol));
if (sym->symbols == NULL)
{
*************** int
*** 1410,1416 ****
bfd_mach_o_scan_read_dysymtab_symbol (bfd *abfd,
bfd_mach_o_dysymtab_command *dysym,
bfd_mach_o_symtab_command *sym,
! asymbol *s,
unsigned long i)
{
unsigned long isymoff = dysym->indirectsymoff + (i * 4);
--- 1621,1627 ----
bfd_mach_o_scan_read_dysymtab_symbol (bfd *abfd,
bfd_mach_o_dysymtab_command *dysym,
bfd_mach_o_symtab_command *sym,
! bfd_mach_o_asymbol *s,
unsigned long i)
{
unsigned long isymoff = dysym->indirectsymoff + (i * 4);
*************** bfd_mach_o_scan_read_thread (bfd *abfd,
*** 1587,1593 ****
bfd_mach_o_data_struct *mdata = NULL;
bfd_mach_o_thread_command *cmd = &command->command.thread;
unsigned char buf[8];
! bfd_vma offset;
unsigned int nflavours;
unsigned int i;
--- 1798,1804 ----
bfd_mach_o_data_struct *mdata = NULL;
bfd_mach_o_thread_command *cmd = &command->command.thread;
unsigned char buf[8];
! unsigned int offset;
unsigned int nflavours;
unsigned int i;
*************** bfd_mach_o_scan (bfd *abfd,
*** 2088,2094 ****
BFD_MACH_O_HEADER_64_SIZE : BFD_MACH_O_HEADER_SIZE;
mdata->header = *header;
- mdata->symbols = NULL;
abfd->flags = abfd->flags & BFD_IN_MEMORY;
switch (header->filetype)
--- 2299,2304 ----
*************** bfd_mach_o_mkobject_init (bfd *abfd)
*** 2167,2177 ****
mdata->header.flags = 0;
mdata->header.byteorder = BFD_ENDIAN_UNKNOWN;
mdata->commands = NULL;
- mdata->nsymbols = 0;
- mdata->symbols = NULL;
mdata->nsects = 0;
mdata->sections = NULL;
- mdata->ibfd = NULL;
return TRUE;
}
--- 2377,2384 ----
*************** bfd_mach_o_bfd_print_private_bfd_data (b
*** 2685,2691 ****
{
bfd_mach_o_symtab_command *symtab = &cmd->command.symtab;
fprintf (file, "\n"
! "LC_SYMTAB: nsyms: %lu, strsize: %lu\n",
symtab->nsyms, symtab->strsize);
break;
}
--- 2892,2898 ----
{
bfd_mach_o_symtab_command *symtab = &cmd->command.symtab;
fprintf (file, "\n"
! "LC_SYMTAB: nsyms: %u, strsize: %u\n",
symtab->nsyms, symtab->strsize);
break;
}
*************** bfd_mach_o_core_file_failing_signal (bfd
*** 2831,2841 ****
return 0;
}
#define TARGET_NAME mach_o_be_vec
#define TARGET_STRING "mach-o-be"
#define TARGET_BIG_ENDIAN 1
#define TARGET_ARCHIVE 0
-
#include "mach-o-target.c"
#undef TARGET_NAME
--- 3038,3053 ----
return 0;
}
+ #define bfd_mach_o_bfd_reloc_type_lookup
_bfd_norelocs_bfd_reloc_type_lookup
+ #define bfd_mach_o_bfd_reloc_name_lookup
_bfd_norelocs_bfd_reloc_name_lookup
+
+ #define bfd_mach_o_swap_reloc_in NULL
+ #define bfd_mach_o_swap_reloc_out NULL
+
#define TARGET_NAME mach_o_be_vec
#define TARGET_STRING "mach-o-be"
#define TARGET_BIG_ENDIAN 1
#define TARGET_ARCHIVE 0
#include "mach-o-target.c"
#undef TARGET_NAME
Index: mach-o.h
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -c -p -r1.14 -r1.15
*** mach-o.h 9 Jun 2009 07:37:19 -0000 1.14
--- mach-o.h 12 Jun 2009 09:15:46 -0000 1.15
***************
*** 24,29 ****
--- 24,30 ----
#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,44 ****
#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)
typedef enum bfd_mach_o_mach_header_magic
{
--- 35,54 ----
#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 /* 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
{
*************** typedef enum bfd_mach_o_section_type
*** 203,213 ****
/* 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. */
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_section_type;
--- 213,245 ----
/* 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. */
BFD_MACH_O_S_SYMBOL_STUBS = 0x8,
/* Section with only function pointers for initialization. */
! 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;
*************** bfd_mach_o_section_type;
*** 233,242 ****
#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_DEBUG 0x02000000
/* Section contains only true machine instructions. */
#define BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS 0x80000000
--- 265,291 ----
#define BFD_MACH_O_S_ATTR_EXT_RELOC 0x00000200
/* Section contains some machine instructions. */
! #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
*************** bfd_mach_o_segment_command;
*** 302,314 ****
#define BFD_MACH_O_PROT_WRITE 0x02
#define BFD_MACH_O_PROT_EXECUTE 0x04
typedef struct bfd_mach_o_symtab_command
{
! unsigned long symoff;
! unsigned long nsyms;
! unsigned long stroff;
! unsigned long strsize;
! asymbol *symbols;
char *strtab;
}
bfd_mach_o_symtab_command;
--- 351,418 ----
#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 int symoff;
! unsigned int nsyms;
! unsigned int stroff;
! unsigned int strsize;
! bfd_mach_o_asymbol *symbols;
char *strtab;
}
bfd_mach_o_symtab_command;
*************** typedef struct bfd_mach_o_load_command
*** 525,532 ****
{
bfd_mach_o_load_command_type type;
bfd_boolean type_required;
! bfd_vma offset;
! bfd_vma len;
union
{
bfd_mach_o_segment_command segment;
--- 629,636 ----
{
bfd_mach_o_load_command_type type;
bfd_boolean type_required;
! unsigned int offset;
! unsigned int len;
union
{
bfd_mach_o_segment_command segment;
*************** bfd_mach_o_load_command;
*** 544,568 ****
typedef struct mach_o_data_struct
{
bfd_mach_o_header header;
bfd_mach_o_load_command *commands;
! unsigned long nsymbols;
! asymbol *symbols;
unsigned long nsects;
bfd_mach_o_section **sections;
! bfd *ibfd;
}
mach_o_data_struct;
! #define bfd_get_mach_o_data(abfd) ((abfd)->tdata.mach_o_data)
! typedef struct mach_o_data_struct bfd_mach_o_data_struct;
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_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_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 *);
--- 648,687 ----
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;
!
! /* Flatten array of sections. The array is 0-based. */
unsigned long nsects;
bfd_mach_o_section **sections;
!
! /* 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;
! /* 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;
! #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 *,
! 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 *,
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 *);
*************** bfd_boolean bfd_mach_o_bfd_copy_private_
*** 580,585 ****
--- 699,708 ----
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);
Index: reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.187
retrieving revision 1.189
diff -c -p -r1.187 -r1.189
*** reloc.c 1 Jun 2009 13:11:52 -0000 1.187
--- reloc.c 12 Jun 2009 09:15:46 -0000 1.189
*************** ENUMX
*** 5174,5179 ****
--- 5180,5195 ----
BFD_RELOC_LM32_RELATIVE
ENUMDOC
Lattice Mico32 relocations.
+
+ ENUM
+ BFD_RELOC_MACH_O_SECTDIFF
+ ENUMDOC
+ Difference between two section addreses. Must be followed by a
+ BFD_RELOC_MACH_O_PAIR.
+ ENUM
+ BFD_RELOC_MACH_O_PAIR
+ ENUMDOC
+ Mach-O generic relocations.
ENDSENUM
BFD_RELOC_UNUSED