[clang] 16a4350 - [MSP430] Actualize the toolchain description
Anatoly Trosinenko via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 17 05:46:36 PDT 2020
Author: Anatoly Trosinenko
Date: 2020-07-17T15:42:12+03:00
New Revision: 16a4350f76d2bead7af32617dd557d2ec096d2c5
URL: https://github.com/llvm/llvm-project/commit/16a4350f76d2bead7af32617dd557d2ec096d2c5
DIFF: https://github.com/llvm/llvm-project/commit/16a4350f76d2bead7af32617dd557d2ec096d2c5.diff
LOG: [MSP430] Actualize the toolchain description
Reviewed By: krisb
Differential Revision: https://reviews.llvm.org/D81676
Added:
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend_no_eh.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/include/stdio.h
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/exceptions/crt0.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/crt0.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/exceptions/crt0.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/crt0.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/exceptions/crt0.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/crt0.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/exceptions/crt0.o
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/MSP430.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/MSP430.cpp
clang/lib/Driver/ToolChains/MSP430.h
clang/test/Driver/msp430-toolchain.c
Removed:
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtbegin.o
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtend.o
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/crtn.o
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 85ff0e6857d7..65049074dc8e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2193,6 +2193,7 @@ def municode : Joined<["-"], "municode">, Group<m_Group>, Flags<[DriverOption]>;
def mthreads : Joined<["-"], "mthreads">, Group<m_Group>, Flags<[DriverOption]>;
def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>;
def mmcu_EQ : Joined<["-"], "mmcu=">, Group<m_Group>;
+def msim : Flag<["-"], "msim">, Group<m_Group>;
def mdynamic_no_pic : Joined<["-"], "mdynamic-no-pic">, Group<m_Group>;
def mfix_and_continue : Flag<["-"], "mfix-and-continue">, Group<clang_ignored_m_Group>;
def mieee_fp : Flag<["-"], "mieee-fp">, Group<clang_ignored_m_Group>;
@@ -2278,9 +2279,9 @@ def m_seses : Flag<["-"], "mseses">, Group<m_Group>, Flags<[CoreOption, DriverOp
def mno_seses : Flag<["-"], "mno-seses">, Group<m_Group>, Flags<[CoreOption, DriverOption]>,
HelpText<"Disable speculative execution side effect suppression (SESES)">;
-def mrelax : Flag<["-"], "mrelax">, Group<m_riscv_Features_Group>,
+def mrelax : Flag<["-"], "mrelax">, Group<m_Group>,
HelpText<"Enable linker relaxation">;
-def mno_relax : Flag<["-"], "mno-relax">, Group<m_riscv_Features_Group>,
+def mno_relax : Flag<["-"], "mno-relax">, Group<m_Group>,
HelpText<"Disable linker relaxation">;
def msmall_data_limit_EQ : Joined<["-"], "msmall-data-limit=">, Group<m_Group>,
Alias<G>,
diff --git a/clang/lib/Basic/Targets/MSP430.cpp b/clang/lib/Basic/Targets/MSP430.cpp
index ef53ee352c32..90890500ae27 100644
--- a/clang/lib/Basic/Targets/MSP430.cpp
+++ b/clang/lib/Basic/Targets/MSP430.cpp
@@ -29,5 +29,6 @@ void MSP430TargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
Builder.defineMacro("MSP430");
Builder.defineMacro("__MSP430__");
+ Builder.defineMacro("__ELF__");
// FIXME: defines for
diff erent 'flavours' of MCU
}
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index c8a7fce07ef1..9ea07e44e37e 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1552,15 +1552,21 @@ static bool findMSP430Multilibs(const Driver &D,
StringRef Path, const ArgList &Args,
DetectedMultilibs &Result) {
FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
- Multilib MSP430Multilib = makeMultilib("/430");
+ Multilib WithoutExceptions = makeMultilib("/430").flag("-exceptions");
+ Multilib WithExceptions = makeMultilib("/430/exceptions").flag("+exceptions");
+
// FIXME: when clang starts to support msp430x ISA additional logic
// to select between multilib must be implemented
// Multilib MSP430xMultilib = makeMultilib("/large");
- Result.Multilibs.push_back(MSP430Multilib);
+ Result.Multilibs.push_back(WithoutExceptions);
+ Result.Multilibs.push_back(WithExceptions);
Result.Multilibs.FilterOut(NonExistent);
Multilib::flags_list Flags;
+ addMultilibFlag(Args.hasFlag(options::OPT_fexceptions,
+ options::OPT_fno_exceptions, false),
+ "exceptions", Flags);
if (Result.Multilibs.select(Flags, Result.SelectedMultilib))
return true;
diff --git a/clang/lib/Driver/ToolChains/MSP430.cpp b/clang/lib/Driver/ToolChains/MSP430.cpp
index b0bc2e014b48..6d663e4909e5 100644
--- a/clang/lib/Driver/ToolChains/MSP430.cpp
+++ b/clang/lib/Driver/ToolChains/MSP430.cpp
@@ -128,7 +128,7 @@ MSP430ToolChain::MSP430ToolChain(const Driver &D, const llvm::Triple &Triple,
}
SmallString<128> SysRootDir(computeSysRoot());
- llvm::sys::path::append(SysRootDir, "lib", MultilibSuf);
+ llvm::sys::path::append(SysRootDir, "msp430-elf", "lib", MultilibSuf);
addPathIfExists(D, SysRootDir, getFilePaths());
}
@@ -138,10 +138,9 @@ std::string MSP430ToolChain::computeSysRoot() const {
SmallString<128> Dir;
if (GCCInstallation.isValid())
- llvm::sys::path::append(Dir, GCCInstallation.getParentLibPath(), "..",
- GCCInstallation.getTriple().str());
+ llvm::sys::path::append(Dir, GCCInstallation.getParentLibPath(), "..");
else
- llvm::sys::path::append(Dir, getDriver().Dir, "..", getTriple().str());
+ llvm::sys::path::append(Dir, getDriver().Dir, "..");
return std::string(Dir.str());
}
@@ -153,7 +152,7 @@ void MSP430ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
return;
SmallString<128> Dir(computeSysRoot());
- llvm::sys::path::append(Dir, "include");
+ llvm::sys::path::append(Dir, "msp430-elf", "include");
addSystemInclude(DriverArgs, CC1Args, Dir.str());
}
@@ -180,6 +179,87 @@ Tool *MSP430ToolChain::buildLinker() const {
return new tools::msp430::Linker(*this);
}
+void msp430::Linker::AddStartFiles(bool UseExceptions, const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+ const ToolChain &ToolChain = getToolChain();
+
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
+ const char *crtbegin = UseExceptions ? "crtbegin.o" : "crtbegin_no_eh.o";
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
+}
+
+void msp430::Linker::AddDefaultLibs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const {
+ const ToolChain &ToolChain = getToolChain();
+ const Driver &D = ToolChain.getDriver();
+
+ CmdArgs.push_back("--start-group");
+ CmdArgs.push_back(Args.MakeArgString(getHWMultLib(Args)));
+ CmdArgs.push_back("-lc");
+ AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
+ CmdArgs.push_back("-lcrt");
+
+ if (Args.hasArg(options::OPT_msim)) {
+ CmdArgs.push_back("-lsim");
+
+ // msp430-sim.ld relies on __crt0_call_exit being implicitly .refsym-ed
+ // in main() by msp430-gcc.
+ // This workaround should work seamlessly unless the compilation unit that
+ // contains main() is compiled by clang and then passed to
+ // gcc compiler driver for linkage.
+ CmdArgs.push_back("--undefined=__crt0_call_exit");
+ } else
+ CmdArgs.push_back("-lnosys");
+
+ CmdArgs.push_back("--end-group");
+ AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
+}
+
+void msp430::Linker::AddEndFiles(bool UseExceptions, const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+ const ToolChain &ToolChain = getToolChain();
+ const Driver &D = ToolChain.getDriver();
+
+ const char *crtend = UseExceptions ? "crtend.o" : "crtend_no_eh.o";
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
+ AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
+}
+
+static void AddSspArgs(const ArgList &Args, ArgStringList &CmdArgs) {
+ Arg *SspFlag = Args.getLastArg(
+ options::OPT_fno_stack_protector, options::OPT_fstack_protector,
+ options::OPT_fstack_protector_all, options::OPT_fstack_protector_strong);
+
+ if (SspFlag &&
+ !SspFlag->getOption().matches(options::OPT_fno_stack_protector)) {
+ CmdArgs.push_back("-lssp_nonshared");
+ CmdArgs.push_back("-lssp");
+ }
+}
+
+static void AddImplicitLinkerScript(const std::string SysRoot,
+ const ArgList &Args,
+ ArgStringList &CmdArgs) {
+ if (Args.hasArg(options::OPT_T))
+ return;
+
+ if (Args.hasArg(options::OPT_msim)) {
+ CmdArgs.push_back("-Tmsp430-sim.ld");
+ return;
+ }
+
+ const Arg *MCUArg = Args.getLastArg(options::OPT_mmcu_EQ);
+ if (!MCUArg)
+ return;
+
+ SmallString<128> MCULinkerScriptPath(SysRoot);
+ llvm::sys::path::append(MCULinkerScriptPath, "include");
+ // -L because <mcu>.ld INCLUDEs <mcu>_symbols.ld
+ CmdArgs.push_back(Args.MakeArgString("-L" + MCULinkerScriptPath));
+ CmdArgs.push_back(
+ Args.MakeArgString("-T" + StringRef(MCUArg->getValue()) + ".ld"));
+}
+
void msp430::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -189,44 +269,49 @@ void msp430::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const Driver &D = ToolChain.getDriver();
std::string Linker = ToolChain.GetProgramPath(getShortName());
ArgStringList CmdArgs;
-
- if (!D.SysRoot.empty())
- CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+ bool UseExceptions = Args.hasFlag(options::OPT_fexceptions,
+ options::OPT_fno_exceptions, false);
+ bool UseStartAndEndFiles = !Args.hasArg(options::OPT_nostdlib, options::OPT_r,
+ options::OPT_nostartfiles);
+
+ if (Args.hasArg(options::OPT_mrelax))
+ CmdArgs.push_back("--relax");
+ if (!Args.hasArg(options::OPT_r, options::OPT_g_Group))
+ CmdArgs.push_back("--gc-sections");
+
+ Args.AddAllArgs(CmdArgs, {
+ options::OPT_e,
+ options::OPT_n,
+ options::OPT_s,
+ options::OPT_t,
+ options::OPT_u,
+ });
+
+ if (UseStartAndEndFiles)
+ AddStartFiles(UseExceptions, Args, CmdArgs);
Args.AddAllArgs(CmdArgs, options::OPT_L);
ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-
- if (!Args.hasArg(options::OPT_T)) {
- if (const Arg *MCUArg = Args.getLastArg(options::OPT_mmcu_EQ))
- CmdArgs.push_back(
- Args.MakeArgString("-T" + StringRef(MCUArg->getValue()) + ".ld"));
- } else {
- Args.AddAllArgs(CmdArgs, options::OPT_T);
- }
-
- if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
- CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
- CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o")));
- }
-
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
- CmdArgs.push_back("--start-group");
- CmdArgs.push_back(Args.MakeArgString(getHWMultLib(Args)));
- CmdArgs.push_back("-lgcc");
- if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
- CmdArgs.push_back("-lc");
- CmdArgs.push_back("-lcrt");
- CmdArgs.push_back("-lnosys");
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_r,
+ options::OPT_nodefaultlibs)) {
+ AddSspArgs(Args, CmdArgs);
+ AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
+ if (!Args.hasArg(options::OPT_nolibc)) {
+ AddDefaultLibs(Args, CmdArgs);
+ AddImplicitLinkerScript(D.SysRoot, Args, CmdArgs);
+ }
}
- CmdArgs.push_back("--end-group");
- if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
- CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
- CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
- }
+ if (UseStartAndEndFiles)
+ AddEndFiles(UseExceptions, Args, CmdArgs);
+
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
+
+ Args.AddAllArgs(CmdArgs, options::OPT_T);
+
C.addCommand(
std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(),
Args.MakeArgString(Linker), CmdArgs, Inputs));
diff --git a/clang/lib/Driver/ToolChains/MSP430.h b/clang/lib/Driver/ToolChains/MSP430.h
index 58fd158cd12f..3789e7442a23 100644
--- a/clang/lib/Driver/ToolChains/MSP430.h
+++ b/clang/lib/Driver/ToolChains/MSP430.h
@@ -40,6 +40,11 @@ class LLVM_LIBRARY_VISIBILITY MSP430ToolChain : public Generic_ELF {
bool isPIEDefault() const override { return false; }
bool isPICDefaultForced() const override { return true; }
+ UnwindLibType
+ GetUnwindLibType(const llvm::opt::ArgList &Args) const override {
+ return UNW_None;
+ }
+
protected:
Tool *buildLinker() const override;
@@ -61,6 +66,14 @@ class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
const InputInfo &Output, const InputInfoList &Inputs,
const llvm::opt::ArgList &TCArgs,
const char *LinkingOutput) const override;
+
+private:
+ void AddStartFiles(bool UseExceptions, const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
+ void AddDefaultLibs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
+ void AddEndFiles(bool UseExceptions, const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
};
void getMSP430TargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin.o
similarity index 100%
rename from clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtbegin.o
rename to clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin.o
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin_no_eh.o
similarity index 100%
rename from clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtend.o
rename to clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin_no_eh.o
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/crtn.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend.o
similarity index 100%
rename from clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/crtn.o
rename to clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend.o
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend_no_eh.o b/clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend_no_eh.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/include/stdio.h b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/include/stdio.h
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/exceptions/crt0.o b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/exceptions/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/crt0.o b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/exceptions/crt0.o b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/exceptions/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/crt0.o b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/exceptions/crt0.o b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/exceptions/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/crt0.o b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/exceptions/crt0.o b/clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/exceptions/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/msp430-toolchain.c b/clang/test/Driver/msp430-toolchain.c
index f741491c94e8..f88b32d66a9b 100644
--- a/clang/test/Driver/msp430-toolchain.c
+++ b/clang/test/Driver/msp430-toolchain.c
@@ -1,78 +1,264 @@
-// A basic clang -cc1 command-line, and simple environment check.
+// Splitting some tests into POS and NEG parts so the latter can validate
+// output fragments as large as possible for absence of some text.
-// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "msp430"
+// Test for include paths and other cc1 flags
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -E \
+// RUN: --sysroot="%S/Inputs/basic_msp430_tree" 2>&1 \
+// RUN: | FileCheck -check-prefix=INCLUDE-DIRS %s
+// INCLUDE-DIRS: "{{.*}}clang{{.*}}" "-cc1" "-triple" "msp430"
+// INCLUDE-DIRS: "-internal-isystem" "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}include"
+
+// Tests for passing flags to msp430-elf-ld (not file-related)
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" > %t 2>&1
+// RUN: FileCheck -check-prefix=DEFAULT-POS %s < %t
+// RUN: FileCheck -check-prefix=DEFAULT-NEG %s < %t
+// DEFAULT-POS: "{{.*}}msp430-elf-ld"
+// DEFAULT-POS: "--gc-sections"
+// DEFAULT-NEG-NOT: "--relax"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" \
+// RUN: -r 2>&1 | FileCheck --check-prefixes=NO-GC-SECTIONS,RELOCATABLE-OBJECT %s
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" \
+// RUN: -g 2>&1 | FileCheck -check-prefix=NO-GC-SECTIONS %s
+// NO-GC-SECTIONS: "{{.*}}msp430-elf-ld"
+// NO-GC-SECTIONS-NOT: "--gc-sections"
+// RELOCATABLE-OBJECT-NOT: crt0.o
+// RELOCATABLE-OBJECT-NOT: crtbegin
+// RELOCATABLE-OBJECT-NOT: crtend
+// RELOCATABLE-OBJECT-NOT: "-l{{.*}}"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" \
+// RUN: -Wl,--some-linker-arg 2>&1 | FileCheck -check-prefix=WL-ARG %s
+// WL-ARG: "{{.*}}msp430-elf-ld"
+// WL-ARG: "--some-linker-arg"
+
+// Trivially mapped options: arbitrarily split into two disjoint groups
+// to check both "on"/present and "off"/absent state (when appropriate).
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" \
+// RUN: -o /tmp/test.elf -r -t -z muldefs -mrelax > %t 2>&1
+// RUN: FileCheck -check-prefix=MISC-FLAGS-1-POS %s < %t
+// RUN: FileCheck -check-prefix=MISC-FLAGS-1-NEG %s < %t
+// MISC-FLAGS-1-POS: "{{.*}}msp430-elf-ld"
+// MISC-FLAGS-1-POS-DAG: "--relax"
+// MISC-FLAGS-1-POS-DAG: "-o" "/tmp/test.elf"
+// MISC-FLAGS-1-POS-DAG: "-r"
+// MISC-FLAGS-1-POS-DAG: "-t"
+// MISC-FLAGS-1-POS-DAG: "-z" "muldefs"
+// MISC-FLAGS-1-NEG: "{{.*}}msp430-elf-ld"
+// MISC-FLAGS-1-NEG-NOT: "-e{{.*}}"
+// MISC-FLAGS-1-NEG-NOT: "-s"
+// MISC-FLAGS-1-NEG-NOT: "-u"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" \
+// RUN: -e EntryPoint -s -u __undef > %t 2>&1
+// RUN: FileCheck -check-prefix=MISC-FLAGS-2-POS %s < %t
+// RUN: FileCheck -check-prefix=MISC-FLAGS-2-NEG %s < %t
+// MISC-FLAGS-2-POS: "{{.*}}msp430-elf-ld"
+// MISC-FLAGS-2-POS: "-e" "EntryPoint" "-s" "-u" "__undef"
+// MISC-FLAGS-2-NEG: "{{.*}}msp430-elf-ld"
+// MISC-FLAGS-2-NEG-NOT: "-r"
+// MISC-FLAGS-2-NEG-NOT: "-t"
+// MISC-FLAGS-2-NEG-NOT: "-z"
+// MISC-FLAGS-2-NEG-NOT: "--relax"
+
+// Tests for -nostdlib, -nostartfiles, -nodefaultfiles and -f(no-)exceptions
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 \
+// RUN: --sysroot="%S/Inputs/basic_msp430_tree" > %t 2>&1
+// RUN: FileCheck -check-prefix=LIBS-DEFAULT-POS %s < %t
+// RUN: FileCheck -check-prefix=LIBS-DEFAULT-NEG %s < %t
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 \
+// RUN: --gcc-toolchain="%S/Inputs/basic_msp430_tree" --sysroot="" 2>&1 \
+// RUN: | FileCheck -check-prefix=LIBS-DEFAULT-GCC-TOOLCHAIN %s
+// LIBS-DEFAULT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-DEFAULT-POS: "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
+// LIBS-DEFAULT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtbegin_no_eh.o"
+// LIBS-DEFAULT-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-DEFAULT-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-DEFAULT-POS: "-lgcc" "--start-group" "-lmul_none" "-lc" "-lgcc" "-lcrt" "-lnosys" "--end-group" "-lgcc"
+// LIBS-DEFAULT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtend_no_eh.o" "-lgcc"
+// LIBS-DEFAULT-GCC-TOOLCHAIN: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-DEFAULT-GCC-TOOLCHAIN: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
+// LIBS-DEFAULT-GCC-TOOLCHAIN: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtbegin_no_eh.o"
+// LIBS-DEFAULT-GCC-TOOLCHAIN: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-DEFAULT-GCC-TOOLCHAIN: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-DEFAULT-GCC-TOOLCHAIN: "-lgcc" "--start-group" "-lmul_none" "-lc" "-lgcc" "-lcrt" "-lnosys" "--end-group" "-lgcc"
+// LIBS-DEFAULT-GCC-TOOLCHAIN: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtend_no_eh.o" "-lgcc"
+// LIBS-DEFAULT-NEG-NOT: crtbegin.o
+// LIBS-DEFAULT-NEG-NOT: -lssp_nonshared
+// LIBS-DEFAULT-NEG-NOT: -lssp
+// LIBS-DEFAULT-NEG-NOT: clang_rt
+// LIBS-DEFAULT-NEG-NOT: crtend.o
+// LIBS-DEFAULT-NEG-NOT: /exceptions
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -rtlib=compiler-rt \
+// RUN: --sysroot="%S/Inputs/basic_msp430_tree" > %t 2>&1
+// RUN: FileCheck -check-prefix=LIBS-COMPILER-RT-POS %s < %t
+// RUN: FileCheck -check-prefix=LIBS-COMPILER-RT-NEG %s < %t
+// LIBS-COMPILER-RT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-COMPILER-RT-POS: "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
+// LIBS-COMPILER-RT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtbegin_no_eh.o"
+// LIBS-COMPILER-RT-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-COMPILER-RT-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-COMPILER-RT-POS: "{{[^"]*}}libclang_rt.builtins-msp430.a" "--start-group" "-lmul_none" "-lc" "{{[^"]*}}libclang_rt.builtins-msp430.a" "-lcrt" "-lnosys" "--end-group" "{{[^"]*}}libclang_rt.builtins-msp430.a"
+// LIBS-COMPILER-RT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtend_no_eh.o" "{{[^"]*}}libclang_rt.builtins-msp430.a"
+// LIBS-COMPILER-RT-NEG-NOT: crtbegin.o
+// LIBS-COMPILER-RT-NEG-NOT: -lssp_nonshared
+// LIBS-COMPILER-RT-NEG-NOT: -lssp
+// LIBS-COMPILER-RT-NEG-NOT: -lgcc
+// LIBS-COMPILER-RT-NEG-NOT: crtend.o
+// LIBS-COMPILER-RT-NEG-NOT: /exceptions
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -fexceptions \
+// RUN: --sysroot="%S/Inputs/basic_msp430_tree" > %t 2>&1
+// RUN: FileCheck -check-prefix=LIBS-EXC-POS %s < %t
+// RUN: FileCheck -check-prefix=LIBS-EXC-NEG %s < %t
+// LIBS-EXC-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-EXC-POS: "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430/exceptions{{/|\\\\}}crt0.o"
+// LIBS-EXC-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions{{/|\\\\}}crtbegin.o"
+// LIBS-EXC-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions"
+// LIBS-EXC-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430/exceptions"
+// LIBS-EXC-POS: "-lgcc" "--start-group" "-lmul_none" "-lc" "-lgcc" "-lcrt" "-lnosys" "--end-group"
+// LIBS-EXC-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions{{/|\\\\}}crtend.o" "-lgcc"
+// LIBS-EXC-NEG-NOT: "{{.*}}/430"
+// LIBS-EXC-NEG-NOT: "{{.*}}430/crt{{.*}}"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 \
-// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430 %s
-
-// MSP430: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
-// MSP430: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
-// MSP430: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
-// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
-// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtbegin.o"
-// MSP430: "--start-group" "-lmul_none" "-lgcc" "-lc" "-lcrt" "-lnosys" "--end-group"
-// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtend.o"
-// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crtn.o"
+// RUN: -fstack-protector --sysroot="%S/Inputs/basic_msp430_tree" 2>&1 \
+// RUN: | FileCheck -check-prefix=LIBS-SSP %s
+// LIBS-SSP: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-SSP: "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
+// LIBS-SSP: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtbegin_no_eh.o"
+// LIBS-SSP: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-SSP: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-SSP: "-lssp_nonshared" "-lssp"
+// LIBS-SSP: "-lgcc" "--start-group" "-lmul_none" "-lc" "-lgcc" "-lcrt" "-lnosys" "--end-group"
+// LIBS-SSP: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtend_no_eh.o" "-lgcc"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nodefaultlibs \
-// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-NO-DFT-LIB %s
-
-// MSP430-NO-DFT-LIB: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
-// MSP430-NO-DFT-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
-// MSP430-NO-DFT-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
-// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
-// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtbegin.o"
-// MSP430-NO-DFT-LIB: "--start-group" "-lmul_none" "-lgcc" "--end-group"
-// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtend.o"
-// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crtn.o"
+// RUN: --sysroot="%S/Inputs/basic_msp430_tree" > %t 2>&1
+// RUN: FileCheck -check-prefix=LIBS-NO-DFT-POS %s < %t
+// RUN: FileCheck -check-prefix=LIBS-NO-DFT-NEG %s < %t
+// LIBS-NO-DFT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-NO-DFT-POS: "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
+// LIBS-NO-DFT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtbegin_no_eh.o"
+// LIBS-NO-DFT-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-NO-DFT-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-NO-DFT-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtend_no_eh.o" "-lgcc"
+// LIBS-NO-DFT-NEG-NOT: "-lc"
+// LIBS-NO-DFT-NEG-NOT: "-lcrt"
+// LIBS-NO-DFT-NEG-NOT: "-lsim"
+// LIBS-NO-DFT-NEG-NOT: "-lnosys"
+// LIBS-NO-DFT-NEG-NOT: "--start-group"
+// LIBS-NO-DFT-NEG-NOT: "--end-group"
-// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nostartfiles \
-// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-NO-START %s
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nolibc \
+// RUN: -fstack-protector --sysroot="%S/Inputs/basic_msp430_tree" > %t 2>&1
+// RUN: FileCheck -check-prefix=LIBS-NO-LIBC-POS %s < %t
+// RUN: FileCheck -check-prefix=LIBS-NO-LIBC-NEG %s < %t
+// LIBS-NO-LIBC-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-NO-LIBC-POS: "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
+// LIBS-NO-LIBC-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtbegin_no_eh.o"
+// LIBS-NO-LIBC-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-NO-LIBC-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-NO-LIBC-POS: "-lssp_nonshared" "-lssp" "-lgcc"
+// LIBS-NO-LIBC-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtend_no_eh.o" "-lgcc"
+// LIBS-NO-LIBC-NEG-NOT: "-lc"
+// LIBS-NO-LIBC-NEG-NOT: "-lcrt"
+// LIBS-NO-LIBC-NEG-NOT: "-lsim"
+// LIBS-NO-LIBC-NEG-NOT: "-lnosys"
+// LIBS-NO-LIBC-NEG-NOT: "--start-group"
+// LIBS-NO-LIBC-NEG-NOT: "--end-group"
-// MSP430-NO-START: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
-// MSP430-NO-START: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
-// MSP430-NO-START: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
-// MSP430-NO-START: "--start-group" "-lmul_none" "-lgcc" "-lc" "-lcrt" "-lnosys" "--end-group"
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nostartfiles \
+// RUN: --sysroot="%S/Inputs/basic_msp430_tree" > %t 2>&1
+// RUN: FileCheck -check-prefix=LIBS-NO-START-POS %s < %t
+// RUN: FileCheck -check-prefix=LIBS-NO-START-NEG %s < %t
+// LIBS-NO-START-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-NO-START-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-NO-START-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-NO-START-POS: "-lgcc" "--start-group" "-lmul_none" "-lc" "-lgcc" "-lcrt" "-lnosys" "--end-group"
+// LIBS-NO-START-NEG-NOT: crt0.o
+// LIBS-NO-START-NEG-NOT: crtbegin
+// LIBS-NO-START-NEG-NOT: crtend
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nostdlib \
-// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-NO-STD-LIB %s
+// RUN: --sysroot="%S/Inputs/basic_msp430_tree" > %t 2>&1
+// RUN: FileCheck -check-prefix=LIBS-NO-STD-POS %s < %t
+// RUN: FileCheck -check-prefix=LIBS-NO-STD-NEG %s < %t
+// LIBS-NO-STD-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LIBS-NO-STD-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// LIBS-NO-STD-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// LIBS-NO-STD-NEG-NOT: crt0.o
+// LIBS-NO-STD-NEG-NOT: crtbegin
+// LIBS-NO-STD-NEG-NOT: crtend
+// LIBS-NO-STD-NEG-NOT: "-lc"
+// LIBS-NO-STD-NEG-NOT: "-lcrt"
+// LIBS-NO-STD-NEG-NOT: "-lnosys"
+// LIBS-NO-STD-NEG-NOT: "--start-group"
+// LIBS-NO-STD-NEG-NOT: "--end-group"
+
+// Test for linker script autodiscovery
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430g2553 \
+// RUN: --sysroot=%S/Inputs/basic_msp430_tree 2>&1 \
+// RUN: | FileCheck -check-prefix=LD-SCRIPT %s
+// LD-SCRIPT: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// LD-SCRIPT: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}include"
+// LD-SCRIPT: "-Tmsp430g2553.ld"
-// MSP430-NO-STD-LIB: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
-// MSP430-NO-STD-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
-// MSP430-NO-STD-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
-// MSP430-NO-STD-LIB: "--start-group" "-lmul_none" "-lgcc" "--end-group"
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430g2553 \
+// RUN: --sysroot=%S/Inputs/basic_msp430_tree \
+// RUN: -T custom_script.ld 2>&1 \
+// RUN: | FileCheck -check-prefix=CUSTOM-LD-SCRIPT %s
+// CUSTOM-LD-SCRIPT: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// CUSTOM-LD_SCRIPT-NOT: "-Tmsp430g2553.ld"
+// CUSTOM-LD-SCRIPT: "-T" "custom_script.ld"
+// CUSTOM-LD_SCRIPT-NOT: "-Tmsp430g2553.ld"
+
+// Test for compiling for simulator
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430g2553 \
+// RUN: -msim --sysroot=%S/Inputs/basic_msp430_tree > %t 2>&1
+// RUN: FileCheck -check-prefix=SIMULATOR-POS %s < %t
+// RUN: FileCheck -check-prefix=SIMULATOR-NEG %s < %t
+// SIMULATOR-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
+// SIMULATOR-POS: "{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
+// SIMULATOR-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtbegin_no_eh.o"
+// SIMULATOR-POS: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430"
+// SIMULATOR-POS: "-L{{.*}}/Inputs/basic_msp430_tree{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
+// SIMULATOR-POS: "-lgcc" "--start-group" "-lmul_none" "-lc" "-lgcc" "-lcrt" "-lsim" "--undefined=__crt0_call_exit" "--end-group"
+// SIMULATOR-POS: "-Tmsp430-sim.ld"
+// SIMULATOR-POS: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430{{/|\\\\}}crtend_no_eh.o" "-lgcc"
+// SIMULATOR-NEG-NOT: "-lnosys"
+
+// Tests for HWMult
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f147 --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-16BIT %s
+// RUN: | FileCheck -check-prefix=HWMult-16BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f147 -mhwmult=auto --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-16BIT %s
+// RUN: | FileCheck -check-prefix=HWMult-16BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=16bit --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-16BIT %s
-
-// MSP430-HWMult-16BIT: "--start-group" "-lmul_16"
+// RUN: | FileCheck -check-prefix=HWMult-16BIT %s
+// HWMult-16BIT: "--start-group" "-lmul_16"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f4783 --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-32BIT %s
+// RUN: | FileCheck -check-prefix=HWMult-32BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f4783 -mhwmult=auto --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-32BIT %s
+// RUN: | FileCheck -check-prefix=HWMult-32BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=32bit --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-32BIT %s
-
-// MSP430-HWMult-32BIT: "--start-group" "-lmul_32"
+// RUN: | FileCheck -check-prefix=HWMult-32BIT %s
+// HWMult-32BIT: "--start-group" "-lmul_32"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=f5series --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-F5 %s
-// MSP430-HWMult-F5: "--start-group" "-lmul_f5"
+// RUN: | FileCheck -check-prefix=HWMult-F5 %s
+// HWMult-F5: "--start-group" "-lmul_f5"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=none --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-NONE %s
+// RUN: | FileCheck -check-prefix=HWMult-NONE %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=none -mmcu=msp430f4783 --sysroot="" 2>&1 \
-// RUN: | FileCheck -check-prefix=MSP430-HWMult-NONE %s
-
-// MSP430-HWMult-NONE: "--start-group" "-lmul_none"
+// RUN: | FileCheck -check-prefix=HWMult-NONE %s
+// HWMult-NONE: "--start-group" "-lmul_none"
More information about the cfe-commits
mailing list