diff mbox

[v2,07/17] uclibc: disable DOPIC on ARM FLAT

Message ID 1458335299-27409-8-git-send-email-thomas.petazzoni@free-electrons.com
State Accepted
Headers show

Commit Message

Thomas Petazzoni March 18, 2016, 9:08 p.m. UTC
As explained by Waldemar, enabling DOPIC in uClibc will lead to the
creation of a Position Independent library. In turn, this will cause
elf2flt to generate a "Has-PIC-GOT" flat binary, which doesn't work on
ARM. In fact, elf2flt on ARM really expect to have non-PIC code as
input, so we must disable DOPIC in the uClibc configuration.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 package/uclibc/uclibc.mk | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Arnout Vandecappelle March 19, 2016, 4:11 p.m. UTC | #1
On 03/18/16 22:08, Thomas Petazzoni wrote:
> As explained by Waldemar, enabling DOPIC in uClibc will lead to the
> creation of a Position Independent library. In turn, this will cause
> elf2flt to generate a "Has-PIC-GOT" flat binary, which doesn't work on
> ARM. In fact, elf2flt on ARM really expect to have non-PIC code as
                                       ^^^^^^expects

> input, so we must disable DOPIC in the uClibc configuration.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

  Otherwise:
Reviewed-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>


  Though I wonder: shouldn't uClibc detect this by itself? Similar to the BX 
handling that you removed. Adding Waldemar in Cc to think about this.

  Regards,
  Arnout


> ---
>   package/uclibc/uclibc.mk | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/package/uclibc/uclibc.mk b/package/uclibc/uclibc.mk
> index ad94494..e3e45f7 100644
> --- a/package/uclibc/uclibc.mk
> +++ b/package/uclibc/uclibc.mk
> @@ -82,6 +82,12 @@ ifeq ($(BR2_GCC_VERSION_4_7_X)$(BR2_GCC_VERSION_4_8_X):$(BR2_ARM_INSTRUCTIONS_TH
>   UCLIBC_EXTRA_CFLAGS += -marm
>   endif
>
> +ifeq ($(BR2_BINFMT_FLAT),y)
> +define UCLIBC_ARM_BINFMT_FLAT
> +	$(call KCONFIG_DISABLE_OPT,DOPIC,$(@D)/.config)
> +endef
> +endif
> +
>   endif # arm
>
>   #
> @@ -354,6 +360,7 @@ define UCLIBC_KCONFIG_FIXUP_CMDS
>   	$(UCLIBC_ARC_TYPE_CONFIG)
>   	$(UCLIBC_ARC_PAGE_SIZE_CONFIG)
>   	$(UCLIBC_ARM_ABI_CONFIG)
> +	$(UCLIBC_ARM_BINFMT_FLAT)
>   	$(UCLIBC_MIPS_ABI_CONFIG)
>   	$(UCLIBC_MIPS_ISA_CONFIG)
>   	$(UCLIBC_SH_TYPE_CONFIG)
>
Ezequiel Garcia March 19, 2016, 7:27 p.m. UTC | #2
+Waldemar

On 18 March 2016 at 18:08, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> As explained by Waldemar, enabling DOPIC in uClibc will lead to the
> creation of a Position Independent library. In turn, this will cause
> elf2flt to generate a "Has-PIC-GOT" flat binary, which doesn't work on
> ARM. In fact, elf2flt on ARM really expect to have non-PIC code as
> input, so we must disable DOPIC in the uClibc configuration.
>

While testing on LPC4350, I found that Lua is built with the Has-PIC-GOT flag:

$ output/host/usr/bin/arm-buildroot-uclinux-uclibcgnueabi-flthdr
output/target/usr/bin/lua
output/target/usr/bin/lua
    Magic:        bFLT
    Rev:          4
    Build Date:   Sat Mar 19 16:14:03 2016
    Entry:        0x45
    Data Start:   0x1f08c
    Data End:     0x23ed8
    BSS End:      0x260c0
    Stack Size:   0x1000
    Reloc Start:  0x23ed8
    Reloc Count:  0x214
    Flags:        0x2 ( Has-PIC-GOT )

The Lua interpreter is not loaded by the binfmt_flat loader, and the
kernel says:

  BINFMT_FLAT: reloc outside program 0x7fffd3e4 (0 - 0x26080/0x1f04c),
killing lua!

When DEBUG is defined in fs/binfmt_flat.c, the kernel says:

  BINFMT_FLAT: reference 0xffd3e4 to shared library 127, killing lua!

On the other side, atftp throws the same error:

  BINFMT_FLAT: reference 0xa0100 to shared library 161, killing atftp!

Any ideas?
Thomas Petazzoni March 19, 2016, 8:50 p.m. UTC | #3
Hello,

On Sat, 19 Mar 2016 16:27:19 -0300, Ezequiel Garcia wrote:

> On 18 March 2016 at 18:08, Thomas Petazzoni
> <thomas.petazzoni@free-electrons.com> wrote:
> > As explained by Waldemar, enabling DOPIC in uClibc will lead to the
> > creation of a Position Independent library. In turn, this will cause
> > elf2flt to generate a "Has-PIC-GOT" flat binary, which doesn't work on
> > ARM. In fact, elf2flt on ARM really expect to have non-PIC code as
> > input, so we must disable DOPIC in the uClibc configuration.
> >
> 
> While testing on LPC4350, I found that Lua is built with the Has-PIC-GOT flag:
> 
> $ output/host/usr/bin/arm-buildroot-uclinux-uclibcgnueabi-flthdr
> output/target/usr/bin/lua
> output/target/usr/bin/lua
>     Magic:        bFLT
>     Rev:          4
>     Build Date:   Sat Mar 19 16:14:03 2016
>     Entry:        0x45
>     Data Start:   0x1f08c
>     Data End:     0x23ed8
>     BSS End:      0x260c0
>     Stack Size:   0x1000
>     Reloc Start:  0x23ed8
>     Reloc Count:  0x214
>     Flags:        0x2 ( Has-PIC-GOT )
> 
> The Lua interpreter is not loaded by the binfmt_flat loader, and the
> kernel says:
> 
>   BINFMT_FLAT: reloc outside program 0x7fffd3e4 (0 - 0x26080/0x1f04c),
> killing lua!
> 
> When DEBUG is defined in fs/binfmt_flat.c, the kernel says:
> 
>   BINFMT_FLAT: reference 0xffd3e4 to shared library 127, killing lua!
> 
> On the other side, atftp throws the same error:
> 
>   BINFMT_FLAT: reference 0xa0100 to shared library 161, killing atftp!
> 
> Any ideas?

Thanks for this testing. Is lua using threads by any chance? I for sure
know that the thread support is causing errors similar to the one that
you are reporting.

The ARM noMMU support is preliminary, for now I've only tested Busybox
and a few other small programs. Once this preliminary support is
merged, we can start looking at additional problems. For example,
adding a check at the end of the build that all binaries have the
appropriate BFLT flags.

Waldemar: in fact maybe the issue I had with threads is that as soon as
you link with -lpthread, you have a Has-PIC-GOT flagged BFLT. I'll
check that when I find some time.

Best regards,

Thomas
Ezequiel Garcia March 20, 2016, 1:59 a.m. UTC | #4
On 19 March 2016 at 17:50, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Hello,
>
> On Sat, 19 Mar 2016 16:27:19 -0300, Ezequiel Garcia wrote:
>
>> On 18 March 2016 at 18:08, Thomas Petazzoni
>> <thomas.petazzoni@free-electrons.com> wrote:
>> > As explained by Waldemar, enabling DOPIC in uClibc will lead to the
>> > creation of a Position Independent library. In turn, this will cause
>> > elf2flt to generate a "Has-PIC-GOT" flat binary, which doesn't work on
>> > ARM. In fact, elf2flt on ARM really expect to have non-PIC code as
>> > input, so we must disable DOPIC in the uClibc configuration.
>> >
>>
>> While testing on LPC4350, I found that Lua is built with the Has-PIC-GOT flag:
>>
>> $ output/host/usr/bin/arm-buildroot-uclinux-uclibcgnueabi-flthdr
>> output/target/usr/bin/lua
>> output/target/usr/bin/lua
>>     Magic:        bFLT
>>     Rev:          4
>>     Build Date:   Sat Mar 19 16:14:03 2016
>>     Entry:        0x45
>>     Data Start:   0x1f08c
>>     Data End:     0x23ed8
>>     BSS End:      0x260c0
>>     Stack Size:   0x1000
>>     Reloc Start:  0x23ed8
>>     Reloc Count:  0x214
>>     Flags:        0x2 ( Has-PIC-GOT )
>>
>> The Lua interpreter is not loaded by the binfmt_flat loader, and the
>> kernel says:
>>
>>   BINFMT_FLAT: reloc outside program 0x7fffd3e4 (0 - 0x26080/0x1f04c),
>> killing lua!
>>
>> When DEBUG is defined in fs/binfmt_flat.c, the kernel says:
>>
>>   BINFMT_FLAT: reference 0xffd3e4 to shared library 127, killing lua!
>>
>> On the other side, atftp throws the same error:
>>
>>   BINFMT_FLAT: reference 0xa0100 to shared library 161, killing atftp!
>>
>> Any ideas?
>
> Thanks for this testing. Is lua using threads by any chance? I for sure
> know that the thread support is causing errors similar to the one that
> you are reporting.
>

No, Lua doesn't uses threads.

> The ARM noMMU support is preliminary, for now I've only tested Busybox
> and a few other small programs. Once this preliminary support is
> merged, we can start looking at additional problems.

Sure, I'm not at all objecting this patchset. I've tested some
programs and all of them seem to work fine, with the sole exception of
lua and atftp.

Interestingly, the atftp binary does not have the Has-PIC-GOT flag
set... so I don't know if it's the real reason for the issue.
Thomas Petazzoni March 29, 2016, 10:20 p.m. UTC | #5
Hello,

On Sat, 19 Mar 2016 17:11:58 +0100, Arnout Vandecappelle wrote:

>   Though I wonder: shouldn't uClibc detect this by itself? Similar to the BX 
> handling that you removed. Adding Waldemar in Cc to think about this.

I don't yet fully understand the different modes of elf2flt, and why
DOPIC affects what elf2flt is capable of doing/not doing.

However, if as Waldemar told me, a uClibc built with DOPIC=y will not
work with elf2flt on ARM, then I could indeed send a patch to uClibc to
disable DOPIC on ARM/noMMU.

Thanks!

Thomas
diff mbox

Patch

diff --git a/package/uclibc/uclibc.mk b/package/uclibc/uclibc.mk
index ad94494..e3e45f7 100644
--- a/package/uclibc/uclibc.mk
+++ b/package/uclibc/uclibc.mk
@@ -82,6 +82,12 @@  ifeq ($(BR2_GCC_VERSION_4_7_X)$(BR2_GCC_VERSION_4_8_X):$(BR2_ARM_INSTRUCTIONS_TH
 UCLIBC_EXTRA_CFLAGS += -marm
 endif
 
+ifeq ($(BR2_BINFMT_FLAT),y)
+define UCLIBC_ARM_BINFMT_FLAT
+	$(call KCONFIG_DISABLE_OPT,DOPIC,$(@D)/.config)
+endef
+endif
+
 endif # arm
 
 #
@@ -354,6 +360,7 @@  define UCLIBC_KCONFIG_FIXUP_CMDS
 	$(UCLIBC_ARC_TYPE_CONFIG)
 	$(UCLIBC_ARC_PAGE_SIZE_CONFIG)
 	$(UCLIBC_ARM_ABI_CONFIG)
+	$(UCLIBC_ARM_BINFMT_FLAT)
 	$(UCLIBC_MIPS_ABI_CONFIG)
 	$(UCLIBC_MIPS_ISA_CONFIG)
 	$(UCLIBC_SH_TYPE_CONFIG)