diff mbox

[U-Boot,3/5] arm: make relocation symbols compiler-generated

Message ID 1368561780-19104-4-git-send-email-albert.u.boot@aribaud.net
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Commit Message

Albert ARIBAUD May 14, 2013, 8:02 p.m. UTC
This change is only done where needed: some linker
scripts may contain relocation symbols yet remain
unchanged.

__rel_dyn_start, __rel_dyn_end and __dynsym_start
each requires its own output section; putting them
in relocation sections changes the sections' nature
which breaks relocation.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 arch/arm/cpu/ixp/u-boot.lds        |   18 +++++++++++++++---
 arch/arm/cpu/u-boot.lds            |   18 +++++++++++++++---
 arch/arm/lib/relocate.S            |   16 +++-------------
 arch/arm/lib/sections.c            |    3 +++
 board/actux1/u-boot.lds            |   18 +++++++++++++++---
 board/actux2/u-boot.lds            |   18 +++++++++++++++---
 board/actux3/u-boot.lds            |   18 +++++++++++++++---
 board/dvlhost/u-boot.lds           |   18 +++++++++++++++---
 board/freescale/mx31ads/u-boot.lds |   18 +++++++++++++++---
 9 files changed, 111 insertions(+), 34 deletions(-)

Comments

Benoît Thébaudeau May 14, 2013, 10:09 p.m. UTC | #1
Hi Albert,

On Tuesday, May 14, 2013 10:02:58 PM, Albert ARIBAUD wrote:
> This change is only done where needed: some linker
> scripts may contain relocation symbols yet remain
> unchanged.
> 
> __rel_dyn_start, __rel_dyn_end and __dynsym_start
> each requires its own output section; putting them
> in relocation sections changes the sections' nature
> which breaks relocation.
> 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

[...]

> diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
> index 2f22c8c..818735c 100644
> --- a/arch/arm/lib/relocate.S
> +++ b/arch/arm/lib/relocate.S
> @@ -54,12 +54,9 @@ copy_loop:
>  	/*
>  	 * fix .rel.dyn relocations
>  	 */
> -	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
> -	add	r10, r10, r9		/* r10 <- sym table in FLASH */
> -	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
> -	add	r2, r2, r9		/* r2 <- rel dyn start in FLASH */
> -	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
> -	add	r3, r3, r9		/* r3 <- rel dyn end in FLASH */
> +	ldr	r10, =__dynsym_start	/* r10 <- sym table ofs */
> +	ldr	r2, =__rel_dyn_start	/* r2 <- rel dyn start ofs */
> +	ldr	r3, =__rel_dyn_end	/* r3 <- rel dyn end ofs */

'ofs' -> 'in FLASH' in the comments of the 3 lines above.

>  fixloop:
>  	ldr	r0, [r2]		/* r0 <- SRC location to fix up */
>  	add	r0, r0, r9		/* r0 <- DST location to fix up */
> @@ -98,11 +95,4 @@ relocate_done:
>          bx        lr
>  #endif
>  
> -_rel_dyn_start_ofs:
> -	.word __rel_dyn_start - relocate_code
> -_rel_dyn_end_ofs:
> -	.word __rel_dyn_end - relocate_code
> -_dynsym_start_ofs:
> -	.word __dynsym_start - relocate_code
> -
>  ENDPROC(relocate_code)

[...]

Best regards,
Benoît
Albert ARIBAUD May 15, 2013, 6:39 a.m. UTC | #2
Hi Benoît,

On Wed, 15 May 2013 00:09:08 +0200 (CEST), Benoît Thébaudeau
<benoit.thebaudeau@advansee.com> wrote:

> Hi Albert,
> 
> On Tuesday, May 14, 2013 10:02:58 PM, Albert ARIBAUD wrote:
> > This change is only done where needed: some linker
> > scripts may contain relocation symbols yet remain
> > unchanged.
> > 
> > __rel_dyn_start, __rel_dyn_end and __dynsym_start
> > each requires its own output section; putting them
> > in relocation sections changes the sections' nature
> > which breaks relocation.
> > 
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> 
> [...]
> 
> > diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
> > index 2f22c8c..818735c 100644
> > --- a/arch/arm/lib/relocate.S
> > +++ b/arch/arm/lib/relocate.S
> > @@ -54,12 +54,9 @@ copy_loop:
> >  	/*
> >  	 * fix .rel.dyn relocations
> >  	 */
> > -	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
> > -	add	r10, r10, r9		/* r10 <- sym table in FLASH */
> > -	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
> > -	add	r2, r2, r9		/* r2 <- rel dyn start in FLASH */
> > -	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
> > -	add	r3, r3, r9		/* r3 <- rel dyn end in FLASH */
> > +	ldr	r10, =__dynsym_start	/* r10 <- sym table ofs */
> > +	ldr	r2, =__rel_dyn_start	/* r2 <- rel dyn start ofs */
> > +	ldr	r3, =__rel_dyn_end	/* r3 <- rel dyn end ofs */
> 
> 'ofs' -> 'in FLASH' in the comments of the 3 lines above.

You are right that 'ofs' should have disappeared from the comments; but
'in FLASH' is right only for some U-Boots and wrong for others, as some
U-Boots indeed run their board_init_f phase in FLASH, but others run in
DDR and thus, copy themselves to DDR from DDR, not FLASH, notably those
with an SPL.

So the most correct commenting is using 'SRC' and 'DST'; will fix in V3
with 'sym table SRC addr' etc.

> Best regards,
> Benoît

Amicalement,
Albert ARIBAUD May 15, 2013, 6:41 a.m. UTC | #3
On Wed, 15 May 2013 08:39:54 +0200, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> [...] will fix in V3

Make that V2.

Amicalement,
diff mbox

Patch

diff --git a/arch/arm/cpu/ixp/u-boot.lds b/arch/arm/cpu/ixp/u-boot.lds
index 514c6ec..933928a 100644
--- a/arch/arm/cpu/ixp/u-boot.lds
+++ b/arch/arm/cpu/ixp/u-boot.lds
@@ -60,14 +60,26 @@  SECTIONS
 		*(.__image_copy_end)
 	}
 
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	}
+
+	.dynsym_start :
+	{
+		*(.__dynsym_start)
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index 8950f5a..4ba2c38 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -62,14 +62,26 @@  SECTIONS
 		*(.__image_copy_end)
 	}
 
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	}
+
+	.dynsym_start :
+	{
+		*(.__dynsym_start)
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S
index 2f22c8c..818735c 100644
--- a/arch/arm/lib/relocate.S
+++ b/arch/arm/lib/relocate.S
@@ -54,12 +54,9 @@  copy_loop:
 	/*
 	 * fix .rel.dyn relocations
 	 */
-	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
-	add	r10, r10, r9		/* r10 <- sym table in FLASH */
-	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
-	add	r2, r2, r9		/* r2 <- rel dyn start in FLASH */
-	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
-	add	r3, r3, r9		/* r3 <- rel dyn end in FLASH */
+	ldr	r10, =__dynsym_start	/* r10 <- sym table ofs */
+	ldr	r2, =__rel_dyn_start	/* r2 <- rel dyn start ofs */
+	ldr	r3, =__rel_dyn_end	/* r3 <- rel dyn end ofs */
 fixloop:
 	ldr	r0, [r2]		/* r0 <- SRC location to fix up */
 	add	r0, r0, r9		/* r0 <- DST location to fix up */
@@ -98,11 +95,4 @@  relocate_done:
         bx        lr
 #endif
 
-_rel_dyn_start_ofs:
-	.word __rel_dyn_start - relocate_code
-_rel_dyn_end_ofs:
-	.word __rel_dyn_end - relocate_code
-_dynsym_start_ofs:
-	.word __dynsym_start - relocate_code
-
 ENDPROC(relocate_code)
diff --git a/arch/arm/lib/sections.c b/arch/arm/lib/sections.c
index 03e846f..d065942 100644
--- a/arch/arm/lib/sections.c
+++ b/arch/arm/lib/sections.c
@@ -39,3 +39,6 @@  char __bss_start[0] __attribute__((section(".__bss_start")));
 char __bss_end[0] __attribute__((section(".__bss_end")));
 char __image_copy_start[0] __attribute__((section(".__image_copy_start")));
 char __image_copy_end[0] __attribute__((section(".__image_copy_end")));
+char __rel_dyn_start[0] __attribute__((section(".__rel_dyn_start")));
+char __rel_dyn_end[0] __attribute__((section(".__rel_dyn_end")));
+char __dynsym_start[0] __attribute__((section(".__dynsym_start")));
diff --git a/board/actux1/u-boot.lds b/board/actux1/u-boot.lds
index 80db9ff..f9b8c54 100644
--- a/board/actux1/u-boot.lds
+++ b/board/actux1/u-boot.lds
@@ -68,14 +68,26 @@  SECTIONS
 		*(.__image_copy_end)
 	}
 
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	}
+
+	.dynsym_start :
+	{
+		*(.__dynsym_start)
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/board/actux2/u-boot.lds b/board/actux2/u-boot.lds
index 61f2e61..3929694 100644
--- a/board/actux2/u-boot.lds
+++ b/board/actux2/u-boot.lds
@@ -68,14 +68,26 @@  SECTIONS
 		*(.__image_copy_end)
 	}
 
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	}
+
+	.dynsym_start :
+	{
+		*(.__dynsym_start)
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/board/actux3/u-boot.lds b/board/actux3/u-boot.lds
index c1ad8b5..5070354 100644
--- a/board/actux3/u-boot.lds
+++ b/board/actux3/u-boot.lds
@@ -68,14 +68,26 @@  SECTIONS
 		*(.__image_copy_end)
 	}
 
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	}
+
+	.dynsym_start :
+	{
+		*(.__dynsym_start)
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/board/dvlhost/u-boot.lds b/board/dvlhost/u-boot.lds
index 71275c1..bb5fa58 100644
--- a/board/dvlhost/u-boot.lds
+++ b/board/dvlhost/u-boot.lds
@@ -68,14 +68,26 @@  SECTIONS
 		*(.__image_copy_end)
 	}
 
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	}
+
+	.dynsym_start :
+	{
+		*(.__dynsym_start)
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}
 
diff --git a/board/freescale/mx31ads/u-boot.lds b/board/freescale/mx31ads/u-boot.lds
index acb8244..63b5108 100644
--- a/board/freescale/mx31ads/u-boot.lds
+++ b/board/freescale/mx31ads/u-boot.lds
@@ -71,14 +71,26 @@  SECTIONS
 		*(.__image_copy_end)
 	}
 
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	}
+
 	.rel.dyn : {
-		__rel_dyn_start = .;
 		*(.rel*)
-		__rel_dyn_end = .;
+	}
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	}
+
+	.dynsym_start :
+	{
+		*(.__dynsym_start)
 	}
 
 	.dynsym : {
-		__dynsym_start = .;
 		*(.dynsym)
 	}