From patchwork Tue May 3 14:04:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1625549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=FrwT1wEK; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=hzYDxIQd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kt1tP6J1vz9s5V for ; Wed, 4 May 2022 00:04:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC3C1394843F for ; Tue, 3 May 2022 14:04:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 1B4CD3856DC6 for ; Tue, 3 May 2022 14:04:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B4CD3856DC6 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 1F4791F38D; Tue, 3 May 2022 14:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651586654; 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=zdjD3frHmo7F3XbdPxtUBUKcbwFcmaTxtDr3BIx3vG0=; b=FrwT1wEK5zG9HxMH82lvyCJ+1lcO+KMb10MkzuT6wvtXmwQT9TMY2L9MOyhGVVohOeClpt YiFrScw055D/ZMTdxsqKNtOASuYq4oVu7UJynekvUkZVPv1FDd93kluA93nbds67jOPecE TrQRFhLZQhUiZi7PUqmVg5GxG0Y67LI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651586654; 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=zdjD3frHmo7F3XbdPxtUBUKcbwFcmaTxtDr3BIx3vG0=; b=hzYDxIQd7+0HkNsMi5UOVHj5jnO+AwNA2IyVwYTyJFL6eG6+JTbVu7bpnJIeFDU3iuH7kO qukIRUfajV+52yDQ== 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 0BD3F13AA3; Tue, 3 May 2022 14:04:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id O1/NAV42cWLwWwAAMHmgww (envelope-from ); Tue, 03 May 2022 14:04:14 +0000 Message-ID: <3be6593e-380c-38a9-9660-164946f7a22f@suse.cz> Date: Tue, 3 May 2022 16:04:13 +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] LTO plugin: modernize a bit. To: gcc-patches@gcc.gnu.org Content-Language: en-US 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: , Cc: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This is a follow up patch of something I sent last stage1. I'm not planning moving to C++, but I would like to see this patch go in. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin include/ChangeLog: * plugin-api.h (enum ld_plugin_tag): Do not set implicit enum values. lto-plugin/ChangeLog: * lto-plugin.c (struct plugin_objfile): Use bool for offset field. (exec_lto_wrapper): Assign true/false to bool variables. (process_offload_section): Likewise. (claim_file_handler): Likewise. (onload): Likewise. --- include/plugin-api.h | 68 ++++++++++++++++++++--------------------- lto-plugin/lto-plugin.c | 19 ++++++------ 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/include/plugin-api.h b/include/plugin-api.h index 4e12c0320d6..8aebe2ff267 100644 --- a/include/plugin-api.h +++ b/include/plugin-api.h @@ -487,40 +487,40 @@ enum ld_plugin_level enum ld_plugin_tag { - LDPT_NULL = 0, - LDPT_API_VERSION = 1, - LDPT_GOLD_VERSION = 2, - LDPT_LINKER_OUTPUT = 3, - LDPT_OPTION = 4, - LDPT_REGISTER_CLAIM_FILE_HOOK = 5, - LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK = 6, - LDPT_REGISTER_CLEANUP_HOOK = 7, - LDPT_ADD_SYMBOLS = 8, - LDPT_GET_SYMBOLS = 9, - LDPT_ADD_INPUT_FILE = 10, - LDPT_MESSAGE = 11, - LDPT_GET_INPUT_FILE = 12, - LDPT_RELEASE_INPUT_FILE = 13, - LDPT_ADD_INPUT_LIBRARY = 14, - LDPT_OUTPUT_NAME = 15, - LDPT_SET_EXTRA_LIBRARY_PATH = 16, - LDPT_GNU_LD_VERSION = 17, - LDPT_GET_VIEW = 18, - LDPT_GET_INPUT_SECTION_COUNT = 19, - LDPT_GET_INPUT_SECTION_TYPE = 20, - LDPT_GET_INPUT_SECTION_NAME = 21, - LDPT_GET_INPUT_SECTION_CONTENTS = 22, - LDPT_UPDATE_SECTION_ORDER = 23, - LDPT_ALLOW_SECTION_ORDERING = 24, - LDPT_GET_SYMBOLS_V2 = 25, - LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS = 26, - LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27, - LDPT_GET_SYMBOLS_V3 = 28, - LDPT_GET_INPUT_SECTION_ALIGNMENT = 29, - LDPT_GET_INPUT_SECTION_SIZE = 30, - LDPT_REGISTER_NEW_INPUT_HOOK = 31, - LDPT_GET_WRAP_SYMBOLS = 32, - LDPT_ADD_SYMBOLS_V2 = 33 + LDPT_NULL, + LDPT_API_VERSION, + LDPT_GOLD_VERSION, + LDPT_LINKER_OUTPUT, + LDPT_OPTION, + LDPT_REGISTER_CLAIM_FILE_HOOK, + LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK, + LDPT_REGISTER_CLEANUP_HOOK, + LDPT_ADD_SYMBOLS, + LDPT_GET_SYMBOLS, + LDPT_ADD_INPUT_FILE, + LDPT_MESSAGE, + LDPT_GET_INPUT_FILE, + LDPT_RELEASE_INPUT_FILE, + LDPT_ADD_INPUT_LIBRARY, + LDPT_OUTPUT_NAME, + LDPT_SET_EXTRA_LIBRARY_PATH, + LDPT_GNU_LD_VERSION, + LDPT_GET_VIEW, + LDPT_GET_INPUT_SECTION_COUNT, + LDPT_GET_INPUT_SECTION_TYPE, + LDPT_GET_INPUT_SECTION_NAME, + LDPT_GET_INPUT_SECTION_CONTENTS, + LDPT_UPDATE_SECTION_ORDER, + LDPT_ALLOW_SECTION_ORDERING, + LDPT_GET_SYMBOLS_V2, + LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS, + LDPT_UNIQUE_SEGMENT_FOR_SECTIONS, + LDPT_GET_SYMBOLS_V3, + LDPT_GET_INPUT_SECTION_ALIGNMENT, + LDPT_GET_INPUT_SECTION_SIZE, + LDPT_REGISTER_NEW_INPUT_HOOK, + LDPT_GET_WRAP_SYMBOLS, + LDPT_ADD_SYMBOLS_V2, }; /* The plugin transfer vector. */ diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c index 33d49571d0e..47378435612 100644 --- a/lto-plugin/lto-plugin.c +++ b/lto-plugin/lto-plugin.c @@ -122,7 +122,7 @@ struct plugin_symtab struct plugin_objfile { int found; - int offload; + bool offload; simple_object_read *objfile; struct plugin_symtab *out; const struct ld_plugin_input_file *file; @@ -205,7 +205,7 @@ static const char *link_output_name = NULL; /* This indicates link_output_name already contains the dot of the suffix, so we can skip it in extensions. */ -static int skip_in_suffix = 0; +static bool skip_in_suffix = false; /* The version of gold being used, or -1 if not gold. The number is MAJOR * 100 + MINOR. */ @@ -636,7 +636,8 @@ exec_lto_wrapper (char *argv[]) /* Write argv to a file to avoid a command line that is too long Save the file locally on save-temps. */ const char *suffix = ".lto_wrapper_args"; - suffix += skip_in_suffix; + if (skip_in_suffix) + suffix++; if (save_temps && link_output_name) arguments_file_name = concat (link_output_name, suffix, NULL); else @@ -1139,7 +1140,7 @@ process_offload_section (void *data, const char *name, off_t offset, off_t len) if (startswith (name, ".gnu.offload_lto_.opts")) { struct plugin_objfile *obj = (struct plugin_objfile *) data; - obj->offload = 1; + obj->offload = true; return 0; } @@ -1182,7 +1183,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) *claimed = 0; obj.file = file; obj.found = 0; - obj.offload = 0; + obj.offload = false; obj.out = <o_file.symtab; errmsg = NULL; obj.objfile = simple_object_start_read (file->fd, file->offset, LTO_SEGMENT_NAME, @@ -1220,7 +1221,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) simple_object_find_sections (obj.objfile, process_offload_section, &obj, &err); - if (obj.found == 0 && obj.offload == 0) + if (obj.found == 0 && !obj.offload) goto err; if (obj.found > 1) @@ -1257,10 +1258,10 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) /* If this is an LTO file without offload, and it is the first LTO file, save the pointer to the last offload file in the list. Further offload LTO files will be inserted after it, if any. */ - if (*claimed && obj.offload == 0 && offload_files_last_lto == NULL) + if (*claimed && !obj.offload && offload_files_last_lto == NULL) offload_files_last_lto = offload_files_last; - if (obj.offload == 1) + if (obj.offload) { /* Add file to the list. The order must be exactly the same as the final order after recompilation and linking, otherwise host and target tables @@ -1547,7 +1548,7 @@ onload (struct ld_plugin_tv *tv) assert (escapes == 0); assert (ticks == oddticks); assert (q - link_output_name == len - 1); - skip_in_suffix = 1; + skip_in_suffix = true; } }