Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | HostTriple("host-triple", cl::ZeroOrMore, | ||||
cl::init(sys::getDefaultTargetTriple()), | cl::init(sys::getDefaultTargetTriple()), | ||||
cl::cat(ClangLinkerWrapperCategory)); | cl::cat(ClangLinkerWrapperCategory)); | ||||
static cl::list<std::string> | static cl::list<std::string> | ||||
PtxasArgs("ptxas-args", cl::ZeroOrMore, | PtxasArgs("ptxas-args", cl::ZeroOrMore, | ||||
cl::desc("Argument to pass to the ptxas invocation"), | cl::desc("Argument to pass to the ptxas invocation"), | ||||
cl::cat(ClangLinkerWrapperCategory)); | cl::cat(ClangLinkerWrapperCategory)); | ||||
static cl::list<std::string> | |||||
LinkerArgs("device-linker", cl::ZeroOrMore, | |||||
cl::desc("Arguments to pass to the device linker invocation"), | |||||
cl::value_desc("<value> or <triple>=<value>"), | |||||
cl::cat(ClangLinkerWrapperCategory)); | |||||
static cl::opt<bool> Verbose("v", cl::ZeroOrMore, | static cl::opt<bool> Verbose("v", cl::ZeroOrMore, | ||||
cl::desc("Verbose output from tools"), | cl::desc("Verbose output from tools"), | ||||
cl::init(false), | cl::init(false), | ||||
cl::cat(ClangLinkerWrapperCategory)); | cl::cat(ClangLinkerWrapperCategory)); | ||||
static cl::opt<DebugKind> DebugInfo( | static cl::opt<DebugKind> DebugInfo( | ||||
cl::desc("Choose debugging level:"), cl::init(NoDebugInfo), | cl::desc("Choose debugging level:"), cl::init(NoDebugInfo), | ||||
cl::values(clEnumValN(NoDebugInfo, "g0", "No debug information"), | cl::values(clEnumValN(NoDebugInfo, "g0", "No debug information"), | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | void printCommands(ArrayRef<StringRef> CmdArgs) { | ||||
if (CmdArgs.empty()) | if (CmdArgs.empty()) | ||||
return; | return; | ||||
llvm::errs() << " \"" << CmdArgs.front() << "\" "; | llvm::errs() << " \"" << CmdArgs.front() << "\" "; | ||||
for (auto IC = std::next(CmdArgs.begin()), IE = CmdArgs.end(); IC != IE; ++IC) | for (auto IC = std::next(CmdArgs.begin()), IE = CmdArgs.end(); IC != IE; ++IC) | ||||
llvm::errs() << *IC << (std::next(IC) != IE ? " " : "\n"); | llvm::errs() << *IC << (std::next(IC) != IE ? " " : "\n"); | ||||
} | } | ||||
// Forward user requested arguments to the device linking job. | |||||
void renderXLinkerArgs(SmallVectorImpl<StringRef> &Args, StringRef Triple) { | |||||
for (StringRef Arg : LinkerArgs) { | |||||
auto TripleAndValue = Arg.split('='); | |||||
if (TripleAndValue.second.empty()) | |||||
Args.push_back(TripleAndValue.first); | |||||
else if (TripleAndValue.first == Triple) | |||||
Args.push_back(TripleAndValue.second); | |||||
} | |||||
} | |||||
std::string getMainExecutable(const char *Name) { | std::string getMainExecutable(const char *Name) { | ||||
void *Ptr = (void *)(intptr_t)&getMainExecutable; | void *Ptr = (void *)(intptr_t)&getMainExecutable; | ||||
auto COWPath = sys::fs::getMainExecutable(Name, Ptr); | auto COWPath = sys::fs::getMainExecutable(Name, Ptr); | ||||
return sys::path::parent_path(COWPath).str(); | return sys::path::parent_path(COWPath).str(); | ||||
} | } | ||||
/// Extract the device file from the string '<kind>-<triple>-<arch>=<library>'. | /// Extract the device file from the string '<kind>-<triple>-<arch>=<library>'. | ||||
DeviceFile getBitcodeLibrary(StringRef LibraryStr) { | DeviceFile getBitcodeLibrary(StringRef LibraryStr) { | ||||
▲ Show 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple, | ||||
CmdArgs.push_back(TempFile); | CmdArgs.push_back(TempFile); | ||||
CmdArgs.push_back("-arch"); | CmdArgs.push_back("-arch"); | ||||
CmdArgs.push_back(Arch); | CmdArgs.push_back(Arch); | ||||
// Add extracted input files. | // Add extracted input files. | ||||
for (StringRef Input : InputFiles) | for (StringRef Input : InputFiles) | ||||
CmdArgs.push_back(Input); | CmdArgs.push_back(Input); | ||||
renderXLinkerArgs(CmdArgs, TheTriple.getTriple()); | |||||
if (Error Err = executeCommands(*NvlinkPath, CmdArgs)) | if (Error Err = executeCommands(*NvlinkPath, CmdArgs)) | ||||
return std::move(Err); | return std::move(Err); | ||||
return static_cast<std::string>(TempFile); | return static_cast<std::string>(TempFile); | ||||
} | } | ||||
Expected<std::string> fatbinary(ArrayRef<StringRef> InputFiles, | Expected<std::string> fatbinary(ArrayRef<StringRef> InputFiles, | ||||
Triple TheTriple, ArrayRef<StringRef> Archs) { | Triple TheTriple, ArrayRef<StringRef> Archs) { | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple, | ||||
CmdArgs.push_back("-shared"); | CmdArgs.push_back("-shared"); | ||||
CmdArgs.push_back("-o"); | CmdArgs.push_back("-o"); | ||||
CmdArgs.push_back(TempFile); | CmdArgs.push_back(TempFile); | ||||
// Add extracted input files. | // Add extracted input files. | ||||
for (StringRef Input : InputFiles) | for (StringRef Input : InputFiles) | ||||
CmdArgs.push_back(Input); | CmdArgs.push_back(Input); | ||||
renderXLinkerArgs(CmdArgs, TheTriple.getTriple()); | |||||
if (Error Err = executeCommands(*LLDPath, CmdArgs)) | if (Error Err = executeCommands(*LLDPath, CmdArgs)) | ||||
return std::move(Err); | return std::move(Err); | ||||
return static_cast<std::string>(TempFile); | return static_cast<std::string>(TempFile); | ||||
} | } | ||||
} // namespace amdgcn | } // namespace amdgcn | ||||
namespace generic { | namespace generic { | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple, | ||||
CmdArgs.push_back("-Bsymbolic"); | CmdArgs.push_back("-Bsymbolic"); | ||||
CmdArgs.push_back("-o"); | CmdArgs.push_back("-o"); | ||||
CmdArgs.push_back(TempFile); | CmdArgs.push_back(TempFile); | ||||
// Add extracted input files. | // Add extracted input files. | ||||
for (StringRef Input : InputFiles) | for (StringRef Input : InputFiles) | ||||
CmdArgs.push_back(Input); | CmdArgs.push_back(Input); | ||||
renderXLinkerArgs(CmdArgs, TheTriple.getTriple()); | |||||
if (Error Err = executeCommands(LinkerUserPath, CmdArgs)) | if (Error Err = executeCommands(LinkerUserPath, CmdArgs)) | ||||
return std::move(Err); | return std::move(Err); | ||||
return static_cast<std::string>(TempFile); | return static_cast<std::string>(TempFile); | ||||
} | } | ||||
} // namespace generic | } // namespace generic | ||||
Expected<std::string> linkDevice(ArrayRef<std::string> InputFiles, | Expected<std::string> linkDevice(ArrayRef<std::string> InputFiles, | ||||
▲ Show 20 Lines • Show All 681 Lines • Show Last 20 Lines |