diff options
Diffstat (limited to 'toolchain/elf2flt/patches')
22 files changed, 1793 insertions, 22 deletions
diff --git a/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0001-riscv32.patch b/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0001-riscv32.patch new file mode 100644 index 000000000..a99de4f9f --- /dev/null +++ b/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0001-riscv32.patch @@ -0,0 +1,42 @@ +diff -Nur elf2flt-v2023.04.orig/elf2flt.c elf2flt-v2023.04/elf2flt.c +--- elf2flt-v2023.04.orig/elf2flt.c 2023-09-04 11:29:05.952417209 +0200 ++++ elf2flt-v2023.04/elf2flt.c 2023-09-04 11:30:05.371065966 +0200 +@@ -81,7 +81,7 @@ + #include <elf/v850.h> + #elif defined(TARGET_xtensa) + #include <elf/xtensa.h> +-#elif defined(TARGET_riscv64) ++#elif defined(TARGET_riscv64) || defined(TARGET_riscv32) + #include <elf/riscv.h> + #endif + +@@ -127,6 +127,8 @@ + #define ARCH "xtensa" + #elif defined(TARGET_riscv64) + #define ARCH "riscv64" ++#elif defined(TARGET_riscv32) ++#define ARCH "riscv32" + #else + #error "Don't know how to support your CPU architecture??" + #endif +@@ -822,7 +824,7 @@ + goto good_32bit_resolved_reloc_update_text; + default: + goto bad_resolved_reloc; +-#elif defined(TARGET_riscv64) ++#elif defined(TARGET_riscv64) || defined(TARGET_riscv32) + case R_RISCV_NONE: + case R_RISCV_32_PCREL: + case R_RISCV_ADD8: +diff -Nur elf2flt-v2023.04.orig/ld-elf2flt.c elf2flt-v2023.04/ld-elf2flt.c +--- elf2flt-v2023.04.orig/ld-elf2flt.c 2023-09-04 11:28:59.072573514 +0200 ++++ elf2flt-v2023.04/ld-elf2flt.c 2023-09-04 11:29:32.507813592 +0200 +@@ -327,7 +327,7 @@ + /* riscv adds a global pointer symbol to the linker file with the + "RISCV_GP:" prefix. Remove the prefix for riscv64 architecture and + the entire line for other architectures. */ +- if (streq(TARGET_CPU, "riscv64")) ++ if (streq(TARGET_CPU, "riscv64") || streq(TARGET_CPU, "riscv32")) + append_sed(&sed, "^RISCV_GP:", ""); + else + append_sed(&sed, "^RISCV_GP:", NULL); diff --git a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-lm32.patch b/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0002-lm32.patch index 5ec55337b..b24b214c7 100644 --- a/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-lm32.patch +++ b/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0002-lm32.patch @@ -1,7 +1,7 @@ -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 @@ +diff -Nur elf2flt.orig/elf2flt.c elf2flt/elf2flt.c +--- elf2flt.orig/elf2flt.c 2023-09-07 15:59:10.019349031 +0200 ++++ elf2flt/elf2flt.c 2023-09-07 16:40:06.281961316 +0200 +@@ -62,6 +62,8 @@ #include <elf/bfin.h> #elif defined(TARGET_h8300) #include <elf/h8.h> @@ -10,7 +10,7 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl #elif defined(TARGET_m68k) #include <elf/m68k.h> #elif defined(TARGET_microblaze) -@@ -120,6 +122,11 @@ +@@ -123,6 +125,11 @@ #define ARCH "nios" #elif defined(TARGET_nios2) #define ARCH "nios2" @@ -21,8 +21,8 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl +#define FLAT_LM32_RELOC_TYPE_LO16_BIT 2 #elif defined(TARGET_xtensa) #define ARCH "xtensa" - #else -@@ -357,7 +364,7 @@ + #elif defined(TARGET_riscv64) +@@ -373,7 +380,7 @@ int bad_relocs = 0; asymbol **symb; long nsymb; @@ -30,8 +30,8 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl +#if defined (TARGET_bfin) || defined (TARGET_lm32) unsigned long persistent_data = 0; #endif - -@@ -682,6 +689,36 @@ + +@@ -690,6 +697,36 @@ break; default: goto bad_resolved_reloc; @@ -68,7 +68,7 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl #elif defined(TARGET_m68k) case R_68K_32: goto good_32bit_resolved_reloc; -@@ -1459,6 +1496,63 @@ +@@ -1478,6 +1515,63 @@ #undef _30BITS_RELOC #undef _28BITS_RELOC #endif @@ -76,7 +76,7 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl + case R_LM32_32: + { + pflags = FLAT_LM32_RELOC_TYPE_32_BIT << 29; -+ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); ++ sym_vma = elf2flt_bfd_section_vma(sym_section); + sym_addr += sym_vma + q->addend; + relocation_needed = 1; + break; @@ -109,7 +109,7 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl + pflags = FLAT_LM32_RELOC_TYPE_LO16_BIT << 29; + } + -+ sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section); ++ sym_vma = elf2flt_bfd_section_vma(sym_section); + sym_addr += sym_vma + q->addend; + + relocation_needed = 1; @@ -131,8 +131,8 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl +#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 @@ + printf("ERROR: bad reloc type (%s)%d\n", q->howto->name, (*p)->howto->type); +@@ -1616,6 +1710,13 @@ break; #endif @@ -146,14 +146,22 @@ diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2fl 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) +diff -Nur elf2flt.orig/elf2flt.ld.in elf2flt/elf2flt.ld.in +--- elf2flt.orig/elf2flt.ld.in 2023-09-07 11:32:34.223463015 +0200 ++++ elf2flt/elf2flt.ld.in 2023-09-07 16:06:02.781672190 +0200 +@@ -73,6 +73,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.*) +@@ -111,6 +112,7 @@ + R_RODAT: *(.rodata1) + R_RODAT: *(.rodata.*) + R_RODAT: *(.gnu.linkonce.r*) ++R_RODAT: *(.rofixup) + *(.data) + *(.data1) + *(.data.*) diff --git a/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0003-sh2.patch b/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0003-sh2.patch new file mode 100644 index 000000000..9587a0315 --- /dev/null +++ b/toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0003-sh2.patch @@ -0,0 +1,52 @@ +diff -Nur elf2flt-26dfb54a59c8c0106418a0c46ccb4288d9e066fd.orig/elf2flt.c elf2flt-26dfb54a59c8c0106418a0c46ccb4288d9e066fd/elf2flt.c +--- elf2flt-26dfb54a59c8c0106418a0c46ccb4288d9e066fd.orig/elf2flt.c 2023-09-08 08:49:00.529082893 +0200 ++++ elf2flt-26dfb54a59c8c0106418a0c46ccb4288d9e066fd/elf2flt.c 2023-09-08 08:51:08.117679134 +0200 +@@ -75,7 +75,7 @@ + #define FLAT_NIOS2_R_HIADJ_LO 2 + #define FLAT_NIOS2_R_CALL26 4 + #include <elf/nios2.h> +-#elif defined(TARGET_sh) ++#elif defined(TARGET_sh2eb) + #include <elf/sh.h> + #elif defined(TARGET_sparc) + #include <elf/sparc.h> +@@ -111,7 +111,7 @@ + #define ARCH "sparc" + #elif defined(TARGET_v850) + #define ARCH "v850" +-#elif defined(TARGET_sh) ++#elif defined(TARGET_sh2eb) + #define ARCH "sh" + #elif defined(TARGET_h8300) + #define ARCH "h8300" +@@ -795,6 +795,12 @@ + + flat_reloc_count++; + break; ++#elif defined (TARGET_sh2eb) ++ case R_SH_DIR32: ++ goto good_32bit_resolved_reloc; ++ case R_SH_REL32: ++ relocation_needed = 0; ++ continue; + #elif defined (TARGET_h8300) + case R_H8_DIR32: + case R_H8_DIR32A16: +@@ -1328,7 +1334,7 @@ + #endif /* TARGET_sparc */ + + +-#ifdef TARGET_sh ++#ifdef TARGET_sh2eb + case R_SH_DIR32: + relocation_needed = 1; + sym_vma = elf2flt_bfd_section_vma(sym_section); +@@ -1339,7 +1345,7 @@ + sym_addr += sym_vma + q->addend; + sym_addr -= q->address; + break; +-#endif /* TARGET_sh */ ++#endif /* TARGET_sh2eb */ + + #ifdef TARGET_e1 + #define htoe1l(x) htonl(x) diff --git a/toolchain/elf2flt/patches/3051fec89bbd30de6f952dc3100712feff3ca076/0001-.rofixup-fix.patch b/toolchain/elf2flt/patches/3051fec89bbd30de6f952dc3100712feff3ca076/0001-.rofixup-fix.patch new file mode 100644 index 000000000..79186642e --- /dev/null +++ b/toolchain/elf2flt/patches/3051fec89bbd30de6f952dc3100712feff3ca076/0001-.rofixup-fix.patch @@ -0,0 +1,33 @@ +From 270b461e88b47781b3ef9bba2779074d0eb4996b Mon Sep 17 00:00:00 2001 +From: Waldemar Brodkorb <wbx@openadk.org> +Date: Fri, 25 Aug 2023 05:04:53 +0200 +Subject: [PATCH] .rofixup fix + +Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> +--- + elf2flt.ld.in | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/elf2flt.ld.in b/elf2flt.ld.in +index c7e01a6..c69531e 100644 +--- a/elf2flt.ld.in ++++ b/elf2flt.ld.in +@@ -31,6 +31,7 @@ W_RODAT *(.rodata) + W_RODAT *(.rodata1) + W_RODAT *(.rodata.*) + W_RODAT *(.gnu.linkonce.r*) ++W_RODAT *(.rofixup) + + /* This is special code area at the end of the normal + text section. It contains a small lookup table at +@@ -60,6 +61,7 @@ R_RODAT *(.rodata) + R_RODAT *(.rodata1) + R_RODAT *(.rodata.*) + R_RODAT *(.gnu.linkonce.r*) ++R_RODAT *(.rofixup) + *(.data) + *(.data1) + *(.data.*) +-- +2.30.2 + 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"); |