From patchwork Fri Feb 24 09:00:01 2023 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: 65576 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 15D82385B530 for ; Fri, 24 Feb 2023 09:00:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 37772385840F for ; Fri, 24 Feb 2023 09:00:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37772385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail 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 A23B4387DD; Fri, 24 Feb 2023 09:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677229201; 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=S3E7yPwIZseHNKLyz1DZF/v2h/hsk6bJi9VbEFb3f14=; b=Hco420e1L9yQEQQbDTH3UO5kWAjOiZUTuBRC5GudxrfQsOjgBl/qy5iQd2TxDwbgc5ysSZ No9Lqejsa51ttZ63BUCuTLIxWRv7R2s2XdPEQWawaTa2ua9mzMJPPqrNaqi8H09k4Tp2PF YFp4zKtR0l6rq1Dv+oWpnX/DAGiTgo0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677229201; 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=S3E7yPwIZseHNKLyz1DZF/v2h/hsk6bJi9VbEFb3f14=; b=3G5qSYC4MFo9t77TG12yvkTqnQkJTXauNaYtr9f9JLpQKgslOzydlCxLn90+vp+3fQJVuz Pv8rsTwGG8zqxBDg== 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 8208A13A3A; Fri, 24 Feb 2023 09:00:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3y2kHZF8+GPUKgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 09:00:01 +0000 Message-ID: <7a627522-bba6-0b50-1d5f-82409a3800df@suse.cz> Date: Fri, 24 Feb 2023 10:00:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] asan: adjust module name for global variables To: gcc-patches@gcc.gnu.org Content-Language: en-US Cc: Jakub Jelinek X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" As mentioned in the PR, when we use LTO, we wrongly use ltrans output file name as a module name of a global variable. That leads to a non-reproducible output. After the suggested change, we emit context name of normal global variables. And for artificial variables (like .Lubsan_data3), we use aux_base_name (e.g. "./a.ltrans0.ltrans"). Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR asan/108834 gcc/ChangeLog: * asan.cc (asan_add_global): Use proper TU name for normal global variables (and aux_base_name for the artificial one). gcc/testsuite/ChangeLog: * c-c++-common/asan/global-overflow-1.c: Test line and column info for a global variable. --- gcc/asan.cc | 7 ++++++- gcc/testsuite/c-c++-common/asan/global-overflow-1.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/asan.cc b/gcc/asan.cc index f56d084bc7a..245abb14388 100644 --- a/gcc/asan.cc +++ b/gcc/asan.cc @@ -3287,7 +3287,12 @@ asan_add_global (tree decl, tree type, vec *v) pp_string (&asan_pp, ""); str_cst = asan_pp_string (&asan_pp); - pp_string (&module_name_pp, main_input_filename); + const_tree tu = get_ultimate_context ((const_tree)decl); + if (tu != NULL_TREE) + pp_string (&module_name_pp, IDENTIFIER_POINTER (DECL_NAME (tu))); + else + pp_string (&module_name_pp, aux_base_name); + module_name_cst = asan_pp_string (&module_name_pp); if (asan_needs_local_alias (decl)) diff --git a/gcc/testsuite/c-c++-common/asan/global-overflow-1.c b/gcc/testsuite/c-c++-common/asan/global-overflow-1.c index b97801da2b7..7e167cee67a 100644 --- a/gcc/testsuite/c-c++-common/asan/global-overflow-1.c +++ b/gcc/testsuite/c-c++-common/asan/global-overflow-1.c @@ -26,4 +26,4 @@ int main() { /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */ /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*global-overflow-1.c:20|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r).*" } */ /* { dg-output "0x\[0-9a-f\]+ is located 0 bytes after global variable" } */ -/* { dg-output ".*YYY\[^\n\r]* of size 10\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output ".*YYY\[^\n\r]*asan/global-overflow-1.c:15:15'\[^\n\r]*of size 10\[^\n\r]*(\n|\r\n|\r)" } */