[U-Boot] armv8 relocation questions

Wolfgang Denk wd at denx.de
Mon May 19 20:30:33 CEST 2014


Dear Jeroen Hofstee,

In message <1400523005.1985.33.camel at yellow> you wrote:
> 
> mm, forget about U-Boot for a second and please consider the following,
> complicated, program:

I think we should NOT forget U-Boot, which comes with it's own,
specifically tuned set of compiler options and linker scripts.

> #include <stdio.h>
> 
> int main(int c, char *argv[])
> {
> 	puts("Hello World");
> 	return 0;
> }
> 
> compiled with `aarch64-linux-gnu-gcc -g -Wall hello.c` results in:

I have no idea how the tool chain was configured here, and what the
linker script might look like.

> int main(int c, char *argv[])
> {
>   400590:	a9be7bfd 	stp	x29, x30, [sp,#-32]!
>   400594:	910003fd 	mov	x29, sp
>   400598:	b90013a0 	str	w0, [x29,#16]
>   40059c:	f9000fa1 	str	x1, [x29,#24]
> 	puts("Hello World");
>   4005a0:	90000000 	adrp	x0, 400000 <_init-0x3b8>
>   4005a4:	91194000 	add	x0, x0, #0x650
>   4005a8:	97ffff9e 	bl	400420 <puts at plt>
> 	return 0;
>   4005ac:	52800000 	mov	w0, #0x0                   	// #0
> }
>   4005b0:	a8c27bfd 	ldp	x29, x30, [sp],#32
>   4005b4:	d65f03c0 	ret
> 
> 
> Notice the adrp and hardcoded offset to load the location of the
> argument. The 90000000 decodes to adrp x0, 0, the value of the program
> counter with its lower 12bits cleared -> which is the 400000 when not
> being relocated. Then the harcoded 650 offset is added to point to: 
> 
> Contents of section .rodata:
> 400648 01000200 00000000 48656c6c 6f20576f  ........Hello Wo
> 400658 726c6400 00000000                    rld.....

Maybe.  This is with some (unknown here) specific set of compiler
options and linker statements.  This does not mean that the same or
silimar code will be generated for U-Boot, or - if it really is - that
this has to be like that.  Eventually the tool chain needs some
tweaking flags to tell it that we intend to relocate the image later?

> > The question is - where does such code get emitted?  Is it generated
> > from C code, or manually created assembly?
> > 
> It is generated, there are no literal adrp instructions in U-boot.
> As far as I understand it, it is a compiler feature..

That depends on specific compiler options / linker settings,
eventually?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Intel told us the Pentium would have "RISK" features...


More information about the U-Boot mailing list