summaryrefslogtreecommitdiff
path: root/toolchain/elf2flt/patches
diff options
context:
space:
mode:
Diffstat (limited to 'toolchain/elf2flt/patches')
-rw-r--r--toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0001-riscv32.patch42
-rw-r--r--toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0002-lm32.patch (renamed from toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-lm32.patch)52
-rw-r--r--toolchain/elf2flt/patches/26dfb54a59c8c0106418a0c46ccb4288d9e066fd/0003-sh2.patch52
-rw-r--r--toolchain/elf2flt/patches/3051fec89bbd30de6f952dc3100712feff3ca076/0001-.rofixup-fix.patch33
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0005-elf2flt-add-riscv-64-bits-support.patch137
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0006-lm32.patch190
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0007-dont-waste-space.patch10
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0008-remove_BFD_VMA_FMT.patch125
-rw-r--r--toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0009-no-build-date.patch11
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0001-elf2flt-handle-binutils-2.34.patch377
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0002-elf2flt.ld-reinstate-32-byte-alignment-for-.data-sec.patch81
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0003-elf2flt-add-riscv-64-bits-support.patch103
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0004-elf2flt-create-a-common-helper-function.patch76
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0005-elf2flt-fix-fatal-error-regression-on-m68k-xtensa-ri.patch74
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0006-elf2flt-xtensa-fix-text-relocations.patch25
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0007-riscv32.patch56
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0008-remove_BFD_VMA_FMT.patch97
-rw-r--r--toolchain/elf2flt/patches/v2021.08/0009-riscv.patch11
-rw-r--r--toolchain/elf2flt/patches/v2024.02/0001-sh2.patch43
-rw-r--r--toolchain/elf2flt/patches/v2024.02/0002-h8300.patch20
-rw-r--r--toolchain/elf2flt/patches/v2024.02/0003-riscv64-alignment.patch12
21 files changed, 1605 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/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]);
diff --git a/toolchain/elf2flt/patches/v2021.08/0001-elf2flt-handle-binutils-2.34.patch b/toolchain/elf2flt/patches/v2021.08/0001-elf2flt-handle-binutils-2.34.patch
new file mode 100644
index 000000000..4aa473c24
--- /dev/null
+++ b/toolchain/elf2flt/patches/v2021.08/0001-elf2flt-handle-binutils-2.34.patch
@@ -0,0 +1,377 @@
+From d78acba6510527aaa01a41eaf4c931f7a57e5f44 Mon Sep 17 00:00:00 2001
+From: Romain Naour <romain.naour@smile.fr>
+Date: Wed, 5 Feb 2020 10:31:32 +0100
+Subject: [PATCH] elf2flt: handle binutils >= 2.34
+
+The latest Binutils release (2.34) is not compatible with elf2flt due
+to a change in bfd_section_* macros [1]. The issue has been reported
+to the Binutils mailing list but Alan Modra recommend to bundle
+libbfd library sources into each projects using it [2]. That's
+because the API is not stable over the time without any backward
+compatibility guaranties.
+
+On the other hand, the elf2flt tools needs to support modified
+version of binutils for specific arch/target [3].
+
+Add two tests in the configure script to detect this API change
+in order to support binutils < 2.34 and binutils >= 2.34.
+
+Upstream status: [4]
+
+[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=fd3619828e94a24a92cddec42cbc0ab33352eeb4
+[2] https://sourceware.org/ml/binutils/2020-02/msg00044.html
+[3] https://github.com/uclinux-dev/elf2flt/issues/14
+[4] https://github.com/uclinux-dev/elf2flt/pull/15
+
+Signed-off-by: Romain Naour <romain.naour@smile.fr>
+---
+ configure.ac | 16 +++++++++++
+ elf2flt.c | 81 +++++++++++++++++++++++++++++-----------------------
+ 2 files changed, 61 insertions(+), 36 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index b7db2cb..fdc0876 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -229,6 +229,22 @@ AC_CHECK_FUNCS([ \
+ strsignal \
+ ])