Hi Waldemar,

On 19/08/16 08:48, Waldemar Brodkorb wrote:
> Hi Greg,
> Greg Ungerer wrote,
> 
>> 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.
> 
> I tested your patch with Buildroot on a STM32F29 device, but it
> fails on boot while executing one of the startup scripts:
> 
> [    0.650000] STM32 USART driver initialized
> [    0.650000] 40011000.serial: ttyS0 at MMIO 0x40011000 (irq = 17, base_baud 
> = 5625000) is a stm32-usart
> [    0.890000] console [ttyS0] enabled
> [    0.910000] Freeing unused kernel memory: 12K (9000a000 - 9000d000) In
> [    1.260000]
> [    1.260000] Unhandled exception: IPSR = 00000003 LR = fffffff1
> [    1.260000] CPU: 0 PID: 26 Comm: S20urandom Not tainted 4.5.0 #2
> [    1.260000] Hardware name: STM32 (Device Tree Support)
> [    1.260000] task: 90550000 ti: 9055a000 task.ti: 9055a000
> [    1.260000] PC is at 0x21000000
> [    1.260000] LR is at 0xfffffffd
> [    1.260000] pc : [<21000000>]    lr : [<fffffffd>]    psr: 40000035
> [    1.260000] sp : 9055bff8  ip : 9055bfe0  fp : 90555008
> [    1.260000] r10: 00000000  r9 : 00000003  r8 : 00000024
> [    1.260000] r7 : 00000072  r6 : 906ccad8  r5 : 00000000  r4 : 00000072
> [    1.260000] r3 : 00000000  r2 : 00000003  r1 : 906ccafc  r0 : ffffffff
> [    1.260000] xPSR: 40000035
> [    1.260000] CPU: 0 PID: 26 Comm: S20urandom Not tainted 4.5.0 #2
> [    1.260000] Hardware name: STM32 (Device Tree Support)
> [    1.260000] [<0800bd41>] (unwind_backtrace) from [<0800b0df>] 
> (show_stack+0xb/0xc)
> [    1.260000] [<0800b0df>] (show_stack) from [<0800b68f>] 
> (__invalid_entry+0x4b/0x4c)
> 
> Without the patch the system boots up fine.

Ok, thanks for the feedback.

Can you try this patch instead then?
It keeps the ARM.edix table at the same relative position, but moves
the _etext symbol to be after the ARM.eidx table. The ARM.eidx section
is marked as read-only in the linked ELF file.

Regards
Greg


>From e50c50accd2505877df19569d3671d06b786aed2 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.

The ARM.eidx section is marked as a read-only ELF section, so lets move it
into the text section proper. This moves the _etext symbol to be after the
ARM.edix section - and keeps the GOT at the start of the data section

Signed-off-by: Greg Ungerer <g...@uclinux.org>
---
 elf2flt.ld.in | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/elf2flt.ld.in b/elf2flt.ld.in
index ec1fe6f..2520ed1 100644
--- a/elf2flt.ld.in
+++ b/elf2flt.ld.in
@@ -45,16 +45,18 @@ W_RODAT		*(.gnu.linkonce.r*)
 		PROVIDE(@SYMBOL_PREFIX@__ctbp = .);
 		*(.call_table_data)
 		*(.call_table_text)
+
+		. = ALIGN(0x20) ;
 	} > 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 = .;
+	__exidx_start = .;
 	.ARM.exidx :
 	{
 		*(.ARM.exidx* .gnu.linkonce.armexidx.*)
-	} > flatmem
-	@SYMBOL_PREFIX@__exidx_end = .;
+	} > flatmem :text
+	__exidx_end = .;
 
 	. = ALIGN(0x20) ;
 	@SYMBOL_PREFIX@_etext = . ;
-- 
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

Reply via email to