Skip to content

Commit

Permalink
[OpenMP] Add verbose output for linker wrapper
Browse files Browse the repository at this point in the history
Summary;
This path adds printing support for the linker wrapper. When the user
passes `-v` it will not print the commands used by the linker wrapper to
indicate to the user what is happening during the linking.
  • Loading branch information
jhuber6 committed Feb 28, 2022
1 parent b07ef4d commit d5b2055
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Expand Up @@ -164,6 +164,15 @@ Expected<Optional<std::string>>
extractFromBuffer(std::unique_ptr<MemoryBuffer> Buffer,
SmallVectorImpl<DeviceFile> &DeviceFiles);

void printCommands(ArrayRef<StringRef> CmdArgs) {
if (CmdArgs.empty())
return;

llvm::errs() << " \"" << CmdArgs.front() << "\" ";
for (auto IC = CmdArgs.begin() + 1, IE = CmdArgs.end(); IC != IE; ++IC)
llvm::errs() << *IC << (IC + 1 != IE ? " " : "\n");
}

static StringRef getDeviceFileExtension(StringRef DeviceTriple,
bool IsBitcode = false) {
Triple TheTriple(DeviceTriple);
Expand Down Expand Up @@ -210,6 +219,9 @@ Error runLinker(std::string &LinkerPath, SmallVectorImpl<std::string> &Args) {
for (auto &Arg : Args)
LinkerArgs.push_back(Arg);

if (Verbose)
printCommands(LinkerArgs);

if (sys::ExecuteAndWait(LinkerPath, LinkerArgs))
return createStringError(inconvertibleErrorCode(), "'linker' failed");
return Error::success();
Expand Down Expand Up @@ -338,6 +350,9 @@ extractFromBinary(const ObjectFile &Obj,
StripArgs.push_back("-o");
StripArgs.push_back(TempFile);

if (Verbose)
printCommands(StripArgs);

if (sys::ExecuteAndWait(*StripPath, StripArgs))
return createStringError(inconvertibleErrorCode(), "'llvm-strip' failed");

Expand Down Expand Up @@ -560,6 +575,9 @@ Expected<std::string> assemble(StringRef InputFile, Triple TheTriple,

CmdArgs.push_back(InputFile);

if (Verbose)
printCommands(CmdArgs);

if (sys::ExecuteAndWait(*PtxasPath, CmdArgs))
return createStringError(inconvertibleErrorCode(), "'ptxas' failed");

Expand Down Expand Up @@ -601,6 +619,9 @@ Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple,
for (StringRef Input : InputFiles)
CmdArgs.push_back(Input);

if (Verbose)
printCommands(CmdArgs);

if (sys::ExecuteAndWait(*NvlinkPath, CmdArgs))
return createStringError(inconvertibleErrorCode(), "'nvlink' failed");

Expand Down Expand Up @@ -639,6 +660,9 @@ Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple,
for (StringRef Input : InputFiles)
CmdArgs.push_back(Input);

if (Verbose)
printCommands(CmdArgs);

if (sys::ExecuteAndWait(*LLDPath, CmdArgs))
return createStringError(inconvertibleErrorCode(), "'lld' failed");

Expand Down Expand Up @@ -716,6 +740,9 @@ Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple,
for (StringRef Input : InputFiles)
CmdArgs.push_back(Input);

if (Verbose)
printCommands(CmdArgs);

if (sys::ExecuteAndWait(LinkerUserPath, CmdArgs))
return createStringError(inconvertibleErrorCode(), "'linker' failed");

Expand Down

0 comments on commit d5b2055

Please sign in to comment.