summaryrefslogtreecommitdiff
path: root/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12
diff options
context:
space:
mode:
Diffstat (limited to 'toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12')
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-arm.patch46
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-elf2flt-add-riscv-64-bits-support.patch137
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0008-remove_BFD_VMA_FMT.patch125
3 files changed, 262 insertions, 46 deletions
diff --git a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-arm.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-arm.patch
deleted file mode 100644
index 247ff2b35..000000000
--- a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-arm.patch
+++ /dev/null
@@ -1,46 +0,0 @@
-diff -Nur elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.c elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.c
---- elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.c 2021-02-08 14:02:15.000000000 +0100
-+++ elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.c 2021-04-09 20:40:19.386179197 +0200
-@@ -424,7 +424,8 @@
- */
- if ((!pic_with_got || ALWAYS_RELOC_TEXT) &&
- ((a->flags & SEC_CODE) ||
-- ((a->flags & (SEC_DATA | SEC_READONLY)) == (SEC_DATA | SEC_READONLY))))
-+ ((a->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
-+ (SEC_DATA | SEC_READONLY | SEC_RELOC))))
- sectionp = text + (a->vma - text_vma);
- else if (a->flags & SEC_DATA)
- sectionp = data + (a->vma - data_vma);
-@@ -1861,7 +1862,9 @@
- bfd_size_type sec_size;
- bfd_vma sec_vma;
-
-- if (s->flags & SEC_CODE) {
-+ if ((s->flags & SEC_CODE) ||
-+ ((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
-+ (SEC_DATA | SEC_READONLY | SEC_RELOC))) {
- vma = &text_vma;
- len = &text_len;
- } else if (s->flags & SEC_DATA) {
-@@ -1896,7 +1899,9 @@
-
- /* Read in all text sections. */
- for (s = abs_bfd->sections; s != NULL; s = s->next)
-- if (s->flags & SEC_CODE)
-+ if ((s->flags & SEC_CODE) ||
-+ ((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
-+ (SEC_DATA | SEC_READONLY | SEC_RELOC)))
- if (!bfd_get_section_contents(abs_bfd, s,
- text + (s->vma - text_vma), 0,
- bfd_section_size(abs_bfd, s)))
-@@ -1922,7 +1927,9 @@
-
- /* Read in all data sections. */
- for (s = abs_bfd->sections; s != NULL; s = s->next)
-- if (s->flags & SEC_DATA)
-+ if ((s->flags & SEC_DATA) &&
-+ ((s->flags & (SEC_READONLY | SEC_RELOC)) !=
-+ (SEC_READONLY | SEC_RELOC)))
- if (!bfd_get_section_contents(abs_bfd, s,
- data + (s->vma - data_vma), 0,
- bfd_section_size(abs_bfd, s)))
diff --git a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-elf2flt-add-riscv-64-bits-support.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-elf2flt-add-riscv-64-bits-support.patch
new file mode 100644
index 000000000..4b0075844
--- /dev/null
+++ b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-elf2flt-add-riscv-64-bits-support.patch
@@ -0,0 +1,137 @@
+From 1dea576eac4289602adc4a37f48c80330bf82e63 Mon Sep 17 00:00:00 2001
+From: Damien Le Moal <damien.lemoal@wdc.com>
+Date: Wed, 9 Sep 2020 17:31:33 +0900
+Subject: [PATCH] elf2flt: add riscv 64-bits support
+
+Add support for riscv 64bits ISA by defining the relocation types
+R_RISCV_32_PCREL, R_RISCV_ADD32, R_RISCV_SUB32, R_RISCV_32 and
+R_RISCV_64. riscv64 support also needs the __global_pointer$ symbol to
+be defined right after the relocation tables in the data section.
+Furthermore, the .got and .got.plt sections must be reversed. These 2
+requirements are handled with runtime modifications of the default
+linker script using the append_sed() function.
+(1) For the .got.plt and .got sections order swap, append_sed() is used
+to rename "(.got.plt)" to "(.got.tmp)" and to rename "(.got)" to
+"(.got.plt)". A last call finalize the name swap by replacing
+"(.got.tmp)" with "(.got)"
+(2) For the global pointer synbol, a definition line starting with
+"RISCV_GP" is added. The "RISCV_GP" string is removed if the target CPU
+type is riscv64. The definition line is dropped for other CPU types.
+
+With these changes, buildroot/busybox builds and run on NOMMU
+systems with kernel 5.13. Tested on Canaan Kendryte K210 boards.
+
+This patch is based on earlier work by Christoph Hellwig <hch@lst.de>.
+
+Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
+---
+ elf2flt.c | 23 +++++++++++++++++++++++
+ elf2flt.ld.in | 9 +++++----
+ ld-elf2flt.c | 16 ++++++++++++++++
+ 3 files changed, 44 insertions(+), 4 deletions(-)
+
+diff --git a/elf2flt.c b/elf2flt.c
+index f87f1fc..dbce467 100644
+--- a/elf2flt.c
++++ b/elf2flt.c
+@@ -80,6 +80,8 @@ const char *elf2flt_progname;
+ #include <elf/v850.h>
+ #elif defined(TARGET_xtensa)
+ #include <elf/xtensa.h>
++#elif defined(TARGET_riscv64)
++#include <elf/riscv.h>
+ #endif
+
+ #if defined(__MINGW32__)
+@@ -122,6 +124,8 @@ const char *elf2flt_progname;
+ #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
+@@ -797,6 +801,16 @@ output_relocs (
+ goto good_32bit_resolved_reloc;
+ default:
+ goto bad_resolved_reloc;
++#elif defined(TARGET_riscv64)
++ case R_RISCV_32_PCREL:
++ case R_RISCV_ADD32:
++ case R_RISCV_SUB32:
++ continue;
++ case R_RISCV_32:
++ case R_RISCV_64:
++ goto good_32bit_resolved_reloc;
++ default:
++ goto bad_resolved_reloc;
+ #else
+ default:
+ /* The default is to assume that the
+@@ -1806,6 +1820,15 @@ int main(int argc, char *argv[])
+ if (!load_to_ram && !pfile)
+ load_to_ram = 1;
+
++#if defined(TARGET_riscv64)
++ /*
++ * riscv only supports loading text and data contiguously.
++ * So fail if load_to_ram is false.
++ */
++ if (!load_to_ram)
++ fatal("Loading to RAM ('-r' option) is required");
++#endif
++
+ fname = argv[argc-1];
+
+ if (pfile) {
+diff --git a/elf2flt.ld.in b/elf2flt.ld.in
+index ec1fe6f..c0c44b8 100644
+--- a/elf2flt.ld.in
++++ b/elf2flt.ld.in
+@@ -70,10 +70,11 @@ W_RODAT *(.gnu.linkonce.r*)
+ . = ALIGN(0x20) ;
+ LONG(-1)
+ . = ALIGN(0x20) ;
+-R_RODAT *(.rodata)
+-R_RODAT *(.rodata1)
+-R_RODAT *(.rodata.*)
+-R_RODAT *(.gnu.linkonce.r*)
++RISCV_GP: __global_pointer$ = . + 0x800 ;
++R_RODAT *(.rodata)
++R_RODAT *(.rodata1)
++R_RODAT *(.rodata.*)
++R_RODAT *(.gnu.linkonce.r*)
+ *(.data)
+ *(.data1)
+ *(.data.*)
+diff --git a/ld-elf2flt.c b/ld-elf2flt.c
+index e5de506..31b565f 100644
+--- a/ld-elf2flt.c
++++ b/ld-elf2flt.c
+@@ -324,6 +324,22 @@ static int do_final_link(void)
+ append_option(&other_options, concat(got_offset, "=", buf, NULL));
+ }
+
++ if (streq(TARGET_CPU, "riscv64")) {
++ /*
++ * The .got section must come before the .got.plt section
++ * (gcc/ld bug ?).
++ */
++ append_sed(&sed, "(.got.plt)", "(.got.tmp)");
++ append_sed(&sed, "(.got.plt)", "(.got)");
++ append_sed(&sed, "(.got.tmp)", "(.got.plt)");
++
++ /* The global pointer symbol is defined after the GOT. */
++ append_sed(&sed, "^RISCV_GP:", "");
++ } else {
++ /* Get rid of the global pointer definition. */
++ append_sed(&sed, "^RISCV_GP:", NULL);
++ }
++
+ /* Locate the default linker script, if we don't have one provided. */
+ if (!linker_script)
+ linker_script = concat(ldscriptpath, "/elf2flt.ld", NULL);
+--
+2.31.1
+
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) {