[clang] Revert stack "[Driver] Add support for GCC installation detection in … (PR #144603)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 17 14:07:21 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Daniel Thornburgh (mysterymath)
<details>
<summary>Changes</summary>
…Baremetal toolchain (#<!-- -->121829)"
This reverts the following stack of commits, due to them breaking the Fuchsia toolchain and corresponding LLVM buildbot.
Revert "[Driver] Fix Arm/AArch64 Link Argument tests (#<!-- -->144582)" This reverts commit a79186c1ea62bbe0579e0b1eed4ad507966cca41.
Revert "[Driver] Add option to force undefined symbols during linking in BareMetal toolchain object. (#<!-- -->132807)" This reverts commit 9cb754509608b9d9143fa17f775631bbfcce0848.
Revert "[Driver] Fix link order of BareMetal toolchain object (#<!-- -->132806)" This reverts commit 31523de4b000ca254259ae3167d28922e1302648.
Revert "[Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (#<!-- -->121830)" This reverts commit ec230aa7a7d13c222c0b34b87c3c16937383b4a0.
Revert "[Driver] Add support for GCC installation detection in Baremetal toolchain (#<!-- -->121829)" This reverts commit eb31c422d0dc816bf285a81bf92690d4d16273ed.
---
Patch is 82.42 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/144603.diff
37 Files Affected:
- (modified) clang/docs/Toolchain.rst (-5)
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (-3)
- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+72-215)
- (modified) clang/lib/Driver/ToolChains/BareMetal.h (+5-17)
- (removed) clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1/.keep ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/.keep ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_gcc_tree/bin/aarch64-none-elf-ld (-1)
- (removed) clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtend.o ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crt0.o ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtbegin.o ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtend.o ()
- (removed) clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/bin/aarch64-none-elf-ld (-1)
- (removed) clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/include/c++/8.2.1/.keep ()
- (removed) clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/.keep ()
- (removed) clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/crt0.o ()
- (removed) clang/test/Driver/Inputs/basic_arm_gcc_tree/bin/armv6m-none-eabi-ld (-1)
- (removed) clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o ()
- (removed) clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtend.o ()
- (removed) clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crt0.o ()
- (removed) clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtbegin.o ()
- (removed) clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtend.o ()
- (removed) clang/test/Driver/Inputs/basic_arm_nogcc_tree/bin/armv6m-none-eabi-ld (-1)
- (removed) clang/test/Driver/aarch64-gnutools.c (-4)
- (removed) clang/test/Driver/aarch64-toolchain-extra.c (-35)
- (removed) clang/test/Driver/aarch64-toolchain.c (-157)
- (removed) clang/test/Driver/arm-gnutools.c (-6)
- (removed) clang/test/Driver/arm-toolchain-extra.c (-36)
- (removed) clang/test/Driver/arm-toolchain.c (-158)
- (modified) clang/test/Driver/baremetal-multilib.yaml (+1-2)
- (modified) clang/test/Driver/baremetal-sysroot.cpp (+3-5)
- (removed) clang/test/Driver/baremetal-undefined-symbols.c (-14)
- (modified) clang/test/Driver/baremetal.cpp (+31-67)
- (removed) clang/test/Driver/check-no-multlib-warning.c (-10)
- (added) clang/test/Driver/riscv-args.c (+6)
- (modified) clang/test/Driver/sanitizer-ld.c (+1-1)
``````````diff
diff --git a/clang/docs/Toolchain.rst b/clang/docs/Toolchain.rst
index d56b21d74c7e3..958199eb7a2e2 100644
--- a/clang/docs/Toolchain.rst
+++ b/clang/docs/Toolchain.rst
@@ -347,8 +347,3 @@ workarounds for issues discovered in libstdc++, and these are removed
as fixed libstdc++ becomes sufficiently old.
You can instruct Clang to use libstdc++ with the ``-stdlib=libstdc++`` flag.
-
-GCC Installation
-=================
-Users can point to their GCC installation by using the ``-gcc-toolchain`` or by
-using ``-gcc-install-dir`` flag.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 94224e1038758..29f6480ba935c 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -847,9 +847,6 @@ def note_drv_available_multilibs : Note<
"available multilibs are:%0">;
def err_drv_multilib_custom_error : Error<
"multilib configuration error: %0">;
-def warn_drv_multilib_not_available_for_target: Warning<
- "no multilib structure encoded for Arm, Aarch64 and PPC targets">,
- InGroup<DiagGroup<"multilib-not-found">>;
def err_drv_experimental_crel : Error<
"-Wa,--allow-experimental-crel must be specified to use -Wa,--crel. "
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index d4e4e6d04b417..d8168ed15febd 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -31,40 +31,6 @@ using namespace clang::driver;
using namespace clang::driver::tools;
using namespace clang::driver::toolchains;
-/// Is the triple {aarch64.aarch64_be}-none-elf?
-static bool isAArch64BareMetal(const llvm::Triple &Triple) {
- if (Triple.getArch() != llvm::Triple::aarch64 &&
- Triple.getArch() != llvm::Triple::aarch64_be)
- return false;
-
- if (Triple.getVendor() != llvm::Triple::UnknownVendor)
- return false;
-
- if (Triple.getOS() != llvm::Triple::UnknownOS)
- return false;
-
- return Triple.getEnvironmentName() == "elf";
-}
-
-static bool isRISCVBareMetal(const llvm::Triple &Triple) {
- if (!Triple.isRISCV())
- return false;
-
- if (Triple.getVendor() != llvm::Triple::UnknownVendor)
- return false;
-
- if (Triple.getOS() != llvm::Triple::UnknownOS)
- return false;
-
- return Triple.getEnvironmentName() == "elf";
-}
-
-/// Is the triple powerpc[64][le]-*-none-eabi?
-static bool isPPCBareMetal(const llvm::Triple &Triple) {
- return Triple.isPPC() && Triple.getOS() == llvm::Triple::UnknownOS &&
- Triple.getEnvironment() == llvm::Triple::EABI;
-}
-
static bool findRISCVMultilibs(const Driver &D,
const llvm::Triple &TargetTriple,
const ArgList &Args, DetectedMultilibs &Result) {
@@ -129,8 +95,7 @@ static bool findRISCVMultilibs(const Driver &D,
return false;
}
-static std::string computeClangRuntimesSysRoot(const Driver &D,
- bool IncludeTriple) {
+static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
if (!D.SysRoot.empty())
return D.SysRoot;
@@ -143,123 +108,56 @@ static std::string computeClangRuntimesSysRoot(const Driver &D,
return std::string(SysRootDir);
}
-// Only consider the GCC toolchain based on the values provided through the
-// `--gcc-toolchain` and `--gcc-install-dir` flags. The function below returns
-// whether the GCC toolchain was initialized successfully.
-bool BareMetal::initGCCInstallation(const llvm::Triple &Triple,
- const llvm::opt::ArgList &Args) {
- if (Args.getLastArg(options::OPT_gcc_toolchain) ||
- Args.getLastArg(clang::driver::options::OPT_gcc_install_dir_EQ)) {
- GCCInstallation.init(Triple, Args);
- return GCCInstallation.isValid();
+BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
+ const ArgList &Args)
+ : ToolChain(D, Triple, Args),
+ SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) {
+ getProgramPaths().push_back(getDriver().Dir);
+
+ findMultilibs(D, Triple, Args);
+ SmallString<128> SysRoot(computeSysRoot());
+ if (!SysRoot.empty()) {
+ for (const Multilib &M : getOrderedMultilibs()) {
+ SmallString<128> Dir(SysRoot);
+ llvm::sys::path::append(Dir, M.osSuffix(), "lib");
+ getFilePaths().push_back(std::string(Dir));
+ getLibraryPaths().push_back(std::string(Dir));
+ }
}
- return false;
}
-// This logic is adapted from RISCVToolChain.cpp as part of the ongoing effort
-// to merge RISCVToolChain into the Baremetal toolchain. It infers the presence
-// of a valid GCC toolchain by checking whether the `crt0.o` file exists in the
-// `bin/../<target-triple>/lib` directory.
-static bool detectGCCToolchainAdjacent(const Driver &D) {
- SmallString<128> GCCDir;
- llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(),
- "lib/crt0.o");
- return llvm::sys::fs::exists(GCCDir);
-}
+/// Is the triple {aarch64.aarch64_be}-none-elf?
+static bool isAArch64BareMetal(const llvm::Triple &Triple) {
+ if (Triple.getArch() != llvm::Triple::aarch64 &&
+ Triple.getArch() != llvm::Triple::aarch64_be)
+ return false;
-// If no sysroot is provided the driver will first attempt to infer it from the
-// values of `--gcc-install-dir` or `--gcc-toolchain`, which specify the
-// location of a GCC toolchain.
-// If neither flag is used, the sysroot defaults to either:
-// - `bin/../<target-triple>`
-// - `bin/../lib/clang-runtimes/<target-triple>`
-//
-// To use the `clang-runtimes` path, ensure that `../<target-triple>/lib/crt0.o`
-// does not exist relative to the driver.
-std::string BareMetal::computeSysRoot() const {
- // Use Baremetal::sysroot if it has already been set.
- if (!SysRoot.empty())
- return SysRoot;
-
- // Use the sysroot specified via the `--sysroot` command-line flag, if
- // provided.
- const Driver &D = getDriver();
- if (!D.SysRoot.empty())
- return D.SysRoot;
+ if (Triple.getVendor() != llvm::Triple::UnknownVendor)
+ return false;
- // Attempt to infer sysroot from a valid GCC installation.
- // If no valid GCC installation, check for a GCC toolchain alongside Clang.
- SmallString<128> inferredSysRoot;
- if (IsGCCInstallationValid) {
- llvm::sys::path::append(inferredSysRoot, GCCInstallation.getParentLibPath(),
- "..", GCCInstallation.getTriple().str());
- } else if (detectGCCToolchainAdjacent(D)) {
- // Use the triple as provided to the driver. Unlike the parsed triple
- // this has not been normalized to always contain every field.
- llvm::sys::path::append(inferredSysRoot, D.Dir, "..", D.getTargetTriple());
- }
- // If a valid sysroot was inferred and exists, use it
- if (!inferredSysRoot.empty() && llvm::sys::fs::exists(inferredSysRoot))
- return std::string(inferredSysRoot);
+ if (Triple.getOS() != llvm::Triple::UnknownOS)
+ return false;
- // Use the clang-runtimes path.
- return computeClangRuntimesSysRoot(D, /*IncludeTriple*/ true);
+ return Triple.getEnvironmentName() == "elf";
}
-static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs,
- const Multilib &Multilib,
- StringRef InstallPath,
- ToolChain::path_list &Paths) {
- if (const auto &PathsCallback = Multilibs.filePathsCallback())
- for (const auto &Path : PathsCallback(Multilib))
- addPathIfExists(D, InstallPath + Path, Paths);
+static bool isRISCVBareMetal(const llvm::Triple &Triple) {
+ if (!Triple.isRISCV())
+ return false;
+
+ if (Triple.getVendor() != llvm::Triple::UnknownVendor)
+ return false;
+
+ if (Triple.getOS() != llvm::Triple::UnknownOS)
+ return false;
+
+ return Triple.getEnvironmentName() == "elf";
}
-// GCC mutltilibs will only work for those targets that have their multlib
-// structure encoded into GCCInstallation. Baremetal toolchain supports ARM,
-// AArch64, RISCV and PPC and of these only RISCV have GCC multilibs hardcoded
-// in GCCInstallation.
-BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
- const ArgList &Args)
- : Generic_ELF(D, Triple, Args) {
- IsGCCInstallationValid = initGCCInstallation(Triple, Args);
- std::string ComputedSysRoot = computeSysRoot();
- if (IsGCCInstallationValid) {
- if (!isRISCVBareMetal(Triple))
- D.Diag(clang::diag::warn_drv_multilib_not_available_for_target);
-
- Multilibs = GCCInstallation.getMultilibs();
- SelectedMultilibs.assign({GCCInstallation.getMultilib()});
-
- path_list &Paths = getFilePaths();
- // Add toolchain/multilib specific file paths.
- addMultilibsFilePaths(D, Multilibs, SelectedMultilibs.back(),
- GCCInstallation.getInstallPath(), Paths);
- // Adding filepath for locating crt{begin,end}.o files.
- Paths.push_back(GCCInstallation.getInstallPath().str());
- // Adding filepath for locating crt0.o file.
- Paths.push_back(ComputedSysRoot + "/lib");
-
- ToolChain::path_list &PPaths = getProgramPaths();
- // Multilib cross-compiler GCC installations put ld in a triple-prefixed
- // directory off of the parent of the GCC installation.
- PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str() + "/bin")
- .str());
- PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str());
- } else {
- getProgramPaths().push_back(getDriver().Dir);
- findMultilibs(D, Triple, Args);
- const SmallString<128> SysRootDir(computeSysRoot());
- if (!SysRootDir.empty()) {
- for (const Multilib &M : getOrderedMultilibs()) {
- SmallString<128> Dir(SysRootDir);
- llvm::sys::path::append(Dir, M.osSuffix(), "lib");
- getFilePaths().push_back(std::string(Dir));
- getLibraryPaths().push_back(std::string(Dir));
- }
- }
- }
+/// Is the triple powerpc[64][le]-*-none-eabi?
+static bool isPPCBareMetal(const llvm::Triple &Triple) {
+ return Triple.isPPC() && Triple.getOS() == llvm::Triple::UnknownOS &&
+ Triple.getEnvironment() == llvm::Triple::EABI;
}
static void
@@ -318,7 +216,7 @@ getMultilibConfigPath(const Driver &D, const llvm::Triple &Triple,
return {};
}
} else {
- MultilibPath = computeClangRuntimesSysRoot(D, /*IncludeTriple=*/false);
+ MultilibPath = computeBaseSysRoot(D, /*IncludeTriple=*/false);
llvm::sys::path::append(MultilibPath, MultilibFilename);
}
return MultilibPath;
@@ -336,7 +234,7 @@ void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
if (D.getVFS().exists(*MultilibPath)) {
// If multilib.yaml is found, update sysroot so it doesn't use a target
// specific suffix
- SysRoot = computeClangRuntimesSysRoot(D, /*IncludeTriple=*/false);
+ SysRoot = computeBaseSysRoot(D, /*IncludeTriple=*/false);
SmallVector<StringRef> CustomFlagMacroDefines;
findMultilibsFromYAML(*this, D, *MultilibPath, Args, Result,
CustomFlagMacroDefines);
@@ -344,7 +242,7 @@ void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
Multilibs = Result.Multilibs;
MultilibMacroDefines.append(CustomFlagMacroDefines.begin(),
CustomFlagMacroDefines.end());
- } else if (isRISCVBareMetal(Triple) && !detectGCCToolchainAdjacent(D)) {
+ } else if (isRISCVBareMetal(Triple)) {
if (findRISCVMultilibs(D, Triple, Args, Result)) {
SelectedMultilibs = Result.SelectedMultilibs;
Multilibs = Result.Multilibs;
@@ -365,6 +263,8 @@ Tool *BareMetal::buildStaticLibTool() const {
return new tools::baremetal::StaticLibTool(*this);
}
+std::string BareMetal::computeSysRoot() const { return SysRoot; }
+
BareMetal::OrderedMultilibs BareMetal::getOrderedMultilibs() const {
// Get multilibs in reverse order because they're ordered most-specific last.
if (!SelectedMultilibs.empty())
@@ -392,10 +292,10 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
if (std::optional<std::string> Path = getStdlibIncludePath())
addSystemInclude(DriverArgs, CC1Args, *Path);
- const SmallString<128> SysRootDir(computeSysRoot());
- if (!SysRootDir.empty()) {
+ const SmallString<128> SysRoot(computeSysRoot());
+ if (!SysRoot.empty()) {
for (const Multilib &M : getOrderedMultilibs()) {
- SmallString<128> Dir(SysRootDir);
+ SmallString<128> Dir(SysRoot);
llvm::sys::path::append(Dir, M.includeSuffix());
llvm::sys::path::append(Dir, "include");
addSystemInclude(DriverArgs, CC1Args, Dir.str());
@@ -409,19 +309,6 @@ void BareMetal::addClangTargetOptions(const ArgList &DriverArgs,
CC1Args.push_back("-nostdsysteminc");
}
-void BareMetal::addLibStdCxxIncludePaths(
- const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args) const {
- if (!IsGCCInstallationValid)
- return;
- const GCCVersion &Version = GCCInstallation.getVersion();
- StringRef TripleStr = GCCInstallation.getTriple().str();
- const Multilib &Multilib = GCCInstallation.getMultilib();
- addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
- TripleStr, Multilib.includeSuffix(), DriverArgs,
- CC1Args);
-}
-
void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
@@ -452,23 +339,23 @@ void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
};
switch (GetCXXStdlibType(DriverArgs)) {
- case ToolChain::CST_Libcxx: {
- SmallString<128> P(D.Dir);
- llvm::sys::path::append(P, "..", "include");
- AddCXXIncludePath(P);
- break;
- }
- case ToolChain::CST_Libstdcxx:
- addLibStdCxxIncludePaths(DriverArgs, CC1Args);
- break;
+ case ToolChain::CST_Libcxx: {
+ SmallString<128> P(D.Dir);
+ llvm::sys::path::append(P, "..", "include");
+ AddCXXIncludePath(P);
+ break;
+ }
+ case ToolChain::CST_Libstdcxx:
+ // We only support libc++ toolchain installation.
+ break;
}
- std::string SysRootDir(computeSysRoot());
- if (SysRootDir.empty())
+ std::string SysRoot(computeSysRoot());
+ if (SysRoot.empty())
return;
for (const Multilib &M : getOrderedMultilibs()) {
- SmallString<128> Dir(SysRootDir);
+ SmallString<128> Dir(SysRoot);
llvm::sys::path::append(Dir, M.gccSuffix());
switch (GetCXXStdlibType(DriverArgs)) {
case ToolChain::CST_Libcxx: {
@@ -568,6 +455,8 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const llvm::Triple::ArchType Arch = TC.getArch();
const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
+ AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
CmdArgs.push_back("-Bstatic");
if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax))
@@ -582,48 +471,19 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
}
- bool NeedCRTs =
- !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
-
- const char *CRTBegin, *CRTEnd;
- if (NeedCRTs) {
- if (!Args.hasArg(options::OPT_r))
- CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
- if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) {
- auto RuntimeLib = TC.GetRuntimeLibType(Args);
- switch (RuntimeLib) {
- case (ToolChain::RLT_Libgcc): {
- CRTBegin = "crtbegin.o";
- CRTEnd = "crtend.o";
- break;
- }
- case (ToolChain::RLT_CompilerRT): {
- CRTBegin =
- TC.getCompilerRTArgString(Args, "crtbegin", ToolChain::FT_Object);
- CRTEnd =
- TC.getCompilerRTArgString(Args, "crtend", ToolChain::FT_Object);
- break;
- }
- }
- CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTBegin)));
- }
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+ options::OPT_r)) {
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
}
- Args.addAllArgs(CmdArgs,
- {options::OPT_L, options::OPT_u, options::OPT_T_Group,
- options::OPT_s, options::OPT_t, options::OPT_r});
+ Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+ options::OPT_s, options::OPT_t, options::OPT_r});
TC.AddFilePathLibArgs(Args, CmdArgs);
for (const auto &LibPath : TC.getLibraryPaths())
CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-L", LibPath)));
- if (D.isUsingLTO())
- addLTOOptions(TC, Args, CmdArgs, Output, Inputs,
- D.getLTOMode() == LTOK_Thin);
-
- AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
-
if (TC.ShouldLinkCXXStdlib(Args)) {
bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
!Args.hasArg(options::OPT_static);
@@ -636,17 +496,14 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
- CmdArgs.push_back("--start-group");
AddRunTimeLibs(TC, D, CmdArgs, Args);
+
CmdArgs.push_back("-lc");
- if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D))
- CmdArgs.push_back("-lgloss");
- CmdArgs.push_back("--end-group");
}
- if ((TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) &&
- NeedCRTs)
- CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTEnd)));
+ if (D.isUsingLTO())
+ addLTOOptions(TC, Args, CmdArgs, Output, Inputs,
+ D.getLTOMode() == LTOK_Thin);
if (TC.getTriple().isRISCV())
CmdArgs.push_back("-X");
diff --git a/clang/lib/Driver/ToolChains/BareMetal.h b/clang/lib/Driver/ToolChains/BareMetal.h
index 54805530bae82..f6295bda0a6a2 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.h
+++ b/clang/lib/Driver/ToolChains/BareMetal.h
@@ -9,7 +9,6 @@
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
-#include "ToolChains/Gnu.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
@@ -20,7 +19,7 @@ namespace driver {
namespace toolchains {
-class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
public:
BareMetal(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
@@ -36,9 +35,7 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
Tool *buildStaticLibTool() const override;
public:
- bool initGCCInstallation(const llvm::Triple &Triple,
- const llvm::opt::ArgList &Args);
- bool hasValidGCCInstallation() const { return IsGCCInstallationValid; }
+ bool useIntegratedAs() const override { return true; }
bool isBareMetal() const override { return true; }
bool isCrossCompiling() const override { return true; }
bool HasNativeLLVMSupport() const override { return true; }
@@ -51,19 +48,15 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
StringRef getOSLibName() const override { return "baremetal"; }
- UnwindTableLevel
- getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override {
- return UnwindTableLevel::None;
- }
-
RuntimeLibType GetDefaultRuntimeLibType() const override {
return ToolChain::RLT_CompilerRT;
}
-
CXXStdlibType GetDefaultCXXStdlibType() const override {
return ToolChain::CST_Libcxx;
}
+ const char *getDefaultLinker() const override { return "ld.lld"; }
+
void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
@@ -74,9 +67,6 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
void AddClangCXXStdlibIncludeArgs(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
- void
- addLibStdCxxIncludePaths(c...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/144603
More information about the cfe-commits
mailing list