diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp --- a/llvm/lib/Support/Signals.cpp +++ b/llvm/lib/Support/Signals.cpp @@ -194,14 +194,42 @@ std::optional Redirects[] = {InputFile.str(), OutputFile.str(), StringRef("")}; - StringRef Args[] = {"llvm-symbolizer", "--functions=linkage", "--inlining", + std::vector Args = { + "llvm-symbolizer", "--functions=linkage", "--inlining", #ifdef _WIN32 - // Pass --relative-address on Windows so that we don't - // have to add ImageBase from PE file. - // FIXME: Make this the default for llvm-symbolizer. - "--relative-address", + // Pass --relative-address on Windows so that we don't + // have to add ImageBase from PE file. + // FIXME: Make this the default for llvm-symbolizer. + "--relative-address", #endif - "--demangle"}; + "--demangle"}; + +#if defined(__APPLE__) && defined(__LP64__) + // Find all of the .dSYM bundles in the LLVM build directory and pass each of + // them to llvm-symbolizer as a --dsym-hint argument. + std::vector DSymHintArgs; + StringRef LLVMDir = Argv0; + while (!LLVMDir.empty()) { + LLVMDir = llvm::sys::path::parent_path(LLVMDir); + if (sys::fs::exists(LLVMDir + "/bin/llvm-config")) + break; + } + if (!LLVMDir.empty()) { + std::error_code ErrorCode; + for (llvm::sys::fs::recursive_directory_iterator I(LLVMDir, ErrorCode), E; + I != E && !ErrorCode; I.increment(ErrorCode)) { + if (!llvm::sys::fs::is_directory(I->path())) + continue; + if (StringRef(I->path()).ends_with(".dSYM")) { + I.no_push(); + DSymHintArgs.push_back(I->path()); + Args.push_back("--dsym-hint"); + Args.push_back(DSymHintArgs.back()); + } + } + } +#endif + int RunResult = sys::ExecuteAndWait(LLVMSymbolizerPath, Args, std::nullopt, Redirects); if (RunResult != 0)