[U-Boot] [u-boot-mips] gp init and -pie option

Hi,
I got a problem while I was trying out v2013.01.01 on the u-boot-mips fork repo. It looks like my u-boot binary built with "-pie" linker option doesn't work due to wrong "gp" initialization.
In the "start.S" file, the gp is supposed to be initialized with "_gp" because ra will hold the address of ".word _gp" line. The below is part of "start.S".
---------------------------- ... /* Initialize $gp */ bal 1f nop .word _gp 1: lw gp, 0(ra) ... ----------------------------
Without the -pie option, linker puts the start address of the .got section. However, with -pie option, the ".word _gp" is translated to "nop". The below is disassembled code.
---------------------------------------------------------------------------- 84001490 <reset>: ... 840014b8: 40804800 mtc0 zero,c0_count 840014bc: 40805800 mtc0 zero,c0_compare 840014c0: 04110002 bal 840014cc <reset+0x3c> 840014c4: 00000000 nop 840014c8: 00000000 nop <--------------- 840014cc: 8ffc0000 lw gp,0(ra) 840014d0: 3c1d8440 lui sp,0x8440 840014d4: 8f9982c0 lw t9,-32064(gp) 840014d8: 03200008 jr t9 840014dc: 00000000 nop ----------------------------------------------------------------------------
Could anyone tell me what is going on here? Am I missing anything?
Thanks, Justin

2013/2/25 Juhyun (Justin) Oh Juhyun_Oh@sigmadesigns.com:
Hi,
I got a problem while I was trying out v2013.01.01 on the u-boot-mips fork repo. It looks like my u-boot binary built with "-pie" linker option doesn't work due to wrong "gp" initialization.
In the "start.S" file, the gp is supposed to be initialized with "_gp" because ra will hold the address of ".word _gp" line. The below is part of "start.S".
... /* Initialize $gp */ bal 1f nop .word _gp 1: lw gp, 0(ra) ...
Without the -pie option, linker puts the start address of the .got section. However, with -pie option, the ".word _gp" is translated to "nop". The below is disassembled code.
84001490 <reset>: ... 840014b8: 40804800 mtc0 zero,c0_count 840014bc: 40805800 mtc0 zero,c0_compare 840014c0: 04110002 bal 840014cc <reset+0x3c> 840014c4: 00000000 nop 840014c8: 00000000 nop <--------------- 840014cc: 8ffc0000 lw gp,0(ra) 840014d0: 3c1d8440 lui sp,0x8440 840014d4: 8f9982c0 lw t9,-32064(gp) 840014d8: 03200008 jr t9 840014dc: 00000000 nop
Could anyone tell me what is going on here? Am I missing anything?
Thanks, Justin
which board and toolchain do you use?
PIE support has been tested with various toolchains from ELDK, CodeSourcery and OpenWRT.

HI Daniel,
I'm using CodeSourcery 4.5.2. I've configured and have built the code for "incaip" board and "dbau1000". The results are the same. (i.e. gp has been set with wrong value)
Could you tell me the CodeSourcery toolchain versions known to be working? I'd like to try out the same version.
Thanks, Justin
________________________________________ From: Daniel Schwierzeck [daniel.schwierzeck@gmail.com] Sent: Tuesday, February 26, 2013 1:52 AM To: Juhyun (Justin) Oh Cc: u-boot@lists.denx.de Subject: Re: [U-Boot] [u-boot-mips] gp init and -pie option
2013/2/25 Juhyun (Justin) Oh Juhyun_Oh@sigmadesigns.com:
Hi,
I got a problem while I was trying out v2013.01.01 on the u-boot-mips fork repo. It looks like my u-boot binary built with "-pie" linker option doesn't work due to wrong "gp" initialization.
In the "start.S" file, the gp is supposed to be initialized with "_gp" because ra will hold the address of ".word _gp" line. The below is part of "start.S".
... /* Initialize $gp */ bal 1f nop .word _gp 1: lw gp, 0(ra) ...
Without the -pie option, linker puts the start address of the .got section. However, with -pie option, the ".word _gp" is translated to "nop". The below is disassembled code.
84001490 <reset>: ... 840014b8: 40804800 mtc0 zero,c0_count 840014bc: 40805800 mtc0 zero,c0_compare 840014c0: 04110002 bal 840014cc <reset+0x3c> 840014c4: 00000000 nop 840014c8: 00000000 nop <--------------- 840014cc: 8ffc0000 lw gp,0(ra) 840014d0: 3c1d8440 lui sp,0x8440 840014d4: 8f9982c0 lw t9,-32064(gp) 840014d8: 03200008 jr t9 840014dc: 00000000 nop
Could anyone tell me what is going on here? Am I missing anything?
Thanks, Justin
which board and toolchain do you use?
PIE support has been tested with various toolchains from ELDK, CodeSourcery and OpenWRT.
-- Best regards, Daniel

Not to hijack this thread, but I've had trouble with recent (2013.01 and perhaps the last 2012) mainline u-boots for Pandaboard when built using recent Codesourcery Lite tools. I've found that arm-2009q1 and arm-2010q1 work but arm-2012.03 and arm-2012.09 do not. SPL works but u-boot hangs very early.
It's on my list of things to look into.
-Michael Cashwell
On Feb 26, 2013, at 1:12 PM, "Juhyun (Justin) Oh" Juhyun_Oh@sigmadesigns.com wrote:
HI Daniel,
I'm using CodeSourcery 4.5.2. I've configured and have built the code for "incaip" board and "dbau1000". The results are the same. (i.e. gp has been set with wrong value)
Could you tell me the CodeSourcery toolchain versions known to be working? I'd like to try out the same version.
Thanks, Justin
From: Daniel Schwierzeck [daniel.schwierzeck@gmail.com] Sent: Tuesday, February 26, 2013 1:52 AM To: Juhyun (Justin) Oh Cc: u-boot@lists.denx.de Subject: Re: [U-Boot] [u-boot-mips] gp init and -pie option
2013/2/25 Juhyun (Justin) Oh Juhyun_Oh@sigmadesigns.com:
Hi,
I got a problem while I was trying out v2013.01.01 on the u-boot-mips fork repo. It looks like my u-boot binary built with "-pie" linker option doesn't work due to wrong "gp" initialization.
In the "start.S" file, the gp is supposed to be initialized with "_gp" because ra will hold the address of ".word _gp" line. The below is part of "start.S".
... /* Initialize $gp */ bal 1f nop .word _gp 1: lw gp, 0(ra) ...
Without the -pie option, linker puts the start address of the .got section. However, with -pie option, the ".word _gp" is translated to "nop". The below is disassembled code.
84001490 <reset>: ... 840014b8: 40804800 mtc0 zero,c0_count 840014bc: 40805800 mtc0 zero,c0_compare 840014c0: 04110002 bal 840014cc <reset+0x3c> 840014c4: 00000000 nop 840014c8: 00000000 nop <--------------- 840014cc: 8ffc0000 lw gp,0(ra) 840014d0: 3c1d8440 lui sp,0x8440 840014d4: 8f9982c0 lw t9,-32064(gp) 840014d8: 03200008 jr t9 840014dc: 00000000 nop
Could anyone tell me what is going on here? Am I missing anything?
Thanks, Justin
which board and toolchain do you use?
PIE support has been tested with various toolchains from ELDK, CodeSourcery and OpenWRT.
-- Best regards, Daniel _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hi Michael,
I'm not working on ARM, but on MIPS. Your problem is certainly different from mine.
Hi Daniel,
I've tried out "gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-63)", and this version initialize gp register properly.
Thanks, Justin
________________________________________ From: Michael Cashwell [mboards@prograde.net] Sent: Tuesday, February 26, 2013 11:44 AM To: Juhyun (Justin) Oh Cc: Daniel Schwierzeck; u-boot@lists.denx.de Subject: Re: [U-Boot] [u-boot-mips] gp init and -pie option
Not to hijack this thread, but I've had trouble with recent (2013.01 and perhaps the last 2012) mainline u-boots for Pandaboard when built using recent Codesourcery Lite tools. I've found that arm-2009q1 and arm-2010q1 work but arm-2012.03 and arm-2012.09 do not. SPL works but u-boot hangs very early.
It's on my list of things to look into.
-Michael Cashwell
On Feb 26, 2013, at 1:12 PM, "Juhyun (Justin) Oh" Juhyun_Oh@sigmadesigns.com wrote:
HI Daniel,
I'm using CodeSourcery 4.5.2. I've configured and have built the code for "incaip" board and "dbau1000". The results are the same. (i.e. gp has been set with wrong value)
Could you tell me the CodeSourcery toolchain versions known to be working? I'd like to try out the same version.
Thanks, Justin
From: Daniel Schwierzeck [daniel.schwierzeck@gmail.com] Sent: Tuesday, February 26, 2013 1:52 AM To: Juhyun (Justin) Oh Cc: u-boot@lists.denx.de Subject: Re: [U-Boot] [u-boot-mips] gp init and -pie option
2013/2/25 Juhyun (Justin) Oh Juhyun_Oh@sigmadesigns.com:
Hi,
I got a problem while I was trying out v2013.01.01 on the u-boot-mips fork repo. It looks like my u-boot binary built with "-pie" linker option doesn't work due to wrong "gp" initialization.
In the "start.S" file, the gp is supposed to be initialized with "_gp" because ra will hold the address of ".word _gp" line. The below is part of "start.S".
... /* Initialize $gp */ bal 1f nop .word _gp 1: lw gp, 0(ra) ...
Without the -pie option, linker puts the start address of the .got section. However, with -pie option, the ".word _gp" is translated to "nop". The below is disassembled code.
84001490 <reset>: ... 840014b8: 40804800 mtc0 zero,c0_count 840014bc: 40805800 mtc0 zero,c0_compare 840014c0: 04110002 bal 840014cc <reset+0x3c> 840014c4: 00000000 nop 840014c8: 00000000 nop <--------------- 840014cc: 8ffc0000 lw gp,0(ra) 840014d0: 3c1d8440 lui sp,0x8440 840014d4: 8f9982c0 lw t9,-32064(gp) 840014d8: 03200008 jr t9 840014dc: 00000000 nop
Could anyone tell me what is going on here? Am I missing anything?
Thanks, Justin
which board and toolchain do you use?
PIE support has been tested with various toolchains from ELDK, CodeSourcery and OpenWRT.
-- Best regards, Daniel _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hi,
2013/2/26 Juhyun (Justin) Oh Juhyun_Oh@sigmadesigns.com:
HI Daniel,
I'm using CodeSourcery 4.5.2. I've configured and have built the code for "incaip" board and "dbau1000". The results are the same. (i.e. gp has been set with wrong value)
Could you tell me the CodeSourcery toolchain versions known to be working? I'd like to try out the same version.
Which CodeSourcery release do you use?
I have tried following toolchains and all of them have _gp initialized correctly.
Sourcery CodeBench Lite 2011.09-75 gcc version 4.5.2 (Sourcery CodeBench Lite 2011.09-75) GNU ld (Sourcery CodeBench Lite 2011.09-75) 2.21.53.20110905
Sourcery CodeBench Lite 2012.03-63: gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-63) GNU ld (Sourcery CodeBench Lite 2012.03-63) 2.21.53.20110905
ELDK-5.2.1: gcc version 4.6.4 20120303 (prerelease) (GCC) GNU ld (GNU Binutils) 2.22
ELDK-5.3: gcc version 4.7.2 (GCC) GNU ld (GNU Binutils) 2.22

Hi Daniel,
I've verified that the CodeSourcery 4.5.2 and 4.6.3 generate the correct _gp as you mentioned.
Thanks, Justin
________________________________________ From: Daniel Schwierzeck [daniel.schwierzeck@gmail.com] Sent: Tuesday, February 26, 2013 12:34 PM To: Juhyun (Justin) Oh Cc: u-boot@lists.denx.de Subject: Re: [U-Boot] [u-boot-mips] gp init and -pie option
Hi,
2013/2/26 Juhyun (Justin) Oh Juhyun_Oh@sigmadesigns.com:
HI Daniel,
I'm using CodeSourcery 4.5.2. I've configured and have built the code for "incaip" board and "dbau1000". The results are the same. (i.e. gp has been set with wrong value)
Could you tell me the CodeSourcery toolchain versions known to be working? I'd like to try out the same version.
Which CodeSourcery release do you use?
I have tried following toolchains and all of them have _gp initialized correctly.
Sourcery CodeBench Lite 2011.09-75 gcc version 4.5.2 (Sourcery CodeBench Lite 2011.09-75) GNU ld (Sourcery CodeBench Lite 2011.09-75) 2.21.53.20110905
Sourcery CodeBench Lite 2012.03-63: gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-63) GNU ld (Sourcery CodeBench Lite 2012.03-63) 2.21.53.20110905
ELDK-5.2.1: gcc version 4.6.4 20120303 (prerelease) (GCC) GNU ld (GNU Binutils) 2.22
ELDK-5.3: gcc version 4.7.2 (GCC) GNU ld (GNU Binutils) 2.22
-- Best regards, Daniel
participants (3)
-
Daniel Schwierzeck
-
Juhyun (Justin) Oh
-
Michael Cashwell