Jump to content


Photo

Building A Native Toolchain


  • Please log in to reply
4 replies to this topic

#1 hmn

hmn

    GP32 Hardcore

  • Members
  • PipPipPipPip
  • 168 posts

Posted 30 October 2010 - 08:51 AM

I have been trying to build a native toolchain for the Wiz (not intended to run on the device, but rather in qemu). I'm currently trying to match version 10.02 of the GPH SDK, using the following components:

  • binutils-2.16.1
  • glibc-2.3.6
  • gcc-4.0.2

I started out by building a cross-compiling toolchain using crosstool. This required finding/modifying some patches, but I eventually got it to work.
I then used that toolchain to build a native toolchain (--build=i686-linux-gnu --host=arm-softfloat-linux-gnu --target=arm-softfloat-linux-gnu).

I then set up a Debian/Arm system in qemu and created a chroot environment in it, containing busybox and the toolchain I built.

Now when I try to link a trivial C program, I get the following error message:

debian-arm:~/wiz-native# chroot . /bin/ash
debian-arm:/# cd root/
debian-arm:/root# gcc -o foo foo.c 
/usr/lib/gcc/arm-softfloat-linux-gnu/4.0.2/../../../../arm-softfloat-linux-gnu/bin/ld: warning: ld-linux.so.2, needed by /lib/libc.so.6, not found (try using -rpath or -rpath-link)
/lib/libc.so.6: undefined reference to `__libc_stack_end@GLIBC_2.1'
/lib/libc.so.6: undefined reference to `_r_debug@GLIBC_2.0'
/lib/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE'
/lib/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
/lib/libc.so.6: undefined reference to `_dl_out_of_memory@GLIBC_PRIVATE'
/lib/libc.so.6: undefined reference to `_rtld_global@GLIBC_PRIVATE'
/lib/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE'
collect2: ld returned 1 exit status

If I follow the advice given in the error message, it works:

debian-arm:/root# gcc -o foo foo.c -Wl,-rpath=/lib

Some googling revealed that this could mean that the toolchain I've built does not know it is a native toolchain,
therefore making no assumptions on library locations... I have not found a way to fix this yet. One hint I found was to change the "specs" file, but my toolchain
has not installed any such file. Also "gcc -dumpspecs" says:

[...]
*cross_compile:
0
[...]

Any ideas on how to proceed?

#2 hmn

hmn

    GP32 Hardcore

  • Members
  • PipPipPipPip
  • 168 posts

Posted 06 November 2010 - 09:05 AM

Turns out that you must not compile the native toolchain (or at least binutils) using "--with-sysroot". :D

#3 hmn

hmn

    GP32 Hardcore

  • Members
  • PipPipPipPip
  • 168 posts

Posted 07 November 2010 - 10:44 AM

I have now succeeded in setting this up. I've put the resulting toolchain (along with busybox, make and the libs/headers from GPH_SDK) in a chroot on the Debian/Arm qemu and was able to natively compile Python and Pygame :)
In case someone is interested, here is the crosstool patch/config and build script I used.

#4 crow_riot

crow_riot

    Mega GP Mania

  • GP32 Hardcore
  • PipPipPipPipPipPip
  • 1133 posts
  • Gender:Male
  • Location:.at
  • Interests:music & programming

Posted 08 November 2010 - 08:32 AM

thanks for your effort. downloaded your script, maybe when i need to compile some third party libs, i'll try this method, as cross-compilation always drives me crazy! :)

#5 hmn

hmn

    GP32 Hardcore

  • Members
  • PipPipPipPip
  • 168 posts

Posted 10 November 2010 - 07:04 PM

As a bonus, here is my qemu launch script, because it took me a while to get it to work the way I wanted :)
export SDL_VIDEO_ALLOW_SCREENSAVER=1
qemu-system-arm \
    -M versatilepb \
    -kernel kernel/vmlinuz \
    -initrd kernel/initrd.img \
    -append "root=/dev/sda1" \
    -hda debian_lenny_arm_small.qcow2 \
    -net user,hostfwd=tcp:127.0.0.1:2244-:22 \
    -net nic,model=smc91c111