Skip to content

Commit d95d432

Browse files
committed
Add -static-libflangrt and -shared-libflangrt option for users to specify which flang-rt to link to.
1 parent a4ccdd8 commit d95d432

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6880,6 +6880,13 @@ let Flags = [TargetSpecific] in {
68806880
defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group<f_Group>;
68816881
} // let Flags = [TargetSpecific]
68826882

6883+
def shared_libflangrt : Flag<["-"], "shared-libflangrt">,
6884+
HelpText<"Dynamically link the shared flang-rt">, Group<Link_Group>,
6885+
Visibility<[FlangOption]>, Flags<[NoArgumentUnused]>;
6886+
def static_libflangrt : Flag<["-"], "static-libflangrt">,
6887+
HelpText<"Statically link the static flang-rt">, Group<Link_Group>,
6888+
Visibility<[FlangOption]>, Flags<[NoArgumentUnused]>;
6889+
68836890
//===----------------------------------------------------------------------===//
68846891
// FLangOption + NoXarchOption
68856892
//===----------------------------------------------------------------------===//

clang/lib/Driver/ToolChain.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args,
746746
case ToolChain::FT_Shared:
747747
Suffix = TT.isOSWindows()
748748
? (TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
749-
: ".so";
749+
: TT.isOSAIX() ? ".a"
750+
: ".so";
750751
break;
751752
}
752753

@@ -852,17 +853,14 @@ void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
852853
void ToolChain::addFlangRTLibPath(const ArgList &Args,
853854
llvm::opt::ArgStringList &CmdArgs) const {
854855
// Link static flang_rt.runtime.a or shared flang_rt.runtime.so
855-
const char *Path;
856-
if (getVFS().exists(Twine(Path = getCompilerRTArgString(
857-
Args, "runtime", ToolChain::FT_Static, true))))
858-
CmdArgs.push_back(Path);
856+
// On AIX, default to static flang-rt
857+
if (Args.hasFlag(options::OPT_static_libflangrt,
858+
options::OPT_shared_libflangrt, getTriple().isOSAIX()))
859+
CmdArgs.push_back(
860+
getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static, true));
859861
else {
860-
if (getVFS().exists(
861-
Twine(Path = getCompilerRTArgString(Args, "runtime",
862-
ToolChain::FT_Shared, true))))
863-
CmdArgs.push_back(Path);
864-
else
865-
CmdArgs.push_back("-lflang_rt.runtime");
862+
CmdArgs.push_back(
863+
getCompilerRTArgString(Args, "runtime", ToolChain::FT_Shared, true));
866864
addArchSpecificRPath(*this, Args, CmdArgs);
867865
}
868866
}

0 commit comments

Comments
 (0)