manojgupta updated this revision to Diff 450910. manojgupta added a comment.
Address more style lints. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131225/new/ https://reviews.llvm.org/D131225 Files: clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/BareMetal.cpp clang/lib/Driver/ToolChains/BareMetal.h clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a clang/test/Driver/baremetal.cpp clang/test/Driver/print-libgcc-file-name-clangrt.c llvm/include/llvm/ADT/Triple.h llvm/lib/Support/Triple.cpp
Index: llvm/lib/Support/Triple.cpp =================================================================== --- llvm/lib/Support/Triple.cpp +++ llvm/lib/Support/Triple.cpp @@ -1932,6 +1932,51 @@ } } +bool Triple::isARMBareMetal() const { + if (getArch() != arm && getArch() != thumb) + return false; + + if (getVendor() != UnknownVendor) + return false; + + if (getOS() != UnknownOS) + return false; + + if (getEnvironment() != EABI && getEnvironment() != EABIHF) + return false; + + return true; +} + +bool Triple::isAArch64BareMetal() const { + if (getArch() != aarch64) + return false; + + if (getVendor() != UnknownVendor) + return false; + + if (getOS() != UnknownOS) + return false; + + return getEnvironmentName() == "elf"; +} + +bool Triple::isRISCVBareMetal() const { + if (getArch() != riscv32 && getArch() != riscv64) + return false; + + if (getVendor() != UnknownVendor) + return false; + + if (getOS() != UnknownOS) + return false; + + return getEnvironmentName() == "elf"; +} + +bool Triple::isBareMetal() const { + return isARMBareMetal() || isAArch64BareMetal() || isRISCVBareMetal(); +} // HLSL triple environment orders are relied on in the front end static_assert(Triple::Vertex - Triple::Pixel == 1, "incorrect HLSL stage order"); Index: llvm/include/llvm/ADT/Triple.h =================================================================== --- llvm/include/llvm/ADT/Triple.h +++ llvm/include/llvm/ADT/Triple.h @@ -912,6 +912,18 @@ return Env == Triple::GNUX32 || Env == Triple::MuslX32; } + /// Tests if the target is {arm,thumb}-none-none-{eabi,eabihf}. + bool isARMBareMetal() const; + + /// Tests if the target is aarch64-none-elf. + bool isAArch64BareMetal() const; + + /// Tests if the target is riscv-none-none-elf. + bool isRISCVBareMetal() const; + + /// Tests if this is a bare metal target. + bool isBareMetal() const; + /// Tests whether the target supports comdat bool supportsCOMDAT() const { return !(isOSBinFormatMachO() || isOSBinFormatXCOFF()); Index: clang/test/Driver/print-libgcc-file-name-clangrt.c =================================================================== --- clang/test/Driver/print-libgcc-file-name-clangrt.c +++ clang/test/Driver/print-libgcc-file-name-clangrt.c @@ -48,3 +48,9 @@ // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ // RUN: | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a + +// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \ +// RUN: --target=armv7m-vendor-none-eabi \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s +// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a Index: clang/test/Driver/baremetal.cpp =================================================================== --- clang/test/Driver/baremetal.cpp +++ clang/test/Driver/baremetal.cpp @@ -31,6 +31,20 @@ // RUN: | FileCheck --check-prefix=CHECK-V6M-LIBINC %s // CHECK-V6M-LIBINC-NOT: "-internal-isystem" +// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \ +// RUN: -target armv7m-vendor-none-eabi \ +// RUN: --sysroot=%S/Inputs/baremetal_arm \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s +// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]" +// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp" +// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" +// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib" +// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi +// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins" +// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o" + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: -target armv6m-none-eabi \ // RUN: --sysroot=%S/Inputs/baremetal_arm \ Index: clang/lib/Driver/ToolChains/BareMetal.h =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.h +++ clang/lib/Driver/ToolChains/BareMetal.h @@ -25,19 +25,11 @@ const llvm::opt::ArgList &Args); ~BareMetal() override = default; - static bool handlesTarget(const llvm::Triple &Triple); - void findMultilibs(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); protected: Tool *buildLinker() const override; - - std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args, - StringRef Component, - FileType Type = ToolChain::FT_Static, - bool AddArch = true) const override; - public: bool useIntegratedAs() const override { return true; } bool isCrossCompiling() const override { return true; } @@ -50,8 +42,6 @@ StringRef getOSLibName() const override { return "baremetal"; } - std::string getCompilerRTPath() const override; - RuntimeLibType GetDefaultRuntimeLibType() const override { return ToolChain::RLT_CompilerRT; } @@ -61,7 +51,6 @@ const char *getDefaultLinker() const override { return "ld.lld"; } - std::string getRuntimesDir() const; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, Index: clang/lib/Driver/ToolChains/BareMetal.cpp =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.cpp +++ clang/lib/Driver/ToolChains/BareMetal.cpp @@ -92,7 +92,7 @@ } BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, - const ArgList &Args) + const ArgList &Args) : ToolChain(D, Triple, Args) { getProgramPaths().push_back(getDriver().getInstalledDir()); if (getDriver().getInstalledDir() != getDriver().Dir) @@ -106,57 +106,10 @@ } } -/// Is the triple {arm,thumb}-none-none-{eabi,eabihf} ? -static bool isARMBareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::arm && - Triple.getArch() != llvm::Triple::thumb) - return false; - - if (Triple.getVendor() != llvm::Triple::UnknownVendor) - return false; - - if (Triple.getOS() != llvm::Triple::UnknownOS) - return false; - - if (Triple.getEnvironment() != llvm::Triple::EABI && - Triple.getEnvironment() != llvm::Triple::EABIHF) - return false; - - return true; -} - -/// Is the triple aarch64-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64) - 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.getArch() != llvm::Triple::riscv32 && - Triple.getArch() != llvm::Triple::riscv64) - return false; - - if (Triple.getVendor() != llvm::Triple::UnknownVendor) - return false; - - if (Triple.getOS() != llvm::Triple::UnknownOS) - return false; - - return Triple.getEnvironmentName() == "elf"; -} - void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) { DetectedMultilibs Result; - if (isRISCVBareMetal(Triple)) { + if (Triple.isRISCVBareMetal()) { if (findRISCVMultilibs(D, Triple, Args, Result)) { SelectedMultilib = Result.SelectedMultilib; Multilibs = Result.Multilibs; @@ -164,30 +117,10 @@ } } -bool BareMetal::handlesTarget(const llvm::Triple &Triple) { - return isARMBareMetal(Triple) || isAArch64BareMetal(Triple) || - isRISCVBareMetal(Triple); -} - Tool *BareMetal::buildLinker() const { return new tools::baremetal::Linker(*this); } -std::string BareMetal::getCompilerRTPath() const { return getRuntimesDir(); } - -std::string BareMetal::buildCompilerRTBasename(const llvm::opt::ArgList &, - StringRef, FileType, - bool) const { - return ("libclang_rt.builtins-" + getTriple().getArchName() + ".a").str(); -} - -std::string BareMetal::getRuntimesDir() const { - SmallString<128> Dir(getDriver().ResourceDir); - llvm::sys::path::append(Dir, "lib", "baremetal"); - Dir += SelectedMultilib.gccSuffix(); - return std::string(Dir.str()); -} - std::string BareMetal::computeSysRoot() const { if (!getDriver().SysRoot.empty()) return getDriver().SysRoot + SelectedMultilib.osSuffix(); @@ -226,8 +159,8 @@ CC1Args.push_back("-nostdsysteminc"); } -void BareMetal::AddClangCXXStdlibIncludeArgs( - const ArgList &DriverArgs, ArgStringList &CC1Args) const { +void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdinc) || DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) @@ -292,10 +225,15 @@ ArgStringList &CmdArgs) const { ToolChain::RuntimeLibType RLT = GetRuntimeLibType(Args); switch (RLT) { - case ToolChain::RLT_CompilerRT: + case ToolChain::RLT_CompilerRT: { + const std::string FileName = getCompilerRT(Args, "builtins"); + llvm::StringRef BaseName = llvm::sys::path::filename(FileName); + BaseName.consume_front("lib"); + BaseName.consume_back(".a"); CmdArgs.push_back( - Args.MakeArgString("-lclang_rt.builtins-" + getTriple().getArchName())); + Args.MakeArgString("-l" + BaseName)); return; + } case ToolChain::RLT_Libgcc: CmdArgs.push_back("-lgcc"); return; @@ -310,7 +248,7 @@ const char *LinkingOutput) const { ArgStringList CmdArgs; - auto &TC = static_cast<const toolchains::BareMetal&>(getToolChain()); + auto &TC = static_cast<const toolchains::BareMetal &>(getToolChain()); AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA); @@ -322,10 +260,17 @@ TC.AddFilePathLibArgs(Args, CmdArgs); - CmdArgs.push_back(Args.MakeArgString("-L" + TC.getRuntimesDir())); + for (const auto &LibPath : TC.getLibraryPaths()) + CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-L", LibPath))); + + const std::string FileName = TC.getCompilerRT(Args, "builtins"); + llvm::SmallString<128> PathBuf{FileName}; + llvm::sys::path::remove_filename(PathBuf); + CmdArgs.push_back(Args.MakeArgString("-L" + PathBuf)); if (TC.ShouldLinkCXXStdlib(Args)) TC.AddCXXStdlibLibArgs(Args, CmdArgs); + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { CmdArgs.push_back("-lc"); CmdArgs.push_back("-lm"); Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -422,6 +422,9 @@ const llvm::Triple &Triple = TC.getTriple(); bool IsWindows = Triple.isOSWindows(); + if (Triple.isBareMetal()) + return Triple.getArchName(); + if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb) return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows) ? "armhf" @@ -459,7 +462,10 @@ std::string ToolChain::getCompilerRTPath() const { SmallString<128> Path(getDriver().ResourceDir); - if (Triple.isOSUnknown()) { + if (Triple.isBareMetal()) { + llvm::sys::path::append(Path, "lib", getOSLibName()); + Path += SelectedMultilib.gccSuffix(); + } else if (Triple.isOSUnknown()) { llvm::sys::path::append(Path, "lib"); } else { llvm::sys::path::append(Path, "lib", getOSLibName()); Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -6165,7 +6165,7 @@ if (Target.getVendor() == llvm::Triple::Myriad) TC = std::make_unique<toolchains::MyriadToolChain>(*this, Target, Args); - else if (toolchains::BareMetal::handlesTarget(Target)) + else if (Target.isBareMetal()) TC = std::make_unique<toolchains::BareMetal>(*this, Target, Args); else if (Target.isOSBinFormatELF()) TC = std::make_unique<toolchains::Generic_ELF>(*this, Target, Args);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits