From patchwork Thu Feb 2 14:30:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 51953 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp272086wrn; Thu, 2 Feb 2023 06:31:27 -0800 (PST) X-Google-Smtp-Source: AK7set+ST1cFxYbSw+EmdUgh86kO//dRtE7VCyW3KDZJz87CE5/oLVi5ZwJc6Yoj4Jp6yFnwhlmy X-Received: by 2002:aa7:c1d7:0:b0:49d:9dd6:862f with SMTP id d23-20020aa7c1d7000000b0049d9dd6862fmr6353162edp.33.1675348287290; Thu, 02 Feb 2023 06:31:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675348287; cv=none; d=google.com; s=arc-20160816; b=vX3kRJY0UImagGjG01X7g6wrnW6iO8ofKBu90gkwvTI9vC2mGw/EgyTCkoPOGGM5PJ kweIPWGfZWFWEBV+KrXyKw88p8lH9idHuyrwjKcAoqLObBUNIY/dHdKx+y07/JdN2xyG 5ibiT5Kw8ZMZl0rfAP3vhAdYXzZV/2AMkXkEGWv5EVZyRcNzv2PRSyZjcZe94Z9/+OcZ 1tr34Z3RkBHnEErC1NEYsdOe9RR22jQCcAcnedDyPMtsrOyTIAFueOGLt65D2EZ5GO/N tDzHqXb0sm5n3l1yFsVwAEyRZbiW4wB1yhrBLdRv4qLzNQPjwZKDS1xv4i9nwq5EDVF5 CJGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=VvrPCKnEwh7C1F9cqnIVmkcS+c/7ODQgiHavdrFK7zM=; b=hjVhTD54tTY3tWrQU7qgelhlBfCEwSKOLJWgJmLX2gmG2ToEqDxrPmq0rOO2FqiNNT iWAhrA7fP0KvQqDt0LqSnzloesCiS+BlHc6lhjoAcEq7pyGyjzR2u7NdDBPu7AIIFJwH C5IaP3Pve/hAoRnX0QX5vgOjzAhpprYiKha6PUpyn4jeY5q7CxxPlfDABinBENrgX7Ua y++UEAAhuyBXAhcji+dilIUOmsfWgQbG4ZvDl1wRHQDJPJ1aa8tSIVXaVR4UBbHcftex ujqE5La5Hf4ExcqeiPixfgijVG9sfhWQSpir8VmDn8+oqxl3DY23Wg8NsUJnfOIw/xfk wdjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rvTYkQP8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cw14-20020a056402228e00b004a24ac0a648si12154019edb.79.2023.02.02.06.31.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 06:31:27 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rvTYkQP8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B4D0385842B for ; Thu, 2 Feb 2023 14:31:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B4D0385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675348286; bh=VvrPCKnEwh7C1F9cqnIVmkcS+c/7ODQgiHavdrFK7zM=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rvTYkQP8+HZltQefGL3p7GWlsFBb3r3O/lZCTTTJ4yqDMOetBJex0MYQnRN1Dgcz6 z0a4i/WpnUbwjBN/MvZYrffIR06BbTHxKL/QVkpuQpo6s4d6amf3MNjvbd4aa/wjHV IWAjpMInOYf2wASOy5XTyU1vNu27Z9GSfc2Y3b2M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D71233858C60 for ; Thu, 2 Feb 2023 14:30:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D71233858C60 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-113-79zrTxgVNQCS4Otg49kYOA-1; Thu, 02 Feb 2023 09:30:35 -0500 X-MC-Unique: 79zrTxgVNQCS4Otg49kYOA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFEFE85A588; Thu, 2 Feb 2023 14:30:34 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76631C15BA0; Thu, 2 Feb 2023 14:30:34 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 312EUUGl1324583 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 2 Feb 2023 15:30:31 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 312EUTMO1324582; Thu, 2 Feb 2023 15:30:29 +0100 Date: Thu, 2 Feb 2023 15:30:29 +0100 To: Richard Biener , Patrick Palka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree: Use comdat tree_code_{type,length} even for C++11/14 [PR108634] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756730005444783654?= X-GMAIL-MSGID: =?utf-8?q?1756730005444783654?= Hi! The recent change to undo the tree_code_type/tree_code_length excessive duplication apparently broke building the Linux kernel plugin. While it is certainly desirable that GCC plugins are built with the same compiler as GCC has been built and with the same options (at least the important ones), it might be hard to arrange that, e.g. if gcc is built using a cross-compiler but the plugin then built natively, or GCC isn't bootstrapped for other reasons, or just as in the kernel case they were building the plugin with -std=gnu++11 while the bootstrapped GCC has been built without any such option and so with whatever the compiler defaulted to. For C++17 and later tree_code_{type,length} are UNIQUE symbols with those assembler names, while for C++11/14 they were _ZL14tree_code_type and _ZL16tree_code_length. The following patch uses a comdat var for those even for C++11/14 as suggested by Maciej Cencora. Relying on weak attribute is not an option because not all hosts support it and there are non-GNU system compilers. While we could use it unconditionally, I think defining a template just to make it comdat is weird, and the compiler itself is always built with the same compiler. Plugins, being separate shared libraries, will have a separate copy of the arrays if they are ODR-used in the plugin, so there is not a big deal if e.g. cc1plus uses tree_code_type while plugin uses _ZN19tree_code_type_tmplILi0EE14tree_code_typeE or vice versa. Tested in non-bootstrapped build with both -std=gnu++17 and -std=gnu++11, ok for trunk if it passes full bootstrap/regtest? 2023-02-02 Jakub Jelinek PR plugins/108634 * tree-core.h (tree_code_type, tree_code_length): For C++11 or C++14, don't declare as extern const arrays. (tree_code_type_tmpl, tree_code_length_tmpl): New types with static constexpr member arrays for C++11 or C++14. * tree.h (TREE_CODE_CLASS): For C++11 or C++14 use tree_code_type_tmpl <0>::tree_code_type instead of tree_code_type. (TREE_CODE_LENGTH): For C++11 or C++14 use tree_code_length_tmpl <0>::tree_code_length instead of tree_code_length. * tree.cc (tree_code_type, tree_code_length): Remove. Jakub --- gcc/tree-core.h.jj 2023-01-27 10:51:27.575399052 +0100 +++ gcc/tree-core.h 2023-02-02 15:06:05.048665279 +0100 @@ -2285,19 +2285,27 @@ struct floatn_type_info { extern bool tree_contains_struct[MAX_TREE_CODES][64]; /* Class of tree given its code. */ -#if __cpp_inline_variables >= 201606L #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, #define END_OF_BASE_TREE_CODES tcc_exceptional, +#if __cpp_inline_variables < 201606L +template +struct tree_code_type_tmpl { + static constexpr enum tree_code_class tree_code_type[] = { +#include "all-tree.def" + }; +}; + +template +constexpr enum tree_code_class tree_code_type_tmpl::tree_code_type[]; +#else constexpr inline enum tree_code_class tree_code_type[] = { #include "all-tree.def" }; +#endif #undef DEFTREECODE #undef END_OF_BASE_TREE_CODES -#else -extern const enum tree_code_class tree_code_type[]; -#endif /* Each tree code class has an associated string representation. These must correspond to the tree_code_class entries. */ @@ -2305,18 +2313,27 @@ extern const char *const tree_code_class /* Number of argument-words in each kind of tree-node. */ -#if __cpp_inline_variables >= 201606L #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, #define END_OF_BASE_TREE_CODES 0, + +#if __cpp_inline_variables < 201606L +template +struct tree_code_length_tmpl { + static constexpr unsigned char tree_code_length[] = { +#include "all-tree.def" + }; +}; + +template +constexpr unsigned char tree_code_length_tmpl::tree_code_length[]; +#else constexpr inline unsigned char tree_code_length[] = { #include "all-tree.def" }; +#endif #undef DEFTREECODE #undef END_OF_BASE_TREE_CODES -#else -extern const unsigned char tree_code_length[]; -#endif /* Vector of all alias pairs for global symbols. */ extern GTY(()) vec *alias_pairs; --- gcc/tree.h.jj 2023-01-27 20:09:16.183970583 +0100 +++ gcc/tree.h 2023-02-02 14:37:17.255004291 +0100 @@ -177,7 +177,12 @@ code_helper::is_builtin_fn () const #define TREE_CODE_CLASS_STRING(CLASS)\ tree_code_class_strings[(int) (CLASS)] +#if __cpp_inline_variables < 201606L +#define TREE_CODE_CLASS(CODE) \ + tree_code_type_tmpl <0>::tree_code_type[(int) (CODE)] +#else #define TREE_CODE_CLASS(CODE) tree_code_type[(int) (CODE)] +#endif /* Nonzero if NODE represents an exceptional code. */ @@ -271,7 +276,12 @@ code_helper::is_builtin_fn () const #define EXPR_P(NODE) IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (NODE))) +#if __cpp_inline_variables < 201606L +#define TREE_CODE_LENGTH(CODE) \ + tree_code_length_tmpl <0>::tree_code_length[(int) (CODE)] +#else #define TREE_CODE_LENGTH(CODE) tree_code_length[(int) (CODE)] +#endif /* Helper macros for math builtins. */ --- gcc/tree.cc.jj 2023-02-02 10:54:44.302473853 +0100 +++ gcc/tree.cc 2023-02-02 14:20:58.712251654 +0100 @@ -74,34 +74,6 @@ along with GCC; see the file COPYING3. #include "asan.h" #include "ubsan.h" -#if __cpp_inline_variables < 201606L -/* Tree code classes. */ - -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, -#define END_OF_BASE_TREE_CODES tcc_exceptional, - -const enum tree_code_class tree_code_type[] = { -#include "all-tree.def" -}; - -#undef DEFTREECODE -#undef END_OF_BASE_TREE_CODES - -/* Table indexed by tree code giving number of expression - operands beyond the fixed part of the node structure. - Not used for types or decls. */ - -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, -#define END_OF_BASE_TREE_CODES 0, - -const unsigned char tree_code_length[] = { -#include "all-tree.def" -}; - -#undef DEFTREECODE -#undef END_OF_BASE_TREE_CODES -#endif - /* Names of tree components. Used for printing out the tree and error messages. */ #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,