• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:toolchain

1 //===- ToolChain.cpp - Collections of tools for one platform --------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "clang/Driver/ToolChain.h"
30 #include "llvm/Config/llvm-config.h"
59 static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, in CalculateRTTIMode()
62 // Explicit rtti/no-rtti args in CalculateRTTIMode()
64 if (CachedRTTIArg->getOption().matches(options::OPT_frtti)) in CalculateRTTIMode()
65 return ToolChain::RM_Enabled; in CalculateRTTIMode()
67 return ToolChain::RM_Disabled; in CalculateRTTIMode()
70 // -frtti is default, except for the PS4 CPU. in CalculateRTTIMode()
71 return (Triple.isPS4CPU()) ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; in CalculateRTTIMode()
74 ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, in ToolChain() function in ToolChain
91 void ToolChain::setTripleEnvironment(llvm::Triple::EnvironmentType Env) { in setTripleEnvironment()
97 ToolChain::~ToolChain() = default;
99 llvm::vfs::FileSystem &ToolChain::getVFS() const { in getVFS()
103 bool ToolChain::useIntegratedAs() const { in useIntegratedAs()
109 bool ToolChain::useRelaxRelocations() const { in useRelaxRelocations()
113 bool ToolChain::isNoExecStackDefault() const { in isNoExecStackDefault()
117 const SanitizerArgs& ToolChain::getSanitizerArgs() const { in getSanitizerArgs()
123 const XRayArgs& ToolChain::getXRayArgs() const { in getXRayArgs()
144 {"clang++", "--driver-mode=g++"}, in FindDriverSuffix()
145 {"clang-c++", "--driver-mode=g++"}, in FindDriverSuffix()
146 {"clang-cc", nullptr}, in FindDriverSuffix()
147 {"clang-cpp", "--driver-mode=cpp"}, in FindDriverSuffix()
148 {"clang-g++", "--driver-mode=g++"}, in FindDriverSuffix()
149 {"clang-gcc", nullptr}, in FindDriverSuffix()
150 {"clang-cl", "--driver-mode=cl"}, in FindDriverSuffix()
152 {"cpp", "--driver-mode=cpp"}, in FindDriverSuffix()
153 {"cl", "--driver-mode=cl"}, in FindDriverSuffix()
154 {"++", "--driver-mode=g++"}, in FindDriverSuffix()
155 {"flang", "--driver-mode=flang"}, in FindDriverSuffix()
161 Pos = ProgName.size() - Suffix.size(); in FindDriverSuffix()
169 /// present and lower-casing the string on Windows.
184 // E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target in parseDriverSuffix()
185 // prefix "x86_64-linux". If such a target prefix is found, it may be in parseDriverSuffix()
186 // added via -target as implicit first argument. in parseDriverSuffix()
191 // clang++3.5 -> clang++ in parseDriverSuffix()
197 // Try again after stripping trailing -component. in parseDriverSuffix()
198 // clang++-tot -> clang++ in parseDriverSuffix()
199 ProgName = ProgName.slice(0, ProgName.rfind('-')); in parseDriverSuffix()
206 ToolChain::getTargetAndModeFromProgramName(StringRef PN) { in getTargetAndModeFromProgramName()
212 size_t SuffixEnd = SuffixPos + strlen(DS->Suffix); in getTargetAndModeFromProgramName()
214 size_t LastComponent = ProgName.rfind('-', SuffixPos); in getTargetAndModeFromProgramName()
216 return ParsedClangName(ProgName.substr(0, SuffixEnd), DS->ModeFlag); in getTargetAndModeFromProgramName()
218 SuffixEnd - LastComponent - 1); in getTargetAndModeFromProgramName()
226 return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag, in getTargetAndModeFromProgramName()
230 StringRef ToolChain::getDefaultUniversalArchName() const { in getDefaultUniversalArchName()
231 // In universal driver terms, the arch name accepted by -arch isn't exactly in getDefaultUniversalArchName()
253 std::string ToolChain::getInputFilename(const InputInfo &Input) const { in getInputFilename()
257 bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const { in IsUnwindTablesDefault()
261 Tool *ToolChain::getClang() const { in getClang()
267 Tool *ToolChain::getFlang() const { in getFlang()
273 Tool *ToolChain::buildAssembler() const { in buildAssembler()
277 Tool *ToolChain::buildLinker() const { in buildLinker()
278 llvm_unreachable("Linking is not supported by this toolchain"); in buildLinker()
281 Tool *ToolChain::buildStaticLibTool() const { in buildStaticLibTool()
282 llvm_unreachable("Creating static lib is not supported by this toolchain"); in buildStaticLibTool()
285 Tool *ToolChain::getAssemble() const { in getAssemble()
291 Tool *ToolChain::getClangAs() const { in getClangAs()
297 Tool *ToolChain::getLink() const { in getLink()
303 Tool *ToolChain::getStaticLibTool() const { in getStaticLibTool()
309 Tool *ToolChain::getIfsMerge() const { in getIfsMerge()
315 Tool *ToolChain::getOffloadBundler() const { in getOffloadBundler()
321 Tool *ToolChain::getOffloadWrapper() const { in getOffloadWrapper()
327 Tool *ToolChain::getTool(Action::ActionClass AC) const { in getTool()
370 static StringRef getArchNameForCompilerRTLib(const ToolChain &TC, in getArchNameForCompilerRTLib()
387 StringRef ToolChain::getOSLibName() const { in getOSLibName()
404 std::string ToolChain::getCompilerRTPath() const { in getCompilerRTPath()
414 std::string ToolChain::getCompilerRTBasename(const ArgList &Args, in getCompilerRTBasename()
422 IsITANMSVCWindows || Type == ToolChain::FT_Object ? "" : "lib"; in getCompilerRTBasename()
425 case ToolChain::FT_Object: in getCompilerRTBasename()
428 case ToolChain::FT_Static: in getCompilerRTBasename()
431 case ToolChain::FT_Shared: in getCompilerRTBasename()
441 const char *Env = TT.isAndroid() ? "-android" : ""; in getCompilerRTBasename()
442 ArchAndEnv = ("-" + Arch + Env).str(); in getCompilerRTBasename()
447 std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, in getCompilerRT()
459 // Fall back to the old expected compiler-rt name if the new one does not in getCompilerRT()
467 const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args, in getCompilerRTArgString()
474 Optional<std::string> ToolChain::getRuntimePath() const { in getRuntimePath()
477 // First try the triple passed to driver as --target=<triple>. in getRuntimePath()
492 Optional<std::string> ToolChain::getCXXStdlibPath() const { in getCXXStdlibPath()
495 // First try the triple passed to driver as --target=<triple>. in getCXXStdlibPath()
510 std::string ToolChain::getArchSpecificLibPath() const { in getArchSpecificLibPath()
517 bool ToolChain::needsProfileRT(const ArgList &Args) { in needsProfileRT()
531 bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) { in needsGCovInstrumentation()
537 Tool *ToolChain::SelectTool(const JobAction &JA) const { in SelectTool()
546 std::string ToolChain::GetFilePath(const char *Name) const { in GetFilePath()
550 std::string ToolChain::GetProgramPath(const char *Name) const { in GetProgramPath()
554 std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD, in GetLinkerPath()
561 // Get -fuse-ld= first to prevent -Wunused-command-line-argument. -fuse-ld= is in GetLinkerPath()
564 StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER; in GetLinkerPath()
566 // --ld-path= takes precedence over -fuse-ld= and specifies the executable in GetLinkerPath()
567 // name. -B, COMPILER_PATH and PATH and consulted if the value does not in GetLinkerPath()
570 std::string Path(A->getValue()); in GetLinkerPath()
573 Path = GetProgramPath(A->getValue()); in GetLinkerPath()
577 getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args); in GetLinkerPath()
580 // If we're passed -fuse-ld= with no argument, or with the argument ld, in GetLinkerPath()
590 // Extending -fuse-ld= to an absolute or relative path is unexpected. Checking in GetLinkerPath()
593 // among -B, COMPILER_PATH and PATH. --ld-path= should be used instead. in GetLinkerPath()
599 // second-guess that. in GetLinkerPath()
622 getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args); in GetLinkerPath()
627 std::string ToolChain::GetStaticLibToolPath() const { in GetStaticLibToolPath()
629 return GetProgramPath("llvm-ar"); in GetStaticLibToolPath()
632 types::ID ToolChain::LookupTypeForExtension(StringRef Ext) const { in LookupTypeForExtension()
644 bool ToolChain::HasNativeLLVMSupport() const { in HasNativeLLVMSupport()
648 bool ToolChain::isCrossCompiling() const { in isCrossCompiling()
664 ObjCRuntime ToolChain::getDefaultObjCRuntime(bool isNonFragile) const { in getDefaultObjCRuntime()
670 ToolChain::GetExceptionModel(const llvm::opt::ArgList &Args) const { in GetExceptionModel()
674 bool ToolChain::isThreadModelSupported(const StringRef Model) const { in isThreadModelSupported()
687 std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, in ComputeLLVMTriple()
699 // x86_64h goes in the triple. Other -march options just use the in ComputeLLVMTriple()
701 StringRef MArch = A->getValue(); in ComputeLLVMTriple()
732 // Handle pseudo-target flags '-mlittle-endian'/'-EL' and in ComputeLLVMTriple()
733 // '-mbig-endian'/'-EB'. in ComputeLLVMTriple()
736 IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian); in ComputeLLVMTriple()
741 // FIXME: Thumb should just be another -target-feaure, not in the triple. in ComputeLLVMTriple()
744 MCPU = A->getValue(); in ComputeLLVMTriple()
746 MArch = A->getValue(); in ComputeLLVMTriple()
765 // Check if ARM ISA was explicitly selected (using -mno-thumb or -marm) for in ComputeLLVMTriple()
766 // M-Class CPUs/architecture variants, which is not supported. in ComputeLLVMTriple()
778 // -mthumb. For assembler files we must check for -mthumb in the options in ComputeLLVMTriple()
779 // passed to the assembler via -Wa or -Xassembler. in ComputeLLVMTriple()
787 // that point. There is no assembler equivalent of -mno-thumb, -marm, or in ComputeLLVMTriple()
788 // -mno-arm. in ComputeLLVMTriple()
791 for (StringRef Value : A->getValues()) { in ComputeLLVMTriple()
792 if (Value == "-mthumb") in ComputeLLVMTriple()
797 // Assembly files should start in ARM mode, unless arch is M-profile, or in ComputeLLVMTriple()
798 // -mthumb has been passed explicitly to the assembler. Windows is always in ComputeLLVMTriple()
831 assert(ABIArg && "Non-default float abi expected to be from arg"); in ComputeLLVMTriple()
833 << ABIArg->getAsString(Args) << Triple.getTriple(); in ComputeLLVMTriple()
844 std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args, in ComputeEffectiveClangTriple()
849 std::string ToolChain::computeSysRoot() const { in computeSysRoot()
853 void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, in AddClangSystemIncludeArgs()
855 // Each toolchain should provide the appropriate include flags. in AddClangSystemIncludeArgs()
858 void ToolChain::addClangTargetOptions( in addClangTargetOptions()
862 void ToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {} in addClangWarningOptions()
864 void ToolChain::addProfileRTLibs(const llvm::opt::ArgList &Args, in addProfileRTLibs()
872 ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( in GetRuntimeLibType()
875 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB; in GetRuntimeLibType()
878 if (LibName == "compiler-rt") in GetRuntimeLibType()
879 return ToolChain::RLT_CompilerRT; in GetRuntimeLibType()
881 return ToolChain::RLT_Libgcc; in GetRuntimeLibType()
886 getDriver().Diag(diag::err_drv_invalid_rtlib_name) << A->getAsString(Args); in GetRuntimeLibType()
891 ToolChain::UnwindLibType ToolChain::GetUnwindLibType( in GetUnwindLibType()
894 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB; in GetUnwindLibType()
897 return ToolChain::UNW_None; in GetUnwindLibType()
899 ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args); in GetUnwindLibType()
900 if (RtLibType == ToolChain::RLT_CompilerRT) in GetUnwindLibType()
901 return ToolChain::UNW_None; in GetUnwindLibType()
902 else if (RtLibType == ToolChain::RLT_Libgcc) in GetUnwindLibType()
903 return ToolChain::UNW_Libgcc; in GetUnwindLibType()
907 return ToolChain::UNW_CompilerRT; in GetUnwindLibType()
909 return ToolChain::UNW_Libgcc; in GetUnwindLibType()
913 << A->getAsString(Args); in GetUnwindLibType()
918 ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ in GetCXXStdlibType()
920 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB; in GetCXXStdlibType()
924 return ToolChain::CST_Libcxx; in GetCXXStdlibType()
926 return ToolChain::CST_Libstdcxx; in GetCXXStdlibType()
931 getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); in GetCXXStdlibType()
937 /*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs, in addSystemInclude()
940 CC1Args.push_back("-internal-isystem"); in addSystemInclude()
952 /*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs, in addExternCSystemInclude()
955 CC1Args.push_back("-internal-externc-isystem"); in addExternCSystemInclude()
959 void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs, in addExternCSystemIncludeIfExists()
967 /*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs, in addSystemIncludes()
971 CC1Args.push_back("-internal-isystem"); in addSystemIncludes()
976 void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, in AddClangCXXStdlibIncludeArgs()
980 // the CC1-layer frontend. As the logic is hoisted out, this generic function in AddClangCXXStdlibIncludeArgs()
984 // '-stdlib=' flag down to CC1 so that it can in turn customize the C++ in AddClangCXXStdlibIncludeArgs()
990 void ToolChain::AddClangCXXStdlibIsystemArgs( in AddClangCXXStdlibIsystemArgs()
1000 bool ToolChain::ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const { in ShouldLinkCXXStdlib()
1006 void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args, in AddCXXStdlibLibArgs()
1013 case ToolChain::CST_Libcxx: in AddCXXStdlibLibArgs()
1014 CmdArgs.push_back("-lc++"); in AddCXXStdlibLibArgs()
1017 case ToolChain::CST_Libstdcxx: in AddCXXStdlibLibArgs()
1018 CmdArgs.push_back("-lstdc++"); in AddCXXStdlibLibArgs()
1023 void ToolChain::AddFilePathLibArgs(const ArgList &Args, in AddFilePathLibArgs()
1027 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); in AddFilePathLibArgs()
1030 void ToolChain::AddCCKextLibArgs(const ArgList &Args, in AddCCKextLibArgs()
1032 CmdArgs.push_back("-lcc_kext"); in AddCCKextLibArgs()
1035 bool ToolChain::isFastMathRuntimeAvailable(const ArgList &Args, in isFastMathRuntimeAvailable()
1037 // Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed in isFastMathRuntimeAvailable()
1040 // Check if -ffast-math or -funsafe-math. in isFastMathRuntimeAvailable()
1046 if (!A || A->getOption().getID() == options::OPT_fno_fast_math || in isFastMathRuntimeAvailable()
1047 A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations) in isFastMathRuntimeAvailable()
1055 bool ToolChain::addFastMathRuntimeIfAvailable(const ArgList &Args, in addFastMathRuntimeIfAvailable()
1066 SanitizerMask ToolChain::getSupportedSanitizers() const { in getSupportedSanitizers()
1091 void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs, in AddCudaIncludeArgs()
1094 void ToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs, in AddHIPIncludeArgs()
1097 void ToolChain::AddIAMCUIncludeArgs(const ArgList &DriverArgs, in AddIAMCUIncludeArgs()
1114 ToolChain::computeMSVCVersion(const Driver *D, in computeMSVCVersion()
1122 D->Diag(diag::err_drv_argument_not_allowed_with) in computeMSVCVersion()
1123 << MSCVersion->getAsString(Args) in computeMSVCVersion()
1124 << MSCompatibilityVersion->getAsString(Args); in computeMSVCVersion()
1130 if (MSVT.tryParse(MSCompatibilityVersion->getValue())) { in computeMSVCVersion()
1132 D->Diag(diag::err_drv_invalid_value) in computeMSVCVersion()
1133 << MSCompatibilityVersion->getAsString(Args) in computeMSVCVersion()
1134 << MSCompatibilityVersion->getValue(); in computeMSVCVersion()
1142 if (StringRef(MSCVersion->getValue()).getAsInteger(10, Version)) { in computeMSVCVersion()
1144 D->Diag(diag::err_drv_invalid_value) in computeMSVCVersion()
1145 << MSCVersion->getAsString(Args) << MSCVersion->getValue(); in computeMSVCVersion()
1154 llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs( in TranslateOpenMPTargetArgs()
1161 // Handle -Xopenmp-target flags in TranslateOpenMPTargetArgs()
1163 // Exclude flags which may only apply to the host toolchain. in TranslateOpenMPTargetArgs()
1165 // matches the current toolchain triple. If it is not present in TranslateOpenMPTargetArgs()
1166 // at all, target and host share a toolchain. in TranslateOpenMPTargetArgs()
1167 if (A->getOption().matches(options::OPT_m_Group)) { in TranslateOpenMPTargetArgs()
1169 DAL->append(A); in TranslateOpenMPTargetArgs()
1178 A->getOption().matches(options::OPT_Xopenmp_target); in TranslateOpenMPTargetArgs()
1180 if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) { in TranslateOpenMPTargetArgs()
1181 // Passing device args: -Xopenmp-target=<triple> -opt=val. in TranslateOpenMPTargetArgs()
1182 if (A->getValue(0) == getTripleString()) in TranslateOpenMPTargetArgs()
1183 Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); in TranslateOpenMPTargetArgs()
1187 // Passing device args: -Xopenmp-target -opt=val. in TranslateOpenMPTargetArgs()
1188 Index = Args.getBaseArgs().MakeIndex(A->getValue(0)); in TranslateOpenMPTargetArgs()
1190 DAL->append(A); in TranslateOpenMPTargetArgs()
1194 // Parse the argument to -Xopenmp-target. in TranslateOpenMPTargetArgs()
1199 << A->getAsString(Args); in TranslateOpenMPTargetArgs()
1207 XOpenMPTargetArg->setBaseArg(A); in TranslateOpenMPTargetArgs()
1210 DAL->append(A); in TranslateOpenMPTargetArgs()
1222 // -Xclang -mframe-pointer=no cannot be passed by -Xarch_. This should be
1224 void ToolChain::TranslateXarchArgs( in TranslateXarchArgs()
1230 if (A->getOption().matches(options::OPT_Xarch_device) || in TranslateXarchArgs()
1231 A->getOption().matches(options::OPT_Xarch_host)) in TranslateXarchArgs()
1234 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(ValuePos)); in TranslateXarchArgs()
1239 // consumed, the -Xarch_ argument's parameter tried to consume in TranslateXarchArgs()
1247 << A->getAsString(Args); in TranslateXarchArgs()
1249 } else if (XarchArg->getOption().hasFlag(options::NoXarchOption)) { in TranslateXarchArgs()
1255 Diags.Report(DiagID) << A->getAsString(Args); in TranslateXarchArgs()
1258 XarchArg->setBaseArg(A); in TranslateXarchArgs()
1261 DAL->AddSynthesizedArg(A); in TranslateXarchArgs()
1263 AllocatedArgs->push_back(A); in TranslateXarchArgs()
1266 llvm::opt::DerivedArgList *ToolChain::TranslateXarchArgs( in TranslateXarchArgs()
1277 if (A->getOption().matches(options::OPT_Xarch_device)) { in TranslateXarchArgs()
1280 } else if (A->getOption().matches(options::OPT_Xarch_host)) { in TranslateXarchArgs()
1283 } else if (A->getOption().matches(options::OPT_Xarch__) && IsGPU) { in TranslateXarchArgs()
1284 // Do not translate -Xarch_ options for non CUDA/HIP toolchain since in TranslateXarchArgs()
1287 if (BoundArch.empty() || A->getValue(0) != BoundArch) in TranslateXarchArgs()
1297 DAL->append(A); in TranslateXarchArgs()