This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[mach-o/committed]: Fix and improve mach-o-x86-64.c
- From: Tristan Gingold <gingold at adacore dot com>
- To: binutils Development <binutils at sourceware dot org>
- Date: Mon, 8 Aug 2011 09:47:24 +0200
- Subject: [mach-o/committed]: Fix and improve mach-o-x86-64.c
Hi,
the x86-64 mach-o part was never tested for writing files and had a few obvious typos.
This patch fixes them and handle a few more relocs.
Committed on trunk.
Tristan.
bfd/
2011-08-08 Tristan Gingold <gingold@adacore.com>
* mach-o-x86-64.c (bfd_mach_o_x86_64_mkobject): Fix cut-and-past typos.
(bfd_mach_o_x86_64_swap_reloc_out): Handle BFD_RELOC_32_PCREL,
BFD_RELOC_MACH_O_X86_64_SUBTRACTOR64 and
BFD_RELOC_MACH_O_X86_64_GOT_LOAD. Share common code.
Index: mach-o-x86-64.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o-x86-64.c,v
retrieving revision 1.1
diff -c -r1.1 mach-o-x86-64.c
*** mach-o-x86-64.c 13 Jan 2010 11:49:36 -0000 1.1
--- mach-o-x86-64.c 8 Aug 2011 07:42:59 -0000
***************
*** 51,61 ****
return FALSE;
mdata = bfd_mach_o_get_data (abfd);
! mdata->header.magic = BFD_MACH_O_MH_MAGIC;
mdata->header.cputype = BFD_MACH_O_CPU_TYPE_X86_64;
mdata->header.cpusubtype = BFD_MACH_O_CPU_SUBTYPE_X86_ALL;
mdata->header.byteorder = BFD_ENDIAN_LITTLE;
! mdata->header.version = 1;
return TRUE;
}
--- 51,61 ----
return FALSE;
mdata = bfd_mach_o_get_data (abfd);
! mdata->header.magic = BFD_MACH_O_MH_MAGIC_64;
mdata->header.cputype = BFD_MACH_O_CPU_TYPE_X86_64;
mdata->header.cpusubtype = BFD_MACH_O_CPU_SUBTYPE_X86_ALL;
mdata->header.byteorder = BFD_ENDIAN_LITTLE;
! mdata->header.version = 2;
return TRUE;
}
***************
*** 220,246 ****
bfd_mach_o_x86_64_swap_reloc_out (arelent *rel, bfd_mach_o_reloc_info *rinfo)
{
rinfo->r_address = rel->address;
switch (rel->howto->type)
{
case BFD_RELOC_64:
- rinfo->r_scattered = 0;
rinfo->r_type = BFD_MACH_O_X86_64_RELOC_UNSIGNED;
rinfo->r_pcrel = 0;
! 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;
default:
return FALSE;
}
return TRUE;
}
--- 220,261 ----
bfd_mach_o_x86_64_swap_reloc_out (arelent *rel, bfd_mach_o_reloc_info *rinfo)
{
rinfo->r_address = rel->address;
+ rinfo->r_scattered = 0;
switch (rel->howto->type)
{
case BFD_RELOC_64:
rinfo->r_type = BFD_MACH_O_X86_64_RELOC_UNSIGNED;
rinfo->r_pcrel = 0;
! rinfo->r_length = 3;
! break;
! case BFD_RELOC_32_PCREL:
! rinfo->r_type = BFD_MACH_O_X86_64_RELOC_BRANCH;
! rinfo->r_pcrel = 1;
! rinfo->r_length = 2;
! break;
! case BFD_RELOC_MACH_O_X86_64_SUBTRACTOR64:
! rinfo->r_type = BFD_MACH_O_X86_64_RELOC_SUBTRACTOR;
! rinfo->r_length = 3;
! break;
! case BFD_RELOC_MACH_O_X86_64_GOT_LOAD:
! rinfo->r_type = BFD_MACH_O_X86_64_RELOC_GOT_LOAD;
! rinfo->r_pcrel = 1;
! rinfo->r_length = 2;
break;
default:
return FALSE;
}
+ 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;
+ }
return TRUE;
}