Skip to content

[PGO][Offload] Don't define GPU entrypoint on Darwin #132966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2025

Conversation

EthanLuisMcDonough
Copy link
Member

This PR partially reverts 83e180c and instead opts to hide the GPU entry point on Darwin platforms. Marking __llvm_write_custom_profile as used was causing issues on embedded platforms.

@llvmbot llvmbot added clang Clang issues not falling into any other category compiler-rt clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' PGO Profile Guided Optimizations labels Mar 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 25, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Ethan Luis McDonough (EthanLuisMcDonough)

Changes

This PR partially reverts 83e180c and instead opts to hide the GPU entry point on Darwin platforms. Marking __llvm_write_custom_profile as used was causing issues on embedded platforms.


Full diff: https://github.com/llvm/llvm-project/pull/132966.diff

3 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+5-9)
  • (modified) compiler-rt/lib/profile/InstrProfilingFile.c (+5-7)
  • (modified) compiler-rt/lib/profile/InstrProfilingPort.h (+2)
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index e67997314da36..4c88722730598 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1481,15 +1481,11 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
   // If we have a symbol export directive and we're linking in the profile
   // runtime, automatically export symbols necessary to implement some of the
   // runtime's functionality.
-  if (hasExportSymbolDirective(Args)) {
-    if (ForGCOV) {
-      addExportedSymbol(CmdArgs, "___gcov_dump");
-      addExportedSymbol(CmdArgs, "___gcov_reset");
-      addExportedSymbol(CmdArgs, "_writeout_fn_list");
-      addExportedSymbol(CmdArgs, "_reset_fn_list");
-    } else {
-      addExportedSymbol(CmdArgs, "___llvm_write_custom_profile");
-    }
+  if (hasExportSymbolDirective(Args) && ForGCOV) {
+    addExportedSymbol(CmdArgs, "___gcov_dump");
+    addExportedSymbol(CmdArgs, "___gcov_reset");
+    addExportedSymbol(CmdArgs, "_writeout_fn_list");
+    addExportedSymbol(CmdArgs, "_reset_fn_list");
   }
 
   // Align __llvm_prf_{cnts,bits,data} sections to the maximum expected page
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 19467429cf4c3..9f75ce5ef97d1 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -1273,13 +1273,11 @@ COMPILER_RT_VISIBILITY int __llvm_profile_set_file_object(FILE *File,
   return 0;
 }
 
-int __llvm_write_custom_profile(const char *Target,
-                                const __llvm_profile_data *DataBegin,
-                                const __llvm_profile_data *DataEnd,
-                                const char *CountersBegin,
-                                const char *CountersEnd, const char *NamesBegin,
-                                const char *NamesEnd,
-                                const uint64_t *VersionOverride) {
+COMPILER_RT_GPU_ENTRYPOINT int __llvm_write_custom_profile(
+    const char *Target, const __llvm_profile_data *DataBegin,
+    const __llvm_profile_data *DataEnd, const char *CountersBegin,
+    const char *CountersEnd, const char *NamesBegin, const char *NamesEnd,
+    const uint64_t *VersionOverride) {
   int ReturnValue = 0, FilenameLength, TargetLength;
   char *FilenameBuf, *TargetFilename;
   const char *Filename;
diff --git a/compiler-rt/lib/profile/InstrProfilingPort.h b/compiler-rt/lib/profile/InstrProfilingPort.h
index 66d697885eaee..ed56beb6577a3 100644
--- a/compiler-rt/lib/profile/InstrProfilingPort.h
+++ b/compiler-rt/lib/profile/InstrProfilingPort.h
@@ -43,8 +43,10 @@
 
 #if defined(__APPLE__)
 #define COMPILER_RT_SEG "__DATA,"
+#define COMPILER_RT_GPU_ENTRYPOINT COMPILER_RT_VISIBILITY
 #else
 #define COMPILER_RT_SEG ""
+#define COMPILER_RT_GPU_ENTRYPOINT
 #endif
 
 #ifdef _MSC_VER

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked before your patch right? Is this what it exposed before then?

@EthanLuisMcDonough
Copy link
Member Author

It worked before your patch right? Is this what it exposed before then?

In 83e180c, I marked __llvm_write_custom_profile as used, which fixed the Darwin code stripping bug but broke the library on embedded systems. In c50d39f, I removed the used attribute, which breaks the Darwin code stripping test. This PR should fix both issues.

const char *CountersEnd, const char *NamesBegin,
const char *NamesEnd,
const uint64_t *VersionOverride) {
COMPILER_RT_GPU_ENTRYPOINT int __llvm_write_custom_profile(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be more straightforward to just ifdef this whole block out on apple.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that's probably easier and less invasive.

@@ -1273,6 +1273,7 @@ COMPILER_RT_VISIBILITY int __llvm_profile_set_file_object(FILE *File,
return 0;
}

#ifdef COMPILER_RT_GPU_ENTRYPOINT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just use __APPLE__?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was that it would give us more configuration power if we had a macro that was defined only when we want an entry point. This would give us an easy way to disable the entry point on other platforms if needed. I don't expect that to happen, so I guess we can use __APPLE__ for now.

@EthanLuisMcDonough EthanLuisMcDonough changed the title [PGO][Offload] Hide GPU entrypoint on Darwin [PGO][Offload] Don't define entrypoint on Darwin Mar 26, 2025
@EthanLuisMcDonough EthanLuisMcDonough changed the title [PGO][Offload] Don't define entrypoint on Darwin [PGO][Offload] Don't define GPU entrypoint on Darwin Mar 26, 2025
@EthanLuisMcDonough EthanLuisMcDonough merged commit 80d5185 into llvm:main Mar 26, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 26, 2025

LLVM Buildbot has detected a new failure on builder lldb-aarch64-ubuntu running on linaro-lldb-aarch64-ubuntu while building clang,compiler-rt at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/14938

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-shell :: Commands/command-backtrace-parser-1.test (1266 of 2110)
PASS: lldb-shell :: Commands/command-backtrace-parser-2.test (1267 of 2110)
PASS: lldb-shell :: Commands/command-disassemble-aarch64-color.s (1268 of 2110)
PASS: lldb-shell :: Commands/command-disassemble-aarch64-extensions.s (1269 of 2110)
PASS: lldb-shell :: Commands/command-breakpoint-by-addr.test (1270 of 2110)
PASS: lldb-shell :: Commands/command-breakpoint-col.test (1271 of 2110)
PASS: lldb-shell :: Commands/command-disassemble-mixed.c (1272 of 2110)
PASS: lldb-shell :: Commands/command-disassemble-mixed.test (1273 of 2110)
PASS: lldb-shell :: Commands/command-disassemble.s (1274 of 2110)
PASS: lldb-shell :: Commands/command-disassemble-process.yaml (1275 of 2110)
FAIL: lldb-api :: types/TestShortTypeExpr.py (1276 of 2110)
******************** TEST 'lldb-api :: types/TestShortTypeExpr.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --arch aarch64 --build-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/types -p TestShortTypeExpr.py
--
Exit Code: -11

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 80d5185bd4288c12e9d5aa0fe2e00f2f4e6397d7)
  clang revision 80d5185bd4288c12e9d5aa0fe2e00f2f4e6397d7
  llvm revision 80d5185bd4288c12e9d5aa0fe2e00f2f4e6397d7
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_short_type_dsym (TestShortTypeExpr.ShortExprTestCase) (test case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_short_type_dwarf (TestShortTypeExpr.ShortExprTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_short_type_dwo (TestShortTypeExpr.ShortExprTestCase)
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_short_type_from_block_dsym (TestShortTypeExpr.ShortExprTestCase) (test case does not fall in any category of interest for this run) 
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_short_type_from_block_dwarf (TestShortTypeExpr.ShortExprTestCase) (requires one of macosx, darwin, ios, tvos, watchos, bridgeos, iphonesimulator, watchsimulator, appletvsimulator) 
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_short_type_from_block_dwo (TestShortTypeExpr.ShortExprTestCase) (requires one of macosx, darwin, ios, tvos, watchos, bridgeos, iphonesimulator, watchsimulator, appletvsimulator) 
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_unsigned_short_type_dsym (TestShortTypeExpr.ShortExprTestCase) (test case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_unsigned_short_type_dwarf (TestShortTypeExpr.ShortExprTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_unsigned_short_type_dwo (TestShortTypeExpr.ShortExprTestCase)
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_unsigned_short_type_from_block_dsym (TestShortTypeExpr.ShortExprTestCase) (test case does not fall in any category of interest for this run) 
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_unsigned_short_type_from_block_dwarf (TestShortTypeExpr.ShortExprTestCase) (requires one of macosx, darwin, ios, tvos, watchos, bridgeos, iphonesimulator, watchsimulator, appletvsimulator) 
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_unsigned_short_type_from_block_dwo (TestShortTypeExpr.ShortExprTestCase) (requires one of macosx, darwin, ios, tvos, watchos, bridgeos, iphonesimulator, watchsimulator, appletvsimulator) 
----------------------------------------------------------------------
Ran 12 tests in 1.940s

OK (skipped=8)

--

********************
PASS: lldb-shell :: Commands/command-disassemble-cpu-features.yaml (1277 of 2110)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category compiler-rt PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants