[llvm] [gcov] Set current_working_directory to . for GCC>=9 (PR #121420)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 31 17:47:57 PST 2024


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/121420

GCC 9 changed the gcov format to set current_working_directory to be
used by gcov --json-format
(https://github.com/linux-test-project/lcov/issues/38).

This change breaks local determinism, which we value more than strict
GCC compatibility. Just write "." to appease GCC's gcov.

Fix #121368


>From a304c82f9e2652110f1f1df45205e922e3ae8c8a Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Tue, 31 Dec 2024 17:47:46 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index f9be7f933d31e4..dc3307a212817a 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -973,8 +973,10 @@ bool GCOVProfiler::emitProfileNotes(
         out.write(Tmp, 4);
       }
       write(Stamp);
+      // getcwd() breaks local determinism and is not easy to adjust with
+      // -ffile-prefix-map. Just write "." to appease GCC's gcov.
       if (Version >= 90)
-        writeString(""); // unuseful current_working_directory
+        writeString(".");
       if (Version >= 80)
         write(0); // unuseful has_unexecuted_blocks
 



More information about the llvm-commits mailing list