From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7558 Path: news.gmane.org!not-for-mail From: Andy Lutomirski Newsgroups: gmane.linux.lib.musl.general Subject: Re: building musl libc.so with gcc -flto Date: Thu, 30 Apr 2015 13:46:21 -0700 Message-ID: <5542949D.8000509@kernel.org> References: <1429742932-6026-1-git-send-email-armccurdy@gmail.com> <20150423022309.GH6817@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1430429495 18188 80.91.229.3 (30 Apr 2015 21:31:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 30 Apr 2015 21:31:35 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7571-gllmg-musl=m.gmane.org@lists.openwall.com Thu Apr 30 23:31:34 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 1Ynw3O-0001MT-Ro for gllmg-musl@m.gmane.org; Thu, 30 Apr 2015 23:31:30 +0200 Original-Received: (qmail 30394 invoked by uid 550); 30 Apr 2015 21:31:28 -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 9694 invoked from network); 30 Apr 2015 20:46:36 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: <20150423022309.GH6817@brightrain.aerifal.cx> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Xref: news.gmane.org gmane.linux.lib.musl.general:7558 Archived-At: On 04/22/2015 07: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. Another > option might be adding -Wl,-u,_dlstart_c to LDFLAGS. Wouldn't adding __attribute__((externally_visible)) to the relevant symbols be more appropriate? It's intended to solve exactly this problem. --Andy