how to keep some basic relocation information in executable binary

Peiyu Li Peiyu.Li at csr.com
Fri Oct 9 02:14:35 EDT 2009


Hi Jason,

Thanks for your kindly help. 
Your means that you do not use any relocation information at the
run-time? If there is below statements in your code, can it work well? 

typedef void (* PFN_VOID)();
Void func1()
{
......
}

Void main()
{
	PFN_VOID pfnVoid = func1;
     pfnVoid();
}

In this example, func1's link address may be 0x10000, and run-time
address may be 0x20000. If there is not run-time relocation, such as
GOT, how can it get the right run-time address?
 
Peiyu
-----Original Message-----
From: Jason McMullan [mailto:jason.mcmullan at netronome.com] 
Sent: Friday, October 09, 2009 2:14 AM
To: Peiyu Li
Cc: linux-arm at lists.infradead.org
Subject: Re: how to keep some basic relocation information in executable
binary

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


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



More information about the linux-arm mailing list