Revert "[Driver] Support linking to compiler-rt for target AVR"

This reverts commit 44a647d21d.
This commit is contained in:
Ben Shi 2022-08-16 07:55:41 +08:00
parent b8f62dc22a
commit 65c022a75f
4 changed files with 5 additions and 61 deletions

View File

@ -19,7 +19,6 @@
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
using namespace clang::driver;
using namespace clang::driver::toolchains;
@ -370,7 +369,8 @@ AVRToolChain::AVRToolChain(const Driver &D, const llvm::Triple &Triple,
: Generic_ELF(D, Triple, Args) {
GCCInstallation.init(Triple, Args);
if (getCPUName(D, Args, Triple).empty())
std::string CPU = getCPUName(D, Args, Triple);
if (CPU.empty())
D.Diag(diag::warn_drv_avr_mcu_not_specified);
// Only add default libraries if the user hasn't explicitly opted out.
@ -418,23 +418,6 @@ Tool *AVRToolChain::buildLinker() const {
return new tools::AVR::Linker(getTriple(), *this);
}
std::string
AVRToolChain::getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
FileType Type = ToolChain::FT_Static) const {
assert(Type == ToolChain::FT_Static && "AVR only supports static libraries");
// Since AVR can never be a host environment, its compiler-rt library files
// should always have ".a" suffix, even on windows.
SmallString<32> File("/libclang_rt.");
File += Component.str();
File += ".a";
// Return the default compiler-rt path appended with
// "avr/libclang_rt.$COMPONENT.a".
SmallString<256> Path(ToolChain::getCompilerRTPath());
llvm::sys::path::append(Path, "avr");
llvm::sys::path::append(Path, File.str());
return std::string(Path.str());
}
void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs, const ArgList &Args,
@ -465,12 +448,6 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddAllArgs(CmdArgs, options::OPT_L);
getToolChain().AddFilePathLibArgs(Args, CmdArgs);
// Currently we only support libgcc and compiler-rt.
auto RtLib = TC.GetRuntimeLibType(Args);
assert(
(RtLib == ToolChain::RLT_Libgcc || RtLib == ToolChain::RLT_CompilerRT) &&
"unknown runtime library");
// Only add default libraries if the user hasn't explicitly opted out.
bool LinkStdlib = false;
if (!Args.hasArg(options::OPT_nostdlib) &&
@ -486,12 +463,10 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
D.Diag(diag::warn_drv_avr_libc_not_found);
} else {
std::string SubPath = GetMCUSubPath(CPU);
// Add path of avr-libc.
CmdArgs.push_back(
Args.MakeArgString(Twine("-L") + *AVRLibcRoot + "/lib/" + SubPath));
if (RtLib == ToolChain::RLT_Libgcc)
CmdArgs.push_back(Args.MakeArgString("-L" + TC.getGCCInstallPath() +
"/" + SubPath));
CmdArgs.push_back(
Args.MakeArgString("-L" + TC.getGCCInstallPath() + "/" + SubPath));
LinkStdlib = true;
}
}
@ -520,29 +495,14 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
std::string CrtFileName = std::string("-l:crt") + CPU + std::string(".o");
CmdArgs.push_back(Args.MakeArgString(CrtFileName));
// Link to libgcc.
if (RtLib == ToolChain::RLT_Libgcc)
CmdArgs.push_back("-lgcc");
// Link to generic libraries of avr-libc.
CmdArgs.push_back("-lgcc");
CmdArgs.push_back("-lm");
CmdArgs.push_back("-lc");
// Add the link library specific to the MCU.
CmdArgs.push_back(Args.MakeArgString(std::string("-l") + CPU));
// Add the relocatable inputs.
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
// We directly use libclang_rt.builtins.a as input file, instead of using
// '-lclang_rt.builtins'.
if (RtLib == ToolChain::RLT_CompilerRT) {
std::string RtLib =
getToolChain().getCompilerRT(Args, "builtins", ToolChain::FT_Static);
if (llvm::sys::fs::exists(RtLib))
CmdArgs.push_back(Args.MakeArgString(RtLib));
}
CmdArgs.push_back("--end-group");
// Add user specified linker script.

View File

@ -33,8 +33,6 @@ public:
llvm::Optional<std::string> findAVRLibcInstallation() const;
StringRef getGCCInstallPath() const { return GCCInstallPath; }
std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
FileType Type) const override;
protected:
Tool *buildLinker() const override;

View File

@ -72,17 +72,3 @@
// RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -mmcu=atmega328 %s -fuse-ld=%S/Inputs/basic_avr_tree/usr/bin/ld.lld -T avr.lds 2>&1 | FileCheck --check-prefix=LDS1 %s
// LDS1: "-T" "avr.lds"
// LDS1-NOT: "-mavr5"
// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir 2>&1 | FileCheck --check-prefix=LIBGCC %s
// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=LIBGCC %s
// LIBGCC: "-lgcc"
// LIBGCC-NOT: libclang_rt
// RUN: %clang %s -### --target=avr -mmcu=atmega328 --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=COMRT %s
// COMRT: avr/libclang_rt.builtins.a
// COMRT-NOT: "-lgcc"
// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=NOMCU %s
// RUN: %clang %s -### --target=avr --sysroot=%S/Inputs/basic_avr_tree/ -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir --rtlib=libgcc 2>&1 | FileCheck --check-prefix=NOMCU %s
// NOMCU-NOT: libclang_rt
// NOMCU-NOT: "-lgcc"