Skip to content

Commit 930d46a

Browse files
committed
[Driver] Support object files in addition to static and shared libraries in compiler-rt
This change introduces support for object files in addition to static and shared libraries which were already supported which requires changing the type of the argument from boolean to an enum. Differential Revision: https://reviews.llvm.org/D56044 llvm-svn: 355891
1 parent e8475f7 commit 930d46a

File tree

6 files changed

+47
-20
lines changed

6 files changed

+47
-20
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class ToolChain {
104104
RM_Disabled,
105105
};
106106

107+
enum FileType { FT_Object, FT_Static, FT_Shared };
108+
107109
private:
108110
friend class RegisterEffectiveTriple;
109111

@@ -371,11 +373,11 @@ class ToolChain {
371373

372374
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
373375
StringRef Component,
374-
bool Shared = false) const;
376+
FileType Type = ToolChain::FT_Static) const;
375377

376-
const char *getCompilerRTArgString(const llvm::opt::ArgList &Args,
377-
StringRef Component,
378-
bool Shared = false) const;
378+
const char *
379+
getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component,
380+
FileType Type = ToolChain::FT_Static) const;
379381

380382
// Returns <ResourceDir>/lib/<OSName>/<arch>. This is used by runtimes (such
381383
// as OpenMP) to find arch-specific libraries.

clang/lib/Driver/ToolChain.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,27 @@ std::string ToolChain::getCompilerRTPath() const {
362362
}
363363

364364
std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
365-
bool Shared) const {
365+
FileType Type) const {
366366
const llvm::Triple &TT = getTriple();
367367
bool IsITANMSVCWindows =
368368
TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
369369

370-
const char *Prefix = IsITANMSVCWindows ? "" : "lib";
371-
const char *Suffix = Shared ? (Triple.isOSWindows() ? ".lib" : ".so")
372-
: (IsITANMSVCWindows ? ".lib" : ".a");
373-
if (Shared && Triple.isWindowsGNUEnvironment())
374-
Suffix = ".dll.a";
370+
const char *Prefix =
371+
IsITANMSVCWindows || Type == ToolChain::FT_Object ? "" : "lib";
372+
const char *Suffix;
373+
switch (Type) {
374+
case ToolChain::FT_Object:
375+
Suffix = IsITANMSVCWindows ? ".obj" : ".o";
376+
break;
377+
case ToolChain::FT_Static:
378+
Suffix = IsITANMSVCWindows ? ".lib" : ".a";
379+
break;
380+
case ToolChain::FT_Shared:
381+
Suffix = Triple.isOSWindows()
382+
? (Triple.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
383+
: ".so";
384+
break;
385+
}
375386

376387
for (const auto &LibPath : getLibraryPaths()) {
377388
SmallString<128> P(LibPath);
@@ -390,8 +401,8 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
390401

391402
const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
392403
StringRef Component,
393-
bool Shared) const {
394-
return Args.MakeArgString(getCompilerRT(Args, Component, Shared));
404+
FileType Type) const {
405+
return Args.MakeArgString(getCompilerRT(Args, Component, Type));
395406
}
396407

397408
std::string ToolChain::getArchSpecificLibPath() const {

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args,
535535
// Wrap any static runtimes that must be forced into executable in
536536
// whole-archive.
537537
if (IsWhole) CmdArgs.push_back("--whole-archive");
538-
CmdArgs.push_back(TC.getCompilerRTArgString(Args, Sanitizer, IsShared));
538+
CmdArgs.push_back(TC.getCompilerRTArgString(
539+
Args, Sanitizer, IsShared ? ToolChain::FT_Shared : ToolChain::FT_Static));
539540
if (IsWhole) CmdArgs.push_back("--no-whole-archive");
540541

541542
if (IsShared) {

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
248248

249249
if (Sanitize.needsAsanRt()) {
250250
// MinGW always links against a shared MSVCRT.
251-
CmdArgs.push_back(
252-
TC.getCompilerRTArgString(Args, "asan_dynamic", true));
251+
CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dynamic",
252+
ToolChain::FT_Shared));
253253
CmdArgs.push_back(
254254
TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
255255
CmdArgs.push_back(Args.MakeArgString("--require-defined"));

clang/lib/Driver/ToolChains/MipsLinux.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,23 @@ void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
118118

119119
std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
120120
StringRef Component,
121-
bool Shared) const {
121+
FileType Type) const {
122122
SmallString<128> Path(getDriver().ResourceDir);
123123
llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix,
124124
getOS());
125-
llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" +
126-
"mips" + (Shared ? ".so" : ".a")));
125+
const char *Suffix;
126+
switch (Type) {
127+
case ToolChain::FT_Object:
128+
Suffix = ".o";
129+
break;
130+
case ToolChain::FT_Static:
131+
Suffix = ".a";
132+
break;
133+
case ToolChain::FT_Shared:
134+
Suffix = ".so";
135+
break;
136+
}
137+
llvm::sys::path::append(
138+
Path, Twine("libclang_rt." + Component + "-" + "mips" + Suffix));
127139
return Path.str();
128140
}

clang/lib/Driver/ToolChains/MipsLinux.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class LLVM_LIBRARY_VISIBILITY MipsLLVMToolChain : public Linux {
3737
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
3838
llvm::opt::ArgStringList &CmdArgs) const override;
3939

40-
std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
41-
bool Shared = false) const override;
40+
std::string
41+
getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
42+
FileType Type = ToolChain::FT_Static) const override;
4243

4344
std::string computeSysRoot() const override;
4445

0 commit comments

Comments
 (0)