mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Hadrien Lacour <hadrien.lacour@posteo.net>
To: musl@lists.openwall.com
Subject: musl-gcc and LTO not working
Date: Wed, 28 Aug 2019 20:34:52 +0200	[thread overview]
Message-ID: <20190828183452.whkhqfsfvwc7qs6b@gentoo-zen2700x> (raw)

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?


                 reply	other threads:[~2019-08-28 18:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190828183452.whkhqfsfvwc7qs6b@gentoo-zen2700x \
    --to=hadrien.lacour@posteo.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).