Bug 14541 - Wrong entry point computation using cross binutils linux amd64->arm-linux-gnueabihf
Summary: Wrong entry point computation using cross binutils linux amd64->arm-linux-gnu...
Status: RESOLVED WORKSFORME
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-03 08:30 UTC by Eric Valette
Modified: 2014-07-19 15:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Valette 2012-09-03 08:30:38 UTC
I'm trying to build a cross compilation tool for raspberry pi on a debian amd64 machine. While I succeeded to build the tools either the debian way or using pure official gnu tools releases unpatched, in both case I get binary that do no execute on the raspberry.

Even a simple hello word statically compiled fails to execute
test.c :

#include <stdio.h>

main()
{
        printf("hello world\n");
        exit (0);
}


I noticed the entry point is wrongly computed on this sample program (native tools on raspberry have _start address as their entry point not _start +1!

arm-linux-gnueabihf-gcc-4.7 -static -v -o test test.c
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc-4.7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.7/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.1-7' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabihf/include/c++/4.7.1 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-cpu=arm1176jzf-s --with-tune=arm1176jzf-s --with-build-sysroot=/home/armDev/raspberry/flashRoot --with-arch=armv6 --with-float=hard --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include --with-headers=/usr/arm-linux-gnueabihf/include --with-libs=/usr/arm-linux-gnueabihf/lib
Thread model: posix
gcc version 4.7.1 (Debian 4.7.1-7) 
COLLECT_GCC_OPTIONS='-static' '-v' '-o' 'test' '-march=armv6' '-mtune=arm1176jzf-s' '-mfloat-abi=hard' '-mtls-dialect=gnu'
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/cc1 -quiet -v -imultilib . -imultiarch arm-linux-gnueabihf test.c -quiet -dumpbase test.c -march=armv6 -mtune=arm1176jzf-s -mfloat-abi=hard -mtls-dialect=gnu -auxbase test -version -o /tmp/cckZtRSC.s
GNU C (Debian 4.7.1-7) version 4.7.1 (arm-linux-gnueabihf)
        compiled by GNU C version 4.7.1, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/include
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/include-fixed
 /usr/arm-linux-gnueabihf/include
End of search list.
GNU C (Debian 4.7.1-7) version 4.7.1 (arm-linux-gnueabihf)
        compiled by GNU C version 4.7.1, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ae23d5d5164dae087e074ab6bd3989a9
test.c: In function ‘main’:
test.c:6:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
COLLECT_GCC_OPTIONS='-static' '-v' '-o' 'test' '-march=armv6' '-mtune=arm1176jzf-s' '-mfloat-abi=hard' '-mtls-dialect=gnu'
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/bin/as -v -march=armv6 -mfloat-abi=hard -meabi=5 -o /tmp/ccHi9bK1.o /tmp/cckZtRSC.s
GNU assembler version 2.22 (arm-linux-gnueabihf) using BFD version (GNU Binutils for Debian) 2.22
COMPILER_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/lib/
COLLECT_GCC_OPTIONS='-static' '-v' '-o' 'test' '-march=armv6' '-mtune=arm1176jzf-s' '-mfloat-abi=hard' '-mtls-dialect=gnu'
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/collect2 --build-id --no-add-needed -Bstatic -dynamic-linker /lib/ld-linux-armhf.so.3 -X --hash-style=both -m armelf_linux_eabi -o test /usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/lib/crt1.o /usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/lib/crti.o /usr/lib/gcc/arm-linux-gnueabihf/4.7/crtbeginT.o -L/usr/lib/gcc/arm-linux-gnueabihf/4.7 -L/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/lib /tmp/ccHi9bK1.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/arm-linux-gnueabihf/4.7/crtend.o /usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/lib/crtn.o
root@serverCompilARMDev:/home/armDev/crossdevSrc/test# nm test | grep start
0006a12c A __bss_start
0006a12c A __bss_start__
000088b8 t call_gmon_start
00069a20 D __data_start
00069a20 W data_start
00011f7c T _dl_start
         w _dl_starting_up
0003c27c T _dl_start_profile
000612d4 a __exidx_start
00069974 t __fini_array_start
         w __gmon_start__
00069970 t __init_array_start
00008a00 T __libc_start_main
00069970 b __preinit_array_start
00008880 T _start   <=======
00060fb0 A __start___libc_atexit
root@serverCompilARMDev:/home/armDev/crossdevSrc/test# arm-linux-gnueabihf-readelf -h test
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x8881  <========
  Start of program headers:          52 (bytes into file)
  Start of section headers:          369336 (bytes into file)
  Flags:                             0x5000002, has entry point, Version5 EABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         28
  Section header string table index: 25
Comment 1 Andreas Schwab 2012-09-03 08:57:17 UTC
How did you configure it?
Comment 2 Eric Valette 2012-09-03 09:03:10 UTC
Last try from config.status is:
../configure'  '--host=x86_64-linux-gnu' '--build=x86_64-linux-gnu' '--target=arm-linux-gnueabihf' '--prefix=/usr' '--enable-shared' '--e
nable-ld=default' '--enable-gold' '--with-build-sysroot=/home/armDev/rasberry/flashRoot'

I did without the --with-build-sysroot also but got the same result. Direct build without explicit --enable-gold le
Comment 3 Nick Clifton 2012-10-26 14:51:28 UTC
Hi Eric,

  The usual reason for the bottom bit of a function-like symbol being set is because it is a THUMB mode function entry point.  Could this be what is happening here.  Ie, are you linking against a thumb encoded version of _start ?  If you disassemble the code at _start, what does it look like ?

Cheers
  Nick
Comment 4 Eric Valette 2012-10-26 15:03:23 UTC
00008880 <_start>:
    8880:       f04f 0b00       mov.w   fp, #0
    8884:       f04f 0e00       mov.w   lr, #0
    8888:       f85d 1b04       ldr.w   r1, [sp], #4
    888c:       466a            mov     r2, sp
    888e:       f84d 2d04       str.w   r2, [sp, #-4]!
    8892:       f84d 0d04       str.w   r0, [sp, #-4]!
    8896:       f8df c014       ldr.w   ip, [pc, #20]   ; 88ac <_start+0x2c>
    889a:       f84d cd04       str.w   ip, [sp, #-4]!
    889e:       4804            ldr     r0, [pc, #16]   ; (88b0 <_start+0x30>)
    88a0:       4b04            ldr     r3, [pc, #16]   ; (88b4 <_start+0x34>)
    88a2:       f000 f8ad       bl      8a00 <__libc_start_main>
    88a6:       f000 fb93       bl      8fd0 <abort>
    88aa:       0000            .short  0x0000
    88ac:       00008f65        .word   0x00008f65
    88b0:       000089e4        .word   0x000089e4
    88b4:       00008ef9        .word   0x00008ef9
Comment 5 Nick Clifton 2012-10-26 16:31:05 UTC
Hi Eric,

  Those are Thumb instructions.  Which explains why the bottom bit is set.

  I am not familiar with the ARM processor on the PI.  Maybe it is incapable of executing these instructions ?  Perhaps you should specify the ARM processor type when you compile your program ?

Cheers
  Nick
Comment 6 Eric Valette 2012-10-29 08:34:14 UTC
(In reply to comment #5)
> Hi Eric,
> 
>   Those are Thumb instructions.  Which explains why the bottom bit is set.
> 
>   I am not familiar with the ARM processor on the PI.  Maybe it is incapable of
> executing these instructions ?  Perhaps you should specify the ARM processor
> type when you compile your program ?
> 
> Cheers
>   Nick

Yes but if you look at the config line, the processor has been specified when building so thumb code should be off
Comment 7 Nick Clifton 2012-10-30 11:38:59 UTC
Hi Eric,

> Yes but if you look at the config line, the processor has been specified when
> building so thumb code should be off

  Are you referring to this part of the output from gcc -v:

    --with-cpu=arm1176jzf-s

  The 1176 series does support Thumb instructions:

http://www.arm.com/products/processors/classic/arm11/arm1176.php?tab=Specifications

  So it seems to me that the compiler is not doing anything wrong.


  If you add "-marm" to your gcc command line when compiling your test program, does that make any difference ?

Cheers
  Nick
Comment 8 Will Newton 2014-07-19 14:31:57 UTC
Any update on this issue? Are you still seeing the problem?

Thanks,
Comment 9 Eric Valette 2014-07-19 14:44:28 UTC
I'm no more working on the raspberry so its a bit late. Close if you want.
Comment 10 Will Newton 2014-07-19 15:44:58 UTC
Closing due to lack of information.