|
Message-ID: <20190828183452.whkhqfsfvwc7qs6b@gentoo-zen2700x> Date: Wed, 28 Aug 2019 20:34:52 +0200 From: Hadrien Lacour <hadrien.lacour@...teo.net> To: musl@...ts.openwall.com Subject: musl-gcc and LTO not working Hello, I'm currently trying to install and use a LTO only static version of musl in order to measure the act of allowing gcc to inline the libc into my code. This is on Gentoo amd64 glibc with gcc-8.3, binutils-2.32-r1 and both bfd and gold. I successfully built and installed it with (yes, the LDFLAGS are useless here): $ AR=gcc-ar RANLIB=gcc-ranlib LDFLAGS=-fuse-linker-plugin CFLAGS='-flto -fno-fat-lto-objects' ./configure --disable-shared $ make AR=gcc-ar RANLIB=gcc-ranlib LDFLAGS=-fuse-linker-plugin CFLAGS='-flto -fno-fat-lto-objects' $ sudo make install but trying to compile a simple hello_world.c gets me: $ /usr/local/musl/bin/musl-gcc hello.c -o hello -flto -fuse-linker-plugin -static crt/crt1.c:11:5: warning: type of ‘__libc_start_main’ does not match original declaration [-Wlto-type-mismatch] src/env/__libc_start_main.c:72:5: note: type mismatch in parameter 4 src/env/__libc_start_main.c:72:5: note: ‘__libc_start_main’ was previously declared here /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cckfcxEi.ltrans0.ltrans.o: in function `_start': <artificial>:(.text+0x12): undefined reference to `_start_c' /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cckfcxEi.ltrans0.ltrans.o: in function `main': <artificial>:(.text+0x27): undefined reference to `printf' collect2: error: ld returned 1 exit status As per a comment on the IRC, I added __attribute__((__used__)) to _start_c in crt1.c before recompiling to solve the first undefined reference, but the 'printf' one still remained: $ /usr/local/musl/bin/musl-gcc hello.c -o hello -flto -fuse-linker-plugin -static crt/crt1.c:11:5: warning: type of ‘__libc_start_main’ does not match original declaration [-Wlto-type-mismatch] src/env/__libc_start_main.c:72:5: note: type mismatch in parameter 4 src/env/__libc_start_main.c:72:5: note: ‘__libc_start_main’ was previously declared here /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccazsBTd.ltrans0.ltrans.o: in function `main': <artificial>:(.text+0x27): undefined reference to `printf' collect2: error: ld returned 1 exit status In addition, I also get two strange behaviours. Linking without -flto nor -fuse-linker-plugin works perfectly (I'll omit the aforementioned warnings for now): $ /usr/local/musl/bin/musl-gcc hello.c -o hello -static $ ./hello Hello world and building without -static completes with no error, but produces an unusable binary: $ /usr/local/musl/bin/musl-gcc hello.c -o hello $ file hello hello: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, not stripped $ ldd hello statically linked $ ./hello zsh: no such file or directory: ./hello Any idea about any of those problems/oddities?
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.