pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/lang/clang clang: Use the full LLVM suite on SunOS.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/aebdcdb22961
branches:  trunk
changeset: 311389:aebdcdb22961
user:      jperkin <jperkin%pkgsrc.org@localhost>
date:      Thu Aug 09 14:56:41 2018 +0000

description:
clang: Use the full LLVM suite on SunOS.

This enables compiler-rt, libcxx, and libunwind, as well as fixing various
assumptions in the code about what should be set on SunOS.  In bulk builds
a while back this was able to compete favourably with GCC.

diffstat:

 lang/clang/Makefile.common                                 |   12 +-
 lang/clang/distinfo                                        |    6 +-
 lang/clang/patches/patch-lib_Basic_Targets_OSTargets.h     |   36 ++
 lang/clang/patches/patch-lib_Driver_ToolChains_Solaris.cpp |  210 +++++++++++++
 lang/clang/patches/patch-lib_Driver_ToolChains_Solaris.h   |   16 +
 lang/clang/patches/patch-lib_Frontend_InitHeaderSearch.cpp |   14 +
 6 files changed, 292 insertions(+), 2 deletions(-)

diffs (truncated from 333 to 300 lines):

diff -r e507959156c0 -r aebdcdb22961 lang/clang/Makefile.common
--- a/lang/clang/Makefile.common        Thu Aug 09 14:52:20 2018 +0000
+++ b/lang/clang/Makefile.common        Thu Aug 09 14:56:41 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.common,v 1.27 2018/08/07 10:44:50 adam Exp $
+# $NetBSD: Makefile.common,v 1.28 2018/08/09 14:56:41 jperkin Exp $
 # used by lang/clang/Makefile
 # used by lang/clang-static-analyzer/Makefile
 
@@ -89,6 +89,16 @@
 CMAKE_ARGS+=                   -DCLANG_DEFAULT_CXX_STDLIB:STRING="libstdc++"
 .endif
 
+# Enable full LLVM suite on SunOS
+.if ${OPSYS} == "SunOS"
+.include "../../lang/compiler-rt/buildlink3.mk"
+.include "../../lang/libcxx/buildlink3.mk"
+.include "../../lang/libcxxabi/buildlink3.mk"
+.include "../../lang/libunwind/buildlink3.mk"
+CMAKE_ARGS+=    -DCLANG_DEFAULT_RTLIB:STRING="compiler-rt"
+CMAKE_ARGS+=    -DCLANG_DEFAULT_CXX_STDLIB:STRING="libc++"
+.endif
+
 # 3.8.0 -> 3.8
 LLVM_MAJOR=    ${PKGVERSION_NOREV:C/^([0-9]+\.[0-9]+)\..*$/\1/}
 PLIST_SUBST+=  LLVM_MAJOR=${LLVM_MAJOR}
diff -r e507959156c0 -r aebdcdb22961 lang/clang/distinfo
--- a/lang/clang/distinfo       Thu Aug 09 14:52:20 2018 +0000
+++ b/lang/clang/distinfo       Thu Aug 09 14:56:41 2018 +0000
@@ -1,6 +1,10 @@
-$NetBSD: distinfo,v 1.52 2018/08/07 10:44:50 adam Exp $
+$NetBSD: distinfo,v 1.53 2018/08/09 14:56:41 jperkin Exp $
 
 SHA1 (cfe-6.0.1.src.tar.xz) = d93d8f3e3d7eb549ac58507383f7fcbdd78804d7
 RMD160 (cfe-6.0.1.src.tar.xz) = c280cd2037b19f9bd733944b765f9ca23b35e0a4
 SHA512 (cfe-6.0.1.src.tar.xz) = f64ba9290059f6e36fee41c8f32bf483609d31c291fcd2f77d41fecfdf3c8233a5e23b93a1c73fed03683823bd6e72757ed993dd32527de3d5f2b7a64bb031b9
 Size (cfe-6.0.1.src.tar.xz) = 11905772 bytes
+SHA1 (patch-lib_Basic_Targets_OSTargets.h) = 73043149874a79bc7f048eb854832381939a1397
+SHA1 (patch-lib_Driver_ToolChains_Solaris.cpp) = 7cf1d43b50e7a0bf0842f2265b0449b0fea44007
+SHA1 (patch-lib_Driver_ToolChains_Solaris.h) = 13849df72a4b719bbb6109ab1d1abf2e7b97014f
+SHA1 (patch-lib_Frontend_InitHeaderSearch.cpp) = 924cb81bd8e2eb07c3577e25c1b1d4f405e9360f
diff -r e507959156c0 -r aebdcdb22961 lang/clang/patches/patch-lib_Basic_Targets_OSTargets.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lang/clang/patches/patch-lib_Basic_Targets_OSTargets.h    Thu Aug 09 14:56:41 2018 +0000
@@ -0,0 +1,36 @@
+$NetBSD: patch-lib_Basic_Targets_OSTargets.h,v 1.1 2018/08/09 14:56:41 jperkin Exp $
+
+Sync SunOS default defines with a working reality.
+
+--- lib/Basic/Targets/OSTargets.h.orig 2018-01-04 07:43:41.000000000 +0000
++++ lib/Basic/Targets/OSTargets.h
+@@ -531,20 +531,16 @@ protected:
+     Builder.defineMacro("__ELF__");
+     Builder.defineMacro("__svr4__");
+     Builder.defineMacro("__SVR4");
+-    // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
+-    // newer, but to 500 for everything else.  feature_test.h has a check to
+-    // ensure that you are not using C99 with an old version of X/Open or C89
+-    // with a new version.
+-    if (Opts.C99)
++    // Compatibility with GCC to satisfy <sys/feature_tests.h> requirements.
++    if (Opts.CPlusPlus) {
++      Builder.defineMacro("__STDC_VERSION__", "199901L");
+       Builder.defineMacro("_XOPEN_SOURCE", "600");
+-    else
+-      Builder.defineMacro("_XOPEN_SOURCE", "500");
+-    if (Opts.CPlusPlus)
+-      Builder.defineMacro("__C99FEATURES__");
+-    Builder.defineMacro("_LARGEFILE_SOURCE");
+-    Builder.defineMacro("_LARGEFILE64_SOURCE");
+-    Builder.defineMacro("__EXTENSIONS__");
+-    Builder.defineMacro("_REENTRANT");
++      Builder.defineMacro("_LARGEFILE_SOURCE");
++      Builder.defineMacro("_LARGEFILE64_SOURCE");
++      Builder.defineMacro("__EXTENSIONS__");
++    }
++    if (Opts.POSIXThreads)
++      Builder.defineMacro("_REENTRANT");
+   }
+ 
+ public:
diff -r e507959156c0 -r aebdcdb22961 lang/clang/patches/patch-lib_Driver_ToolChains_Solaris.cpp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lang/clang/patches/patch-lib_Driver_ToolChains_Solaris.cpp        Thu Aug 09 14:56:41 2018 +0000
@@ -0,0 +1,210 @@
+$NetBSD: patch-lib_Driver_ToolChains_Solaris.cpp,v 1.1 2018/08/09 14:56:41 jperkin Exp $
+
+Use compiler-rt instead of libgcc.
+Pull in libcxx correctly.
+Specify paths to system objects explicitly.
+Don't specify --dynamic-linker, makes it impossible for the user to use -Wl,-r
+Ensure we reset to -zdefaultextract prior to adding compiler-rt.
+Test removing -Bdynamic for golang.
+
+--- lib/Driver/ToolChains/Solaris.cpp.orig     2018-01-04 07:43:41.000000000 +0000
++++ lib/Driver/ToolChains/Solaris.cpp
+@@ -49,8 +49,29 @@ void solaris::Linker::ConstructJob(Compi
+                                    const InputInfoList &Inputs,
+                                    const ArgList &Args,
+                                    const char *LinkingOutput) const {
++  const Driver &D = getToolChain().getDriver();
+   ArgStringList CmdArgs;
+ 
++  // XXX: assumes pkgsrc layout
++  std::string LibPath;
++  LibPath = llvm::sys::path::parent_path(D.getInstalledDir());
++  LibPath += "/lib/";
++
++  std::string SysPath = "/usr/lib/";
++  switch (getToolChain().getArch()) {
++  case llvm::Triple::x86:
++  case llvm::Triple::sparc:
++    break;
++  case llvm::Triple::x86_64:
++    SysPath += "amd64/";
++    break;
++  case llvm::Triple::sparcv9:
++    SysPath += "sparcv9/";
++    break;
++  default:
++    llvm_unreachable("Unsupported architecture");
++  }
++
+   // Demangle C++ names in errors
+   CmdArgs.push_back("-C");
+ 
+@@ -62,15 +83,8 @@ void solaris::Linker::ConstructJob(Compi
+   if (Args.hasArg(options::OPT_static)) {
+     CmdArgs.push_back("-Bstatic");
+     CmdArgs.push_back("-dn");
+-  } else {
+-    CmdArgs.push_back("-Bdynamic");
+-    if (Args.hasArg(options::OPT_shared)) {
+-      CmdArgs.push_back("-shared");
+-    } else {
+-      CmdArgs.push_back("--dynamic-linker");
+-      CmdArgs.push_back(
+-          Args.MakeArgString(getToolChain().GetFilePath("ld.so.1")));
+-    }
++  } else if (Args.hasArg(options::OPT_shared)) {
++    CmdArgs.push_back("-shared");
+   }
+ 
+   if (Output.isFilename()) {
+@@ -83,13 +97,11 @@ void solaris::Linker::ConstructJob(Compi
+   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+     if (!Args.hasArg(options::OPT_shared))
+       CmdArgs.push_back(
+-          Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
++          Args.MakeArgString(SysPath + "crt1.o"));
+ 
+-    CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
+-    CmdArgs.push_back(
+-        Args.MakeArgString(getToolChain().GetFilePath("values-Xa.o")));
++    CmdArgs.push_back(Args.MakeArgString(SysPath + "crti.o"));
+     CmdArgs.push_back(
+-        Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
++        Args.MakeArgString(SysPath + "values-Xa.o"));
+   }
+ 
+   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
+@@ -100,21 +112,21 @@ void solaris::Linker::ConstructJob(Compi
+   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+ 
+   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+-    if (getToolChain().ShouldLinkCXXStdlib(Args))
+-      getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+-    CmdArgs.push_back("-lgcc_s");
+-    CmdArgs.push_back("-lc");
+-    if (!Args.hasArg(options::OPT_shared)) {
+-      CmdArgs.push_back("-lgcc");
++    // This specifically uses -Wl to avoid CMake parsing it and trying to
++    // feed "-zdefaultextract" back into clang, which doesn't support the
++    // non-space version.
++    CmdArgs.push_back("-Wl,-zdefaultextract");
++    AddRunTimeLibs(getToolChain(), D, CmdArgs, Args);
++    CmdArgs.push_back(Args.MakeArgString(LibPath + "libunwind.a"));
++    if (D.CCCIsCXX()) {
++      if (getToolChain().ShouldLinkCXXStdlib(Args))
++        getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+       CmdArgs.push_back("-lm");
+     }
++    CmdArgs.push_back("-lc");
+   }
+ 
+-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+-    CmdArgs.push_back(
+-        Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
+-  }
+-  CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
++  CmdArgs.push_back(Args.MakeArgString(SysPath + "crtn.o"));
+ 
+   getToolChain().addProfileRTLibs(Args, CmdArgs);
+ 
+@@ -127,35 +139,9 @@ void solaris::Linker::ConstructJob(Compi
+ Solaris::Solaris(const Driver &D, const llvm::Triple &Triple,
+                  const ArgList &Args)
+     : Generic_ELF(D, Triple, Args) {
+-
+-  GCCInstallation.init(Triple, Args);
+-
+-  path_list &Paths = getFilePaths();
+-  if (GCCInstallation.isValid())
+-    addPathIfExists(D, GCCInstallation.getInstallPath(), Paths);
+-
+-  addPathIfExists(D, getDriver().getInstalledDir(), Paths);
+-  if (getDriver().getInstalledDir() != getDriver().Dir)
+-    addPathIfExists(D, getDriver().Dir, Paths);
+-
+-  addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths);
+-
+-  std::string LibPath = "/usr/lib/";
+-  switch (Triple.getArch()) {
+-  case llvm::Triple::x86:
+-  case llvm::Triple::sparc:
+-    break;
+-  case llvm::Triple::x86_64:
+-    LibPath += "amd64/";
+-    break;
+-  case llvm::Triple::sparcv9:
+-    LibPath += "sparcv9/";
+-    break;
+-  default:
+-    llvm_unreachable("Unsupported architecture");
+-  }
+-
+-  addPathIfExists(D, getDriver().SysRoot + LibPath, Paths);
++  // No special handling, the C runtime files are found directly above
++  // and crle handles adding the default system library paths if they
++  // are necessary.
+ }
+ 
+ Tool *Solaris::buildAssembler() const {
+@@ -164,30 +150,41 @@ Tool *Solaris::buildAssembler() const {
+ 
+ Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); }
+ 
++void Solaris::AddCXXStdlibLibArgs(const ArgList &Args,
++                                  ArgStringList &CmdArgs) const {
++  CXXStdlibType Type = GetCXXStdlibType(Args);
++
++  // Currently assumes pkgsrc layout where libcxx and libcxxabi are installed
++  // in the same prefixed directory that we are.
++  std::string LibPath;
++  LibPath = llvm::sys::path::parent_path(getDriver().getInstalledDir());
++  LibPath += "/lib";
++
++  switch (Type) {
++  case ToolChain::CST_Libcxx:
++    CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
++    CmdArgs.push_back(Args.MakeArgString(StringRef("-R") + LibPath));
++    CmdArgs.push_back("-lc++");
++    CmdArgs.push_back("-lc++abi");
++    break;
++
++  // XXX: This won't work without being told exactly where libstdc++ is, but
++  // that changes based on distribution.  Maybe return ENOTSUP here?
++  case ToolChain::CST_Libstdcxx:
++    CmdArgs.push_back("-lstdc++");
++    break;
++  }
++}
++
+ void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
+                                            ArgStringList &CC1Args) const {
+   if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+       DriverArgs.hasArg(options::OPT_nostdincxx))
+     return;
+ 
+-  // Include the support directory for things like xlocale and fudged system
+-  // headers.
+-  // FIXME: This is a weird mix of libc++ and libstdc++. We should also be
+-  // checking the value of -stdlib= here and adding the includes for libc++
+-  // rather than libstdc++ if it's requested.
+-  addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris");
+-
+-  if (GCCInstallation.isValid()) {
+-    GCCVersion Version = GCCInstallation.getVersion();
+-    addSystemInclude(DriverArgs, CC1Args,
+-                     getDriver().SysRoot + "/usr/gcc/" +
+-                     Version.MajorStr + "." +
+-                     Version.MinorStr +
+-                     "/include/c++/" + Version.Text);
+-    addSystemInclude(DriverArgs, CC1Args,
+-                     getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr +
+-                     "." + Version.MinorStr + "/include/c++/" +
+-                     Version.Text + "/" +
+-                     GCCInstallation.getTriple().str());
+-  }
++  // Currently assumes pkgsrc layout.
++  addSystemInclude(DriverArgs, CC1Args,
++                   llvm::sys::path::parent_path(getDriver().getInstalledDir())
++                   + "/include/c++/v1");
++  return;
+ }
diff -r e507959156c0 -r aebdcdb22961 lang/clang/patches/patch-lib_Driver_ToolChains_Solaris.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lang/clang/patches/patch-lib_Driver_ToolChains_Solaris.h  Thu Aug 09 14:56:41 2018 +0000
@@ -0,0 +1,16 @@
+$NetBSD: patch-lib_Driver_ToolChains_Solaris.h,v 1.1 2018/08/09 14:56:41 jperkin Exp $



Home | Main Index | Thread Index | Old Index