From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 9B2B53858D33 for ; Mon, 2 May 2022 07:51:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B2B53858D33 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-out1.suse.de (Postfix) with ESMTPS id 5C6DF21875; Mon, 2 May 2022 07:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651477863; 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; bh=CyV4CKIsqUJ+QZ0I79Q0B8YFW7FaGenAYnQX/jnCkHY=; b=ipYKDVJCWN+c2aNHg2CmYLNGoanQHytrRDATHVrbTQB111fK5kntOaSr4Ie0yxj8ST7TcP DF28nSlD4pyOq21fkt/KuvDLjC3iZCMNacYngWw0OnD8jiEOReR+RNyTMJyVgVYWTIvdWq bBAp9KuZEUi6tOU5Y5ga0y7eRzOiQbk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651477863; 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; bh=CyV4CKIsqUJ+QZ0I79Q0B8YFW7FaGenAYnQX/jnCkHY=; b=NsscgpYrBMOhk15lI8NH7m6A32nbU4ddjek2PVuIuBNLlegK7pslILjha058x6o33SEwsb sBrWu9nZCf4/81CQ== 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 43811133E5; Mon, 2 May 2022 07:51:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id r6KTD2eNb2J9fgAAMHmgww (envelope-from ); Mon, 02 May 2022 07:51:03 +0000 Message-ID: <63633ead-aa7e-c424-9851-ac332ac13df3@suse.cz> Date: Mon, 2 May 2022 09:51:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Support LDPT_GET_SYMBOLS_V3. To: gcc-patches@gcc.gnu.org Content-Language: en-US Cc: Jan Hubicka , Cary Coutant Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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, 02 May 2022 07:51:06 -0000 That supports skipping of an object file (LDPS_NO_SYMS). The API will be used by mold and is there for some time in linkers. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin lto-plugin/ChangeLog: * lto-plugin.c (struct plugin_file_info): Add skip_file flag. (write_resolution): Write resolution only if get_symbols != LDPS_NO_SYMS. (all_symbols_read_handler): Ignore file if skip_file is true. (onload): Handle LDPT_GET_SYMBOLS_V3. --- lto-plugin/lto-plugin.c | 42 ++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c index 33d49571d0e..aa5eab48b9d 100644 --- a/lto-plugin/lto-plugin.c +++ b/lto-plugin/lto-plugin.c @@ -136,6 +136,7 @@ struct plugin_file_info void *handle; struct plugin_symtab symtab; struct plugin_symtab conflicts; + bool skip_file; }; /* List item with name of the file with offloading. */ @@ -159,7 +160,7 @@ enum symbol_style static char *arguments_file_name; static ld_plugin_register_claim_file register_claim_file; static ld_plugin_register_all_symbols_read register_all_symbols_read; -static ld_plugin_get_symbols get_symbols, get_symbols_v2; +static ld_plugin_get_symbols get_symbols, get_symbols_v2, get_symbols_v3; static ld_plugin_register_cleanup register_cleanup; static ld_plugin_add_input_file add_input_file; static ld_plugin_add_input_library add_input_library; @@ -547,15 +548,13 @@ free_symtab (struct plugin_symtab *symtab) static void write_resolution (void) { - unsigned int i; + unsigned int i, included_files = 0; FILE *f; check (resolution_file, LDPL_FATAL, "resolution file not specified"); f = fopen (resolution_file, "w"); check (f, LDPL_FATAL, "could not open file"); - fprintf (f, "%d\n", num_claimed_files); - for (i = 0; i < num_claimed_files; i++) { struct plugin_file_info *info = &claimed_files[i]; @@ -563,13 +562,38 @@ write_resolution (void) struct ld_plugin_symbol *syms = symtab->syms; /* Version 2 of API supports IRONLY_EXP resolution that is - accepted by GCC-4.7 and newer. */ - if (get_symbols_v2) + accepted by GCC-4.7 and newer. + Version 3 can return LDPS_NO_SYMS that means the object + will not be used at all. */ + if (get_symbols_v3) + { + enum ld_plugin_status status + = get_symbols_v3 (info->handle, symtab->nsyms, syms); + if (status == LDPS_NO_SYMS) + { + info->skip_file = true; + continue; + } + } + else if (get_symbols_v2) get_symbols_v2 (info->handle, symtab->nsyms, syms); else get_symbols (info->handle, symtab->nsyms, syms); + ++included_files; + finish_conflict_resolution (symtab, &info->conflicts); + } + + fprintf (f, "%d\n", included_files); + + for (i = 0; i < num_claimed_files; i++) + { + struct plugin_file_info *info = &claimed_files[i]; + struct plugin_symtab *symtab = &info->symtab; + + if (info->skip_file) + continue; fprintf (f, "%s %d\n", info->name, symtab->nsyms + info->conflicts.nsyms); dump_symtab (f, symtab); @@ -832,7 +856,8 @@ all_symbols_read_handler (void) { struct plugin_file_info *info = &claimed_files[i]; - *lto_arg_ptr++ = info->name; + if (!info->skip_file) + *lto_arg_ptr++ = info->name; } *lto_arg_ptr++ = NULL; @@ -1409,6 +1434,9 @@ onload (struct ld_plugin_tv *tv) case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK: register_all_symbols_read = p->tv_u.tv_register_all_symbols_read; break; + case LDPT_GET_SYMBOLS_V3: + get_symbols_v3 = p->tv_u.tv_get_symbols; + break; case LDPT_GET_SYMBOLS_V2: get_symbols_v2 = p->tv_u.tv_get_symbols; break; -- 2.36.0