[PATCH] D73904: [clang] stop baremetal driver to append .a to lib

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 11 14:04:28 PST 2020


MaskRay added a comment.

A probably better approach is to use something like `TC.getCompilerRT(Args, "profile")`. The function returns a full path which can avoid `-L` problems.

  std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
                                       FileType Type) const {
    const llvm::Triple &TT = getTriple();
    bool IsITANMSVCWindows =
        TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
  
    const char *Prefix =
        IsITANMSVCWindows || Type == ToolChain::FT_Object ? "" : "lib";
    const char *Suffix;
    switch (Type) {
    case ToolChain::FT_Object:
      Suffix = IsITANMSVCWindows ? ".obj" : ".o";
      break;
    case ToolChain::FT_Static:
      Suffix = IsITANMSVCWindows ? ".lib" : ".a";
      break;
    case ToolChain::FT_Shared:
      Suffix = Triple.isOSWindows()
                   ? (Triple.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
                   : ".so";
      break;
    }
  
    for (const auto &LibPath : getLibraryPaths()) {
      SmallString<128> P(LibPath);
      llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix);
      if (getVFS().exists(P))
        return std::string(P.str());
    }
  
    StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
    const char *Env = TT.isAndroid() ? "-android" : "";
    SmallString<128> Path(getCompilerRTPath());
    llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
                                      Arch + Env + Suffix);
    return std::string(Path.str());
  }


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73904/new/

https://reviews.llvm.org/D73904





More information about the cfe-commits mailing list