Skip to contentSkip to conversation

arm: config: enforce -fno-pic for gcc

PATCH New Peng Fan 3 participants 3 messages Jan 30, 2016 – Jan 31, 2016 Arm (32-bit)

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH v2 1/1 arm: config: enforce -fno-pic for gcc

Android's tool chain enable the -mandroid at default. This option will enable the -fpic, which cause uboot compilation failure:
"
LD u-boot
u-boot contains unexpected relocations: R_ARM_ABS32 R_ARM_RELATIVE
"

In my testcase, arm-linux-androideabi-gcc-4.9 internally enables '-fpic', so when compiling code, there will be relocation entries using type R_ARM_GOT_BREL and .got section. When linking all the built-in.o using ld, there will be R_ARM_ABS32 relocation entry and .got section in the final u-boot elf image. This can not be handled by u-boot, since u-boot only expects R_ARM_RELATIVE relocation entry.
arm-poky-linux-gnueabi-gcc-4.9 default does not enable '-fpic', so there is not .got section and R_ARM_GOT_BREL in built-in.o. And in the final u-boot elf image, all relocation entries are R_ARM_RELATIVE.

we can pass '-fno-pic' to xxx-gcc to disable pic. whether the toolchain internally enables or disables pic, '-fno-pic' can work well.

Cc Albert Aribaud <[email protected]>

---

V2:
Drop RFC.

 arch/arm/config.mk | 1 +
 1 file changed, 1 insertion(+)
arch/arm/config.mk +1 -0
index a3e14a8..8fa57ec 100644
@@ -107,6 +107,7 @@ ALL-y += checkarmreloc
 # instruction. Relocation is not supported for that case, so disable
 # such usage by requiring word relocations.
 PLATFORM_CPPFLAGS += $(call cc-option, -mword-relocations)
+PLATFORM_CPPFLAGS += $(call cc-option, -fno-pic)
 endif
 
 # limit ourselves to the sections we want in the .bin.
Signature · 1 line
2.6.2
#1 lore raw

PATCH v2 1/1 arm: config: enforce -fno-pic for gcc

Quoted 22 lines · Peng Fan

Android's tool chain enable the -mandroid at default. This option will enable the -fpic, which cause uboot compilation failure:
"
LD u-boot
u-boot contains unexpected relocations: R_ARM_ABS32 R_ARM_RELATIVE
"

In my testcase, arm-linux-androideabi-gcc-4.9 internally enables '-fpic', so when compiling code, there will be relocation entries using type R_ARM_GOT_BREL and .got section. When linking all the built-in.o using ld, there will be R_ARM_ABS32 relocation entry and .got section in the final u-boot elf image. This can not be handled by u-boot, since u-boot only expects R_ARM_RELATIVE relocation entry.
arm-poky-linux-gnueabi-gcc-4.9 default does not enable '-fpic', so there is not .got section and R_ARM_GOT_BREL in built-in.o. And in the final u-boot elf image, all relocation entries are R_ARM_RELATIVE.

Quoted 6 lines

we can pass '-fno-pic' to xxx-gcc to disable pic. whether the toolchain internally enables or disables pic, '-fno-pic' can work well.

Cc Albert Aribaud <[email protected]>
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160130/07823740/attachment.sig>
#2 lore raw

PATCH v2 1/1 arm: config: enforce -fno-pic for gcc

In reply to Peng Fan

Hello Peng,

Quoted 51 lines · Peng Fan

Android's tool chain enable the -mandroid at default. This option will enable the -fpic, which cause uboot compilation failure:
"
LD u-boot
u-boot contains unexpected relocations: R_ARM_ABS32 R_ARM_RELATIVE
"

In my testcase, arm-linux-androideabi-gcc-4.9 internally enables '-fpic', so when compiling code, there will be relocation entries using type R_ARM_GOT_BREL and .got section. When linking all the built-in.o using ld, there will be R_ARM_ABS32 relocation entry and .got section in the final u-boot elf image. This can not be handled by u-boot, since u-boot only expects R_ARM_RELATIVE relocation entry.
arm-poky-linux-gnueabi-gcc-4.9 default does not enable '-fpic', so there is not .got section and R_ARM_GOT_BREL in built-in.o. And in the final u-boot elf image, all relocation entries are R_ARM_RELATIVE.

we can pass '-fno-pic' to xxx-gcc to disable pic. whether the toolchain internally enables or disables pic, '-fno-pic' can work well.

Cc Albert Aribaud <[email protected]>

---

V2:
Drop RFC.

 arch/arm/config.mk | 1 +
 1 file changed, 1 insertion(+)
arch/arm/config.mk +1 -0
index a3e14a8..8fa57ec 100644
@@ -107,6 +107,7 @@ ALL-y += checkarmreloc
 # instruction. Relocation is not supported for that case, so disable
 # such usage by requiring word relocations.
 PLATFORM_CPPFLAGS += $(call cc-option, -mword-relocations)
+PLATFORM_CPPFLAGS += $(call cc-option, -fno-pic)
 endif
 
 # limit ourselves to the sections we want in the .bin.
Signature · 1 line
2.6.2

Applied to u-boot-arm/master, thanks!

Amicalement,

Signature · 1 line
Albert.