* undefined reference to `raise' with musl static toolchain @ 2018-05-08 12:44 Thomas Petazzoni 2018-05-08 13:28 ` Alexander Monakov 2018-05-08 16:22 ` Markus Wichmann 0 siblings, 2 replies; 11+ messages in thread From: Thomas Petazzoni @ 2018-05-08 12:44 UTC (permalink / raw) To: musl Hello, When building an ARM Cortex-A8 toolchain with Buildroot, using the musl C library, and its --disable-shared option (to build a static only toolchain), building some simple programs fail: thomas@windsurf:~/projets/buildroot (master)$ cat foo.c int main(void) { mktime(); return 0; } $ ./output/host/bin/arm-linux-gcc -o foo foo.c foo.c: In function ‘main’: foo.c:1:18: warning: implicit declaration of function ‘mktime’ [-Wimplicit-function-declaration] int main(void) { mktime(); return 0; } ^~~~~~ /home/thomas/projets/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/libgcc.a(_dvmd_lnx.o): In function `__aeabi_idiv0': /home/thomas/projets/buildroot/output/build/host-gcc-final-6.4.0/build/arm-buildroot-linux-musleabihf/libgcc/../../../libgcc/config/arm/lib1funcs.S:1354: undefined reference to `raise' collect2: error: ld returned 1 exit status Does that ring any bell ? It can be reproduced using the following Buildroot defconfig: BR2_arm=y BR2_cortex_a8=y BR2_STATIC_LIBS=y BR2_TOOLCHAIN_BUILDROOT_MUSL=y BR2_TOOLCHAIN_BUILDROOT_CXX=y BR2_INIT_NONE=y BR2_SYSTEM_BIN_SH_NONE=y # BR2_TARGET_ROOTFS_TAR is not set And then using the cross-compiler to build that simple program calling mktime(). Any idea ? Note: this is reported in the Buildroot bug tracker as https://bugs.busybox.net/show_bug.cgi?id=10996. Best regards, Thomas -- Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-08 12:44 undefined reference to `raise' with musl static toolchain Thomas Petazzoni @ 2018-05-08 13:28 ` Alexander Monakov 2018-05-08 16:22 ` Markus Wichmann 1 sibling, 0 replies; 11+ messages in thread From: Alexander Monakov @ 2018-05-08 13:28 UTC (permalink / raw) To: Thomas Petazzoni; +Cc: musl On Tue, 8 May 2018, Thomas Petazzoni wrote: > $ ./output/host/bin/arm-linux-gcc -o foo foo.c Please add '-v' to the command line and post the resulting log. Alexander ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-08 12:44 undefined reference to `raise' with musl static toolchain Thomas Petazzoni 2018-05-08 13:28 ` Alexander Monakov @ 2018-05-08 16:22 ` Markus Wichmann 2018-05-08 16:34 ` Rich Felker 1 sibling, 1 reply; 11+ messages in thread From: Markus Wichmann @ 2018-05-08 16:22 UTC (permalink / raw) To: musl On Tue, May 08, 2018 at 02:44:17PM +0200, Thomas Petazzoni wrote: > /home/thomas/projets/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/libgcc.a(_dvmd_lnx.o): In function `__aeabi_idiv0': > /home/thomas/projets/buildroot/output/build/host-gcc-final-6.4.0/build/arm-buildroot-linux-musleabihf/libgcc/../../../libgcc/config/arm/lib1funcs.S:1354: undefined reference to `raise' [...] > > Does that ring any bell ? > It would appear that your version of libgcc references libc. Now, with static linking, the libraries must appear in the correct order to satisfy all dependencies, but here you have a circular dependency between libgcc and libc. Since all gcc compiled code depends on libgcc, and libc is compiled with gcc, there are only two ways to break the cycle: 1. Remove the dependency. No idea how, not unless you basically inline raise() into __aeabi_idiv0(). 2. Add libc again after the command line. I suspect, once spec files have been taken care of, that the linker command line will be something like ld -o a.out crt1.o crtbegin.o crti.o $YOUR_PRJ_OFILES crtend.o crtn.o -lc -lgcc That would need another "-lc" at the end. Patching the specfile should do it. Things like this somewhat highlight the uselessness of collect2, don't you think? I thought fixing things like this is entirely within its remit, but no, apparently not. Another distinct possibility is that your gcc is somehow broken, either through your action or maybe that version isn't good, but I tend to try and fix the simple problem first. And patching the spec file is simpler than debugging gcc. Ciao, Markus ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-08 16:22 ` Markus Wichmann @ 2018-05-08 16:34 ` Rich Felker 2018-05-09 9:29 ` Thomas Petazzoni 0 siblings, 1 reply; 11+ messages in thread From: Rich Felker @ 2018-05-08 16:34 UTC (permalink / raw) To: musl On Tue, May 08, 2018 at 06:22:27PM +0200, Markus Wichmann wrote: > On Tue, May 08, 2018 at 02:44:17PM +0200, Thomas Petazzoni wrote: > > /home/thomas/projets/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/libgcc.a(_dvmd_lnx.o): In function `__aeabi_idiv0': > > /home/thomas/projets/buildroot/output/build/host-gcc-final-6.4.0/build/arm-buildroot-linux-musleabihf/libgcc/../../../libgcc/config/arm/lib1funcs.S:1354: undefined reference to `raise' > [...] > > > > Does that ring any bell ? > > > > It would appear that your version of libgcc references libc. Now, with > static linking, the libraries must appear in the correct order to > satisfy all dependencies, but here you have a circular dependency between > libgcc and libc. Since all gcc compiled code depends on libgcc, and libc > is compiled with gcc, there are only two ways to break the cycle: > > 1. Remove the dependency. No idea how, not unless you basically inline > raise() into __aeabi_idiv0(). > > 2. Add libc again after the command line. gcc already does this if you pass -static. I suspect the issue is that Thomas is using a toolchain where gcc doesn't know it's static-linking, and ld only static-links because there's no libc.so present. This setup is highly fragile and afaik it's not intended by the gcc developers to work. I don't know if there's anything like --enable-default-static for gcc but that would be the right solution for a static-only toolchain I think. Rich ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-08 16:34 ` Rich Felker @ 2018-05-09 9:29 ` Thomas Petazzoni 2018-05-09 13:44 ` Thomas Petazzoni 0 siblings, 1 reply; 11+ messages in thread From: Thomas Petazzoni @ 2018-05-09 9:29 UTC (permalink / raw) To: Rich Felker; +Cc: musl Hello, On Tue, 8 May 2018 12:34:23 -0400, Rich Felker wrote: > > It would appear that your version of libgcc references libc. Now, with > > static linking, the libraries must appear in the correct order to > > satisfy all dependencies, but here you have a circular dependency between > > libgcc and libc. Since all gcc compiled code depends on libgcc, and libc > > is compiled with gcc, there are only two ways to break the cycle: > > > > 1. Remove the dependency. No idea how, not unless you basically inline > > raise() into __aeabi_idiv0(). > > > > 2. Add libc again after the command line. > > gcc already does this if you pass -static. I suspect the issue is that > Thomas is using a toolchain where gcc doesn't know it's > static-linking, and ld only static-links because there's no libc.so > present. This setup is highly fragile and afaik it's not intended by > the gcc developers to work. I don't know if there's anything like > --enable-default-static for gcc but that would be the right solution > for a static-only toolchain I think. Indeed, passing -static explicitly fixes the problem. Without -static: test@build:~/buildroot$ ./output/host/bin/arm-linux-gcc -o foo foo.c -v Using built-in specs. COLLECT_GCC=/home/test/buildroot/output/host/bin/arm-linux-gcc.br_real COLLECT_LTO_WRAPPER=/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/lto-wrapper Target: arm-buildroot-linux-musleabihf Configured with: ./configure --prefix=/home/test/buildroot/output/host --sysconfdir=/home/test/buildroot/output/host/etc --enable-static --target=arm-buildroot-linux-musleabihf --with-sysroot=/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/home/test/buildroot/output/host --with-mpc=/home/test/buildroot/output/host --with-mpfr=/home/test/buildroot/output/host --with-pkgversion='Buildroot 2018.05-git-01130-gd007bca' --with-bugurl=http://bugs.buildroot.net/ --disable-libmpx --disable-libquadmath --disable-libsanitizer --enable-tls --disable-libmudflap --enable-threads --without-isl --without-cloog --disable-decimal-float --with-abi=aapcs-linux --with-cpu=cortex-a8 --with-fpu=vfpv3-d16 --with-float=hard --with-mode=arm --enable-languages=c,c++ --with-build-time-tools=/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/bin --disable-shared --disable-libcilkrts --disable -libgomp Thread model: posix gcc version 6.4.0 (Buildroot 2018.05-git-01130-gd007bca) COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/cc1 -quiet -v -isysroot /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot foo.c -quiet -dumpbase foo.c -mcpu=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -mabi=aapcs-linux -marm -mtls-dialect=gnu -auxbase foo -version -o /tmp/cc9R8ARE.s GNU C11 (Buildroot 2018.05-git-01130-gd007bca) version 6.4.0 (arm-buildroot-linux-musleabihf) compiled by GNU C version 4.7.2, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/local/include" #include "..." search starts here: #include <...> search starts here: /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/include /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/include /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/include End of search list. GNU C11 (Buildroot 2018.05-git-01130-gd007bca) version 6.4.0 (arm-buildroot-linux-musleabihf) compiled by GNU C version 4.7.2, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 4fc01250e8946128cafb87416e07c618 foo.c: In function 'main': foo.c:1:18: warning: implicit declaration of function 'mktime' [-Wimplicit-function-declaration] int main(void) { mktime(); return 0; } ^~~~~~ COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/bin/as -v -mcpu=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5 -o /tmp/ccIJ7oOn.o /tmp/cc9R8ARE.s GNU assembler version 2.29.1 (arm-buildroot-linux-musleabihf) using BFD version (GNU Binutils) 2.29.1 COMPILER_PATH=/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/bin/ LIBRARY_PATH=/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/lib/:/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/:/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/lib/ COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/collect2 -plugin /home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/liblto_plugin.so -plugin-opt=/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccHzI6L6.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc --sysroot=/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot --eh-frame-hdr -dynamic-linker /lib/ld-musl-armhf.so.1 -X -m armelf_linux_eabi -o foo /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/crt1.o /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/crti.o /home/test/buildroot/out put/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/crtbegin.o -L/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0 -L/home/test/buildroot/output/host/lib/gcc/arm-buildr oot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/lib -L/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib -L/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/lib /tmp/ccIJ7oOn.o -lgcc -lc -lgcc /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/crtend.o /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/crtn.o /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/libgcc.a(_dvmd_lnx.o): In function `__aeabi_idiv0': /home/test/buildroot/output/build/host-gcc-final-6.4.0/build/arm-buildroot-linux-musleabihf/libgcc/../../../libgcc/config/arm/lib1funcs.S:1354: undefined reference to `raise' collect2: error: ld returned 1 exit status With -static: test@build:~/buildroot$ ./output/host/bin/arm-linux-gcc -o foo foo.c -static -v Using built-in specs. COLLECT_GCC=/home/test/buildroot/output/host/bin/arm-linux-gcc.br_real COLLECT_LTO_WRAPPER=/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/lto-wrapper Target: arm-buildroot-linux-musleabihf Configured with: ./configure --prefix=/home/test/buildroot/output/host --sysconfdir=/home/test/buildroot/output/host/etc --enable-static --target=arm-buildroot-linux-musleabihf --with-sysroot=/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/home/test/buildroot/output/host --with-mpc=/home/test/buildroot/output/host --with-mpfr=/home/test/buildroot/output/host --with-pkgversion='Buildroot 2018.05-git-01130-gd007bca' --with-bugurl=http://bugs.buildroot.net/ --disable-libmpx --disable-libquadmath --disable-libsanitizer --enable-tls --disable-libmudflap --enable-threads --without-isl --without-cloog --disable-decimal-float --with-abi=aapcs-linux --with-cpu=cortex-a8 --with-fpu=vfpv3-d16 --with-float=hard --with-mode=arm --enable-languages=c,c++ --with-build-time-tools=/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/bin --disable-shared --disable-libcilkrts --disable -libgomp Thread model: posix gcc version 6.4.0 (Buildroot 2018.05-git-01130-gd007bca) COLLECT_GCC_OPTIONS='-o' 'foo' '-static' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/cc1 -quiet -v -isysroot /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot foo.c -quiet -dumpbase foo.c -mcpu=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -mabi=aapcs-linux -marm -mtls-dialect=gnu -auxbase foo -version -o /tmp/ccAsjDgp.s GNU C11 (Buildroot 2018.05-git-01130-gd007bca) version 6.4.0 (arm-buildroot-linux-musleabihf) compiled by GNU C version 4.7.2, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/local/include" #include "..." search starts here: #include <...> search starts here: /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/include /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/include /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/include End of search list. GNU C11 (Buildroot 2018.05-git-01130-gd007bca) version 6.4.0 (arm-buildroot-linux-musleabihf) compiled by GNU C version 4.7.2, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 4fc01250e8946128cafb87416e07c618 foo.c: In function 'main': foo.c:1:18: warning: implicit declaration of function 'mktime' [-Wimplicit-function-declaration] int main(void) { mktime(); return 0; } ^~~~~~ COLLECT_GCC_OPTIONS='-o' 'foo' '-static' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/bin/as -v -mcpu=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5 -o /tmp/ccx5VIfD.o /tmp/ccAsjDgp.s GNU assembler version 2.29.1 (arm-buildroot-linux-musleabihf) using BFD version (GNU Binutils) 2.29.1 COMPILER_PATH=/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/bin/ LIBRARY_PATH=/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/:/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/lib/:/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/:/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/lib/ COLLECT_GCC_OPTIONS='-o' 'foo' '-static' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/collect2 -plugin /home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/liblto_plugin.so -plugin-opt=/home/test/buildroot/output/host/libexec/gcc/arm-buildroot-linux-musleabihf/6.4.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccEXBDfR.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc --sysroot=/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot -Bstatic -X -m armelf_linux_eabi -o foo /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/crt1.o /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/crti.o /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/crtbeginT.o -L/home/test /buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0 -L/home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/../../../../arm-buildroot-linux-musleabihf/lib -L/ home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib -L/home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/usr/lib /tmp/ccx5VIfD.o --start-group -lgcc -lc --end-group /home/test/buildroot/output/host/lib/gcc/arm-buildroot-linux-musleabihf/6.4.0/crtend.o /home/test/buildroot/output/host/arm-buildroot-linux-musleabihf/sysroot/lib/crtn.o COLLECT_GCC_OPTIONS='-o' 'foo' '-static' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' Does this means we *must* pass -static, even if the toolchain only has the static variant of the C library ? I'm doing a build to confirm, but I don't think we have the same requirement with uClibc-ng. Best regards, Thomas -- Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-09 9:29 ` Thomas Petazzoni @ 2018-05-09 13:44 ` Thomas Petazzoni 2018-05-09 15:24 ` Szabolcs Nagy 0 siblings, 1 reply; 11+ messages in thread From: Thomas Petazzoni @ 2018-05-09 13:44 UTC (permalink / raw) To: Rich Felker; +Cc: musl Hello Rich, On Wed, 9 May 2018 11:29:32 +0200, Thomas Petazzoni wrote: > I'm doing a build to confirm, but I don't think we have the same > requirement with uClibc-ng. A uClibc-ng toolchain works fine without the explicit -static: test@build:~/outputs/uclibc-static$ cat foo.c int main(void) { mktime(); return 0; } test@build:~/outputs/uclibc-static$ ./host/bin/arm-linux-gcc -o foo foo.c -v Using built-in specs. COLLECT_GCC=/home/test/outputs/uclibc-static/host/bin/arm-linux-gcc.br_real COLLECT_LTO_WRAPPER=/home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/lto-wrapper Target: arm-buildroot-linux-uclibcgnueabihf Configured with: ./configure --prefix=/home/test/outputs/uclibc-static/host --sysconfdir=/home/test/outputs/uclibc-static/host/etc --enable-static --target=arm-buildroot-linux-uclibcgnueabihf --with-sysroot=/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/home/test/outputs/uclibc-static/host --with-mpc=/home/test/outputs/uclibc-static/host --with-mpfr=/home/test/outputs/uclibc-static/host --with-pkgversion='Buildroot 2018.05-git-01130-gd007bca' --with-bugurl=http://bugs.buildroot.net/ --disable-libquadmath --disable-libsanitizer --enable-tls --disable-libmudflap --enable-threads --without-isl --without-cloog --disable-decimal-float --with-abi=aapcs-linux --with-cpu=cortex-a 8 --with-fpu=vfpv3-d16 --with-float=hard --with-mode=arm --enable-languages=c,c++ --with-build-time-tools=/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/bin --disable-shar ed --disable-libcilkrts --disable-libgomp Thread model: posix gcc version 6.4.0 (Buildroot 2018.05-git-01130-gd007bca) COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/cc1 -quiet -v -isysroot /home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot foo.c -quiet -dumpbase foo.c -mcpu=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -mabi=aapcs-linux -marm -mtls-dialect=gnu -auxbase foo -version -o /tmp/ccrBk49l.s GNU C11 (Buildroot 2018.05-git-01130-gd007bca) version 6.4.0 (arm-buildroot-linux-uclibcgnueabihf) compiled by GNU C version 4.7.2, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/local/include" #include "..." search starts here: #include <...> search starts here: /home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/include /home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/include-fixed /home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/../../../../arm-buildroot-linux-uclibcgnueabihf/include /home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/include End of search list. GNU C11 (Buildroot 2018.05-git-01130-gd007bca) version 6.4.0 (arm-buildroot-linux-uclibcgnueabihf) compiled by GNU C version 4.7.2, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 64d3b70b605ed06af58d56698f38a6fa foo.c: In function 'main': foo.c:1:18: warning: implicit declaration of function 'mktime' [-Wimplicit-function-declaration] int main(void) { mktime(); return 0; } ^~~~~~ COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/../../../../arm-buildroot-linux-uclibcgnueabihf/bin/as -v -mcpu=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5 -o /tmp/ccVtxQ2w.o /tmp/ccrBk49l.s GNU assembler version 2.29.1 (arm-buildroot-linux-uclibcgnueabihf) using BFD version (GNU Binutils) 2.29.1 COMPILER_PATH=/home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/:/home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/:/home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/:/home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/:/home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/:/home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/../../../../arm-buildroot-linux-uclibcgnueabihf/bin/ LIBRARY_PATH=/home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/:/home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/../../../../arm-buildroot-linux-uclibcgnueabihf/lib/:/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/lib/:/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/ COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' /home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/collect2 -plugin /home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/liblto_plugin.so -plugin-opt=/home/test/outputs/uclibc-static/host/libexec/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccbL5nWH.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc --sysroot=/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot --eh-frame-hdr -dynamic-linker /lib/ld-uClibc.so.0 -X -m armelf_linux_eabi -o foo /home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/crt1.o /home/test/outputs/uclibc-static/host/arm-buildroot-linux -uclibcgnueabihf/sysroot/usr/lib/crti.o /home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/crtbegin.o -L/home/test/outputs/uclibc-static/host/lib/gcc/arm-buildro ot-linux-uclibcgnueabihf/6.4.0 -L/home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/../../../../arm-buildroot-linux-uclibcgnueabihf/lib -L/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/lib -L/home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib /tmp/ccVtxQ2w.o -lgcc -lc -lgcc /home/test/outputs/uclibc-static/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/crtend.o /home/test/outputs/uclibc-static/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/crtn.o COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-mcpu=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' test@build:~/outputs/uclibc-static$ file foo foo: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped And the sysroot really only has a static variant of the C library: test@build:~/outputs/uclibc-static$ ls -l staging/lib staging/usr/lib staging/lib: total 68 -rw-r--r-- 1 test test 63630 May 9 09:35 libatomic.a -rwxr-xr-x 1 test test 962 May 9 09:35 libatomic.la staging/usr/lib: total 6368 -rw-r--r-- 1 test test 984 May 9 09:33 crt1.o -rw-r--r-- 1 test test 992 May 9 09:33 crti.o -rw-r--r-- 1 test test 976 May 9 09:33 crtn.o -rw-r--r-- 1 test test 2085880 May 9 09:33 libc.a -rw-r--r-- 1 test test 8 May 9 09:33 libcrypt.a -rw-r--r-- 1 test test 8 May 9 09:33 libdl.a -rw-r--r-- 1 test test 8 May 9 09:33 libiconv.a -rw-r--r-- 1 test test 8 May 9 09:33 libintl.a -rw-r--r-- 1 test test 8 May 9 09:33 libm.a -rw-r--r-- 1 test test 8 May 9 09:33 libnsl.a -rw-r--r-- 1 test test 8 May 9 09:33 libpthread.a -rw-r--r-- 1 test test 8 May 9 09:33 libresolv.a -rw-r--r-- 1 test test 8 May 9 09:33 librt.a -rw-r--r-- 1 test test 4367292 May 9 09:35 libstdc++.a -rw-r--r-- 1 test test 8 May 9 09:33 libutil.a So: why does a musl-based toolchain requires an explicit -static, while it isn't needed with uClibc-ng ? Best regards, Thomas -- Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-09 13:44 ` Thomas Petazzoni @ 2018-05-09 15:24 ` Szabolcs Nagy 2018-05-09 17:28 ` Rich Felker 2018-05-11 15:59 ` Thomas Petazzoni 0 siblings, 2 replies; 11+ messages in thread From: Szabolcs Nagy @ 2018-05-09 15:24 UTC (permalink / raw) To: musl; +Cc: Rich Felker, Thomas Petazzoni * Thomas Petazzoni <thomas.petazzoni@bootlin.com> [2018-05-09 15:44:07 +0200]: > > So: why does a musl-based toolchain requires an explicit -static, while > it isn't needed with uClibc-ng ? > there can be many reasons.. e.g. if mktime in uclibc-ng happens to reference raise then it would get linked in independently of libgcc. or maybe uclibc-ng has its own __aeabi_*div implementation. or the way libgcc was configured, the raise(SIGFPE) was disabled (it is only enabled for linux targets, but who knows how *-linux-uclibcgnueabihf is interpreted). you can check these using nm/objdump/readelf on libc.a and libgcc.a ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-09 15:24 ` Szabolcs Nagy @ 2018-05-09 17:28 ` Rich Felker 2018-05-11 15:59 ` Thomas Petazzoni 1 sibling, 0 replies; 11+ messages in thread From: Rich Felker @ 2018-05-09 17:28 UTC (permalink / raw) To: musl; +Cc: Thomas Petazzoni On Wed, May 09, 2018 at 05:24:37PM +0200, Szabolcs Nagy wrote: > * Thomas Petazzoni <thomas.petazzoni@bootlin.com> [2018-05-09 15:44:07 +0200]: > > > > So: why does a musl-based toolchain requires an explicit -static, while > > it isn't needed with uClibc-ng ? > > > > there can be many reasons.. > > e.g. if mktime in uclibc-ng happens to reference raise then it > would get linked in independently of libgcc. > > or maybe uclibc-ng has its own __aeabi_*div implementation. > > or the way libgcc was configured, the raise(SIGFPE) was disabled > (it is only enabled for linux targets, but who knows how > *-linux-uclibcgnueabihf is interpreted). > > you can check these using nm/objdump/readelf on libc.a and libgcc.a It would be nice if this raise dependency could be removed from libgcc. It's not necessary for any defined behavior; it's only there for the sake of emulating x86 behavior on div-by-zero. Either way you need to be using the right link order that -static gives (potentially for other reasons) but it would be nice to avoid unnecessary code getting static-linked like this. Rich ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-09 15:24 ` Szabolcs Nagy 2018-05-09 17:28 ` Rich Felker @ 2018-05-11 15:59 ` Thomas Petazzoni 2018-05-11 16:05 ` Rich Felker 1 sibling, 1 reply; 11+ messages in thread From: Thomas Petazzoni @ 2018-05-11 15:59 UTC (permalink / raw) To: Szabolcs Nagy; +Cc: musl, Rich Felker Hello, Thanks for your feedback. On Wed, 9 May 2018 17:24:37 +0200, Szabolcs Nagy wrote: > there can be many reasons.. > > e.g. if mktime in uclibc-ng happens to reference raise then it > would get linked in independently of libgcc. In the static binary linked against uClibc, there are two references to __GI_raise: __GI_abort __aeabi_idiv0 __GI_abort is reference from _start, so I guess this means that __GI_abort is always pulled in, therefore __GI_raise is always pulled in, and __aeabi_idiv0 is happy. Now my question remains: do you consider it normal that -static is required, or do you consider it a bug of the musl/gcc integration that -static is required even when the only variant available of the library is the static one ? Thanks, Thomas -- Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-11 15:59 ` Thomas Petazzoni @ 2018-05-11 16:05 ` Rich Felker 2018-05-11 21:28 ` Thomas Petazzoni 0 siblings, 1 reply; 11+ messages in thread From: Rich Felker @ 2018-05-11 16:05 UTC (permalink / raw) To: musl On Fri, May 11, 2018 at 05:59:01PM +0200, Thomas Petazzoni wrote: > Hello, > > Thanks for your feedback. > > On Wed, 9 May 2018 17:24:37 +0200, Szabolcs Nagy wrote: > > > there can be many reasons.. > > > > e.g. if mktime in uclibc-ng happens to reference raise then it > > would get linked in independently of libgcc. > > In the static binary linked against uClibc, there are two references to > __GI_raise: > > __GI_abort > __aeabi_idiv0 > > __GI_abort is reference from _start, so I guess this means that > __GI_abort is always pulled in, therefore __GI_raise is always pulled > in, and __aeabi_idiv0 is happy. > > Now my question remains: do you consider it normal that -static is > required, or do you consider it a bug of the musl/gcc integration that > -static is required even when the only variant available of the library > is the static one ? I don't think gcc is intended to work right in configurations where it supports dynamic linking but the only libc available is static, unless you pass -static, and I don't see a good way to make it work in that case. You've only hit the tip of the iceberg; there's more stuff that could break subtly when gcc is passing ld options that were intended for dynamic linking, but ld actually ends up performing static linking. It "working" with uClibc is just "getting lucky" (or "unlucky" depending on your perspective about ignoring vs catching unsafe things). If gcc doesn't have any option to tell it you're building a static-only toolchain and make static linking the default, I see that as something of an omission, and maybe we should try to get that added to gcc. Rich ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: undefined reference to `raise' with musl static toolchain 2018-05-11 16:05 ` Rich Felker @ 2018-05-11 21:28 ` Thomas Petazzoni 0 siblings, 0 replies; 11+ messages in thread From: Thomas Petazzoni @ 2018-05-11 21:28 UTC (permalink / raw) To: Rich Felker; +Cc: musl Hello, Thanks for your feedback! On Fri, 11 May 2018 12:05:44 -0400, Rich Felker wrote: > > Now my question remains: do you consider it normal that -static is > > required, or do you consider it a bug of the musl/gcc integration that > > -static is required even when the only variant available of the library > > is the static one ? > > I don't think gcc is intended to work right in configurations where it > supports dynamic linking but the only libc available is static, unless > you pass -static, and I don't see a good way to make it work in that > case. You've only hit the tip of the iceberg; there's more stuff that > could break subtly when gcc is passing ld options that were intended > for dynamic linking, but ld actually ends up performing static > linking. It "working" with uClibc is just "getting lucky" (or > "unlucky" depending on your perspective about ignoring vs catching > unsafe things). OK. > If gcc doesn't have any option to tell it you're building a > static-only toolchain and make static linking the default, I see that > as something of an omission, and maybe we should try to get that added > to gcc. I don't see anything like that. Buildroot already builds gcc with --enable-static --disable-shared when building a static toolchain, and I don't see any other option that would be relevant, from a quick look. Thomas -- Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-05-11 21:28 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-05-08 12:44 undefined reference to `raise' with musl static toolchain Thomas Petazzoni 2018-05-08 13:28 ` Alexander Monakov 2018-05-08 16:22 ` Markus Wichmann 2018-05-08 16:34 ` Rich Felker 2018-05-09 9:29 ` Thomas Petazzoni 2018-05-09 13:44 ` Thomas Petazzoni 2018-05-09 15:24 ` Szabolcs Nagy 2018-05-09 17:28 ` Rich Felker 2018-05-11 15:59 ` Thomas Petazzoni 2018-05-11 16:05 ` Rich Felker 2018-05-11 21:28 ` Thomas Petazzoni
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/musl/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).