mailing list of musl libc
 help / color / mirror / code / Atom feed
* musl-gcc and LTO not working
@ 2019-08-28 18:34 Hadrien Lacour
  0 siblings, 0 replies; only message in thread
From: Hadrien Lacour @ 2019-08-28 18:34 UTC (permalink / raw)
  To: musl

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?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-28 18:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-28 18:34 musl-gcc and LTO not working Hadrien Lacour

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).