Skip to content

Commit 97b989b

Browse files
[compiler-rt] During profile flushing, setup SIGKILL mask earlier (#68622)
In multi threaded application, it is possible for one thread to terminate the program while another is flushing profile information. We setup a signal mask to delay SIGKILL so that we can safely flush the profile. This patch setups the mask earlier: it reduces the window during which a SIGKILL can end the computation prematurely. This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1850940, where a profiled firefox was encountering several: LLVM Profile Error: Failed to write file "default_*.profraw": Broken pipe Co-authored-by: serge-sans-paille <[email protected]>
1 parent 135f57d commit 97b989b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,14 @@ int __llvm_profile_write_file(void) {
10341034
int rc, Length;
10351035
const char *Filename;
10361036
char *FilenameBuf;
1037-
int PDeathSig = 0;
1037+
1038+
// Temporarily suspend getting SIGKILL when the parent exits.
1039+
int PDeathSig = lprofSuspendSigKill();
10381040

10391041
if (lprofProfileDumped() || __llvm_profile_is_continuous_mode_enabled()) {
10401042
PROF_NOTE("Profile data not written to file: %s.\n", "already written");
1043+
if (PDeathSig == 1)
1044+
lprofRestoreSigKill();
10411045
return 0;
10421046
}
10431047

@@ -1048,6 +1052,8 @@ int __llvm_profile_write_file(void) {
10481052
/* Check the filename. */
10491053
if (!Filename) {
10501054
PROF_ERR("Failed to write file : %s\n", "Filename not set");
1055+
if (PDeathSig == 1)
1056+
lprofRestoreSigKill();
10511057
return -1;
10521058
}
10531059

@@ -1057,12 +1063,11 @@ int __llvm_profile_write_file(void) {
10571063
"expected %d, but get %d\n",
10581064
INSTR_PROF_RAW_VERSION,
10591065
(int)GET_VERSION(__llvm_profile_get_version()));
1066+
if (PDeathSig == 1)
1067+
lprofRestoreSigKill();
10601068
return -1;
10611069
}
10621070

1063-
// Temporarily suspend getting SIGKILL when the parent exits.
1064-
PDeathSig = lprofSuspendSigKill();
1065-
10661071
/* Write profile data to the file. */
10671072
rc = writeFile(Filename);
10681073
if (rc)
@@ -1095,7 +1100,9 @@ int __llvm_orderfile_write_file(void) {
10951100
int rc, Length, LengthBeforeAppend, SuffixLength;
10961101
const char *Filename;
10971102
char *FilenameBuf;
1098-
int PDeathSig = 0;
1103+
1104+
// Temporarily suspend getting SIGKILL when the parent exits.
1105+
int PDeathSig = lprofSuspendSigKill();
10991106

11001107
SuffixLength = strlen(OrderFileSuffix);
11011108
Length = getCurFilenameLength() + SuffixLength;
@@ -1105,6 +1112,8 @@ int __llvm_orderfile_write_file(void) {
11051112
/* Check the filename. */
11061113
if (!Filename) {
11071114
PROF_ERR("Failed to write file : %s\n", "Filename not set");
1115+
if (PDeathSig == 1)
1116+
lprofRestoreSigKill();
11081117
return -1;
11091118
}
11101119

@@ -1119,12 +1128,11 @@ int __llvm_orderfile_write_file(void) {
11191128
"expected %d, but get %d\n",
11201129
INSTR_PROF_RAW_VERSION,
11211130
(int)GET_VERSION(__llvm_profile_get_version()));
1131+
if (PDeathSig == 1)
1132+
lprofRestoreSigKill();
11221133
return -1;
11231134
}
11241135

1125-
// Temporarily suspend getting SIGKILL when the parent exits.
1126-
PDeathSig = lprofSuspendSigKill();
1127-
11281136
/* Write order data to the file. */
11291137
rc = writeOrderFile(Filename);
11301138
if (rc)

0 commit comments

Comments
 (0)