From 4e1923366576ac4dcfd807173b09eb3eed3bcfdb Mon Sep 17 00:00:00 2001 From: Gunther Nikl Date: Fri, 15 May 2015 19:35:50 +0000 Subject: [PATCH] Add support for relocation hunks with short (16bit) data. * bfd/amigaos.c (write_words): Add protototype. (write_words): New function to write 16bit words. (amiga_write_section_contents): Use write_words to write 16bit relocs. --- bfd/amigaos.c | 55 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/bfd/amigaos.c b/bfd/amigaos.c index f946423..39ad923 100644 --- a/bfd/amigaos.c +++ b/bfd/amigaos.c @@ -181,6 +181,8 @@ static bfd_boolean amiga_mkobject PARAMS ((bfd *)); static bfd_boolean amiga_mkarchive PARAMS ((bfd *)); static bfd_boolean write_longs PARAMS ((const unsigned long *, unsigned long, bfd *)); +static bfd_boolean write_words PARAMS ((const unsigned long *, unsigned long, + bfd *)); static long determine_datadata_relocs PARAMS ((bfd *, sec_ptr)); static void remove_section_index PARAMS ((sec_ptr, int *)); static bfd_boolean amiga_write_object_contents PARAMS ((bfd *)); @@ -1327,6 +1329,26 @@ write_longs (in, nb, abfd) return TRUE; } +static bfd_boolean +write_words (in, nb, abfd) + const unsigned long *in; + unsigned long nb; + bfd *abfd; +{ + unsigned char out[10*2]; + unsigned long i; + + while (nb) + { + for (i=0; i 0) { /* Sample every reloc type */ for (i = 0; i < NB_RELOC_TYPES; i++) { + int rel32 = reloc_types[i] != HUNK_RELOC32SHORT && reloc_types[i] != HUNK_RELRELOC32 ? TRUE : FALSE; int written = FALSE; for (j = 0; j <= max_hunk; j++) { long relocs; @@ -2037,8 +2060,14 @@ amiga_write_section_contents (abfd, section, data_sec, datadata_relocs, n[0] = relocs; n[1] = j; - if (!write_longs (n, 2, abfd)) - return FALSE; + if (rel32) { + if (!write_longs (n, 2, abfd)) + return FALSE; + } + else { + if (!write_words (n, 2, abfd)) + return FALSE; + } reloc_counts[i+(j*NB_RELOC_TYPES)] -= relocs; reloc_count -= relocs; @@ -2067,8 +2096,14 @@ amiga_write_section_contents (abfd, section, data_sec, datadata_relocs, #endif if (jj == j && i == determine_type(r)) { section->orelocation[k] = NULL; - if (!write_longs (&r->address, 1, abfd)) - return FALSE; + if (rel32) { + if (!write_longs (&r->address, 1, abfd)) + return FALSE; + } + else { + if (!write_words (&r->address, 1, abfd)) + return FALSE; + } if (--relocs == 0) break; } @@ -2076,8 +2111,16 @@ amiga_write_section_contents (abfd, section, data_sec, datadata_relocs, } } /* write a zero to finish the relocs */ - if (written && !write_longs (&zero, 1, abfd)) - return FALSE; + if (written) { + if (rel32 || (bfd_tell (abfd) & 2) == 0) { + if (!write_longs (&zero, 1, abfd)) + return FALSE; + } + else { + if (!write_words (&zero, 1, abfd)) + return FALSE; + } + } } }