diff mbox

[U-Boot,V2] arm: config: enforce -fno-pic for gcc

Message ID 1454127049-4851-1-git-send-email-peng.fan@nxp.com
State Accepted
Delegated to: Albert ARIBAUD
Headers show

Commit Message

Peng Fan Jan. 30, 2016, 4:10 a.m. UTC
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.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Albert Aribaud <albert.u.boot@aribaud.net>
---

V2:
 Drop RFC.

 arch/arm/config.mk | 1 +
 1 file changed, 1 insertion(+)

Comments

Tom Rini Jan. 30, 2016, 2:59 p.m. UTC | #1
On Sat, Jan 30, 2016 at 12:10:49PM +0800, Peng Fan wrote:

> 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.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> Cc: Albert Aribaud <albert.u.boot@aribaud.net>

Reviewed-by: Tom Rini <trini@konsulko.com>
Albert ARIBAUD Jan. 31, 2016, 3:30 p.m. UTC | #2
Hello Peng,

On Sat, 30 Jan 2016 12:10:49 +0800, Peng Fan <van.freenix@gmail.com> wrote:
> 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.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> Cc: Albert Aribaud <albert.u.boot@aribaud.net>
> ---
> 
> V2:
>  Drop RFC.
> 
>  arch/arm/config.mk | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/config.mk b/arch/arm/config.mk
> index a3e14a8..8fa57ec 100644
> --- a/arch/arm/config.mk
> +++ b/arch/arm/config.mk
> @@ -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.
> -- 
> 2.6.2
> 

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

Amicalement,
diff mbox

Patch

diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index a3e14a8..8fa57ec 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -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.