Skip to content

Commit b29813f

Browse files
jhuber6tstellar
authored andcommitted
[OpenMP] Use executable path when searching for lld
Summary: This patch changes the ClangLinkerWrapper to use the executable path when searching for the lld binary. Previously we relied on the program name. Also not finding 'llvm-strip' is not considered an error anymore because it is an optional optimization. (cherry picked from commit 7ee8bd6)
1 parent 14c432b commit b29813f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ static StringRef getDeviceFileExtension(StringRef DeviceTriple,
174174
return "o";
175175
}
176176

177+
std::string getMainExecutable(const char *Name) {
178+
void *Ptr = (void *)(intptr_t)&getMainExecutable;
179+
auto COWPath = sys::fs::getMainExecutable(Name, Ptr);
180+
return sys::path::parent_path(COWPath).str();
181+
}
182+
177183
/// Extract the device file from the string '<triple>-<arch>=<library>.bc'.
178184
DeviceFile getBitcodeLibrary(StringRef LibraryStr) {
179185
auto DeviceAndPath = StringRef(LibraryStr).split('=');
@@ -310,16 +316,12 @@ extractFromBinary(const ObjectFile &Obj,
310316

311317
// We will use llvm-strip to remove the now unneeded section containing the
312318
// offloading code.
313-
void *P = (void *)(intptr_t)&Help;
314-
StringRef COWDir = "";
315-
auto COWPath = sys::fs::getMainExecutable("llvm-strip", P);
316-
if (!COWPath.empty())
317-
COWDir = sys::path::parent_path(COWPath);
318319
ErrorOr<std::string> StripPath =
319-
sys::findProgramByName("llvm-strip", {COWDir});
320+
sys::findProgramByName("llvm-strip", {getMainExecutable("llvm-strip")});
320321
if (!StripPath)
321-
return createStringError(StripPath.getError(),
322-
"Unable to find 'llvm-strip' in path");
322+
StripPath = sys::findProgramByName("llvm-strip");
323+
if (!StripPath)
324+
return None;
323325

324326
SmallString<128> TempFile;
325327
if (Error Err = createOutputFile(Prefix + "-host", Extension, TempFile))
@@ -608,9 +610,9 @@ Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple,
608610
namespace amdgcn {
609611
Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple,
610612
StringRef Arch) {
611-
// AMDGPU uses the lld binary to link device object files.
613+
// AMDGPU uses lld to link device object files.
612614
ErrorOr<std::string> LLDPath =
613-
sys::findProgramByName("lld", sys::path::parent_path(LinkerExecutable));
615+
sys::findProgramByName("lld", {getMainExecutable("lld")});
614616
if (!LLDPath)
615617
LLDPath = sys::findProgramByName("lld");
616618
if (!LLDPath)

0 commit comments

Comments
 (0)