From patchwork Wed Mar 6 21:50:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Morten Linderud X-Patchwork-Id: 86902 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 9E4CD3857C7C for ; Wed, 6 Mar 2024 21:56:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from linderud.pw (linderud.dev [163.172.10.146]) by sourceware.org (Postfix) with ESMTPS id 27E133858C5F for ; Wed, 6 Mar 2024 21:55:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27E133858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linderud.pw Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linderud.pw ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27E133858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=163.172.10.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709762146; cv=none; b=M1dNT2/L21WJf65QpPkWVeTHtyKMGg2G4OxL0K4/hYWAhlHE5IVvD3KRha/dxoPGySN5URJRQXvi53Nla5nti2kabXX/YeRotNjdnGT/FtKJuVfmOwIr3YrrIeScxfkFkYRQp4e+RcaVC3g+7KNuhinYGCGxFpz9EuE0euken/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709762146; c=relaxed/simple; bh=2TDOV02gwI+s+nNXtaRIkviDVBnGjLhpnQaub7QaqRc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=i25HpYdoNIp1EuapB8Rk2AkmXjvjU2uCk1vj6hRXjAB3cWtouyV8KknVz3lt4ShGWTLlfeY7A9Hg1ftCTcrOCvqp6nukeqdXIrgIguKQOXFc90HaMlelf8tirhlYxCgVbLExKpZz0idFIcn78wv/wzvskVbwV1DtG6hHRilWXyM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from linderud.pw (localhost [127.0.0.1]) by linderud.pw (Postfix) with ESMTP id E60D9C02E7; Wed, 6 Mar 2024 22:55:40 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_SOMETLD_ARE_BAD_TLD, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linderud.pw; s=linderud; t=1709762140; bh=2TDOV02gwI+s+nNXtaRIkviDVBnGjLhpnQaub7QaqRc=; h=From:To:Cc:Subject:Date; b=bUHTC0hLOc4BhK4ui8Z6MGCCK+J1aMEX3NbCtxbb0HClw9GR7VVIqnTksSfHtITy0 w6pTofvGs+dac468KWCBwdSAd6XjqPE0JBNjJ3dJSORrqhZnaxPEcIqa+ir/QIHPc5 Nxja1cPMtcDtAKPkM8GzTk8NQxEHtzdKCg/tmNYUEAdCUnmrHhHNLHK/SAxRlCFeJM F1CpZSoefDEPvxcR6rvr5cgglJGEiM1Z5jS90o05UyZqOuSwohWyvbrANvUCy/wW4e UQdwpoGw5QYmtbi624Mef+HWbtYAjgFacQspRt9LpWjMjSGcvgTr5bZW/ZBekIAklB NoIVZsc7/lv2lNHBcmjVXm335GKrDuIvnOKrCZJTa2olwm/hlADspSo7Q1uzwdrlmR 0gLc6yIH6yroQUqLQieSr3a8vKSVd3a6jbF+mT27a36wsm2HwQkaIoz1qsJiCm7nKQ l/s916vd4BTunnC2nj0V+LoIuqZqdTlwaH6YXU0iXyvtGxyBkT6Dk2xMc2Sqhw2HXx 6sKa+pVW6yyvtVn4XJyLknVmxHEYruxRzTLWuwFbzYQMGbsMvB1hkX2cQd0OVi547Y gdicBEuN41WElj6WHmv4MlGI3qYPUuvxUdpMBj+tenZDbhztABB5SfyonAH1vO0Tp4 8lfNdbLExBXKSfR44uOGSM1g= Received: from localhost (unknown [178.232.143.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: morten) by linderud.pw (Postfix) with ESMTPSA id A70F7C006C; Wed, 6 Mar 2024 22:55:40 +0100 (CET) From: Morten Linderud To: gcc-patches@gcc.gnu.org Cc: Morten Linderud , iant@golang.org Subject: [PATCH] lto-streamer: Ensure src_pwd is remapped Date: Wed, 6 Mar 2024 22:50:43 +0100 Message-ID: <20240306215435.914126-3-morten@linderud.pw> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 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+patchwork=sourceware.org@gcc.gnu.org I've made an attempt at patching this issue as it produces unreproducible unreproducible binaries for Golang. I don't know C/C++ and it's my first gcc patch so please bear with me :) -- >8 -- When -flto is used with line macros containing bare symbols instead of absolute paths the full path is added but never remapped with -ffile-prefix-map. This could produce unreproducible binaries. Fixes: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108534 Signed-off-by: Morten Linderud --- gcc/lto-streamer-in.cc | 6 ++++-- gcc/lto-streamer-out.cc | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc index ad0ca24007a..799f9eec478 100644 --- a/gcc/lto-streamer-in.cc +++ b/gcc/lto-streamer-in.cc @@ -44,6 +44,7 @@ along with GCC; see the file COPYING3. If not see #include "debug.h" #include "alloc-pool.h" #include "toplev.h" +#include "file-prefix-map.h" /* remap_debug_filename() */ /* Allocator used to hold string slot entries for line map streaming. */ static struct object_allocator *string_slot_allocator; @@ -557,11 +558,12 @@ lto_location_cache::input_location_and_block (location_t *loc, { const char *pwd = bp_unpack_string (data_in, bp); const char *src_pwd = get_src_pwd (); - if (strcmp (pwd, src_pwd) == 0) + const char *remapped_src_pwd = remap_debug_filename (src_pwd); + if (strcmp (pwd, remapped_src_pwd) == 0) stream_relative_path_prefix = NULL; else stream_relative_path_prefix - = canon_relative_path_prefix (pwd, src_pwd); + = canon_relative_path_prefix (pwd, remapped_src_pwd); } stream_file = canon_file_name (stream_relative_path_prefix, bp_unpack_string (data_in, bp)); diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc index d4f728094ed..379e256a1e7 100644 --- a/gcc/lto-streamer-out.cc +++ b/gcc/lto-streamer-out.cc @@ -230,8 +230,10 @@ lto_output_location_1 (struct output_block *ob, struct bitpack_d *bp, ob->emit_pwd = false; } bp_pack_value (bp, stream_pwd, 1); - if (stream_pwd) - bp_pack_string (ob, bp, get_src_pwd (), true); + if (stream_pwd){ + const char *remapped_pwd = remap_debug_filename (get_src_pwd ()); + bp_pack_string (ob, bp, remapped_pwd, true); + } bp_pack_string (ob, bp, remapped, true); bp_pack_value (bp, xloc.sysp, 1); }