From patchwork Thu Dec 1 15:33:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Coplan X-Patchwork-Id: 1711059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jD6W3vqu; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NNKqb4WqWz23ng for ; Fri, 2 Dec 2022 02:34:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B06D3855176 for ; Thu, 1 Dec 2022 15:34:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B06D3855176 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669908840; bh=EiWkSayVZ5mH9gHowqsyT0fy/bgSEShhT+HrMGvFMy8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jD6W3vqujiYBe9mbpg0I5jKGmB+Kg4oS0pDnL3o4eURpB3HBdcZ9TlJR/3N1N2t6/ ZbKaLzKVJh785qHc1xMKmQ+o5BHaGdBGzv/GmtFHLrVJtiZN3f4O7hyEtgmtszPoZB VdH4JDcOEekzA0ZKkauUPX67lVVAcOpnerJb5NOQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2061.outbound.protection.outlook.com [40.107.105.61]) by sourceware.org (Postfix) with ESMTPS id 22C5E3858C33 for ; Thu, 1 Dec 2022 15:33:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22C5E3858C33 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DCPriy+HJLvMQUO4NffiMNpmyHywuFTmBA8XshcOF1s44Ek/LsOYCnX8Dq3cw4DxZzCGNvtPSn5QYzS+iTh0NthjHkblHWb19Fc9aIPW8C4PRYDdMPruhUBx/3tRI+oam/J5xzfaE57VRAzQ7Du+T6Rq43auGHgGljlgQ+XBrY0dat8KOryUQnp5G8OXDaeCtUkB9/rDHqEweyNHcCfnh+g210/wDVTTGHw7+zAJU5YTfRWij5VaJDVY9Fih87E7apKeH/vgxsy8pDaJpMuAS9K5f39ZuFREmPMMxoWwpOCMwGjt+VEfKQD/Cl2rijn539AVWheLQuJlIgK3ebYdrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EiWkSayVZ5mH9gHowqsyT0fy/bgSEShhT+HrMGvFMy8=; b=DvCCp81IOKXPQ9CFtfS71PcLYDjqm6kovCvtoSLVU75cbNHqCtSHtmnxBmmi5oPxvfZeLPUVkuZgboJxnpFS90uwSVW01UhvJlDZCg1GE9YGcXBC4gDX/TVSVuzRIMcHvTu/QYhHyV8+hwboB4TJDp6YXjqEL97TBC7jAAZkAOHNGBBCx25g6+CsVMOPsNfiN5Tn2wxI51Bd0P7KUUT/7jtrKqlqIFkN/lyehZShFs/p5CwaUjg3X6gUZRlDJWhP1l4d9jGxjFOjbff6A4vs/ZIjh7kKrJKHnozp/GMq+0n0Ds6ncZWTFaiL7gxfZXmyoND/Gp9/Sg8s1VKYaz2YsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Received: from PAXPR08MB7201.eurprd08.prod.outlook.com (2603:10a6:102:20b::17) by PAXPR08MB6416.eurprd08.prod.outlook.com (2603:10a6:102:152::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Thu, 1 Dec 2022 15:33:35 +0000 Received: from PAXPR08MB7201.eurprd08.prod.outlook.com ([fe80::40bc:b698:5059:f02]) by PAXPR08MB7201.eurprd08.prod.outlook.com ([fe80::40bc:b698:5059:f02%4]) with mapi id 15.20.5880.008; Thu, 1 Dec 2022 15:33:34 +0000 Date: Thu, 1 Dec 2022 15:33:30 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH] varasm: Fix type confusion bug Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO2P123CA0019.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::31) To PAXPR08MB7201.eurprd08.prod.outlook.com (2603:10a6:102:20b::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR08MB7201:EE_|PAXPR08MB6416:EE_ X-MS-Office365-Filtering-Correlation-Id: f93693f9-a3dd-4528-b26e-08dad3b167c5 NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EL6fMyX3aqzoQHIYGRGapy6LAwLeMeMcFO6MCinilqtHACh8HqMiyEvBVYcL1TKyoMwo1rTXb026PgfqPll/WW47ASPmW0D4iQd8ogqNI+oBCiS9NoODCXfnx7qHmM4Z6yfHwvXGMamoNkpVx1SIc3WexB0s03J2hSexeyA7MQyGi0ddAS5G8KKEPVNQ9fU7T6fNu2Mi6eJ+fwuI2qLsPr2ivNcYrUmHHD4FqbhKy/mFx9GlczHwW2m5VILPN86LI3qdnoCYnaMbDlmr/tRWN0TdBW3Icqt6BKjOZLRa3SsNxL6FncmpAmli+O+6BjcqO+HbbmWs7GZ6JkQAnPYkcsEYixKuiEOIJmIhfPx2R19Q9IUkN+3OtRqDKxDUjLJ6TwXrsZU+DTHQjwGcwx+7OOC7dwZsvP+kySY+0CrHKk59RwYxcmpCZnU+kIiCl+nHXGijf62PHgGbJ/cIArqhHd4KWoInOFU9ZCrNG1zNT4DIV8Bb0Y6qHgEnBFJkru/M1k3pPJZOHHN8ZdSue9PGqZga/n3b0ofOm0hI29UThyeZ70n/Ha76iQjCmmfbty5IODSPLsQY+xE7TxbNPGIS0sBD8ZDkCl7XKywGm08k7CfBN5ObGODq9uzXyZiHonGAG6kdw+7+aJ6mXR20hD4HKveEBKFuWdkWa+hJb59fTcLUQPjZJc0+Qd1hgh5sRhPCVt8OJxosfCrihstoB305BA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB7201.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(136003)(366004)(39860400002)(346002)(396003)(376002)(451199015)(86362001)(33964004)(21480400003)(6666004)(83380400001)(26005)(6506007)(44144004)(2906002)(6512007)(5660300002)(38100700002)(235185007)(44832011)(6916009)(316002)(478600001)(8676002)(8936002)(66946007)(186003)(66556008)(66476007)(6486002)(2616005)(41300700001)(36756003)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?6I4Vi/j+PDwa7xyCHS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JyqBPXL9SAhojKt/tKD?= =?utf-8?q?wG23KI3g7ytRY1GcFsfFn8g0Kt+g5VU2BZ9X817uc5Gy1tQET9JvewebVkgQIYy8y?= =?utf-8?q?VGbnhp4Z/CqvByKui1gkcf+7KhkaZuWyXlALQ4Un39w9ljpiWBXGnFNlOGHZ1JS/c?= =?utf-8?q?SQXK930z7WEa9BrPnqKNE5na7mLJD0hNt+3ZfTK9fRBLplA6TUAZiEzBGPOKtfY/r?= =?utf-8?q?a3VsTGzSN4Guv2shAUmaD6d5PEMe4bPdLyY3oNGeByJwpmDz3BFsmHzUb22oZl2ra?= =?utf-8?q?8fc5cRTwkENueMXvL3bpLzHkfZim63vV7iXC0VjzMv7Z03xR5P1yedRmyhO8Awtm7?= =?utf-8?q?BCnLwH/JBSEg+PrLwOPECLz1Q7KKVw19+QkH0aVayw+27VmviBGN0QnagY8kQkzMf?= =?utf-8?q?T1lxAT1vqr8+z7q9AEOlbKjp/Cd/FCl+PbnojeeHOIkhV1/eZ8IvR2Q0skKYVYGp3?= =?utf-8?q?1VSsFtK8Dtadiw53bPCOUQ/aTidg4+dWFKj8m9xTxkn5ReiTQyrmIBUyQ8sUTkYJ7?= =?utf-8?q?exhaFMMdmyvaZhK64dYY4P5W5oUy7Vuk1W1RbviKCfNXI09wiuttB36XM2uaAozcv?= =?utf-8?q?qplNLbjHMRTT9eu8ka46eA1JWKWIWqQiUVsySU15eEGWG7XkxHECjnD9wEQ5hoiFj?= =?utf-8?q?tKakyaTLlQXf?= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: f93693f9-a3dd-4528-b26e-08dad3b167c5 X-MS-Exchange-CrossTenant-AuthSource: PAXPR08MB7201.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2022 15:33:34.7850 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SWs1IcYF3sHLkiYLUd1tTESXFbIplr+1826MLYlxJ1D7norkQnjf6WqFGbMn8KzM4EFj9xbzmNMdaMJ+LiMQRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6416 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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: Alex Coplan via Gcc-patches From: Alex Coplan Reply-To: Alex Coplan Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch fixes a type confusion bug in varasm.cc:assemble_variable. The problem is that the current code calls: sect = get_variable_section (decl, false); and then accesses sect->named.name without checking whether the section is in fact a named section. In the surrounding else clause, we only know that SECTION_STYLE (sect) != SECTION_NOSWITCH, so it is possible that the section is an unnamed section. In practice, this means that we end up doing a wild string compare between a function pointer and the string literal ".vtable_map_vars". This is because sect->named.name aliases sect->unnamed.callback in the section union. This can be seen in GDB with a simple testcase such as "int x;". This patch fixes the issue by checking the SECTION_STYLE of the section is in fact SECTION_NAMED before trying to do the string comparison. We drop the existing check of whether sect->named.name is non-NULL because this should presumably always be the case for a named section. Bootstrapped/regtested on aarch64-none-linux-gnu, OK for trunk? Thanks, Alex gcc/ChangeLog: * varasm.cc (assemble_variable): Fix type confusion bug when checking for ".vtable_map_vars" section. diff --git a/gcc/varasm.cc b/gcc/varasm.cc index 9dfbebbb915..6851201b6a2 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -2400,7 +2400,7 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED, else { /* Special-case handling of vtv comdat sections. */ - if (sect->named.name + if (SECTION_STYLE (sect) == SECTION_NAMED && (strcmp (sect->named.name, ".vtable_map_vars") == 0)) handle_vtv_comdat_section (sect, decl); else