diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2023-01-31 11:33:33 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2023-02-03 09:56:38 +0100 |
commit | 8d12c84b5b23a5fa9082d6246f788d25b50b8653 (patch) | |
tree | 5130c071f07a7a28db86b489d06389d2ea2fbe4d /toolchain/elf2flt/patches | |
parent | 53ad4fe57a1d4bb39efb68eb9d06b941275fe59b (diff) |
binutils: update to 2.40
Diffstat (limited to 'toolchain/elf2flt/patches')
-rw-r--r-- | toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0008-remove_BFD_VMA_FMT.patch | 125 | ||||
-rw-r--r-- | toolchain/elf2flt/patches/v2021.08/0008-remove_BFD_VMA_FMT.patch | 2214 |
2 files changed, 2339 insertions, 0 deletions
diff --git a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0008-remove_BFD_VMA_FMT.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0008-remove_BFD_VMA_FMT.patch new file mode 100644 index 000000000..d20b993da --- /dev/null +++ b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0008-remove_BFD_VMA_FMT.patch @@ -0,0 +1,125 @@ +diff -Nur elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.c elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.c +--- elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.c 2023-01-30 08:48:56.632981732 +0100 ++++ elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.c 2023-01-30 08:53:34.510426754 +0100 +@@ -222,7 +222,7 @@ + long i; + printf("SYMBOL TABLE:\n"); + for (i=0; i<number_of_symbols; i++) { +- printf(" NAME=%s VALUE=0x%"BFD_VMA_FMT"x\n", ++ printf(" NAME=%s VALUE=0x%x\n", + symbol_table[i]->name, symbol_table[i]->value); + } + printf("\n"); +@@ -458,7 +458,7 @@ + if (r == NULL) + continue; + if (verbose) +- printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%"BFD_VMA_FMT"x\n", ++ printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%x\n", + r->name, r, r->flags, elf2flt_bfd_section_vma(abs_bfd, r)); + if ((r->flags & SEC_RELOC) == 0) + continue; +@@ -903,8 +903,8 @@ + if (verbose) + fprintf(stderr, + "%s vma=0x%x, " +- "value=0x%"BFD_VMA_FMT"x, " +- "address=0x%"BFD_VMA_FMT"x " ++ "value=0x%x, " ++ "address=0x%x " + "sym_addr=0x%x rs=0x%x, opcode=0x%x\n", + "ABS32", + sym_vma, (*(q->sym_ptr_ptr))->value, +@@ -922,8 +922,8 @@ + if (verbose) + fprintf(stderr, + "%s vma=0x%x, " +- "value=0x%"BFD_VMA_FMT"x, " +- "address=0x%"BFD_VMA_FMT"x " ++ "value=0x%x, " ++ "address=0x%x " + "sym_addr=0x%x rs=0x%x, opcode=0x%x\n", + "PLT32", + sym_vma, (*(q->sym_ptr_ptr))->value, +@@ -945,7 +945,7 @@ + case R_V850_ZDA_16_16_OFFSET: + case R_V850_ZDA_16_16_SPLIT_OFFSET: + /* Can't support zero-relocations. */ +- printf ("ERROR: %s+0x%"BFD_VMA_FMT"x: zero relocations not supported\n", ++ printf ("ERROR: %s+0x%x: zero relocations not supported\n", + sym_name, q->addend); + continue; + #endif /* TARGET_v850 */ +@@ -1038,15 +1038,15 @@ + sprintf(&addstr[0], "+0x%ld", sym_addr - (*(q->sym_ptr_ptr))->value - + elf2flt_bfd_section_vma(abs_bfd, sym_section)); + if (verbose) +- printf(" RELOC[%d]: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf(" RELOC[%d]: offset=0x%x symbol=%s%s " + "section=%s size=%d " +- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x)\n", ++ "fixup=0x%x (reloc=0x%x)\n", + flat_reloc_count, + q->address, sym_name, addstr, + section_name, sym_reloc_size, + sym_addr, section_vma + q->address); + if (verbose) +- printf("reloc[%d] = 0x%"BFD_VMA_FMT"x\n", ++ printf("reloc[%d] = 0x%x\n", + flat_reloc_count, section_vma + q->address); + + continue; +@@ -1163,9 +1163,9 @@ + temp |= (exist_val & 0x3f); + *(unsigned long *)r_mem = htoniosl(temp); + if (verbose) +- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf("omit: offset=0x%x symbol=%s%s " + "section=%s size=%d " +- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x) GPREL\n", ++ "fixup=0x%x (reloc=0x%x) GPREL\n", + q->address, sym_name, addstr, + section_name, sym_reloc_size, + sym_addr, section_vma + q->address); +@@ -1183,9 +1183,9 @@ + exist_val |= ((sym_addr & 0xFFFF) << 6); + *(unsigned long *)r_mem = htoniosl(exist_val); + if (verbose) +- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf("omit: offset=0x%x symbol=%s%s " + "section=%s size=%d " +- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x) PCREL\n", ++ "fixup=0x%x (reloc=0x%x) PCREL\n", + q->address, sym_name, addstr, + section_name, sym_reloc_size, + sym_addr, section_vma + q->address); +@@ -1200,7 +1200,7 @@ + && (p[-1]->sym_ptr_ptr == p[0]->sym_ptr_ptr) + && (p[-1]->addend == p[0]->addend)) { + if (verbose) +- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf("omit: offset=0x%x symbol=%s%s " + "section=%s size=%d LO16\n", + q->address, sym_name, addstr, + section_name, sym_reloc_size); +@@ -1610,9 +1610,9 @@ + } + + if (verbose) +- printf(" RELOC[%d]: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf(" RELOC[%d]: offset=0x%x symbol=%s%s " + "section=%s size=%d " +- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x)\n", ++ "fixup=0x%x (reloc=0x%x)\n", + flat_reloc_count, + q->address, sym_name, addstr, + section_name, sym_reloc_size, +@@ -1630,7 +1630,7 @@ + (section_vma + q->address); + + if (verbose) +- printf("reloc[%d] = 0x%"BFD_VMA_FMT"x\n", ++ printf("reloc[%d] = 0x%x\n", + flat_reloc_count, section_vma + q->address); + #else + switch ((*p)->howto->type) { diff --git a/toolchain/elf2flt/patches/v2021.08/0008-remove_BFD_VMA_FMT.patch b/toolchain/elf2flt/patches/v2021.08/0008-remove_BFD_VMA_FMT.patch new file mode 100644 index 000000000..abb481186 --- /dev/null +++ b/toolchain/elf2flt/patches/v2021.08/0008-remove_BFD_VMA_FMT.patch @@ -0,0 +1,2214 @@ +diff -Nur elf2flt-v2021.08.orig/elf2flt.c elf2flt-v2021.08/elf2flt.c +--- elf2flt-v2021.08.orig/elf2flt.c 2023-01-29 16:47:24.791851890 +0100 ++++ elf2flt-v2021.08/elf2flt.c 2023-01-29 16:49:46.628476326 +0100 +@@ -222,7 +222,7 @@ + long i; + printf("SYMBOL TABLE:\n"); + for (i=0; i<number_of_symbols; i++) { +- printf(" NAME=%s VALUE=0x%"BFD_VMA_FMT"x\n", ++ printf(" NAME=%s VALUE=0x%x\n", + symbol_table[i]->name, symbol_table[i]->value); + } + printf("\n"); +@@ -471,7 +471,7 @@ + if (r == NULL) + continue; + if (verbose) +- printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%"BFD_VMA_FMT"x\n", ++ printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%x\n", + r->name, r, r->flags, elf2flt_bfd_section_vma(r)); + if ((r->flags & SEC_RELOC) == 0) + continue; +@@ -966,8 +966,8 @@ + if (verbose) + fprintf(stderr, + "%s vma=0x%x, " +- "value=0x%"BFD_VMA_FMT"x, " +- "address=0x%"BFD_VMA_FMT"x " ++ "value=0x%x, " ++ "address=0x%x " + "sym_addr=0x%x rs=0x%x, opcode=0x%x\n", + "ABS32", + sym_vma, (*(q->sym_ptr_ptr))->value, +@@ -985,8 +985,8 @@ + if (verbose) + fprintf(stderr, + "%s vma=0x%x, " +- "value=0x%"BFD_VMA_FMT"x, " +- "address=0x%"BFD_VMA_FMT"x " ++ "value=0x%x, " ++ "address=0x%x " + "sym_addr=0x%x rs=0x%x, opcode=0x%x\n", + "PLT32", + sym_vma, (*(q->sym_ptr_ptr))->value, +@@ -1008,7 +1008,7 @@ + case R_V850_ZDA_16_16_OFFSET: + case R_V850_ZDA_16_16_SPLIT_OFFSET: + /* Can't support zero-relocations. */ +- printf ("ERROR: %s+0x%"BFD_VMA_FMT"x: zero relocations not supported\n", ++ printf ("ERROR: %s+0x%x: zero relocations not supported\n", + sym_name, q->addend); + continue; + #endif /* TARGET_v850 */ +@@ -1208,9 +1208,9 @@ + temp |= (exist_val & 0x3f); + *(unsigned long *)r_mem = htoniosl(temp); + if (verbose) +- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf("omit: offset=0x%x symbol=%s%s " + "section=%s size=%d " +- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x) GPREL\n", ++ "fixup=0x%x (reloc=0x%x) GPREL\n", + q->address, sym_name, addstr, + section_name, sym_reloc_size, + sym_addr, section_vma + q->address); +@@ -1228,9 +1228,9 @@ + exist_val |= ((sym_addr & 0xFFFF) << 6); + *(unsigned long *)r_mem = htoniosl(exist_val); + if (verbose) +- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf("omit: offset=0x%x symbol=%s%s " + "section=%s size=%d " +- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x) PCREL\n", ++ "fixup=0x%x (reloc=0x%x) PCREL\n", + q->address, sym_name, addstr, + section_name, sym_reloc_size, + sym_addr, section_vma + q->address); +@@ -1245,7 +1245,7 @@ + && (p[-1]->sym_ptr_ptr == p[0]->sym_ptr_ptr) + && (p[-1]->addend == p[0]->addend)) { + if (verbose) +- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf("omit: offset=0x%x symbol=%s%s " + "section=%s size=%d LO16\n", + q->address, sym_name, addstr, + section_name, sym_reloc_size); +@@ -1660,9 +1660,9 @@ + */ + if (relocation_needed) { + if (verbose) +- printf(" RELOC[%d]: offset=0x%"BFD_VMA_FMT"x symbol=%s%s " ++ printf(" RELOC[%d]: offset=0x%x symbol=%s%s " + "section=%s size=%d " +- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x)\n", ++ "fixup=0x%x (reloc=0x%x)\n", + flat_reloc_count, + q->address, sym_name, addstr, + section_name, sym_reloc_size, +diff -Nur elf2flt-v2021.08.orig/elf2flt.c.orig elf2flt-v2021.08/elf2flt.c.orig +--- elf2flt-v2021.08.orig/elf2flt.c.orig 2023-01-29 16:47:18.264007463 +0100 ++++ elf2flt-v2021.08/elf2flt.c.orig 1970-01-01 01:00:00.000000000 +0100 +@@ -1,2113 +0,0 @@ +-/* +- * elf2flt.c: Convert ELF (or any BFD format) to FLAT binary format +- * +- * (c) 1999-2002, Greg Ungerer <gerg@snapgear.com> +- * Created elf2flt from coff2flt (see copyrights below). Added all the +- * ELF format file handling. Extended relocation support for all of +- * text and data. +- * +- * (c) 2008-2009, Xtensa support, Oskar Schirmer <os@emlix.com> +- * (c) 2006 Support the -a (use_resolved) option for TARGET_arm. +- * Shaun Jackman <sjackman@gmail.com> +- * (c) 2004, Nios II support, Wentao Xu <wentao@microtronix.com> +- * (c) 2003, H8 support, ktrace <davidm@snapgear.com> +- * (c) 2003-2004, MicroBlaze support, John Williams <jwilliams@itee.uq.edu.au> +- * (c) 2001-2003, arm/arm-pic/arm-big-endian support <davidm@snapgear.com> +- * (c) 2001, v850 changes, Mile Bader <miles@lsi.nec.co.jp> +- * (c) 2003, SuperH support, Paul Mundt <lethal@linux-sh.org> +- * (c) 2001, zflat support <davidm@snapgear.com> +- * (c) 2001, Changes for GOT entries Paul Dale <pauli@snapgear.com> and +- * David McCullough <davidm@snapgear.com> +- * +- * Now supports PIC with GOT tables. This works by taking a '.elf' file +- * and a fully linked elf executable (at address 0) and produces a flat +- * file that can be loaded with some fixups. It still supports the old +- * style fully relocatable elf format files. +- * +- * Originally obj-res.c +- * +- * (c) 1998, Kenneth Albanowski <kjahds@kjahds.com> +- * (c) 1998, D. Jeff Dionne +- * (c) 1998, The Silver Hammer Group Ltd. +- * (c) 1996, 1997 Dionne & Associates <jeff@ryeham.ee.ryerson.ca> +- * +- * This is Free Software, under the GNU Public Licence v2 or greater. +- * +- * Relocation added March 1997, Kresten Krab Thorup +- * krab@california.daimi.aau.dk +- */ +- +-#include <inttypes.h> /* All the standard PRI define times for printf */ +-#include <stdio.h> /* Userland pieces of the ANSI C standard I/O package */ +-#include <stdlib.h> /* Userland prototypes of the ANSI C std lib functions */ +-#include <stdarg.h> /* Allows va_list to exist in the these namespaces */ +-#include <string.h> /* Userland prototypes of the string handling funcs */ +-#include <strings.h> +-#include <unistd.h> /* Userland prototypes of the Unix std system calls */ +-#include <fcntl.h> /* Flag value for file handling functions */ +-#include <time.h> +-#include <errno.h> +- +-/* from $(INSTALLDIR)/include */ +-#include <bfd.h> /* Main header file for the BFD library */ +-#include <libiberty.h> +- +-#include "stubs.h" +-const char *elf2flt_progname; +- +-/* Include the right header file for the R_xxx defines. */ +-#if defined(TARGET_arm) +-#include <elf/arm.h> +-#elif defined(TARGET_bfin) +-#include <elf/bfin.h> +-#elif defined(TARGET_h8300) +-#include <elf/h8.h> +-#elif defined(TARGET_m68k) +-#include <elf/m68k.h> +-#elif defined(TARGET_microblaze) +-#include <elf/microblaze.h> +-#elif defined(TARGET_nios) || defined(TARGET_nios2) +-/* Altera NIOS specific definitions. */ +-#define FLAT_NIOS2_R_32 0 /* Normal 32-bit reloc */ +-#define FLAT_NIOS2_R_HI_LO 1 +-#define FLAT_NIOS2_R_HIADJ_LO 2 +-#define FLAT_NIOS2_R_CALL26 4 +-#include <elf/nios2.h> +-#elif defined(TARGET_sh) +-#include <elf/sh.h> +-#elif defined(TARGET_sparc) +-#include <elf/sparc.h> +-#elif defined(TARGET_v850) +-#include <elf/v850.h> +-#elif defined(TARGET_xtensa) +-#include <elf/xtensa.h> +-#elif defined(TARGET_riscv64) +-#include <elf/riscv.h> +-#endif +- +-#if defined(__MINGW32__) +-#include <getopt.h> +-#endif +- +-/* from uClinux-x.x.x/include/linux */ +-#include "flat.h" /* Binary flat header description */ +-#include "compress.h" +- +-#ifdef TARGET_e1 +-#include <e1.h> +-#endif +- +-#ifdef TARGET_v850e +-#define TARGET_v850 +-#endif +- +-#if defined(TARGET_m68k) +-#define ARCH "m68k/coldfire" +-#elif defined(TARGET_arm) +-#define ARCH "arm" +-#elif defined(TARGET_sparc) +-#define ARCH "sparc" +-#elif defined(TARGET_v850) +-#define ARCH "v850" +-#elif defined(TARGET_sh) +-#define ARCH "sh" +-#elif defined(TARGET_h8300) +-#define ARCH "h8300" +-#elif defined(TARGET_microblaze) +-#define ARCH "microblaze" +-#elif defined(TARGET_e1) +-#define ARCH "e1-coff" +-#elif defined(TARGET_bfin) +-#define ARCH "bfin" +-#elif defined(TARGET_nios) +-#define ARCH "nios" +-#elif defined(TARGET_nios2) +-#define ARCH "nios2" +-#elif defined(TARGET_xtensa) +-#define ARCH "xtensa" +-#elif defined(TARGET_riscv64) +-#define ARCH "riscv64" +-#else +-#error "Don't know how to support your CPU architecture??" +-#endif +- +-#if defined(TARGET_m68k) || defined(TARGET_h8300) || defined(TARGET_bfin) +-/* +- * Define a maximum number of bytes allowed in the offset table. +- * We'll fail if the table is larger than this. +- * +- * This limit may be different for platforms other than m68k, but +- * 8000 entries is a lot, trust me :-) (davidm) +- */ +-#define GOT_LIMIT 32767 +-/* +- * we have to mask out the shared library id here and there, this gives +- * us the real address bits when needed +- */ +-#define real_address_bits(x) (pic_with_got ? ((x) & 0xffffff) : (x)) +-#else +-#define real_address_bits(x) (x) +-#endif +- +-#ifndef O_BINARY +-#define O_BINARY 0 +-#endif +- +-/* +- * The bfd parameter isn't actually used by any of the bfd_section funcs and +- * have been removed since binutils 2.34. +- */ +-#ifdef HAVE_BFD_SECTION_API_TAKES_BFD +-#define elf2flt_bfd_section_size(s) bfd_section_size(NULL, s) +-#define elf2flt_bfd_section_vma(s) bfd_section_vma(NULL, s) +-#else +-#define elf2flt_bfd_section_size(s) bfd_section_size(s) +-#define elf2flt_bfd_section_vma(s) bfd_section_vma(s) +-#endif +- +-/* Extra output when running. */ +-static int verbose = 0; +-/* Do ELF/GOT processing with PIC code. */ +-static int pic_with_got = 0; +-/* Instruct loader to allocate everything into RAM. */ +-static int load_to_ram = 0; +-/* Instruct kernel loader to output debug/trace info when loading. */ +-static int ktrace = 0; +-/* 1 = compress everything, 2 = compress data only. */ +-static int docompress = 0; +-/* If true, get the value of symbol references from the program contents, +- not from the relocation table. In this case, the input ELF file must +- be already fully resolved (using the `-q' flag with recent versions of +- GNU ld will give you a fully resolved output file with relocation +- entries). */ +-static int use_resolved = 0; +- +-/* Set if the text section contains any relocations. If it does, we must +- set the load_to_ram flag. */ +-static int text_has_relocs = 0; +- +-static asymbol ** +-get_symbols (bfd *abfd, long *num) +-{ +- int32_t storage_needed; +- asymbol **symbol_table; +- long number_of_symbols; +- +- storage_needed = bfd_get_symtab_upper_bound (abfd); +- +- if (storage_needed < 0) +- abort (); +- +- if (storage_needed == 0) +- return NULL; +- +- symbol_table = xmalloc (storage_needed); +- +- number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); +- +- if (number_of_symbols < 0) +- abort (); +- +- *num = number_of_symbols; +- return symbol_table; +-} +- +- +- +-static int +-dump_symbols(asymbol **symbol_table, long number_of_symbols) +-{ +- long i; +- printf("SYMBOL TABLE:\n"); +- for (i=0; i<number_of_symbols; i++) { +- printf(" NAME=%s VALUE=0x%"BFD_VMA_FMT"x\n", +- symbol_table[i]->name, symbol_table[i]->value); +- } +- printf("\n"); +- return(0); +-} +- +- +- +-#if !defined TARGET_e1 && !defined TARGET_bfin +-static long +-get_symbol_offset(char *name, asection *sec, asymbol **symbol_table, long number_of_symbols) +-{ +- long i; +- for (i=0; i<number_of_symbols; i++) { +- if (symbol_table[i]->section == sec) { +- if (!strcmp(symbol_table[i]->name, name)) { +- return symbol_table[i]->value; +- } +- } +- } +- return -1; +-} +-#endif +- +- +- +-#ifdef TARGET_nios2 +-static long +-get_gp_value(asymbol **symbol_table, long number_of_symbols) +-{ +- long i; +- for (i=0; i<number_of_symbols; i++) { +- if (!strcmp(symbol_table[i]->name, "_gp")) +- return symbol_table[i]->value; +- } +- return -1; +-} +-#endif +- +- +- +-static int32_t +-add_com_to_bss(asymbol **symbol_table, int32_t number_of_symbols, int32_t bss_len) +-{ +- int32_t i, comsize; +- int32_t offset; +- +- comsize = 0; +- for (i=0; i<number_of_symbols; i++) { +- if (strcmp("*COM*", symbol_table[i]->section->name) == 0) { +- offset = bss_len + comsize; +- comsize += symbol_table[i]->value; +- symbol_table[i]->value = offset; +- } +- } +- return comsize; +-} +- +-#ifdef TARGET_bfin +-/* FUNCTION : weak_und_symbol +- ABSTRACT : return true if symbol is weak and undefined. +-*/ +-static int +-weak_und_symbol(const char *reloc_section_name, +- struct bfd_symbol *symbol) +-{ +- if (!(strstr (reloc_section_name, "text") +- || strstr (reloc_section_name, "data") +- || strstr (reloc_section_name, "bss"))) { +- if (symbol->flags & BSF_WEAK) { +-#ifdef DEBUG_BFIN +- fprintf(stderr, "found weak undefined symbol %s\n", symbol->name); +-#endif +- return TRUE; +- } +- } +- return FALSE; +-} +- +-static int +-bfin_set_reloc (uint32_t *reloc, +- const char *reloc_section_name, +- const char *sym_name, +- struct bfd_symbol *symbol, +- int sp, int32_t offset) +-{ +- unsigned int type = 0; +- uint32_t val; +- +- if (strstr (reloc_section_name, "stack")) { +- if (verbose) +- printf("Stack-relative reloc, offset %08"PRIx32"\n", offset); +- /* This must be a stack_start reloc for stack checking. */ +- type = 1; +- } +- val = (offset & ((1 << 26) - 1)); +- val |= (sp & ((1 << 3) - 1)) << 26; +- val |= type << 29; +- *reloc = val; +- return 0; +-} +- +-static bfd *compare_relocs_bfd; +- +-static int +-compare_relocs (const void *pa, const void *pb) +-{ +- const arelent *const *a = pa, *const *b = pb; +- const arelent *ra = *a, *rb = *b; +- unsigned long va, vb; +- uint32_t a_vma, b_vma; +- +- if (!ra->sym_ptr_ptr || !*ra->sym_ptr_ptr) +- return -1; +- else if (!rb->sym_ptr_ptr || !*rb->sym_ptr_ptr) +- return 1; +- +- a_vma = elf2flt_bfd_section_vma((*(ra->sym_ptr_ptr))->section); +- b_vma = elf2flt_bfd_section_vma((*(rb->sym_ptr_ptr))->section); +- va = (*(ra->sym_ptr_ptr))->value + a_vma + ra->addend; +- vb = (*(rb->sym_ptr_ptr))->value + b_vma + rb->addend; +- return va - vb; +-} +-#endif +- +-static bool +-ro_reloc_data_section_should_be_in_text(asection *s) +-{ +- if ((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) == +- (SEC_DATA | SEC_READONLY | SEC_RELOC)) { +-#if defined(TARGET_m68k) || defined(TARGET_riscv64) || defined(TARGET_xtensa) +- if (!strcmp(".eh_frame", s->name)) +- return false; +-#endif +- return true; +- } +- return false; +-} +- +-static uint32_t * +-output_relocs ( +- bfd *abs_bfd, +- asymbol **symbols, +- int number_of_symbols, +- uint32_t *n_relocs, +- unsigned char *text, int text_len, uint32_t text_vma, +- unsigned char *data, int data_len, uint32_t data_vma, +- bfd *rel_bfd) +-{ +- uint32_t *flat_relocs; +- asection *a, *sym_section, *r; +- arelent **relpp, **p, *q; +- const char *sym_name, *section_name; +- unsigned char *sectionp; +- unsigned long pflags; +- char addstr[20]; +- uint32_t sym_addr, sym_vma, section_vma; +- int relsize, relcount; +- int flat_reloc_count; +- int sym_reloc_size, rc; +- int got_size = 0; +- int bad_relocs = 0; +- asymbol **symb; +- long nsymb; +-#ifdef TARGET_bfin +- unsigned long persistent_data = 0; +-#endif +- +-#if 0 +- printf("%s(%d): output_relocs(abs_bfd=%d,symbols=0x%x,number_of_symbols=%d," +- "n_relocs=0x%x,text=0x%x,text_len=%d,data=0x%x,data_len=%d)\n", +- __FILE__, __LINE__, abs_bfd, symbols, number_of_symbols, n_relocs, +- text, text_len, data, data_len); +-#endif +- +- if (0) +- dump_symbols(symbols, number_of_symbols); +- +- *n_relocs = 0; +- flat_relocs = NULL; +- flat_reloc_count = 0; +- sym_reloc_size = 0; +- rc = 0; +- pflags = 0; +- /* Silence gcc warnings */ +- (void) pflags; +- (void) sym_vma; +- +- /* Determine how big our offset table is in bytes. +- * This isn't too difficult as we've terminated the table with -1. +- * Also note that both the relocatable and absolute versions have this +- * terminator even though the relocatable one doesn't have the GOT! +- */ +- if (pic_with_got && !use_resolved) { +- uint32_t *lp = (uint32_t *)data; +- /* Should call ntohl(*lp) here but is isn't going to matter */ +- while (*lp != 0xffffffff) lp++; +- got_size = ((unsigned char *)lp) - data; +- if (verbose) +- printf("GOT table contains %zu entries (%d bytes)\n", +- got_size/sizeof(uint32_t), got_size); +-#ifdef TARGET_m68k +- if (got_size > GOT_LIMIT) +- fatal("GOT too large: %d bytes (limit = %d bytes)", +- got_size, GOT_LIMIT); +-#endif +- } +- +- for (a = abs_bfd->sections; (a != (asection *) NULL); a = a->next) { +- section_vma = elf2flt_bfd_section_vma(a); +- +- if (verbose) +- printf("SECTION: %s [%p]: flags=0x%x vma=0x%"PRIx32"\n", +- a->name, a, a->flags, section_vma); +- +-// if (bfd_is_abs_section(a)) +-// continue; +- if (bfd_is_und_section(a)) +- continue; +- if (bfd_is_com_section(a)) +- continue; +-// if ((a->flags & SEC_RELOC) == 0) +-// continue; +- +- /* +- * Only relocate things in the writable data sections if we are PIC/GOT. +- * Otherwise do text (and read only data) as well. +- */ +- if ((!pic_with_got || ALWAYS_RELOC_TEXT) && +- ((a->flags & SEC_CODE) || +- ro_reloc_data_section_should_be_in_text(a))) +- sectionp = text + (a->vma - text_vma); +- else if (a->flags & SEC_DATA) +- sectionp = data + (a->vma - data_vma); +- else +- continue; +- +- /* Now search for the equivalent section in the relocation binary +- * and use that relocation information to build reloc entries +- * for this one. +- */ +- for (r=rel_bfd->sections; r != NULL; r=r->next) +- if (strcmp(a->name, r->name) == 0) +- break; +- if (r == NULL) +- continue; +- if (verbose) +- printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%"BFD_VMA_FMT"x\n", +- r->name, r, r->flags, elf2flt_bfd_section_vma(r)); +- if ((r->flags & SEC_RELOC) == 0) +- continue; +- relsize = bfd_get_reloc_upper_bound(rel_bfd, r); +- if (relsize <= 0) { +- if (verbose) +- printf("%s(%d): no relocation entries section=%s\n", +- __FILE__, __LINE__, r->name); +- continue; +- } +- +- symb = get_symbols(rel_bfd, &nsymb); +- relpp = xmalloc(relsize); +- +- relcount = bfd_canonicalize_reloc(rel_bfd, r, relpp, symb); +- if (relcount <= 0) { +- if (verbose) +- printf("%s(%d): no relocation entries section=%s\n", +- __FILE__, __LINE__, r->name); +- continue; +- } else { +-#ifdef TARGET_bfin +- compare_relocs_bfd = abs_bfd; +- qsort (relpp, relcount, sizeof *relpp, compare_relocs); +-#endif +- for (p = relpp; (relcount && (*p != NULL)); p++, relcount--) { +- unsigned char *r_mem = NULL; +- int relocation_needed = 0; +- /* Do we need to update the text segment? By default yes if not pic_with_got */ +- int update_text = !pic_with_got; +- +-#ifdef TARGET_v850 +- /* Skip this relocation entirely if possible (we +- do this early, before doing any other +- processing on it). */ +- switch ((*p)->howto->type) { +- case R_V850_9_PCREL: +- case R_V850_22_PCREL: +- case R_V850_SDA_16_16_OFFSET: +- case R_V850_SDA_15_16_OFFSET: +- case R_V850_ZDA_15_16_OFFSET: +- case R_V850_TDA_6_8_OFFSET: +- case R_V850_TDA_7_8_OFFSET: +- case R_V850_TDA_7_7_OFFSET: +- case R_V850_TDA_16_16_OFFSET: +- case R_V850_TDA_4_5_OFFSET: +- case R_V850_TDA_4_4_OFFSET: +- case R_V850_SDA_16_16_SPLIT_OFFSET: +- case R_V850_CALLT_6_7_OFFSET: +- case R_V850_CALLT_16_16_OFFSET: +- /* These are relative relocations, which +- have already been fixed up by the +- linker at this point, so just ignore +- them. */ +- continue; +- } +-#endif /* USE_V850_RELOCS */ +- +- q = *p; +- if (q->sym_ptr_ptr && *q->sym_ptr_ptr) { +- sym_name = (*(q->sym_ptr_ptr))->name; +- sym_section = (*(q->sym_ptr_ptr))->section; +- section_name=(*(q->sym_ptr_ptr))->section->name; +- } else { +- printf("ERROR: undefined relocation entry\n"); +- rc = -1; +- continue; +- } +-#ifndef TARGET_bfin +- /* Adjust the address to account for the GOT table which wasn't +- * present in the relative file link. +- */ +- if (pic_with_got && !use_resolved) +- q->address += got_size; +-#endif +- +- /* A pointer to what's being relocated, used often +- below. */ +- r_mem = sectionp + q->address; +- +- /* +- * Fixup offset in the actual section. +- */ +- addstr[0] = 0; +-#if !defined TARGET_e1 && !defined TARGET_bfin +- if ((sym_addr = get_symbol_offset((char *) sym_name, +- sym_section, symbols, number_of_symbols)) == -1) { +- sym_addr = 0; +- } +-#else +- sym_addr = (*(q->sym_ptr_ptr))->value; +-#endif +- if (use_resolved) { +- /* Use the address of the symbol already in +- the program text. How this is handled may +- still depend on the particular relocation +- though. */ +- switch (q->howto->type) { +-#ifdef TARGET_v850 +- int r2_type; +- case R_V850_HI16_S: +- /* We specially handle adjacent +- HI16_S/ZDA_15_16_OFFSET and +- HI16_S/LO16 pairs that reference the +- same address (these are usually +- movhi/ld and movhi/movea pairs, +- respectively). */ +- if (relcount == 0) +- r2_type = R_V850_NONE; +- else +- r2_type = p[1]->howto->type; +- if ((r2_type == R_V850_ZDA_15_16_OFFSET +- || r2_type == R_V850_LO16) +- && (p[0]->sym_ptr_ptr +- == p[1]->sym_ptr_ptr) +- && (p[0]->addend == p[1]->addend)) +- { +- relocation_needed = 1; +- +- switch (r2_type) { +- case R_V850_ZDA_15_16_OFFSET: +- pflags = 0x10000000; +- break; +- case R_V850_LO16: +- pflags = 0x20000000; +- break; +- } +- +- /* We don't really need the +- actual value -- the bits +- produced by the linker are +- what we want in the final +- flat file -- but get it +- anyway if useful for +- debugging. */ +- if (verbose) { +- unsigned char *r2_mem = +- sectionp +- + p[1]->address; +- /* little-endian */ +- int hi = r_mem[0] +- + (r_mem[1] << 8); +- int lo = r2_mem[0] +- + (r2_mem[1] << 8); +- /* Sign extend LO. */ +- lo = (lo ^ 0x8000) +- - 0x8000; +- +- /* Maybe ignore the LSB +- of LO, which is +- actually part of the +- instruction. */ +- if (r2_type != R_V850_LO16) +- lo &= ~1; +- +- sym_addr = +- (hi << 16) +- + lo; +- } +- } else +- goto bad_resolved_reloc; +- break; +- +- case R_V850_LO16: +- /* See if this is actually the +- 2nd half of a pair. */ +- if (p > relpp +- && (p[-1]->howto->type +- == R_V850_HI16_S) +- && (p[-1]->sym_ptr_ptr +- == p[0]->sym_ptr_ptr) +- && (p[-1]->addend == p[0]->addend)) +- break; /* not an error */ +- else +- goto bad_resolved_reloc; +- +- case R_V850_HI16: +- goto bad_resolved_reloc; +- default: +- goto good_32bit_resolved_reloc; +-#elif defined(TARGET_microblaze) +- case R_MICROBLAZE_64: +- sym_addr = +- (r_mem[2] << 24) +- + (r_mem[3] << 16) +- + (r_mem[6] << 8) +- + r_mem[7]; +- relocation_needed = 1; +- update_text = 0; +- pflags = 0x80000000; +- break; +- case R_MICROBLAZE_GOTPC_64: +- /* This is data-relative. We can't support this with bflt */ +- goto bad_resolved_reloc; +- case R_MICROBLAZE_GOT_64: +- /* This is a GOT relocation. But it is accessed via the GOT register (r20) +- * so doesn't need relocation +- */ +- relocation_needed = 0; +- break; +- case R_MICROBLAZE_32: +- goto good_32bit_resolved_reloc; +- /* These are already relocated for us as text-relative, or are dummy entries */ +- case R_MICROBLAZE_64_PCREL: +- case R_MICROBLAZE_PLT_64: +- case R_MICROBLAZE_NONE: +- case R_MICROBLAZE_64_NONE: +- case R_MICROBLAZE_32_PCREL_LO: +- relocation_needed = 0; +- continue; +- default: +- goto bad_resolved_reloc; +-#elif defined(TARGET_arm) +- case R_ARM_TARGET1: +- case R_ARM_TARGET2: +- case R_ARM_ABS32: +- relocation_needed = 1; +- break; +- case R_ARM_REL32: +- case R_ARM_JUMP24: +- case R_ARM_CALL: +- case R_ARM_THM_PC11: +- case R_ARM_THM_PC22: +- case R_ARM_THM_JUMP24: +- case R_ARM_PC24: +- case R_ARM_PLT32: +- case R_ARM_GOTPC: +- case R_ARM_GOT32: +- case R_ARM_PREL31: +- case R_ARM_V4BX: +- case R_ARM_NONE: +- relocation_needed = 0; +- break; +- default: +- goto bad_resolved_reloc; +-#elif defined(TARGET_m68k) +- case R_68K_32: +- goto good_32bit_resolved_reloc; +- case R_68K_PC32: +- case R_68K_PC16: +- /* The linker has already resolved +- PC relocs for us. In PIC links, +- the symbol must be in the data +- segment. */ +- case R_68K_NONE: +- continue; +- default: +- goto bad_resolved_reloc; +-#elif defined TARGET_bfin +- case R_BFIN_RIMM16: +- case R_BFIN_LUIMM16: +- case R_BFIN_HUIMM16: +- sym_vma = elf2flt_bfd_section_vma(sym_section); +- sym_addr += sym_vma + q->addend; +- +- if (weak_und_symbol(sym_section->name, (*(q->sym_ptr_ptr)))) +- continue; +- if (q->howto->type == R_BFIN_RIMM16 && (0xFFFF0000 & sym_addr)) { +- fprintf (stderr, "Relocation overflow for rN = %s\n",sym_name); +- bad_relocs++; +- } +- if ((0xFFFF0000 & sym_addr) != persistent_data) { +- flat_relocs = (uint32_t *) +- (realloc (flat_relocs, (flat_reloc_count + 1) * sizeof (uint32_t))); +- if (verbose) +- printf("New persistent data for %08"PRIx32"\n", sym_addr); +- persistent_data = 0xFFFF0000 & sym_addr; +- flat_relocs[flat_reloc_count++] +- = (sym_addr >> 16) | (3 << 26); +- } +- +- flat_relocs = (uint32_t *) +- (realloc (flat_relocs, (flat_reloc_count + 1) * sizeof (uint32_t))); +- if (bfin_set_reloc (flat_relocs + flat_reloc_count, +- sym_section->name, sym_name, +- (*(q->sym_ptr_ptr)), +- q->howto->type == R_BFIN_HUIMM16 ? 1 : 0, +- section_vma + q->address)) +- bad_relocs++; +- if (a->flags & SEC_CODE) +- text_has_relocs = 1; +- flat_reloc_count++; +- break; +- +- case R_BFIN_BYTE4_DATA: +- sym_vma = elf2flt_bfd_section_vma(sym_section); +- sym_addr += sym_vma + q->addend; +- +- if (weak_und_symbol (sym_section->name, (*(q->sym_ptr_ptr)))) +- continue; +- +- flat_relocs = (uint32_t *) +- (realloc (flat_relocs, (flat_reloc_count + 1) * sizeof (uint32_t))); +- if (bfin_set_reloc (flat_relocs + flat_reloc_count, +- sym_section->name, sym_name, +- (*(q->sym_ptr_ptr)), +- 2, section_vma + q->address)) +- bad_relocs++; +- if (a->flags & SEC_CODE) +- text_has_relocs = 1; +- +- flat_reloc_count++; +- break; +-#elif defined (TARGET_h8300) +- case R_H8_DIR32: +- case R_H8_DIR32A16: +- case R_H8_DISP32A16: +- r_mem[0] = 0; +- case R_H8_DIR24A8: +- case R_H8_DIR24R8: +- goto good_32bit_resolved_reloc; +- case R_H8_PCREL8: +- case R_H8_PCREL16: +- continue; +-#elif defined(TARGET_xtensa) +- case R_XTENSA_NONE: +- case R_XTENSA_OP0: +- case R_XTENSA_OP1: +- case R_XTENSA_OP2: +- case R_XTENSA_SLOT0_OP: +- case R_XTENSA_SLOT1_OP: +- case R_XTENSA_SLOT2_OP: +- case R_XTENSA_SLOT3_OP: +- case R_XTENSA_SLOT4_OP: +- case R_XTENSA_SLOT5_OP: +- case R_XTENSA_SLOT6_OP: +- case R_XTENSA_SLOT7_OP: +- case R_XTENSA_SLOT8_OP: +- case R_XTENSA_SLOT9_OP: +- case R_XTENSA_SLOT10_OP: +- case R_XTENSA_SLOT11_OP: +- case R_XTENSA_SLOT12_OP: +- case R_XTENSA_SLOT13_OP: +- case R_XTENSA_SLOT14_OP: +- case R_XTENSA_SLOT0_ALT: +- case R_XTENSA_SLOT1_ALT: +- case R_XTENSA_SLOT2_ALT: +- case R_XTENSA_SLOT3_ALT: +- case R_XTENSA_SLOT4_ALT: +- case R_XTENSA_SLOT5_ALT: +- case R_XTENSA_SLOT6_ALT: +- case R_XTENSA_SLOT7_ALT: +- case R_XTENSA_SLOT8_ALT: +- case R_XTENSA_SLOT9_ALT: +- case R_XTENSA_SLOT10_ALT: |