Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Cross Toolchain linker issue (-lgcc -lc -lgcc_s)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
NTU
Tux's lil' helper
Tux's lil' helper


Joined: 17 Jul 2015
Posts: 116

PostPosted: Fri Aug 04, 2017 7:59 pm    Post subject: [SOLVED] Cross Toolchain linker issue (-lgcc -lc -lgcc_s) Reply with quote

Hello all, I could really use the help. Admins and mods, feel free to move this post to where you feel fit, IMO it's a bit of a programing issue (Bash script) but also a general Linux question so I'm not too sure where to stick this.

I'm currently working on a grass roots (no pun intended) ARM64 root filesystem builder that builds a complete working Linux system from an x86 host, in Bash. Buildroot and Crosstool-NG have many obscure "magic" lines and all kinds of weird hacks. The point of this project is to be able to build an ARM64 environment with all of the instructions right in front of you and be able to track and trace every step of the way with ease, with a minimalist and simplistic design. Outside of this linker issue, all is well, but I need to be able to fix this in order to really start building.

The issues are explained here:

https://github.com/NTULINUX/clfs-arm64/commit/a91e6c3f9d0fee2fe173ebfb84085f289614c7e6

Basically, how can I get the cross ld linker to automatically find -lc -lgcc and lgcc_s (and whatever else) without having to manually pipe a long string on every link command? I want to be able to type for example:

Code:
aarch64-barf-linux-gnu-ld -lc
aarch64-barf-linux-gnu-ld -lgcc
aarch64-barf-linux-gnu-ld -lgcc_s


And have it just work. What am I missing? If you help me, you'll be able to make me finish this project and build a complete embedded ARM64 Linux system in Bash without any secrets, or having to do it all by hand. I've been trying to solve this problem for awhile and I've been messing with LDFLAGS and /etc/ld.so.conf but because this is a cross architecture, using BINFMT_MISC doesn't work with /etc/ld.so.conf so what am I supposed to do? How can I get the cross linker to find -lc and such, without having to use drawn out lines? If you `cd` into glibc or Binutils and run make check for example, it dies right away because ld can't find the libraries that those commands (make check) need. This needs to be fixed (cleanly and properly) and then I can finish this up. Thank you!

Edit: Cross GCC finds everything LD can't by just adding -lc -lgcc etc to the cross compiler.


Last edited by NTU on Tue Aug 15, 2017 9:49 pm; edited 2 times in total
Back to top
View user's profile Send private message
NTU
Tux's lil' helper
Tux's lil' helper


Joined: 17 Jul 2015
Posts: 116

PostPosted: Sat Aug 12, 2017 8:18 pm    Post subject: Reply with quote

Hello! After looking over the CLFS documentation for MIPS I've been able to fix the -lc -lgcc and -lgcc_s issues without messing with CFLAGS or LDFLAGS. It was all related to a configure line with Binutils.

The fix:

https://github.com/NTULINUX/clfs-arm64/commit/91dcff5e5700c38cf776ea8b2c636b67cb621360

The cross Binutils testsuite passes now for ARM64, now I just need to fix these undefined references to -pthread:

Code:
aarch64-barf-linux-gnu-gcc -B/home/ntu/clfs-arm64/barf/barf_cross_bin/bin/   -shared -static-libgcc -Wl,-O1  -Wl,-z,defs -Wl,-dynamic-linker=/home/ntu/clfs-arm64/barf/barf_cross_bin/lib/ld-linux-aarch64.so.1  -B/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/csu/  -Wl,--version-script=/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/librt.map -Wl,-soname=librt.so.1 -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both  -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/math -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/elf -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/dlfcn -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/nss -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/nis -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/resolv -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/crypt -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/mathvec -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/support -L/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/nptl -Wl,-rpath-link=/home/ntu/clfs-arm64/barf/src/glibc-2.25/build:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/math:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/elf:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/dlfcn:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/nss:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/nis:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/resolv:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/crypt:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/mathvec:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/support:/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/nptl -o /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt.so -T /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/shlib.lds /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/csu/abi-note.o -Wl,--whole-archive /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a -Wl,--no-whole-archive  -Wl,--start-group /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/libc.so /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/libc_nonshared.a -Wl,--as-needed /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/elf/ld.so -Wl,--no-as-needed -Wl,--end-group
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(aio_misc.os): In function `handle_fildes_io':
aio_misc.c:(.text+0x590): undefined reference to `pthread_create'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(aio_misc.os): In function `__aio_enqueue_request':
aio_misc.c:(.text+0xaac): undefined reference to `__pthread_get_minstack'
aio_misc.c:(.text+0xab8): undefined reference to `pthread_attr_setstacksize'
aio_misc.c:(.text+0xaf0): undefined reference to `pthread_create'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(aio_notify.os): In function `__aio_notify_only':
aio_notify.c:(.text+0x140): undefined reference to `pthread_create'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(timer_create.os): In function `timer_create':
timer_create.c:(.text+0x110): undefined reference to `pthread_once'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(shm_open.os): In function `shm_open':
shm_open.c:(.text+0x3c): undefined reference to `__shm_directory'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(shm_unlink.os): In function `shm_unlink':
shm_unlink.c:(.text+0x30): undefined reference to `__shm_directory'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(mq_notify.os): In function `helper_thread':
mq_notify.c:(.text+0xa0): undefined reference to `pthread_create'
mq_notify.c:(.text+0xac): undefined reference to `__pthread_barrier_wait'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(mq_notify.os): In function `change_sigmask':
mq_notify.c:(.text+0xf8): undefined reference to `pthread_sigmask'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(mq_notify.os): In function `init_mq_netlink':
mq_notify.c:(.text+0x168): undefined reference to `__pthread_barrier_init'
mq_notify.c:(.text+0x1f8): undefined reference to `__pthread_get_minstack'
mq_notify.c:(.text+0x204): undefined reference to `pthread_attr_setstacksize'
mq_notify.c:(.text+0x22c): undefined reference to `pthread_create'
mq_notify.c:(.text+0x26c): undefined reference to `pthread_sigmask'
mq_notify.c:(.text+0x288): undefined reference to `pthread_atfork'
mq_notify.c:(.text+0x294): undefined reference to `pthread_cancel'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(mq_notify.os): In function `notification_function':
mq_notify.c:(.text+0x2c0): undefined reference to `__pthread_barrier_wait'
mq_notify.c:(.text+0x2c8): undefined reference to `pthread_detach'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(mq_notify.os): In function `mq_notify':
mq_notify.c:(.text+0x380): undefined reference to `pthread_once'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(timer_routines.os): In function `timer_helper_thread':
timer_routines.c:(.text+0x114): undefined reference to `pthread_create'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(timer_routines.os): In function `__start_helper_thread':
timer_routines.c:(.text+0x258): undefined reference to `__pthread_get_minstack'
timer_routines.c:(.text+0x264): undefined reference to `pthread_attr_setstacksize'
timer_routines.c:(.text+0x2a8): undefined reference to `pthread_create'
timer_routines.c:(.text+0x2f0): undefined reference to `pthread_atfork'
/home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt_pic.a(librt-cancellation.os): In function `__librt_enable_asynccancel':
librt-cancellation.c:(.text+0xe0): undefined reference to `__pthread_unwind'
collect2: error: ld returned 1 exit status
make[2]: *** [../Makerules:582: /home/ntu/clfs-arm64/barf/src/glibc-2.25/build/rt/librt.so] Error 1
make[2]: Leaving directory '/home/ntu/clfs-arm64/barf/src/glibc-2.25/nptl'
make[1]: *** [Makefile:215: nptl/tests] Error 2
make[1]: Leaving directory '/home/ntu/clfs-arm64/barf/src/glibc-2.25'


I haven't dug into that problem at all yet but it shouldn't be too hard to fix (hopefully) At least I got one problem out of the way!
Back to top
View user's profile Send private message
NTU
Tux's lil' helper
Tux's lil' helper


Joined: 17 Jul 2015
Posts: 116

PostPosted: Tue Aug 15, 2017 10:20 pm    Post subject: Reply with quote

Fixed the glibc testsuite issue with pthread as well. Fix:

https://github.com/NTULINUX/clfs-arm64/commit/5552b5e148abb79ef83f9c1261a764931a7b425d

Quite a few changes here, more features throughout stage 1-2, but the isolated fix was making a symlink from the top cross toolchain lib64 directory to lib, and inside the target toolchain directory; make another symlink from lib64 to lib. To cut down the amount of libraries being spread out I added the same --libdir option to Binutils and GCC (stage 1-3) but I have not been able to install all of Glibc inside of a single directory. Currently Glibc rests top/cross/directory/lib{64} and top/cross/directory/target-arch/lib{64} to satisfy the compilation of GCC stages 2 and 3, as opposed to it just being in the top lib64 directory.

The glibc testsuite returns this:
Code:
1 FAIL
659 PASS
8 XFAIL


After reviewing some random glibc testsuite results online, including those posted to CLFS/LFS, a few failures is expected it seems, and this is as good as it's going to get. The Binutils testsuite runs fine, I haven't messed with DejaGNU a lot but down the road I'll do further testing and run the GCC testsuite as well. At this point, it seems stable enough to start building the ARM64 root filesystem and working on that portion.

There is absolutely no documentation from the CLFS website on building so I had to do this from scratch, learning as I go, testing, trial and error. I've been working on this for a little over a month and my efforts have finally payed off.

ARM64 from bare-metal is finally now possible (at least the toolchain so far) with all configure options documented such as compilation instructions as it's in plain Bash, and kept distribution-generic. In the process of this, I have mastered the cross compilation build process of GCC, Binutils, and Glibc. With the use of a user configuration file (Bash variables) all target specific options are easily modifiable and hopefully once complete, this project will be easy to port to other architectures (such as MIPS/MIPS64, PPC/PPC64 and ARM) and build a from-scratch root filesystem for other platforms. Perhaps have sample/example Kernel config files for specific embedded devices (I'll be making one personally for the raspberry pi 3) sitting in the tree, such as for Allwinner/SUNXI boards and such. I think this could really turn into something and improve embedded Linux development tasks with some more clean-up and progress.

Cheers and I hope you find this useful. ARM64 toolchain is done!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum