From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7530 Path: news.gmane.org!not-for-mail From: Andre McCurdy Newsgroups: gmane.linux.lib.musl.general Subject: Re: building musl libc.so with gcc -flto Date: Mon, 27 Apr 2015 17:16:12 -0700 Message-ID: References: <1429742932-6026-1-git-send-email-armccurdy@gmail.com> <20150423022309.GH6817@brightrain.aerifal.cx> <20150423094520.GA17573@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1430180196 20447 80.91.229.3 (28 Apr 2015 00:16:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 28 Apr 2015 00:16:36 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7543-gllmg-musl=m.gmane.org@lists.openwall.com Tue Apr 28 02:16:32 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YmtCM-0006or-04 for gllmg-musl@m.gmane.org; Tue, 28 Apr 2015 02:16:26 +0200 Original-Received: (qmail 13772 invoked by uid 550); 28 Apr 2015 00:16:24 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 13754 invoked from network); 28 Apr 2015 00:16:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=L8+PJAzP1bFgTMgp2hit+SFMRXRfl7h8JhD3qD+ffDE=; b=AiURzcYf3lsxNm479IGnWi3LbamFWkHoD8IjF4l6WDXrn0E/cDM0IkGQJS9TnChDbY maB43WYW7qkJ5irXqXu3z+DJFsN+zykTx+j+Vw+TS09q5KbEXRMjf8L3hQv6Q6RRkwES lhitdsR8mk/FTh5VU3AMuEaaqUf+YBWDJMcWKTLfVSJQ78VarzZjt7zyAEpI6CLZw0BO 09opBtNiFrVdYAfLqznSPdB43L2skfNbHG3HLNi2gOgpRlNsbpMQLeIa3BEV0Ilbo2dp CQGnvA0YIsytulwPwi8pNOAXSw9yw8kOH7hiXptGkauIyMOBzZbOsscoSBxdi/unOrwt 1GnQ== X-Received: by 10.182.158.134 with SMTP id wu6mr12129442obb.25.1430180172395; Mon, 27 Apr 2015 17:16:12 -0700 (PDT) In-Reply-To: <20150423094520.GA17573@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:7530 Archived-At: On Thu, Apr 23, 2015 at 2:45 AM, Rich Felker wrote: > On Wed, Apr 22, 2015 at 10:34:40PM -0700, Andre McCurdy wrote: >> On Wed, Apr 22, 2015 at 7:23 PM, Rich Felker wrote: >> > On Wed, Apr 22, 2015 at 03:48:52PM -0700, Andre McCurdy wrote: >> >> Hi all, >> >> >> >> Below are some observations from building musl libc.so with gcc's -flto >> >> (link time optimization) option. >> > >> > Interesting! >> > >> >> 1) With today's master (afbcac68), adding -flto to CFLAGS causes the >> >> build to fail: >> >> >> >> | `_dlstart_c' referenced in section `.text' of /tmp/cc8ceNIy.ltrans0.ltrans.o: defined in discarded section `.text' of src/ldso/dlstart.lo (symbol from plugin) >> >> | collect2: error: ld returned 1 exit status >> >> | make: *** [lib/libc.so] Error 1 >> >> >> >> Reverting f1faa0e1 (make _dlstart_c function use hidden visibility) >> >> seems to be a workaround. >> > >> > I think the problem is that LTO is garbage collecting "unused" symbols >> > before it gets to the step of linking with asm for which there is no >> > IR code, thereby losing anything that's only referenced from asm. A >> > better workaround might be to define _dlstart_c with a different name >> > as a non-hidden function (e.g. call it __dls1) and then make >> > _dlstart_c a hidden alias for it via: >> > >> > __attribute__((__visibility__("hidden"))) >> > void _dlstart_c(size_t *, size_t *); >> > >> > weak_alias(__dls1, _dlstart_c); >> > >> > If you get a chance to try that, let me know if it works. >> >> That change does fix the build, but the resulting binary fails to run: >> >> $ gdb ./lib/libc.so >> .... >> (gdb) run >> Starting program: /home/andre/.../lib/libc.so >> >> Program received signal SIGILL, Illegal instruction. >> 0x56572ab8 in _dlstart () >> (gdb) disassemble >> Dump of assembler code for function _dlstart: >> 0x56572aa0 <+0>: xor %ebp,%ebp >> 0x56572aa2 <+2>: mov %esp,%eax >> 0x56572aa4 <+4>: and $0xfffffff0,%esp >> 0x56572aa7 <+7>: push %eax >> 0x56572aa8 <+8>: push %eax >> 0x56572aa9 <+9>: call 0x56572aae <_dlstart+14> >> 0x56572aae <+14>: addl $0x7864a,(%esp) >> 0x56572ab5 <+21>: push %eax >> 0x56572ab6 <+22>: call 0x56572ab7 <_dlstart+23> >> 0x56572abb <+27>: nop >> 0x56572abc <+28>: lea 0x0(%esi,%eiz,1),%esi >> End of assembler dump. >> (gdb) > > OK, it looks like the _dlstart_c symbol got removed before linking the > asm. What about selectively compiling this file with -fno-lto via > something like this in config.mak: > > src/ldso/dlstart.lo: CFLAGS += -fno-lto That works. Should I send a patch? >> > Also seems rather like what I would expect. Any idea if performance is >> > significantly better? It's not very comprehensive but you could try >> > libc-bench. >> >> I modified libc-bench so that it loops though everything in main() ten >> times and then ran the same libc-bench binary with each version of >> libc.so, sending output to /dev/null. >> >> The -O3 -flto build seems to be consistently very slightly *slower* >> than the non -flto version... > > That makes the whole thing somewhat less interesting. LTO is probably > more interesting for static libc. Yes, quite disappointing... I'll try to experiment a little with static linking. > > Rich