From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8139 invoked by alias); 26 Feb 2011 03:48:12 -0000 Received: (qmail 8130 invoked by uid 22791); 26 Feb 2011 03:48:12 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-iy0-f169.google.com (HELO mail-iy0-f169.google.com) (209.85.210.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 26 Feb 2011 03:48:07 +0000 Received: by iyf13 with SMTP id 13so1819950iyf.0 for ; Fri, 25 Feb 2011 19:48:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.166.138 with SMTP id o10mr1786845icy.22.1298692086142; Fri, 25 Feb 2011 19:48:06 -0800 (PST) Received: by 10.42.60.129 with HTTP; Fri, 25 Feb 2011 19:48:06 -0800 (PST) In-Reply-To: <4D687545.8010303@gmail.com> References: <4D684CB8.6020106@gmail.com> <4D687545.8010303@gmail.com> Date: Sat, 26 Feb 2011 03:48:00 -0000 Message-ID: Subject: Re: [PATCH,trunk+2.20] Fix issues in ld.bfd plugin interface [0/6] From: "H.J. Lu" To: Dave Korn Cc: "binutils@sourceware.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00342.txt.bz2 On Fri, Feb 25, 2011 at 7:36 PM, Dave Korn wro= te: > On 26/02/2011 02:14, H.J. Lu wrote: > >> >> The question is if LTO linker should link in non-LTO copy of the same fu= nction >> and ignore the LTO-IR copy: > > =A0Well, I think the linker should link at least one of them in, preferab= ly the > IR one if it can so that it can be optimised along with the rest of the > program, but if for some reason the linker can't see that it's needed unt= il > after ltrans, then it has no choice but to link the non-LTO copy, and set= tle > for what should after all only be a missed optimisation rather than > correctness problem. The fact that linker doesn't link in the LTO copy means that the non-LTO co= py isn't required by GCC. >> [hjl@gnu-6 pr12496-2]$ make >> as --32 =A0-o start.o start.s >> /usr/gcc-4.6/bin/gcc -m32 -B./ -flto =A0 -c -o main.o main.c >> /usr/gcc-4.6/bin/gcc -m32 -B./ -flto =A0 -c -o div.o div.c >> ar rv libdiv.a div.o >> ar: creating libdiv.a >> a - div.o >> /usr/gcc-4.6/bin/gcc -m32 -B./ -O2 -flto -nostdlib -o prog >> -Wl,--start-group start.o main.o libdiv.a -Wl,--end-group > > =A0When I tried this with ld.hjl on i686-pc-cygwin, I got an undefined > reference to __udivdi3, is that supposed to happen? That is also my question. What should happen if div.o only has IR? My take on this is this is a user error. >> Here div.o is compiled with -O0 -flto and the final link is compiled >> with -O2 -flto. I would expect div.c is compiled with -O2 -flto, not -O0, >> if div.c is linked in. Am I expecting too much? > > =A0Well, to make that work, wouldn't we have to treat all archives as if = they > were opened in --whole-archive mode during stage1, and let the plugin cla= im > every archive member that contains any IR and then rely on LTRANS to opti= mise > away all but the used code, right? > > =A0I must admit I don't understand why LTO doesn't emit undefs in the LTO > symtab for builtins. =A0I think life would be easier all round if the LTO= symtab > for main.o contained a reference to __udivdi3 all along, so that we could= just > let the usual mechanism pull in all (and only) the needed stuff straight = off > in stage1 and not give LTRANS so much redundant work to do. > That will be wrong since LTO may not need to call __udivdi3 if it can be folded. --=20 H.J.