Skip to contentSkip to conversation

arm: change relocation flag from -fPIC to -fPIE

PATCH New Albert Aribaud 5 participants 13 messages Sep 28, 2010 – Oct 1, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 arm: change relocation flag from -fPIC to -fPIE

Replace GOT indirect addressing with more efficient pic-base relative addressing for initialized data (uninitialized data still use GOTi indirect addressing). This also reduces code size by 0.4% compared to -fPIC.

---
SUMMARY

This patch aims at optimizing relocatable code both in size and speed. The first patch switches from '-fPIC' to '-fPIE', which makes initialized data accesses pc-relative rather than GOT-indirect, and the second adds '-msingle-pic-base' which factors out GOT addressing by computing it once and for all.

PATCHSET HISTORY

V1 Initial submission
V2 Compute RAM pic base only if actually relocating
Fixed RAM pic base computation and copy loop
V3 Added fix for tx25

 arch/arm/config.mk |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/config.mk +1 -1
index 6923f6d..138c43a 100644
@@ -35,7 +35,7 @@ endif
 
 ifndef CONFIG_SYS_ARM_WITHOUT_RELOC
 # needed for relocation
-PLATFORM_RELFLAGS += -fPIC
+PLATFORM_RELFLAGS += -fPIE
 endif
 
 ifdef CONFIG_SYS_ARM_WITHOUT_RELOC
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Add -msingle-pic-base to the relocation flags, and compute the pic base in start.S twice and for all -- once before relocation to run board_init_f, and once after relocation to run board_init_r and the rest of u-boot. This further reduces code size by 2.5% compared to -fPIE alone.

---
 arch/arm/cpu/arm926ejs/config.mk    |    5 ++++
 arch/arm/cpu/arm926ejs/start.S      |   40 +++++++++++++++++++++++++++++-----
 arch/arm/cpu/arm926ejs/u-boot.lds   |    1 +
 board/karo/tx25/config.mk           |    2 +-
 include/configs/tx25.h              |    2 +-
 nand_spl/board/karo/tx25/u-boot.lds |    1 +
 6 files changed, 43 insertions(+), 8 deletions(-)
arch/arm/cpu/arm926ejs/config.mk +5 -0
index f8ef90f..aa84706 100644
@@ -23,6 +23,11 @@
 
 PLATFORM_RELFLAGS += -fno-common -ffixed-r8 -msoft-float
 
+ifndef CONFIG_SYS_ARM_WITHOUT_RELOC
+# needed for optimal relocation
+PLATFORM_RELFLAGS += -msingle-pic-base
+endif
+
 PLATFORM_CPPFLAGS += -march=armv5te
 # =========================================================================
 #
arch/arm/cpu/arm926ejs/start.S +34 -6
index 16ee972..904bd8d 100644
@@ -198,9 +198,23 @@ reset:
 	bl	cpu_init_crit
 #endif
 
-/* Set stackpointer in internal RAM to call board_init_f */
-call_board_init_f:
+	/*
+	 * Set stack pointer in internal RAM
+	 */
 	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
+
+	/*
+	 * Set pic base register to the link-time GOT position.
+	 * At the moment this is also our run-time position.
+	 * Set both r10 and r9 because either could be used as pic base
+	 * depending on whether stack checking is off or on.
+	 */
+	ldr	r10, _got_base
+	mov	r9, r10
+
+	/*
+	 * Call board_init_f, passing it 0 for bootflag
+	 */
 	ldr	r0,=0x00000000
 	bl	board_init_f
 
@@ -220,7 +234,9 @@ relocate_code:
 	mov	r6, r2	/* save addr of destination */
 	mov	r7, r2	/* save addr of destination */
 
-	/* Set up the stack						    */
+	/*
+	 * Set up the stack
+	 */
 stack_setup:
 	mov	sp, r4
 
@@ -234,9 +250,9 @@ stack_setup:
 
 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
 copy_loop:
-	ldmia	r0!, {r9-r10}		/* copy from source address [r0]    */
-	stmia	r6!, {r9-r10}		/* copy to   target address [r1]    */
-	cmp	r0, r2			/* until source end addreee [r2]    */
+	ldmia	r0!, {r11-r12}		/* copy from source address [r0]    */
+	stmia	r6!, {r11-r12}		/* copy to   target address [r6]    */
+	cmp	r0, r2			/* until source end address [r2]    */
 	ble	copy_loop
 
 #ifndef CONFIG_PRELOADER
@@ -259,6 +275,15 @@ fixloop:
 	cmp	r2, r3
 	bne	fixloop
 #endif
+
+	/*
+	 * Fix pic base register as well
+	 */
+	sub	r9, r9, r1
+	add	r9, r9, r0
+	sub	r10, r10, r1
+	add	r10, r10, r0
+
 #endif	/* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
 
 clear_bss:
@@ -305,6 +330,9 @@ _nand_boot: .word nand_boot
 _board_init_r: .word board_init_r
 #endif
 
+_got_base:
+	.word __got_base
+
 #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
 /*
  * the actual reset code
arch/arm/cpu/arm926ejs/u-boot.lds +1 -0
index 02eb8ca..b6e21f2 100644
@@ -53,6 +53,7 @@ SECTIONS
 
 	__got_start = .;
 	. = ALIGN(4);
+	__got_base = .;
 	.got : { *(.got) }
 
 	__got_end = .;
board/karo/tx25/config.mk +1 -1
index 51ca1ab..1a32c87 100644
@@ -1,5 +1,5 @@
 ifdef CONFIG_NAND_SPL
 TEXT_BASE = 0x810c0000
 else
-TEXT_BASE = 0x81fc0000
+TEXT_BASE = 0x81fc1000
 endif
include/configs/tx25.h +1 -1
index c798570..b83c95f 100644
@@ -41,7 +41,7 @@
 #define CONFIG_SYS_NAND_U_BOOT_OFFS	0x800
 #define CONFIG_SYS_NAND_U_BOOT_SIZE	0x30000
 
-#define CONFIG_SYS_NAND_U_BOOT_DST      (0x81fc0000)
+#define CONFIG_SYS_NAND_U_BOOT_DST      (0x81fc1000)
 #define CONFIG_SYS_NAND_U_BOOT_START    CONFIG_SYS_NAND_U_BOOT_DST
 
 #define CONFIG_SYS_NAND_PAGE_SIZE	2048
nand_spl/board/karo/tx25/u-boot.lds +1 -0
index c572557..b60c0df 100644
@@ -55,6 +55,7 @@ SECTIONS
 
 	__got_start = .;
 	. = ALIGN(4);
+	__got_base = .;
 	.got : { *(.got) }
 
 	__got_end = .;
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Quoted 6 lines · Albert Aribaud

Add -msingle-pic-base to the relocation flags, and compute the pic base in start.S twice and for all -- once before relocation to run board_init_f, and once after relocation to run board_init_r and the rest of u-boot. This further reduces code size by 2.5% compared to -fPIE alone.

Applies cleanly to 3df61957938586c512c17e72d83551d190400981 of u-boot/next.

Tested on da850evm -- u-boot prompt is obtained and bootm of linux uImage is possible with the fix for bootparam address on the da850evm.

Best Regards,
Ben Gardiner

---
Nanometrics Inc.
http://www.nanometrics.ca

#3 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Le 28/09/2010 15:39, Ben Gardiner a ?crit :

Quoted 6 lines · Albert Aribaud
Quoted 5 lines

Add -msingle-pic-base to the relocation flags, and compute the pic base in start.S twice and for all -- once before relocation to run board_init_f, and once after relocation to run board_init_r and the rest of u-boot. This further reduces code size by 2.5% compared to -fPIE alone.

Quoted 8 lines
Quoted 1 line

Applies cleanly to 3df61957938586c512c17e72d83551d190400981 of u-boot/next.

Tested on da850evm -- u-boot prompt is obtained and bootm of linux uImage is possible with the fix for bootparam address on the da850evm.

Thanks Ben.

Amicalement,

Signature · 1 line
Albert.
#4 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

In reply to Albert Aribaud

Hello Albert,

Quoted 6 lines · Albert Aribaud

Add -msingle-pic-base to the relocation flags, and compute the pic base in start.S twice and for all -- once before relocation to run board_init_f, and once after relocation to run board_init_r and the rest of u-boot. This further reduces code size by 2.5% compared to -fPIE alone.

Tested on the tx25 board.

bye,
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#5 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Le 28/09/2010 15:57, Heiko Schocher a ?crit :

Quoted 8 lines

Hello Albert,

Quoted 5 lines · Albert Aribaud

Add -msingle-pic-base to the relocation flags, and compute the pic base in start.S twice and for all -- once before relocation to run board_init_f, and once after relocation to run board_init_r and the rest of u-boot. This further reduces code size by 2.5% compared to -fPIE alone.

Quoted 5 lines
Quoted 1 line

Tested on the tx25 board.

Thanks Heiko.

BTW, I forgot to mention that patch 2/2 of this set, being partly written by Heiko for the tx25 part, is

Quoted 2 lines

bye,
Heiko

Amicalement,

Signature · 1 line
Albert.
#6 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Dear Albert ARIBAUD,

Quoted 10 lines · In message <[email protected]> you wrote:
Quoted 2 lines

Thanks Heiko.

BTW, I forgot to mention that patch 2/2 of this set, being partly =

written by Heiko for the tx25 part, is

Do you expect any further work on this, or should we apply this to the public repo now?

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 Those who do not understand Unix are condemned to reinvent it,
poorly. - Henry Spencer, University of Toronto Unix hack

#7 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Hi Wolfgang,

Le 29/09/2010 08:50, Wolfgang Denk a ?crit :

Quoted 12 lines

Dear Albert ARIBAUD,

Quoted 9 lines · In message<[email protected]> you wrote:
Quoted 2 lines

Thanks Heiko.

BTW, I forgot to mention that patch 2/2 of this set, being partly =

written by Heiko for the tx25 part, is

Quoted 8 lines
Quoted 1 line

Do you expect any further work on this, or should we apply this to the public repo now?

Best regards,

Wolfgang Denk

As far as Ben, Heiko and myself are concerned, there is not further work expected on this. You may possibly want acks from custodians, Tom for arm changes and Prafulla for orion5x (marvell) ones.

Amicalement,

Signature · 1 line
Albert.
#8 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Dear Albert ARIBAUD,

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines

Do you expect any further work on this, or should we apply this to the public repo now?

As far as Ben, Heiko and myself are concerned, there is not further work expected on this. You may possibly want acks from custodians, Tom for arm changes and Prafulla for orion5x (marvell) ones.

I'm acting as Tom, and as such you have my ACK.

Prafulla, do you agree that we pull this into mainline?

Best regards,

Wolfgang Denk

Signature · 8 lines
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
Repeat after me:
Usenet is not a word processor; it's a medium where aesthetics count.
Mozilla is not a newsreader; it's a web browser.
Windows is not an operating system; it's a GUI on a program loader.
         -- Tom Christiansen in <[email protected]>
#9 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Le 29/09/2010 10:55, Wolfgang Denk a ?crit :

Quoted 11 lines

Dear Albert ARIBAUD,

Quoted 7 lines · In message<[email protected]> you wrote:
Quoted 3 lines

Do you expect any further work on this, or should we apply this to the public repo now?

As far as Ben, Heiko and myself are concerned, there is not further work expected on this. You may possibly want acks from custodians, Tom for arm changes and Prafulla for orion5x (marvell) ones.

Quoted 7 lines

I'm acting as Tom, and as such you have my ACK.

Prafulla, do you agree that we pull this into mainline?

Best regards,

Wolfgang Denk

Prafulla,

Can you ack these patches -- or nak and comment? I've got new board support code which is waiting for them to get through.

Wolfgang,

Do you need a formal resubmit against master now that next is gone?

Thanks in advance.

Amicalement,

Signature · 1 line
Albert.
#10 lore raw

PATCH v3 2/2 arm926ejs: reduce code size with -msingle-pic-base

Quoted 29 lines

-----Original Message-----
From: Albert ARIBAUD [mailto:albert.aribaud at free.fr]
Sent: Friday, October 01, 2010 10:23 AM
To: Wolfgang Denk
Cc: Prafulla Wadaskar; u-boot at lists.denx.de; hs at denx.de
Subject: Re: [PATCH V3 2/2] [NEXT] arm926ejs: reduce code size with -msingle-pic-base

Le 29/09/2010 10:55, Wolfgang Denk a ?crit :

Quoted 5 lines

Dear Albert ARIBAUD,

Quoted 2 lines · In message<[email protected]> you wrote:
Quoted 2 lines

Do you expect any further work on this, or should we

apply this to the

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

public repo now?

As far as Ben, Heiko and myself are concerned, there is

not further work

Quoted 1 line
Quoted 1 line

expected on this. You may possibly want acks from

custodians, Tom for

Quoted 6 lines
Quoted 1 line

arm changes and Prafulla for orion5x (marvell) ones.

I'm acting as Tom, and as such you have my ACK.

Prafulla, do you agree that we pull this into mainline?

Quoted 8 lines
Quoted 3 lines

Best regards,

Wolfgang Denk

Prafulla,

Can you ack these patches -- or nak and comment? I've got new board support code which is waiting for them to get through.

Agree, Ack for getting it mainlined

Regards..
Prafulla . .

Quoted 11 lines

Wolfgang,

Do you need a formal resubmit against master now that next is gone?

Thanks in advance.

Amicalement,

Signature · 1 line
Albert.
#11 lore raw

PATCH v3 1/2 arm: change relocation flag from -fPIC to -fPIE

In reply to Albert Aribaud
Quoted 6 lines · Albert Aribaud

Replace GOT indirect addressing with more efficient pic-base relative addressing for initialized data (uninitialized data still use GOTi indirect addressing). ?This also reduces code size by 0.4% compared to -fPIC.

Applies cleanly to 3df61957938586c512c17e72d83551d190400981 of u-boot/next.

Tested on da850evm -- u-boot prompt is obtained and bootm of linux uImage is possible with the fix for bootparam address on the da850evm.

Best Regards,
Ben Gardiner

---
Nanometrics Inc.
http://www.nanometrics.ca

#12 lore raw

PATCH v3 1/2 arm: change relocation flag from -fPIC to -fPIE

In reply to Albert Aribaud

Hello Albert,

Quoted 6 lines · Albert Aribaud

Replace GOT indirect addressing with more efficient pic-base relative addressing for initialized data (uninitialized data still use GOTi indirect addressing). This also reduces code size by 0.4% compared to -fPIC.

Tested on the tx25 board.

bye,
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany