how to keep some basic relocation information in executable binary

Jason McMullan jason.mcmullan at netronome.com
Thu Oct 8 14:13:39 EDT 2009


On Thu, 2009-10-08 at 06:54 -0700, Peiyu Li wrote:
> I am trying to find a way to build out one ARM-instruction binary that
> can run at any address in the bare metal environment.

Tricky. In my case, I wanted to create a binary that can run from
any address, *including* read-only ROM space.

For my solution, the following requirements were needed:

 * I can have no .data segment (only .rodata)
 * No exceptions (no C++, setjmp or longjmp)

I compile all the objects with "gcc -fpie -fomit-frame-pointer"

I linked with "gcc -static -nodefaultlibs -nostartfiles -Wl,-Ttext=0
-Wl,-Tdata=0"

The .data == .text is just a linker trick to make sure that the
linker dies with an error if any data or bss segment is defined.

Final binary created with "objcopy -O binary file.elf file.bin" 

My 'start.S' routine is as follows:

	.global main
	.global _start
_start:
	ldr	sp, =(CHIP_SRAM_64K - 0xf000)
	b	main

My main.c just has a void main(void) {} routine that works from there.

If you wanted to have a .bss, you can extend your _start to zero it out,
and add -Wl,--section-start=.bss=WHEREVER to locate your BSS at a
constant location.

This may not fully handle what you need, but it may provide you with
some ideas.

-- 
Jason McMullan <jason.mcmullan at netronome.com>
Netronome Systems
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm/attachments/20091008/525041e8/attachment.sig>


More information about the linux-arm mailing list