From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14599 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Hadrien Lacour Newsgroups: gmane.linux.lib.musl.general Subject: musl-gcc and LTO not working Date: Wed, 28 Aug 2019 20:34:52 +0200 Message-ID: <20190828183452.whkhqfsfvwc7qs6b@gentoo-zen2700x> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="224203"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 To: musl@lists.openwall.com Original-X-From: musl-return-14615-gllmg-musl=m.gmane.org@lists.openwall.com Wed Aug 28 20:35:16 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1i32mo-000wBN-PI for gllmg-musl@m.gmane.org; Wed, 28 Aug 2019 20:35:14 +0200 Original-Received: (qmail 27998 invoked by uid 550); 28 Aug 2019 18:35:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 27960 invoked from network); 28 Aug 2019 18:35:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1567017297; bh=aMGHq5pkUuhcG4J6gyu7Gp7emNNMvqbGYMp/zLrZrOY=; h=Date:From:To:Subject:From; b=XswPRga7LODDDwr81aucL0cvxMP3Nis03SR6eFpSJSE8sBnBfwQo8QDV/lAvpaJzo Repo5QqRsi86bMbH7VHJDfCkV7A5WenE3Pu6omUr1/6mmh7mdujPvOzcIURXDOdVHd /9Qo5ePQPcHA9gVhJDk62jJzYul9WGi35l56pVp3a8rKyMqXvXk3oWga7pxI1US+VQ HIZrKV/5SzAm/kPZMG3JmlikcsosxrrphsyH1XFyLQ145iXbHd7rpf43Kwq80AB3HC Ti/JcxJcQRPZjAD+1/jCDyLq3UD4wKORS67DnNXU5PxQGJvgXIE0dw8JZXPBFiXj5T 7lpx1MWkzvlZw== Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:14599 Archived-At: 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': :(.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': :(.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': :(.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?