[llvm] [BOLT][runtime] harden profile file open. (PR #191669)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 11 14:51:56 PDT 2026
https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/191669
None
>From ba51b30420f87bf441e43c387f62c87cb52bee0f Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sat, 11 Apr 2026 22:50:53 +0100
Subject: [PATCH] [BOLT][runtime] harden profile file open.
---
bolt/runtime/common.h | 1 +
bolt/runtime/instr.cpp | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/bolt/runtime/common.h b/bolt/runtime/common.h
index f4ab28f10a815..8689bc8b72041 100644
--- a/bolt/runtime/common.h
+++ b/bolt/runtime/common.h
@@ -74,6 +74,7 @@ typedef int int32_t;
#define O_CREAT 64
#define O_TRUNC 512
#define O_APPEND 1024
+#define O_CLOEXEC 524288
// Functions that are required by freestanding environment. Compiler may
// generate calls to these implicitly.
diff --git a/bolt/runtime/instr.cpp b/bolt/runtime/instr.cpp
index a44f1266ea65d..0499dd1378bb6 100644
--- a/bolt/runtime/instr.cpp
+++ b/bolt/runtime/instr.cpp
@@ -1500,8 +1500,8 @@ int openProfile() {
Ptr = strCopy(Ptr, ".fdata", BufSize - (Ptr - Buf + 1));
}
*Ptr++ = '\0';
- uint64_t FD = __open(Buf, O_WRONLY | O_TRUNC | O_CREAT,
- /*mode=*/0666);
+ uint64_t FD = __open(Buf, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC,
+ /*mode=*/0600);
if (static_cast<int64_t>(FD) < 0) {
report("Error while trying to open profile file for writing: ");
report(Buf);
More information about the llvm-commits
mailing list