diff options
Diffstat (limited to 'toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12')
7 files changed, 661 insertions, 159 deletions
diff --git a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-lm32.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-lm32.patch deleted file mode 100644 index 5ec55337b..000000000 --- a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-lm32.patch +++ /dev/null @@ -1,159 +0,0 @@ -diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.c ---- elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c 2017-09-27 06:06:04.000000000 +0200 -+++ elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.c 2017-09-27 06:07:51.032597579 +0200 -@@ -61,6 +61,8 @@ - #include <elf/bfin.h> - #elif defined(TARGET_h8300) - #include <elf/h8.h> -+#elif defined(TARGET_lm32) -+#include <elf/lm32.h> - #elif defined(TARGET_m68k) - #include <elf/m68k.h> - #elif defined(TARGET_microblaze) -@@ -120,6 +122,11 @@ - #define ARCH "nios" - #elif defined(TARGET_nios2) - #define ARCH "nios2" -+#elif defined(TARGET_lm32) -+#define ARCH "lm32" -+#define FLAT_LM32_RELOC_TYPE_32_BIT 0 -+#define FLAT_LM32_RELOC_TYPE_HI16_BIT 1 -+#define FLAT_LM32_RELOC_TYPE_LO16_BIT 2 - #elif defined(TARGET_xtensa) - #define ARCH "xtensa" - #else -@@ -357,7 +364,7 @@ - int bad_relocs = 0; - asymbol **symb; - long nsymb; --#ifdef TARGET_bfin -+#if defined (TARGET_bfin) || defined (TARGET_lm32) - unsigned long persistent_data = 0; - #endif - -@@ -682,6 +689,36 @@ - break; - default: - goto bad_resolved_reloc; -+#elif defined(TARGET_lm32) -+ case R_LM32_HI16: -+ case R_LM32_LO16: -+ if (q->howto->type == R_LM32_HI16) { -+ pflags = FLAT_LM32_RELOC_TYPE_HI16_BIT << 29; -+ } else { -+ pflags = FLAT_LM32_RELOC_TYPE_LO16_BIT << 29; -+ } -+ -+ relocation_needed = 1; -+ -+ /* remember the upper 16 bits */ -+ 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 %08lx\n", sym_addr); -+ persistent_data = 0xffff0000 & sym_addr; -+ flat_relocs[flat_reloc_count++] = (sym_addr >> 16) | (3 << 29); -+ } -+ break; -+ case R_LM32_32: -+ pflags = FLAT_LM32_RELOC_TYPE_32_BIT << 29; -+ relocation_needed = 1; -+ break; -+ case R_LM32_CALL: -+ relocation_needed = 0; -+ break; -+ default: -+ goto bad_resolved_reloc; - #elif defined(TARGET_m68k) - case R_68K_32: - goto good_32bit_resolved_reloc; -@@ -1459,6 +1496,63 @@ - #undef _30BITS_RELOC - #undef _28BITS_RELOC - #endif -+#ifdef TARGET_lm32 -+ case R_LM32_32: -+ { -+ pflags = FLAT_LM32_RELOC_TYPE_32_BIT << 29; -+ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); -+ sym_addr += sym_vma + q->addend; -+ relocation_needed = 1; -+ break; -+ } -+ case R_LM32_CALL: -+ { -+ sym_vma = 0; -+ sym_addr += sym_vma + q->addend; -+ sym_addr -= q->address; -+ sym_addr = (int32_t)sym_addr >> q->howto->rightshift; -+ -+ if ((int32_t)sym_addr < -0x8000000 || (int32_t)sym_addr > 0x7ffffff) { -+ printf("ERROR: Relocation overflow for R_LM32_CALL relocation against %s\n", sym_name); -+ bad_relocs++; -+ continue; -+ } -+ -+ r_mem[0] |= (sym_addr >> 24) & 0x03; -+ r_mem[1] = (sym_addr >> 16) & 0xff; -+ r_mem[2] = (sym_addr >> 8) & 0xff; -+ r_mem[3] = sym_addr & 0xff; -+ break; -+ } -+ case R_LM32_HI16: -+ case R_LM32_LO16: -+ { -+ if (q->howto->type == R_LM32_HI16) { -+ pflags = FLAT_LM32_RELOC_TYPE_HI16_BIT << 29; -+ } else { -+ pflags = FLAT_LM32_RELOC_TYPE_LO16_BIT << 29; -+ } -+ -+ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); -+ sym_addr += sym_vma + q->addend; -+ -+ relocation_needed = 1; -+ -+ /* remember the upper 16 bits */ -+ 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 %08lx\n", sym_addr); -+ persistent_data = 0xffff0000 & sym_addr; -+ flat_relocs[flat_reloc_count++] = (sym_addr >> 16) | (3 << 29); -+ } -+ -+ r_mem[2] = (sym_addr >> 8) & 0xff; -+ r_mem[3] = sym_addr & 0xff; -+ break; -+ } -+#endif /* TARGET_lm32 */ - default: - /* missing support for other types of relocs */ - printf("ERROR: bad reloc type %d\n", (*p)->howto->type); -@@ -1596,6 +1690,13 @@ - break; - #endif - -+#ifdef TARGET_lm32 -+ case R_LM32_HI16: -+ case R_LM32_LO16: -+ case R_LM32_CALL: -+ /* entry has already been written */ -+ break; -+#endif - default: - /* The alignment of the build host - might be stricter than that of the -diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.ld.in elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.ld.in ---- elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.ld.in 2017-09-27 06:06:04.000000000 +0200 -+++ elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.ld.in 2017-09-29 18:11:30.999698955 +0200 -@@ -34,6 +34,7 @@ - W_RODAT *(.rodata1) - W_RODAT *(.rodata.*) - W_RODAT *(.gnu.linkonce.r*) -+W_RODAT *(.rofixup) - - /* .ARM.extab name sections containing exception unwinding information */ - *(.ARM.extab* .gnu.linkonce.armextab.*) diff --git a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0004-elf2flt.c-add-new-relocation-types-for-xtensa.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0004-elf2flt.c-add-new-relocation-types-for-xtensa.patch new file mode 100644 index 000000000..953bd79cc --- /dev/null +++ b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0004-elf2flt.c-add-new-relocation-types-for-xtensa.patch @@ -0,0 +1,188 @@ +From d7eb73163bcea31168c438fc132a0967ac172e3d Mon Sep 17 00:00:00 2001 +From: Max Filippov <jcmvbkbc@gmail.com> +Date: Thu, 7 May 2020 21:11:43 -0700 +Subject: [PATCH] elf2flt.c: add new relocation types for xtensa + +Xtensa have added new relocation types R_XTENSA_[NP]DIFF{8,16,32} with +the same properties as the existing types R_XTENSA_DIFF{8,16,32}. +Add them to the list of ignored relocation types. + +This fixes the following error when invoking elf2flt on xtensa binaries +built with the recent binutils: + + ERROR: reloc type R_XTENSA_PDIFF32 unsupported in this context + +Reported-by: Romain Naour <romain.naour@gmail.com> +Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> +Backported from: d7eb73163bcea31168c438fc132a0967ac172e3d +--- + Makefile.in | 3 ++- + configure | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + configure.ac | 14 ++++++++++++ + elf2flt.c | 8 +++++++ + 4 files changed, 88 insertions(+), 1 deletion(-) + +diff --git a/Makefile.in b/Makefile.in +index 52b3347d7f43..0529c7f0a25a 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -30,7 +30,8 @@ DEFS = @DEFS@ \ + -DNO_GOT_CHECK=@got_check@ \ + -DUSE_EMIT_RELOCS=@emit_relocs@ \ + -DEMIT_CTOR_DTOR=@emit_ctor_dtor@ \ +- -DALWAYS_RELOC_TEXT=@always_reloc_text@ ++ -DALWAYS_RELOC_TEXT=@always_reloc_text@ \ ++ -DHAVE_BFD_XTENSA_PDIFF_RELOCS=@HAVE_BFD_XTENSA_PDIFF_RELOCS@ + EXEEXT = @EXEEXT@ + OBJEXT = @OBJEXT@ + +diff --git a/configure b/configure +index bb8e33f9cb28..bca38c34247e 100755 +--- a/configure ++++ b/configure +@@ -621,6 +621,7 @@ ac_includes_default="\ + + ac_subst_vars='LTLIBOBJS + LIBOBJS ++HAVE_BFD_XTENSA_PDIFF_RELOCS + SYMBOL_PREFIX + always_reloc_text + emit_ctor_dtor +@@ -1729,6 +1730,52 @@ fi + + } # ac_fn_c_try_link + ++# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES ++# --------------------------------------------- ++# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR ++# accordingly. ++ac_fn_c_check_decl () ++{ ++ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack ++ as_decl_name=`echo $2|sed 's/ *(.*//'` ++ as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` ++ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 ++$as_echo_n "checking whether $as_decl_name is declared... " >&6; } ++if eval \${$3+:} false; then : ++ $as_echo_n "(cached) " >&6 ++else ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++$4 ++int ++main () ++{ ++#ifndef $as_decl_name ++#ifdef __cplusplus ++ (void) $as_decl_use; ++#else ++ (void) $as_decl_name; ++#endif ++#endif ++ ++ ; ++ return 0; ++} ++_ACEOF ++if ac_fn_c_try_compile "$LINENO"; then : ++ eval "$3=yes" ++else ++ eval "$3=no" ++fi ++rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ++fi ++eval ac_res=\$$3 ++ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 ++$as_echo "$ac_res" >&6; } ++ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno ++ ++} # ac_fn_c_check_decl ++ + # ac_fn_c_check_func LINENO FUNC VAR + # ---------------------------------- + # Tests whether FUNC exists, setting the cache variable VAR accordingly +@@ -4272,6 +4319,22 @@ $as_echo "#define const /**/" >>confdefs.h + fi + + ++HAVE_BFD_XTENSA_PDIFF_RELOCS=0 ++case $target in ++ xtensa*) ++ OLD_CPPFLAGS=$CPPFLAGS ++ CPPFLAGS="-I$bfd_include_dir -I$binutils_include_dir $CPPFLAGS" ++ ac_fn_c_check_decl "$LINENO" "R_XTENSA_PDIFF8" "ac_cv_have_decl_R_XTENSA_PDIFF8" "#include \"bfd.h\" ++ #include \"elf/xtensa.h\" ++" ++if test "x$ac_cv_have_decl_R_XTENSA_PDIFF8" = xyes; then : ++ HAVE_BFD_XTENSA_PDIFF_RELOCS=1 ++fi ++ ++ CPPFLAGS=$OLD_CPPFLAGS ++ ;; ++esac ++ + for ac_func in vprintf + do : + ac_fn_c_check_func "$LINENO" "vprintf" "ac_cv_func_vprintf" +@@ -4333,6 +4396,7 @@ fi + + + ++ + ac_config_files="$ac_config_files ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld" + + cat >confcache <<\_ACEOF +diff --git a/configure.ac b/configure.ac +index d6b4119eb18a..19969b1045f6 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -202,6 +202,19 @@ AC_CHECK_HEADERS(fcntl.h unistd.h bfd.h) + dnl Checks for typedefs, structures, and compiler characteristics. + AC_C_CONST + ++HAVE_BFD_XTENSA_PDIFF_RELOCS=0 ++case $target in ++ xtensa*) ++ AS_VAR_COPY([OLD_CPPFLAGS], [CPPFLAGS]) ++ AS_VAR_SET([CPPFLAGS], ["-I$bfd_include_dir -I$binutils_include_dir $CPPFLAGS"]) ++ AC_CHECK_DECL([R_XTENSA_PDIFF8], ++ [HAVE_BFD_XTENSA_PDIFF_RELOCS=1],, ++ [#include "bfd.h" ++ #include "elf/xtensa.h"]) ++ AS_VAR_COPY([CPPFLAGS], [OLD_CPPFLAGS]) ++ ;; ++esac ++ + dnl Checks for library functions. + AC_FUNC_VPRINTF + +@@ -235,6 +248,7 @@ AC_SUBST(emit_relocs) + AC_SUBST(emit_ctor_dtor) + AC_SUBST(always_reloc_text) + AC_SUBST(SYMBOL_PREFIX) ++AC_SUBST(HAVE_BFD_XTENSA_PDIFF_RELOCS) + + AC_OUTPUT(ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld) + +diff --git a/elf2flt.c b/elf2flt.c +index b7c4a490df02..961534973f56 100644 +--- a/elf2flt.c ++++ b/elf2flt.c +@@ -776,6 +776,14 @@ output_relocs ( + case R_XTENSA_DIFF8: + case R_XTENSA_DIFF16: + case R_XTENSA_DIFF32: ++#if HAVE_BFD_XTENSA_PDIFF_RELOCS ++ case R_XTENSA_PDIFF8: ++ case R_XTENSA_PDIFF16: ++ case R_XTENSA_PDIFF32: ++ case R_XTENSA_NDIFF8: ++ case R_XTENSA_NDIFF16: ++ case R_XTENSA_NDIFF32: ++#endif + case R_XTENSA_32_PCREL: + continue; + case R_XTENSA_32: +-- +2.20.1 + 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/0006-lm32.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0006-lm32.patch new file mode 100644 index 000000000..0e0a96092 --- /dev/null +++ b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0006-lm32.patch @@ -0,0 +1,190 @@ +--- elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.c 2025-04-14 19:50:51.016711969 +0000 ++++ elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.c 2025-04-14 21:41:22.134771290 +0000 +@@ -62,6 +62,8 @@ const char *elf2flt_progname; + #include <elf/bfin.h> + #elif defined(TARGET_h8300) + #include <elf/h8.h> ++#elif defined(TARGET_lm32) ++#include <elf/lm32.h> + #elif defined(TARGET_m68k) + #include <elf/m68k.h> + #elif defined(TARGET_microblaze) +@@ -115,6 +117,12 @@ const char *elf2flt_progname; + #define ARCH "sh2" + #elif defined(TARGET_h8300) + #define ARCH "h8300" ++#elif defined(TARGET_lm32) ++#define ARCH "lm32" ++#define FLAT_LM32_RELOC_TYPE_32_BIT 0 ++#define FLAT_LM32_RELOC_TYPE_HI16_BIT 1 ++#define FLAT_LM32_RELOC_TYPE_LO16_BIT 2 ++#define FLAT_LM32_RELOC_TYPE_PERSIST 3 + #elif defined(TARGET_microblaze) + #define ARCH "microblaze" + #elif defined(TARGET_e1) +@@ -375,7 +383,7 @@ output_relocs ( + int bad_relocs = 0; + asymbol **symb; + long nsymb; +-#ifdef TARGET_bfin ++#if defined(TARGET_bfin) || defined(TARGET_lm32) + unsigned long persistent_data = 0; + #endif + +@@ -674,6 +682,40 @@ output_relocs ( + break; + default: + goto bad_resolved_reloc; ++#elif defined(TARGET_lm32) ++ case R_LM32_HI16: ++ case R_LM32_LO16: ++ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); ++ sym_addr += sym_vma + q->addend; ++ /* remember the upper 16 bits */ ++ if ((0xFFFF0000UL & 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 = 0xFFFF0000UL & sym_addr; ++ pflags = FLAT_LM32_RELOC_TYPE_PERSIST; ++ pflags <<= 29; ++ flat_relocs[flat_reloc_count++] = pflags | (sym_addr >> 16); ++ } ++ pflags = q->howto->type == R_LM32_HI16 ? ++ FLAT_LM32_RELOC_TYPE_HI16_BIT : ++ FLAT_LM32_RELOC_TYPE_LO16_BIT; ++ pflags <<= 29; ++ relocation_needed = 1; ++ break; ++ case R_LM32_32: ++ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); ++ sym_addr += sym_vma + q->addend; ++ pflags = FLAT_LM32_RELOC_TYPE_32_BIT; ++ pflags <<= 29; ++ relocation_needed = 1; ++ break; ++ case R_LM32_CALL: ++ relocation_needed = 0; ++ break; ++ default: ++ goto bad_resolved_reloc; + #elif defined(TARGET_m68k) + case R_68K_32: + goto good_32bit_resolved_reloc; +@@ -1010,6 +1052,63 @@ output_relocs ( + continue; + #endif + ++#ifdef TARGET_lm32 ++ case R_LM32_HI16: ++ case R_LM32_LO16: ++ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); ++ sym_addr += sym_vma + q->addend; ++ /* remember the upper 16 bits */ ++ if ((0xFFFF0000UL & 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 = 0xFFFF0000UL & sym_addr; ++ pflags = FLAT_LM32_RELOC_TYPE_PERSIST; ++ pflags <<= 29; ++ flat_relocs[flat_reloc_count++] = pflags | (sym_addr >> 16); ++ } ++ pflags = q->howto->type == R_LM32_HI16 ? ++ FLAT_LM32_RELOC_TYPE_HI16_BIT : ++ FLAT_LM32_RELOC_TYPE_LO16_BIT; ++ pflags <<= 29; ++ relocation_needed = 1; ++ break; ++ case R_LM32_32: ++ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); ++ sym_addr += sym_vma + q->addend; ++ pflags = FLAT_LM32_RELOC_TYPE_32_BIT; ++ pflags <<= 29; ++ relocation_needed = 1; ++ break; ++ case R_LM32_CALL: ++ sym_vma = 0; ++ sym_addr += sym_vma + q->addend; ++ sym_addr -= q->address; ++ sym_addr = (int32_t)sym_addr >> q->howto->rightshift; ++ { ++ union { ++ uint32_t u; ++ int32_t s; ++ } rangecheck; ++ ++ rangecheck.u = (unsigned)sym_addr << 6; ++ rangecheck.s >>= 6; ++ if (rangecheck.u != sym_addr) { ++ printf("ERROR: Relocation overflow for R_LM32_CALL relocation against %s\n", sym_name); ++ ++bad_relocs; ++ continue; ++ } ++ } ++ relocation_needed = 0; ++ r_mem[0] = (r_mem[0] & 0xFCU) | ++ ((sym_addr >> 24) & 0x03U); ++ r_mem[1] = (sym_addr >> 16) & 0xFFU; ++ r_mem[2] = (sym_addr >> 8) & 0xFFU; ++ r_mem[3] = sym_addr & 0xFFU; ++ break; ++#endif ++ + #ifdef TARGET_microblaze + case R_MICROBLAZE_64: + /* The symbol is split over two consecutive instructions. +@@ -1596,6 +1695,21 @@ DIS29_RELOCATION: + break; + #endif + ++#ifdef TARGET_lm32 ++ case R_LM32_HI16: ++ case R_LM32_LO16: ++ r_mem[2] = (sym_addr >> 8) & 0xFFU; ++ r_mem[3] = sym_addr & 0xFFU; ++ break; ++ case R_LM32_CALL: ++ /* ++ * use_resolved=… ++ * 0: already written above ++ * 1: no write necessary ++ */ ++ break; ++#endif ++ + default: + /* The alignment of the build host + might be stricter than that of the +--- elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.ld.in 2025-04-14 19:50:51.020711942 +0000 ++++ elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.ld.in 2025-04-14 22:23:40.078052838 +0000 +@@ -34,6 +34,7 @@ W_RODAT *(.rodata) + W_RODAT *(.rodata1) + W_RODAT *(.rodata.*) + W_RODAT *(.gnu.linkonce.r*) ++W_RODAT *(.rofixup) + + /* .ARM.extab name sections containing exception unwinding information */ + *(.ARM.extab* .gnu.linkonce.armextab.*) +--- elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/flthdr.c 2025-04-14 19:50:43.924759193 +0000 ++++ elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/flthdr.c 2025-04-14 22:01:24.467101158 +0000 +@@ -33,6 +33,8 @@ const char *elf2flt_progname; + + #if defined TARGET_bfin + # define flat_get_relocate_addr(addr) (addr & 0x03ffffff) ++#elif defined(TARGET_lm32) ++# define flat_get_relocate_addr(addr) ((addr) & 0x1FFFFFFFU) + #else + # define flat_get_relocate_addr(addr) (addr) + #endif +@@ -173,6 +175,8 @@ process_file(const char *ifile, const ch + addr = ntohl(addr); + if (r & 1) + addr &= 0x00ffffff; ++#elif defined(TARGET_lm32) ++ addr = ntohl(addr); + #endif + printf("%"PRIx32"\n", addr); + } diff --git a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0007-dont-waste-space.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0007-dont-waste-space.patch new file mode 100644 index 000000000..66b0c12f1 --- /dev/null +++ b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0007-dont-waste-space.patch @@ -0,0 +1,10 @@ +--- elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.ld.in 2025-04-14 19:50:51.020711942 +0000 ++++ elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.ld.in 2025-04-14 22:23:40.078052838 +0000 +@@ -13,7 +13,6 @@ PHDRS { + SECTIONS { + + .text 0x0 : { +- . = . + 4; + . = ALIGN(0x4) ; + @SYMBOL_PREFIX@_stext = . ; + *(.literal .text) 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/453398f917d167f8c308c8f997270c48ae8f8b12/0009-no-build-date.patch b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0009-no-build-date.patch new file mode 100644 index 000000000..06273ef4b --- /dev/null +++ b/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0009-no-build-date.patch @@ -0,0 +1,11 @@ +--- elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12.orig/elf2flt.c 2025-04-14 19:50:51.016711969 +0000 ++++ elf2flt-453398f917d167f8c308c8f997270c48ae8f8b12/elf2flt.c 2025-04-14 23:14:52.212092781 +0000 +@@ -2132,7 +2132,7 @@ int main(int argc, char *argv[]) + | (pic_with_got ? FLAT_FLAG_GOTPIC : 0) + | (docompress ? (docompress == 2 ? FLAT_FLAG_GZDATA : FLAT_FLAG_GZIP) : 0) + ); +- hdr.build_date = htonl((uint32_t)get_build_date()); ++ hdr.build_date = 0; + memset(hdr.filler, 0x00, sizeof(hdr.filler)); + + for (i=0; i<reloc_len; i++) reloc[i] = htonl(reloc[i]); |