Hi Waldemar, On 19/03/16 13:53, Greg Ungerer wrote: > Hi Waldemar, > > On 14/03/16 15:01, Waldemar Brodkorb wrote: >> Add patchset from ptxdist which is required to produce working >> ARM flat binaries. Tested with busybox on Kinetis K70. >> >> Signed-off-by: Waldemar Brodkorb <w...@openadk.org> > > Thanks. Applied to the github elf2flt repository (with Thomas' > Tested-by).
The adding of the ARM.eidx section in this patch breaks binaries that have a global offset table (GOT). I propose the attached fix that puts it within the data section proper - and not effectively at the start of the data section. The original patch would have no impact on fully relocated binaries, generally only those compiled with -fpic or similar. Regards Greg >> v1 -> v2: >> - segfault problem fixed, r_mem pointer should be initialized >> - v1 was successfully tested by Thomas Petazzoni with buildroot >> generated image for STM32F429 >> >> --- >> elf2flt.c | 11 ++++++++++- >> elf2flt.ld.in | 17 ++++++++++++++--- >> 2 files changed, 24 insertions(+), 4 deletions(-) >> >> diff --git a/elf2flt.c b/elf2flt.c >> index fcd797c..7d0e639 100644 >> --- a/elf2flt.c >> +++ b/elf2flt.c >> @@ -56,6 +56,8 @@ const char *elf2flt_progname; >> >> #if defined(TARGET_h8300) >> #include <elf/h8.h> /* TARGET_* ELF support for the BFD library >> */ >> +#elif defined(TARGET_arm) >> +#include <elf/arm.h> >> #elif defined(__CYGWIN__) || defined(__MINGW32__) || defined(TARGET_nios) >> || defined(TARGET_nios2) >> #include "cygwin-elf.h" /* Cygwin uses a local copy */ >> #elif defined(TARGET_xtensa) >> @@ -451,7 +453,7 @@ dump_symbols(symbols, number_of_symbols); >> qsort (relpp, relcount, sizeof *relpp, compare_relocs); >> #endif >> for (p = relpp; (relcount && (*p != NULL)); p++, relcount--) { >> - unsigned char *r_mem; >> + unsigned char *r_mem = NULL; >> int relocation_needed = 0; >> >> #ifdef TARGET_microblaze >> @@ -646,16 +648,23 @@ dump_symbols(symbols, number_of_symbols); >> default: >> goto good_32bit_resolved_reloc; >> #elif defined(TARGET_arm) >> + case R_ARM_TARGET1: >> + case R_ARM_TARGET2: >> case R_ARM_ABS32: >> relocation_needed = 1; >> break; >> case R_ARM_REL32: >> + case R_ARM_JUMP24: >> + case R_ARM_CALL: >> case R_ARM_THM_PC11: >> case R_ARM_THM_PC22: >> + case R_ARM_THM_JUMP24: >> case R_ARM_PC24: >> case R_ARM_PLT32: >> case R_ARM_GOTPC: >> case R_ARM_GOT32: >> + case R_ARM_PREL31: >> + case R_ARM_NONE: >> relocation_needed = 0; >> break; >> default: >> diff --git a/elf2flt.ld.in b/elf2flt.ld.in >> index bfda0ef..ec1fe6f 100644 >> --- a/elf2flt.ld.in >> +++ b/elf2flt.ld.in >> @@ -35,6 +35,8 @@ W_RODAT *(.rodata1) >> W_RODAT *(.rodata.*) >> W_RODAT *(.gnu.linkonce.r*) >> >> + /* .ARM.extab name sections containing exception unwinding >> information */ >> + *(.ARM.extab* .gnu.linkonce.armextab.*) >> /* This is special code area at the end of the normal >> text section. It contains a small lookup table at >> the start followed by the code pointed to by entries >> @@ -43,11 +45,20 @@ W_RODAT *(.gnu.linkonce.r*) >> PROVIDE(@SYMBOL_PREFIX@__ctbp = .); >> *(.call_table_data) >> *(.call_table_text) >> - >> - . = ALIGN(0x20) ; >> - @SYMBOL_PREFIX@_etext = . ; >> } > flatmem :text >> >> + /* .ARM.exidx name sections containing index entries for section >> unwinding */ >> + /* .ARM.exidx is sorted, so has to go in its own output section. */ >> + @SYMBOL_PREFIX@__exidx_start = .; >> + .ARM.exidx : >> + { >> + *(.ARM.exidx* .gnu.linkonce.armexidx.*) >> + } > flatmem >> + @SYMBOL_PREFIX@__exidx_end = .; >> + >> + . = ALIGN(0x20) ; >> + @SYMBOL_PREFIX@_etext = . ; >> + >> .data : { >> . = ALIGN(0x4) ; >> @SYMBOL_PREFIX@_sdata = . ; >>
>From 78bbedc222a63089befc1d87a42778a6a8e2aa7e Mon Sep 17 00:00:00 2001 From: Greg Ungerer <g...@linux-m68k.org> Date: Thu, 18 Aug 2016 16:39:56 +1000 Subject: [PATCH] elf2flt: move ARM.eidx sections to end of data Currently .ARM.eidx section is put in between the text and data sections of the output binary. But a flat binary really only understands text and data sections, and they are written contiguously to the bariny file. The flat header data start is expected to be the end of the text section. The problem is that the start of the data section may contain a GOT. binfmt_flat header flags the presence of a GOT, and binfmt_flat will simply try to carry out relocations on the start of the data section assuming it is a GOT. But it won't be now if the ARM.eidx section is there. Move the ARM.eidx section into the data section proper. Signed-off-by: Greg Ungerer <g...@uclinux.org> --- elf2flt.ld.in | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/elf2flt.ld.in b/elf2flt.ld.in index ec1fe6f..0f17a9e 100644 --- a/elf2flt.ld.in +++ b/elf2flt.ld.in @@ -45,19 +45,10 @@ W_RODAT *(.gnu.linkonce.r*) PROVIDE(@SYMBOL_PREFIX@__ctbp = .); *(.call_table_data) *(.call_table_text) - } > flatmem :text - /* .ARM.exidx name sections containing index entries for section unwinding */ - /* .ARM.exidx is sorted, so has to go in its own output section. */ - @SYMBOL_PREFIX@__exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > flatmem - @SYMBOL_PREFIX@__exidx_end = .; - - . = ALIGN(0x20) ; - @SYMBOL_PREFIX@_etext = . ; + . = ALIGN(0x20) ; + @SYMBOL_PREFIX@_etext = . ; + } > flatmem :text .data : { . = ALIGN(0x4) ; @@ -158,6 +149,15 @@ TOR: @SYMBOL_PREFIX@__DTOR_END__ = .; KEEP(*(.gcc_except_table.*)) } >flatmem + /* .ARM.exidx name sections containing index entries for section unwinding */ + /* .ARM.exidx is sorted, so has to go in its own output section. */ + @SYMBOL_PREFIX@__exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > flatmem + @SYMBOL_PREFIX@__exidx_end = .; + . = ALIGN(0x10) ; @SYMBOL_PREFIX@_edata = . ; -- 1.9.1
_______________________________________________ uClinux-dev mailing list uClinux-dev@uclinux.org http://mailman.uclinux.org/mailman/listinfo/uclinux-dev This message was resent by uclinux-dev@uclinux.org To unsubscribe see: http://mailman.uclinux.org/mailman/options/uclinux-dev