From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 5F65E3858427 for ; Mon, 9 May 2022 09:05:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F65E3858427 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 806581F74D; Mon, 9 May 2022 09:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1652087142; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AEYEJOSEKM0l6JNh2iGMKAf2r6MQ48iAFrauws844NA=; b=gPckWUm/EW6q2RWffytzOQ0mXtuGk5UP9f1rkMs3jlWl0WnjqqVJa2Ju1aixyP+IwtJ/GC gNxvIJfCLF3gCm7fJuWLhB0NUCAlD8cGxgL16XIF3QhrXmunRMdFJVS4JlJCFmLP1s6UYL S7H6eR1RmY4k87yR+1pJgdPT9IJT9dU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1652087142; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AEYEJOSEKM0l6JNh2iGMKAf2r6MQ48iAFrauws844NA=; b=28M32wwk1eDfiDiTbjwVCGbz8kQadAaHRWacvhSr5geau3ptwOQ1GHtiV8QPFL1prtJgNc jcq/jevU/6fXYxAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5709013AA5; Mon, 9 May 2022 09:05:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TvgqFGbZeGJkVgAAMHmgww (envelope-from ); Mon, 09 May 2022 09:05:42 +0000 Message-ID: <62cd2acb-7072-5f9e-a787-ae02a605fbd5@suse.cz> Date: Mon, 9 May 2022 11:05:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] lto-plugin: add support for feature detection Content-Language: en-US To: Alexander Monakov Cc: Richard Biener , GCC Patches , Jan Hubicka , rui314@gmail.com References: <63633ead-aa7e-c424-9851-ac332ac13df3@suse.cz> <27841a42-baef-d53e-c601-ad265030854d@suse.cz> <80f37f2-efdf-673-a8f4-69f2d5842ea2@ispras.ru> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= In-Reply-To: <80f37f2-efdf-673-a8f4-69f2d5842ea2@ispras.ru> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2022 09:05:48 -0000 CCing mold's author. On 5/6/22 16:46, Alexander Monakov wrote: > > > On Thu, 5 May 2022, Martin Liška wrote: > >> On 5/5/22 12:52, Alexander Monakov wrote: >>> Feels a bit weird to ask, but before entertaining such an API extension, >>> can we step back and understand the v3 variant of get_symbols? It is not >>> documented, and from what little I saw I did not get the "motivation" for >>> its existence (what it is doing that couldn't be done with the v2 api). >> >> Please see here: >> https://github.com/rui314/mold/issues/181#issuecomment-1037927757 > > Thanks. I've also re-read [1] and [2] which provided some relevant ideas. > > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86490 > [2] https://sourceware.org/bugzilla/show_bug.cgi?id=23411 > > > OK, so the crux of the issue is that sometimes the linker needs to feed the > compiler plugin with LTO .o files extracted from static archives. This is > not really obvious, because normally .a archives have an index that enumerates > symbols defined/used by its .o files, and even during LTO the linker can simply > consult the index to find out which members to extract. In theory, at least. > > The theory breaks in the following cases: > > - ld.bfd and common symbols (I wonder if weak/comdat code is also affected?): > archive index does not indicate which definitions are common, so ld.bfd > extracts the member and feeds it to the plugin to find out; > > - ld.gold and emulated archives via --start-lib a.o b.o ... --end-lib: here > there's no index to consult and ld.gold feeds each .o to the plugin. > > In those cases it may happen that the linker extracts an .o file that would > not be extracted during non-LTO link, and if that happens, the linker needs to > inform the plugin. This is not the same as marking each symbol from spuriously > extracted .o file as PREEMPTED when the .o file has constructors (the plugin > will assume the constructors are kept while the linker needs to discard them). > > So get_symbols_v3 allows the linker to discard an LTO .o file to solve this. > > In absence of get_symbols_v3 mold tries to ensure correctness by restarting > itself while appending a list of .o files to be discarded to its command line. > > I wonder if mold can invoke plugin cleanup callback to solve this without > restarting. > > (also, hm, it seems to confirm my idea that LTO .o files should have had the > correct symbol table so normal linker algorithms would work) > > Hopefully this was useful. > Alexander