Skip to content

Commit 83e180c

Browse files
[Clang][PGO] Fix profile function visibility bug (#127257)
This pull request fixes an issue that was introduced in #93365. `__llvm_write_custom_profile` visibility was causing issues on Darwin. This function needs to be publicly accessible in order to be accessed by libomptarget, so this pull request makes `__llvm_write_custom_profile` an explicitly exported symbol on Darwin. Tested on M3 and X86 macs.
1 parent 6fde8fe commit 83e180c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -1480,11 +1480,15 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
14801480
// If we have a symbol export directive and we're linking in the profile
14811481
// runtime, automatically export symbols necessary to implement some of the
14821482
// runtime's functionality.
1483-
if (hasExportSymbolDirective(Args) && ForGCOV) {
1484-
addExportedSymbol(CmdArgs, "___gcov_dump");
1485-
addExportedSymbol(CmdArgs, "___gcov_reset");
1486-
addExportedSymbol(CmdArgs, "_writeout_fn_list");
1487-
addExportedSymbol(CmdArgs, "_reset_fn_list");
1483+
if (hasExportSymbolDirective(Args)) {
1484+
if (ForGCOV) {
1485+
addExportedSymbol(CmdArgs, "___gcov_dump");
1486+
addExportedSymbol(CmdArgs, "___gcov_reset");
1487+
addExportedSymbol(CmdArgs, "_writeout_fn_list");
1488+
addExportedSymbol(CmdArgs, "_reset_fn_list");
1489+
} else {
1490+
addExportedSymbol(CmdArgs, "___llvm_write_custom_profile");
1491+
}
14881492
}
14891493

14901494
// Align __llvm_prf_{cnts,bits,data} sections to the maximum expected page

compiler-rt/lib/profile/InstrProfilingFile.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -1362,12 +1362,10 @@ COMPILER_RT_VISIBILITY int __llvm_profile_set_file_object(FILE *File,
13621362
return 0;
13631363
}
13641364

1365-
int __llvm_write_custom_profile(const char *Target,
1366-
const __llvm_profile_data *DataBegin,
1367-
const __llvm_profile_data *DataEnd,
1368-
const char *CountersBegin,
1369-
const char *CountersEnd, const char *NamesBegin,
1370-
const char *NamesEnd) {
1365+
COMPILER_RT_USED int __llvm_write_custom_profile(
1366+
const char *Target, const __llvm_profile_data *DataBegin,
1367+
const __llvm_profile_data *DataEnd, const char *CountersBegin,
1368+
const char *CountersEnd, const char *NamesBegin, const char *NamesEnd) {
13711369
int ReturnValue = 0, FilenameLength, TargetLength;
13721370
char *FilenameBuf, *TargetFilename;
13731371
const char *Filename;

0 commit comments

Comments
 (0)