diff --git a/bfd/amigaoslink.c b/bfd/amigaoslink.c index c9dde7c..1690737 100644 --- a/bfd/amigaoslink.c +++ b/bfd/amigaoslink.c @@ -111,7 +111,8 @@ bfd_boolean amiga_final_link PARAMS ((bfd *, struct bfd_link_info *)); bfd_boolean aout_amiga_final_link PARAMS ((bfd *, struct bfd_link_info *)); - +static int +my_get_offset PARAMS ((arelent *r, PTR data, int flags)); static bfd_reloc_status_type my_add_to PARAMS ((arelent *, PTR, int, int)); static void amiga_update_target_section PARAMS ((sec_ptr)); @@ -269,8 +270,51 @@ error_return: return NULL; } +static int my_get_offset (r, data, flags) + arelent *r; + PTR data; +int flags; +{ + bfd_byte *p = ((bfd_byte *)data) + r->address; + int val; + asymbol *sym = *(r->sym_ptr_ptr); -/* Add a value to a location */ + DPRINT(5, ("Entering my_get_offset for %s \n", sym->name)); + + switch (r->howto->size) + { + case 0: /* byte size */ + if ((flags & ADDEND_UNSIGNED) == 0) + val = ((*p & 0xff) ^ 0x80) - 0x80; + else + val = (*p & 0xff); + break; + + case 1: /* word size */ + if ((flags & ADDEND_UNSIGNED) == 0) + val = bfd_getb_signed_16(p); + else + val = bfd_getb16(p); + break; + + case 2: /* long word */ + val = bfd_getb_signed_32(p); + break; + + default: /* Error */ + val = 0x5a5a5a5a; + break; + }/* Of switch */ + + DPRINT(5, ("Leaving my_get_offset\n")); + return val; +} + + + +/* Add a value to a location. + * The code is patched directly by adding the 'add' to the existing value at data[r->address] +*/ static bfd_reloc_status_type my_add_to (r, data, add, flags) arelent *r; @@ -739,8 +783,14 @@ aout_perform_reloc (abfd, r, data, sec, obfd, error_message) relocation = sym->value + target_section->output_offset; /* if the symbol is in .bss, subtract the offset that gas has put into the opcode */ +// if (target_section->index == 2) +// relocation -= adata(abfd).datasec->_raw_size; + // SBF: nope. rather subtract the existing offset. if (target_section->index == 2) - relocation -= adata(abfd).datasec->_raw_size; + { + relocation -= my_get_offset(r, data, flags); + r->addend = 0; + } DPRINT(20,("symbol=%s (0x%lx)\nsection %s (0x%lx; %s; output=0x%lx)" "\nrelocation @0x%lx\n", sym->name, sym->value, target_section->name, target_section,