Browse Source

binutils: update to 2.34

Waldemar Brodkorb 4 years ago
parent
commit
43299210e1

+ 3 - 3
target/config/Config.in.binutils

@@ -8,7 +8,7 @@ default ADK_TOOLCHAIN_BINUTILS_AVR32 if ADK_TARGET_ARCH_AVR32
 default ADK_TOOLCHAIN_BINUTILS_NDS32 if ADK_TARGET_ARCH_NDS32
 default ADK_TOOLCHAIN_BINUTILS_2_28 if ADK_TARGET_CPU_SH_J2
 default ADK_TOOLCHAIN_BINUTILS_2_29 if ADK_TARGET_ARCH_CRIS
-default ADK_TOOLCHAIN_BINUTILS_2_32
+default ADK_TOOLCHAIN_BINUTILS_2_34
 
 config ADK_TOOLCHAIN_BINUTILS_GIT
 	bool "git"
@@ -16,8 +16,8 @@ config ADK_TOOLCHAIN_BINUTILS_GIT
 	depends on !ADK_TARGET_ARCH_CSKY
 	depends on !ADK_TARGET_ARCH_NDS32
 
-config ADK_TOOLCHAIN_BINUTILS_2_32
-	bool "2.32"
+config ADK_TOOLCHAIN_BINUTILS_2_34
+	bool "2.34"
 	depends on !ADK_TARGET_ARCH_ARC
 	depends on !ADK_TARGET_ARCH_AVR32
 	depends on !ADK_TARGET_ARCH_NDS32

+ 3 - 3
toolchain/binutils/Makefile.inc

@@ -2,10 +2,10 @@
 # material, please see the LICENCE file in the top-level directory.
 
 PKG_NAME:=		binutils
-ifeq ($(ADK_TOOLCHAIN_BINUTILS_2_32),y)
-PKG_VERSION:=		2.32
+ifeq ($(ADK_TOOLCHAIN_BINUTILS_2_34),y)
+PKG_VERSION:=		2.34
 PKG_RELEASE:=		1
-PKG_HASH:=		0ab6c55dd86a92ed561972ba15b9b70a8b9f75557f896446c82e8b36e473ee04
+PKG_HASH:=		f00b0e8803dc9bab1e2165bd568528135be734df3fabf8d0161828cd56028952
 PKG_SITES:=		${MASTER_SITE_GNU:=binutils/}
 DISTFILES:=		${PKG_NAME}-${PKG_VERSION}.tar.xz
 endif

+ 3 - 2
toolchain/elf2flt/Makefile

@@ -9,8 +9,8 @@ include $(ADK_TOPDIR)/mk/buildhlp.mk
 ifeq ($(ADK_TOOLCHAIN_BINUTILS_GIT),y)
 BINUTILS_VERSION:=	git
 endif
-ifeq ($(ADK_TOOLCHAIN_BINUTILS_2_32),y)
-BINUTILS_VERSION:=	2.32
+ifeq ($(ADK_TOOLCHAIN_BINUTILS_2_34),y)
+BINUTILS_VERSION:=	2.34
 endif
 ifeq ($(ADK_TOOLCHAIN_BINUTILS_2_29),y)
 BINUTILS_VERSION:=	2.29.1
@@ -20,6 +20,7 @@ BINUTILS_VERSION:=	2.28
 endif
 
 $(WRKBUILD)/.configured:
+	(cd $(WRKBUILD); autoreconf -vif;)
 	(cd $(WRKBUILD); \
 	CPPFLAGS="-idirafter $(ADK_TOPDIR)/adk/include" \
 	./configure --prefix=$(STAGING_HOST_DIR)/usr \

+ 1 - 1
toolchain/elf2flt/Makefile.inc

@@ -2,7 +2,7 @@
 # material, please see the LICENCE file in the top-level directory.
 
 PKG_NAME:=		elf2flt
-PKG_VERSION:=		7e33f28df198c46764021ed14408bd262751e148
+PKG_VERSION:=		453398f917d167f8c308c8f997270c48ae8f8b12
 PKG_GIT:=		hash
 PKG_RELEASE:=		1
 PKG_SITES:=		https://github.com/uclinux-dev/elf2flt.git

+ 391 - 0
toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-elf2flt-handle-binutils-2.34.patch

@@ -0,0 +1,391 @@
+From fa0e77afba7d8d4107af5f8ddc8d38d23c3dd19d 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. The issue has been reported to
+the Binutils mailing list but Alan Modra recommend to bundle libbfd
+library sources into each projects using it [1]. 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 [2].
+
+Add two tests in the configure script to detect this API change
+in order to support binutils < 2.34 and binutils >= 2.34.
+
+[1] https://sourceware.org/ml/binutils/2020-02/msg00044.html
+[2] https://github.com/uclinux-dev/elf2flt/issues/14
+
+Signed-off-by: Romain Naour <romain.naour@smile.fr>
+Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
+---
+ configure.ac | 25 +++++++++++++++++++
+ elf2flt.c    | 81 ++++++++++++++++++++++++++++++++++--------------------------
+ 2 files changed, 71 insertions(+), 35 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index d6b4119..caae869 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -212,6 +212,31 @@ AC_CHECK_FUNCS([ \
+ 	strsignal \
+ ])
+ 
++dnl Various bfd section macros and functions like bfd_section_size() has been
++dnl modified starting binutils >= 2.34.
++dnl Check if the prototype is "bfd_section_size (sec)" or "bfd_section_size(bfd, ptr)"
++if test "$binutils_build_dir" != "NONE"; then
++    CFLAGS="-I$binutils_include_dir -I$bfd_include_dir $CFLAGS"
++fi
++
++AC_TRY_COMPILE([#include <bfd.h>],
++ [const asection *sec; bfd_section_size(sec);],
++ bfd_section_size_macro_has_one_arg=yes,
++ bfd_section_size_macro_has_one_arg=no)
++if test "$bfd_section_size_macro_has_one_arg" = "yes" ; then
++  AC_DEFINE(HAVE_BFD_SECTION_SIZE_MACRO_HAS_ONE_ARG, 1,
++   [define to 1 for binutils >= 2.34])
++fi
++
++AC_TRY_COMPILE([#include <bfd.h>],
++ [const asection *sec; bfd_section_vma(sec);],
++ bfd_section_vma_macro_has_one_arg=yes,
++ bfd_section_vma_macro_has_one_arg=no)
++if test "$bfd_section_vma_macro_has_one_arg" = "yes" ; then
++  AC_DEFINE(HAVE_BFD_SECTION_VMA_MACRO_HAS_ONE_ARG, 1,
++   [define to 1 for binutils >= 2.34])
++fi
++
+ if test "$GCC" = yes ; then
+ 	CFLAGS="-Wall $CFLAGS"
+ 	if test "$werror" = 1 ; then
+diff --git a/elf2flt.c b/elf2flt.c
+index b7c4a49..8dbd9b2 100644
+--- a/elf2flt.c
++++ b/elf2flt.c
+@@ -149,6 +149,17 @@ const char *elf2flt_progname;
+ #define O_BINARY 0
+ #endif
+ 
++#if defined(HAVE_BFD_SECTION_SIZE_MACRO_HAS_ONE_ARG)
++#define elf2flt_bfd_section_size(abs_bfd, s) bfd_section_size(s)
++#else
++#define elf2flt_bfd_section_size(abs_bfd, s) bfd_section_size(abs_bfd, s)
++#endif
++
++#if defined(HAVE_BFD_SECTION_VMA_MACRO_HAS_ONE_ARG)
++#define elf2flt_bfd_section_vma(abs_bfd, s)  bfd_section_vma(s)
++#else
++#define elf2flt_bfd_section_vma(abs_bfd, s)  bfd_section_vma(abs_bfd, s)
++#endif
+ 
+ /* Extra output when running.  */
+ static int verbose = 0;
+@@ -323,9 +334,9 @@ compare_relocs (const void *pa, const void *pb)
+ 	else if (!rb->sym_ptr_ptr || !*rb->sym_ptr_ptr)
+ 		return 1;
+ 
+-	a_vma = bfd_section_vma(compare_relocs_bfd,
++	a_vma = elf2flt_bfd_section_vma(compare_relocs_bfd,
+ 				(*(ra->sym_ptr_ptr))->section);
+-	b_vma = bfd_section_vma(compare_relocs_bfd,
++	b_vma = elf2flt_bfd_section_vma(compare_relocs_bfd,
+ 				(*(rb->sym_ptr_ptr))->section);
+ 	va = (*(ra->sym_ptr_ptr))->value + a_vma + ra->addend;
+ 	vb = (*(rb->sym_ptr_ptr))->value + b_vma + rb->addend;
+@@ -403,7 +414,7 @@ output_relocs (
+   }
+ 
+   for (a = abs_bfd->sections; (a != (asection *) NULL); a = a->next) {
+-  	section_vma = bfd_section_vma(abs_bfd, a);
++	section_vma = elf2flt_bfd_section_vma(abs_bfd, a);
+ 
+ 	if (verbose)
+ 		printf("SECTION: %s [%p]: flags=0x%x vma=0x%"PRIx32"\n",
+@@ -442,7 +453,7 @@ output_relocs (
+ 	  continue;
+ 	if (verbose)
+ 	  printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%"BFD_VMA_FMT"x\n",
+-			r->name, r, r->flags, bfd_section_vma(abs_bfd, r));
++			r->name, r, r->flags, elf2flt_bfd_section_vma(abs_bfd, r));
+   	if ((r->flags & SEC_RELOC) == 0)
+   	  continue;
+ 	relsize = bfd_get_reloc_upper_bound(rel_bfd, r);
+@@ -674,7 +685,7 @@ output_relocs (
+ 				case R_BFIN_RIMM16:
+ 				case R_BFIN_LUIMM16:
+ 				case R_BFIN_HUIMM16:
+-				    sym_vma = bfd_section_vma(abs_bfd, sym_section);
++				    sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 				    sym_addr += sym_vma + q->addend;
+ 
+ 				    if (weak_und_symbol(sym_section->name, (*(q->sym_ptr_ptr))))
+@@ -707,7 +718,7 @@ output_relocs (
+ 				    break;
+ 
+ 				case R_BFIN_BYTE4_DATA:
+-				    sym_vma = bfd_section_vma(abs_bfd, sym_section);
++				    sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 				    sym_addr += sym_vma + q->addend;
+ 
+ 				    if (weak_und_symbol (sym_section->name, (*(q->sym_ptr_ptr))))
+@@ -851,7 +862,7 @@ output_relocs (
+ #if defined(TARGET_m68k)
+ 				case R_68K_32:
+ 					relocation_needed = 1;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					break;
+ 				case R_68K_PC16:
+@@ -876,7 +887,7 @@ output_relocs (
+ 							q->address, sym_addr,
+ 							(*p)->howto->rightshift,
+ 							*(uint32_t *)r_mem);
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					break;
+ 				case R_ARM_GOT32:
+@@ -904,7 +915,7 @@ output_relocs (
+ #ifdef TARGET_v850
+ 				case R_V850_ABS32:
+ 					relocation_needed = 1;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					break;
+ 				case R_V850_ZDA_16_16_OFFSET:
+@@ -926,7 +937,7 @@ output_relocs (
+ 					sym_addr = (*(q->sym_ptr_ptr))->value;
+ 					q->address -= 1;
+ 					r_mem -= 1; /* tracks q->address */
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					sym_addr |= (*(unsigned char *)r_mem<<24);
+ 					break;
+@@ -939,7 +950,7 @@ output_relocs (
+ 					/* Absolute symbol done not relocation */
+ 					relocation_needed = !bfd_is_abs_section(sym_section);
+ 					sym_addr = (*(q->sym_ptr_ptr))->value;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					break;
+ 				case R_H8_DIR32:
+@@ -952,7 +963,7 @@ output_relocs (
+ 					}
+ 					relocation_needed = 1;
+ 					sym_addr = (*(q->sym_ptr_ptr))->value;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					break;
+ 				case R_H8_PCREL16:
+@@ -985,7 +996,7 @@ output_relocs (
+ 					pflags=0x80000000;
+ 
+ 					/* work out the relocation */
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					/* Write relocated pointer back */
+ 					p[2] = (sym_addr >> 24) & 0xff;
+@@ -1001,7 +1012,7 @@ output_relocs (
+ 					relocation_needed = 0;
+ 					pflags = 0;
+ 			sprintf(&addstr[0], "+0x%ld", sym_addr - (*(q->sym_ptr_ptr))->value -
+-					 bfd_section_vma(abs_bfd, sym_section));
++					 elf2flt_bfd_section_vma(abs_bfd, sym_section));
+ 			if (verbose)
+ 				printf("  RELOC[%d]: offset=0x%"BFD_VMA_FMT"x symbol=%s%s "
+ 					"section=%s size=%d "
+@@ -1017,7 +1028,7 @@ output_relocs (
+ 					continue;
+ 				}
+ 				case R_MICROBLAZE_32:
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					relocation_needed = 1;
+ 					break;
+@@ -1042,7 +1053,7 @@ output_relocs (
+ 				case R_NIOS2_BFD_RELOC_32:
+ 					relocation_needed = 1;
+ 					pflags = (FLAT_NIOS2_R_32 << 28);
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					/* modify target, in target order */
+ 					*(unsigned long *)r_mem = htoniosl(sym_addr);
+@@ -1052,7 +1063,7 @@ output_relocs (
+ 					unsigned long exist_val;
+ 					relocation_needed = 1;
+ 					pflags = (FLAT_NIOS2_R_CALL26 << 28);
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					
+ 					/* modify target, in target order */
+@@ -1083,7 +1094,7 @@ output_relocs (
+ 								? FLAT_NIOS2_R_HIADJ_LO : FLAT_NIOS2_R_HI_LO;
+ 							pflags <<= 28;
+ 						
+-							sym_vma = bfd_section_vma(abs_bfd, sym_section);
++							sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 							sym_addr += sym_vma + q->addend;
+ 
+ 							/* modify high 16 bits, in target order */
+@@ -1116,7 +1127,7 @@ output_relocs (
+ 						goto NIOS2_RELOC_ERR;
+ 					}
+ 					/* _gp holds a absolute value, otherwise the ld cannot generate correct code */
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					//printf("sym=%x, %d, _gp=%x, %d\n", sym_addr+sym_vma, sym_addr+sym_vma, gp, gp);
+ 					sym_addr += sym_vma + q->addend;
+ 					sym_addr -= gp;
+@@ -1197,7 +1208,7 @@ NIOS2_RELOC_ERR:
+ 				case R_SPARC_32:
+ 				case R_SPARC_UA32:
+ 					relocation_needed = 1;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					break;
+ 				case R_SPARC_PC22:
+@@ -1216,7 +1227,7 @@ NIOS2_RELOC_ERR:
+ 				case R_SPARC_HI22:
+ 					relocation_needed = 1;
+ 					pflags = 0x80000000;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					sym_addr |= (
+ 						htonl(*(uint32_t *)r_mem)
+@@ -1226,7 +1237,7 @@ NIOS2_RELOC_ERR:
+ 				case R_SPARC_LO10:
+ 					relocation_needed = 1;
+ 					pflags = 0x40000000;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					sym_addr &= 0x000003ff;
+ 					sym_addr |= (
+@@ -1240,7 +1251,7 @@ NIOS2_RELOC_ERR:
+ #ifdef TARGET_sh
+ 				case R_SH_DIR32:
+ 					relocation_needed = 1;
+-					sym_vma = bfd_section_vma(abs_bfd, sym_section);
++					sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 					sym_addr += sym_vma + q->addend;
+ 					break;
+ 				case R_SH_REL32:
+@@ -1272,7 +1283,7 @@ NIOS2_RELOC_ERR:
+ 				case R_E1_CONST31:
+ 						relocation_needed = 1;
+ 						DBG_E1("Handling Reloc <CONST31>\n");
+-						sec_vma = bfd_section_vma(abs_bfd, sym_section);
++						sec_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 						DBG_E1("sec_vma : [0x%x], sym_addr : [0x%x], q->address : [0x%x]\n",
+ 										sec_vma, sym_addr, q->address);
+ 						sym_addr = sec_vma + sym_addr;
+@@ -1287,7 +1298,7 @@ NIOS2_RELOC_ERR:
+ 						relocation_needed = 0;
+ 						DBG_E1("Handling Reloc <CONST31_PCREL>\n");
+ 						DBG_E1("DONT RELOCATE AT LOADING\n");
+-						sec_vma = bfd_section_vma(abs_bfd, sym_section);
++						sec_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 						DBG_E1("sec_vma : [0x%x], sym_addr : [0x%x], q->address : [0x%x]\n",
+ 										sec_vma, sym_addr, q->address);
+ 						sym_addr =  sec_vma + sym_addr;
+@@ -1314,7 +1325,7 @@ NIOS2_RELOC_ERR:
+ 						relocation_needed = 0;
+ 						DBG_E1("Handling Reloc <DIS29W_PCREL>\n");
+ 						DBG_E1("DONT RELOCATE AT LOADING\n");
+-						sec_vma = bfd_section_vma(abs_bfd, sym_section);
++						sec_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 						DBG_E1("sec_vma : [0x%x], sym_addr : [0x%x], q->address : [0x%x]\n",
+ 										sec_vma, sym_addr, q->address);
+ 						sym_addr =  sec_vma + sym_addr;
+@@ -1347,7 +1358,7 @@ NIOS2_RELOC_ERR:
+ 						DBG_E1("Handling Reloc <DIS29B>\n");
+ DIS29_RELOCATION:
+ 						relocation_needed = 1;
+-						sec_vma = bfd_section_vma(abs_bfd, sym_section);
++						sec_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 						DBG_E1("sec_vma : [0x%x], sym_addr : [0x%08x]\n",
+ 										sec_vma, sym_addr);
+ 						sym_addr =  sec_vma + sym_addr;
+@@ -1364,7 +1375,7 @@ DIS29_RELOCATION:
+ 						relocation_needed = 0;
+ 						DBG_E1("Handling Reloc <IMM32_PCREL>\n");
+ 						DBG_E1("DONT RELOCATE AT LOADING\n");
+-						sec_vma = bfd_section_vma(abs_bfd, sym_section);
++						sec_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 						DBG_E1("sec_vma : [0x%x], sym_addr : [0x%x]\n",
+ 										sec_vma, sym_addr);
+ 						sym_addr =  sec_vma + sym_addr;
+@@ -1390,7 +1401,7 @@ DIS29_RELOCATION:
+ 				case R_E1_IMM32:
+ 						relocation_needed = 1;
+ 						DBG_E1("Handling Reloc <IMM32>\n");
+-						sec_vma = bfd_section_vma(abs_bfd, sym_section);
++						sec_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 						DBG_E1("sec_vma : [0x%x], sym_addr : [0x%x]\n",
+ 										sec_vma, sym_addr);
+ 						sym_addr =  sec_vma + sym_addr;
+@@ -1406,7 +1417,7 @@ DIS29_RELOCATION:
+ 				case R_E1_WORD:
+ 						relocation_needed = 1;
+ 						DBG_E1("Handling Reloc <WORD>\n");
+-						sec_vma = bfd_section_vma(abs_bfd, sym_section);
++						sec_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
+ 						DBG_E1("sec_vma : [0x%x], sym_addr : [0x%x]\n",
+ 										sec_vma, sym_addr);
+ 						sym_addr =  sec_vma + sym_addr;
+@@ -1433,7 +1444,7 @@ DIS29_RELOCATION:
+ 			}
+ 
+ 			sprintf(&addstr[0], "+0x%lx", sym_addr - (*(q->sym_ptr_ptr))->value -
+-					 bfd_section_vma(abs_bfd, sym_section));
++					 elf2flt_bfd_section_vma(abs_bfd, sym_section));
+ 
+ 
+ 			/*
+@@ -1873,8 +1884,8 @@ int main(int argc, char *argv[])
+     } else
+       continue;
+ 
+-    sec_size = bfd_section_size(abs_bfd, s);
+-    sec_vma  = bfd_section_vma(abs_bfd, s);
++    sec_size = elf2flt_bfd_section_size(abs_bfd, s);
++    sec_vma  = elf2flt_bfd_section_vma(abs_bfd, s);
+ 
+     if (sec_vma < *vma) {
+       if (*len > 0)
+@@ -1899,7 +1910,7 @@ int main(int argc, char *argv[])
+     if (s->flags & SEC_CODE) 
+       if (!bfd_get_section_contents(abs_bfd, s,
+ 				   text + (s->vma - text_vma), 0,
+-				   bfd_section_size(abs_bfd, s)))
++				   elf2flt_bfd_section_size(abs_bfd, s)))
+       {
+ 	fatal("read error section %s", s->name);
+       }
+@@ -1925,7 +1936,7 @@ int main(int argc, char *argv[])
+     if (s->flags & SEC_DATA) 
+       if (!bfd_get_section_contents(abs_bfd, s,
+ 				   data + (s->vma - data_vma), 0,
+-				   bfd_section_size(abs_bfd, s)))
++				   elf2flt_bfd_section_size(abs_bfd, s)))
+       {
+ 	fatal("read error section %s", s->name);
+       }
+-- 
+2.11.0
+

+ 159 - 0
toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0001-lm32.patch

@@ -0,0 +1,159 @@
+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.*)

+ 43 - 0
toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0002-sh2.patch

@@ -0,0 +1,43 @@
+diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.c
+--- elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c	2017-10-03 10:36:02.718919968 +0200
++++ elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.c	2017-10-03 10:37:42.402568044 +0200
+@@ -74,7 +74,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_sh2) || defined(TARGET_sh2eb)
+ #include <elf/sh.h>
+ #elif defined(TARGET_sparc)
+ #include <elf/sparc.h>
+@@ -108,8 +108,10 @@
+ #define	ARCH	"sparc"
+ #elif defined(TARGET_v850)
+ #define	ARCH	"v850"
+-#elif defined(TARGET_sh)
+-#define	ARCH	"sh"
++#elif defined(TARGET_sh2)
++#define	ARCH	"sh2"
++#elif defined(TARGET_sh2eb)
++#define	ARCH	"sh2"
+ #elif defined(TARGET_h8300)
+ #define	ARCH	"h8300"
+ #elif defined(TARGET_microblaze)
+@@ -1309,7 +1311,7 @@
+ #endif /* TARGET_sparc */
+ 
+ 
+-#ifdef TARGET_sh
++#if defined(TARGET_sh2) || defined(TARGET_sh2eb)
+ 				case R_SH_DIR32:
+ 					relocation_needed = 1;
+ 					sym_vma = bfd_section_vma(abs_bfd, sym_section);
+@@ -1320,7 +1322,7 @@
+ 					sym_addr += sym_vma + q->addend;
+ 					sym_addr -= q->address;
+ 					break;
+-#endif /* TARGET_sh */
++#endif /* TARGET_sh2 / TARGET_sh2eb */
+ 
+ #ifdef TARGET_e1
+ #define  htoe1l(x)              htonl(x)

+ 20 - 0
toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0003-h8300.patch

@@ -0,0 +1,20 @@
+diff -Nur elf2flt-7e33f28df198c46764021ed14408bd262751e148.orig/flthdr.c elf2flt-7e33f28df198c46764021ed14408bd262751e148/flthdr.c
+--- elf2flt-7e33f28df198c46764021ed14408bd262751e148.orig/flthdr.c	2019-09-30 22:07:49.000000000 +0200
++++ elf2flt-7e33f28df198c46764021ed14408bd262751e148/flthdr.c	2020-03-09 14:41:48.348042903 +0100
+@@ -164,8 +164,16 @@
+ 				r = ntohl(relocs[i]);
+ 				raddr = flat_get_relocate_addr(r);
+ 				printf("    %u\t0x%08lx (0x%08"PRIx32")\t", i, r, raddr);
++#if defined(TARGET_h8300)
++				raddr &= ~0x00000001;
++#endif
+ 				fseek_stream(&ifp, sizeof(old_hdr) + raddr, SEEK_SET);
+ 				fread_stream(&addr, sizeof(addr), 1, &ifp);
++#if defined(TARGET_h8300)
++				addr = ntohl(addr);
++				if (r & 1)
++					addr &= 0x00ffffff;
++#endif
+ 				printf("%"PRIx32"\n", addr);
+ 			}
+