From patchwork Tue Oct 29 14:29:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 2003755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=NYz6wbFp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XdCMj5JxHz1xwF for ; Wed, 30 Oct 2024 01:30:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7F783858408 for ; Tue, 29 Oct 2024 14:30:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xmbghk7.mail.qq.com (xmbghk7.mail.qq.com [43.163.128.44]) by sourceware.org (Postfix) with UTF8SMTPS id B8D933858C98 for ; Tue, 29 Oct 2024 14:29:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8D933858C98 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cyyself.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cyyself.name ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B8D933858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=43.163.128.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730212186; cv=none; b=mcv+j4N6BTfS8KW8eIxxCr0voxy9JveR5UEejoJBrU7UDXr7lYxjE+CE1sbtQWh+5mNHWTUCs3sscyGqXWiYFE8mLyiUAskI9XhDiggyIy+KqSFtZ6TBdTqwUfJ3uOZGED0cxp7dehUPhyWCmmjd6WE4YrmhmPhZE8zkH1U0t60= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730212186; c=relaxed/simple; bh=iHwFJMHFWCLeLz0/ctWQwClRLnSCpEWCgrB+d58K9Sc=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=P2H6mVWsjtejXcj4VU5PEEcxtZdjJHGFapqgES4reb0i6MGm3GgqlxK+fCSE2kOP1FfJX8IbtUIbq5pRfrHmKf+beHEZrOnoe7FQ7UNGwFNu9XGAkp8AmDhGvQ32j4pFqxMmTuopqmKXvuXjw4YjOgrHR0AE9SBd9tLu5Sg5vaY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1730212176; bh=NhCqulWAtfb92Sj1f3sk/liw0N77LJ+lTwH3DPGKch8=; h=From:To:Cc:Subject:Date; b=NYz6wbFpsZJ7Ttmn15IjvBVguZjPuUJcMQFB+nOTh5yHa1J2k/LM5XryuQFoGw5Vv 3p0oKcc1Xpb86HYYpjyzI4c81Nv2ch+vJs0mw4HybnxZmjuqC54NFficcKutIeYrdc JbsKYheig/yLZpiL6aRGShmyZORG7We9+W6QA6l4= Received: from m1.lan ([2001:da8:c800:d69b:38c2:6067:5d9d:4102]) by newxmesmtplogicsvrsza36-0.qq.com (NewEsmtp) with SMTP id 76105CCA; Tue, 29 Oct 2024 22:29:33 +0800 X-QQ-mid: xmsmtpt1730212173t1wf9pyx6 Message-ID: X-QQ-XMAILINFO: NPZcszwnKSXOjjbVXIo293Tf2z6eEIA1krNt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-patches@gcc.gnu.org Cc: Andrew Carlotti , Richard Sandiford , Yangyu Chen Subject: [PATCH v3] [aarch64] Fix function multiversioning dispatcher link error with LTO Date: Tue, 29 Oct 2024 14:29:28 +0000 X-OQ-MSGID: <20241029142928.580423-1-cyy@cyyself.name> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org We forgot to apply DECL_EXTERNAL to __init_cpu_features_resolver decl. When building with LTO, the linker cannot find the __init_cpu_features_resolver.lto_priv* symbol, causing the link error. This patch gets this fixed by adding DECL_EXTERNAL to the decl. To avoid used but never defined warning for this symbol, we also mark TREE_PUBLIC to the decl. We should also mark the decl having hidden visibility. And fix the attribute in the same way for __aarch64_cpu_features identifier. Minimal steps to reproduce the bug: echo '__attribute__((target_clones("default", "aes"))) void func1() { }' > 1.c echo '__attribute__((target_clones("default", "aes"))) void func2() { }' > 2.c echo 'void func1();void func2();int main(){func1();func2();return 0;}' > main.c gcc -flto -c 1.c 2.c gcc -flto main.c 1.o 2.o Fixes: 0cfde688e213 ("[aarch64] Add function multiversioning support") gcc/ChangeLog: * config/aarch64/aarch64.cc (dispatch_function_versions): Adding DECL_EXTERNAL, TREE_PUBLIC and hidden DECL_VISIBILITY to __init_cpu_features_resolver and __aarch64_cpu_features. --- gcc/config/aarch64/aarch64.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 5770491b30c..2b2d5b9e390 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -20437,6 +20437,10 @@ dispatch_function_versions (tree dispatch_decl, tree init_fn_id = get_identifier ("__init_cpu_features_resolver"); tree init_fn_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, init_fn_id, init_fn_type); + DECL_EXTERNAL (init_fn_decl) = 1; + TREE_PUBLIC (init_fn_decl) = 1; + DECL_VISIBILITY (init_fn_decl) = VISIBILITY_HIDDEN; + DECL_VISIBILITY_SPECIFIED (init_fn_decl) = 1; tree arg1 = DECL_ARGUMENTS (dispatch_decl); tree arg2 = TREE_CHAIN (arg1); ifunc_cpu_init_stmt = gimple_build_call (init_fn_decl, 2, arg1, arg2); @@ -20456,6 +20460,9 @@ dispatch_function_versions (tree dispatch_decl, get_identifier ("__aarch64_cpu_features"), global_type); DECL_EXTERNAL (global_var) = 1; + TREE_PUBLIC (global_var) = 1; + DECL_VISIBILITY (global_var) = VISIBILITY_HIDDEN; + DECL_VISIBILITY_SPECIFIED (global_var) = 1; tree mask_var = create_tmp_var (long_long_unsigned_type_node); tree component_expr = build3 (COMPONENT_REF, long_long_unsigned_type_node,