[PATCH] D51510: Move AESNI generation to Skylake and Goldmont

2018-08-30 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira created this revision.
thiagomacieira added reviewers: erichkeane, GBuella.
Herald added a subscriber: cfe-commits.

The instruction set first appeared with Westmere, but not all processors
in that and the next few generations have the instructions. According to
Wikipedia[1], the first generation in which all SKUs have AES
instructions are Skylake and Goldmont. I can't find any Skylake,
Kabylake, Kabylake-R or Cannon Lake currently listed at
https://ark.intel.com that says "IntelĀ® AES New Instructions" "No".

This matches GCC commit 
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01940.html

[1] https://en.wikipedia.org/wiki/AES_instruction_set


Repository:
  rC Clang

https://reviews.llvm.org/D51510

Files:
  lib/Basic/Targets/X86.cpp


Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -170,6 +170,7 @@
   setFeatureEnabledImpl(Features, "sgx", true);
 setFeatureEnabledImpl(Features, "clflushopt", true);
 setFeatureEnabledImpl(Features, "rtm", true);
+setFeatureEnabledImpl(Features, "aes", true);
 LLVM_FALLTHROUGH;
   case CK_Broadwell:
 setFeatureEnabledImpl(Features, "rdseed", true);
@@ -196,7 +197,6 @@
 setFeatureEnabledImpl(Features, "xsaveopt", true);
 LLVM_FALLTHROUGH;
   case CK_Westmere:
-setFeatureEnabledImpl(Features, "aes", true);
 setFeatureEnabledImpl(Features, "pclmul", true);
 LLVM_FALLTHROUGH;
   case CK_Nehalem:
@@ -248,10 +248,10 @@
 setFeatureEnabledImpl(Features, "clflushopt", true);
 setFeatureEnabledImpl(Features, "mpx", true);
 setFeatureEnabledImpl(Features, "fsgsbase", true);
+setFeatureEnabledImpl(Features, "aes", true);
 LLVM_FALLTHROUGH;
   case CK_Silvermont:
 setFeatureEnabledImpl(Features, "rdrnd", true);
-setFeatureEnabledImpl(Features, "aes", true);
 setFeatureEnabledImpl(Features, "pclmul", true);
 setFeatureEnabledImpl(Features, "sse4.2", true);
 setFeatureEnabledImpl(Features, "prfchw", true);


Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -170,6 +170,7 @@
   setFeatureEnabledImpl(Features, "sgx", true);
 setFeatureEnabledImpl(Features, "clflushopt", true);
 setFeatureEnabledImpl(Features, "rtm", true);
+setFeatureEnabledImpl(Features, "aes", true);
 LLVM_FALLTHROUGH;
   case CK_Broadwell:
 setFeatureEnabledImpl(Features, "rdseed", true);
@@ -196,7 +197,6 @@
 setFeatureEnabledImpl(Features, "xsaveopt", true);
 LLVM_FALLTHROUGH;
   case CK_Westmere:
-setFeatureEnabledImpl(Features, "aes", true);
 setFeatureEnabledImpl(Features, "pclmul", true);
 LLVM_FALLTHROUGH;
   case CK_Nehalem:
@@ -248,10 +248,10 @@
 setFeatureEnabledImpl(Features, "clflushopt", true);
 setFeatureEnabledImpl(Features, "mpx", true);
 setFeatureEnabledImpl(Features, "fsgsbase", true);
+setFeatureEnabledImpl(Features, "aes", true);
 LLVM_FALLTHROUGH;
   case CK_Silvermont:
 setFeatureEnabledImpl(Features, "rdrnd", true);
-setFeatureEnabledImpl(Features, "aes", true);
 setFeatureEnabledImpl(Features, "pclmul", true);
 setFeatureEnabledImpl(Features, "sse4.2", true);
 setFeatureEnabledImpl(Features, "prfchw", true);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51510: Move AESNI generation to Skylake and Goldmont

2018-08-31 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira added a comment.

Sure. Hadn't seen that file.


Repository:
  rC Clang

https://reviews.llvm.org/D51510



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51510: Move AESNI generation to Skylake and Goldmont

2018-08-31 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira added a comment.

See https://reviews.llvm.org/D51565


Repository:
  rC Clang

https://reviews.llvm.org/D51510



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53042: [X86] Remove FeatureRTM from Skylake processor list

2018-10-09 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira created this revision.
thiagomacieira added reviewers: erichkeane, craig.topper.
Herald added a subscriber: cfe-commits.
craig.topper retitled this revision from "Remove FeatureRTM from Skylake 
processor list" to "[X86] Remove FeatureRTM from Skylake processor list".

There are a LOT of Skylakes and later without TSX-NI. Examples:

- SKL: 
https://ark.intel.com/products/136863/Intel-Core-i3-8121U-Processor-4M-Cache-up-to-3-20-GHz-
- KBL: 
https://ark.intel.com/products/97540/Intel-Core-i7-7560U-Processor-4M-Cache-up-to-3-80-GHz-
- KBL-R: 
https://ark.intel.com/products/149091/Intel-Core-i7-8565U-Processor-8M-Cache-up-to-4-60-GHz-
- CNL: 
https://ark.intel.com/products/136863/Intel-Core-i3-8121U-Processor-4M-Cache-up-to-3_20-GHz

This feature seems to be present only on high-end desktop and server
chips (I can't find any SKX without). This commit leaves it disabled
for all processors, but can be re-enabled for specific builds with
-mrtm.

Matches https://reviews.llvm.org/D53041


Repository:
  rC Clang

https://reviews.llvm.org/D53042

Files:
  lib/Basic/Targets/X86.cpp


Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -169,7 +169,6 @@
 if (Kind != CK_SkylakeServer) // SKX inherits all SKL features, except SGX
   setFeatureEnabledImpl(Features, "sgx", true);
 setFeatureEnabledImpl(Features, "clflushopt", true);
-setFeatureEnabledImpl(Features, "rtm", true);
 setFeatureEnabledImpl(Features, "aes", true);
 LLVM_FALLTHROUGH;
   case CK_Broadwell:


Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -169,7 +169,6 @@
 if (Kind != CK_SkylakeServer) // SKX inherits all SKL features, except SGX
   setFeatureEnabledImpl(Features, "sgx", true);
 setFeatureEnabledImpl(Features, "clflushopt", true);
-setFeatureEnabledImpl(Features, "rtm", true);
 setFeatureEnabledImpl(Features, "aes", true);
 LLVM_FALLTHROUGH;
   case CK_Broadwell:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53042: [X86] Remove FeatureRTM from Skylake processor list

2018-10-09 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira added inline comments.



Comment at: lib/Basic/Targets/X86.cpp:169
 setFeatureEnabledImpl(Features, "mpx", true);
 if (Kind != CK_SkylakeServer) // SKX inherits all SKL features, except SGX
   setFeatureEnabledImpl(Features, "sgx", true);

craig.topper wrote:
> craig.topper wrote:
> > lebedev.ri wrote:
> > > > high-end desktop and server chips (I can't find any SKX without).
> > > 
> > > Are you sure you didn't want to move it into an else of this `if()` ?
> > > This commit leaves it disabled for all processors, but can be re-enabled 
> > > for specific builds with -mrtm.
> > 
> > So I think this was intended.
> It's also consistent with gcc based on grepping for _RTM_ in their predefined 
> macro output. https://godbolt.org/z/dtfrQU They don't infer it from 
> -mcpu=skylake-avx512, but do when adding -mrtm
I'm sure I didn't want to :-) Do you want me to do that? And do you want me to 
do it for IcelakeServer too?

This matches GCC's behaviour:

```
$ gcc -march=skylake-avx512 -dM -E -xc /dev/null | grep -c RTM
0
```


Repository:
  rC Clang

https://reviews.llvm.org/D53042



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53042: [X86] Remove FeatureRTM from Skylake processor list

2018-10-09 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira updated this revision to Diff 168936.
thiagomacieira added a comment.

Added test update


https://reviews.llvm.org/D53042

Files:
  lib/Basic/Targets/X86.cpp
  test/Preprocessor/predefined-arch-macros.c

Index: test/Preprocessor/predefined-arch-macros.c
===
--- test/Preprocessor/predefined-arch-macros.c
+++ test/Preprocessor/predefined-arch-macros.c
@@ -670,7 +670,6 @@
 // CHECK_SKL_M32: #define __PRFCHW__ 1
 // CHECK_SKL_M32: #define __RDRND__ 1
 // CHECK_SKL_M32: #define __RDSEED__ 1
-// CHECK_SKL_M32: #define __RTM__ 1
 // CHECK_SKL_M32: #define __SGX__ 1
 // CHECK_SKL_M32: #define __SSE2__ 1
 // CHECK_SKL_M32: #define __SSE3__ 1
@@ -706,7 +705,6 @@
 // CHECK_SKL_M64: #define __PRFCHW__ 1
 // CHECK_SKL_M64: #define __RDRND__ 1
 // CHECK_SKL_M64: #define __RDSEED__ 1
-// CHECK_SKL_M64: #define __RTM__ 1
 // CHECK_SKL_M64: #define __SGX__ 1
 // CHECK_SKL_M64: #define __SSE2_MATH__ 1
 // CHECK_SKL_M64: #define __SSE2__ 1
@@ -747,7 +745,6 @@
 // CHECK_KNL_M32: #define __PREFETCHWT1__ 1
 // CHECK_KNL_M32: #define __PRFCHW__ 1
 // CHECK_KNL_M32: #define __RDRND__ 1
-// CHECK_KNL_M32: #define __RTM__ 1
 // CHECK_KNL_M32: #define __SSE2__ 1
 // CHECK_KNL_M32: #define __SSE3__ 1
 // CHECK_KNL_M32: #define __SSE4_1__ 1
@@ -785,7 +782,6 @@
 // CHECK_KNL_M64: #define __PREFETCHWT1__ 1
 // CHECK_KNL_M64: #define __PRFCHW__ 1
 // CHECK_KNL_M64: #define __RDRND__ 1
-// CHECK_KNL_M64: #define __RTM__ 1
 // CHECK_KNL_M64: #define __SSE2_MATH__ 1
 // CHECK_KNL_M64: #define __SSE2__ 1
 // CHECK_KNL_M64: #define __SSE3__ 1
@@ -827,7 +823,6 @@
 // CHECK_KNM_M32: #define __PREFETCHWT1__ 1
 // CHECK_KNM_M32: #define __PRFCHW__ 1
 // CHECK_KNM_M32: #define __RDRND__ 1
-// CHECK_KNM_M32: #define __RTM__ 1
 // CHECK_KNM_M32: #define __SSE2__ 1
 // CHECK_KNM_M32: #define __SSE3__ 1
 // CHECK_KNM_M32: #define __SSE4_1__ 1
@@ -863,7 +858,6 @@
 // CHECK_KNM_M64: #define __PREFETCHWT1__ 1
 // CHECK_KNM_M64: #define __PRFCHW__ 1
 // CHECK_KNM_M64: #define __RDRND__ 1
-// CHECK_KNM_M64: #define __RTM__ 1
 // CHECK_KNM_M64: #define __SSE2_MATH__ 1
 // CHECK_KNM_M64: #define __SSE2__ 1
 // CHECK_KNM_M64: #define __SSE3__ 1
@@ -907,7 +901,6 @@
 // CHECK_SKX_M32: #define __PRFCHW__ 1
 // CHECK_SKX_M32: #define __RDRND__ 1
 // CHECK_SKX_M32: #define __RDSEED__ 1
-// CHECK_SKX_M32: #define __RTM__ 1
 // CHECK_SKX_M32-NOT: #define __SGX__ 1
 // CHECK_SKX_M32: #define __SSE2__ 1
 // CHECK_SKX_M32: #define __SSE3__ 1
@@ -954,7 +947,6 @@
 // CHECK_SKX_M64: #define __PRFCHW__ 1
 // CHECK_SKX_M64: #define __RDRND__ 1
 // CHECK_SKX_M64: #define __RDSEED__ 1
-// CHECK_SKX_M64: #define __RTM__ 1
 // CHECK_SKX_M64-NOT: #define __SGX__ 1
 // CHECK_SKX_M64: #define __SSE2_MATH__ 1
 // CHECK_SKX_M64: #define __SSE2__ 1
@@ -1006,7 +998,6 @@
 // CHECK_CNL_M32: #define __PRFCHW__ 1
 // CHECK_CNL_M32: #define __RDRND__ 1
 // CHECK_CNL_M32: #define __RDSEED__ 1
-// CHECK_CNL_M32: #define __RTM__ 1
 // CHECK_CNL_M32: #define __SGX__ 1
 // CHECK_CNL_M32: #define __SHA__ 1
 // CHECK_CNL_M32: #define __SSE2__ 1
@@ -1056,7 +1047,6 @@
 // CHECK_CNL_M64: #define __PRFCHW__ 1
 // CHECK_CNL_M64: #define __RDRND__ 1
 // CHECK_CNL_M64: #define __RDSEED__ 1
-// CHECK_CNL_M64: #define __RTM__ 1
 // CHECK_CNL_M64: #define __SGX__ 1
 // CHECK_CNL_M64: #define __SHA__ 1
 // CHECK_CNL_M64: #define __SSE2__ 1
@@ -1113,7 +1103,6 @@
 // CHECK_ICL_M32: #define __RDPID__ 1
 // CHECK_ICL_M32: #define __RDRND__ 1
 // CHECK_ICL_M32: #define __RDSEED__ 1
-// CHECK_ICL_M32: #define __RTM__ 1
 // CHECK_ICL_M32: #define __SGX__ 1
 // CHECK_ICL_M32: #define __SHA__ 1
 // CHECK_ICL_M32: #define __SSE2__ 1
@@ -1172,7 +1161,6 @@
 // CHECK_ICL_M64: #define __RDPID__ 1
 // CHECK_ICL_M64: #define __RDRND__ 1
 // CHECK_ICL_M64: #define __RDSEED__ 1
-// CHECK_ICL_M64: #define __RTM__ 1
 // CHECK_ICL_M64: #define __SGX__ 1
 // CHECK_ICL_M64: #define __SHA__ 1
 // CHECK_ICL_M64: #define __SSE2__ 1
@@ -1233,7 +1221,6 @@
 // CHECK_ICX_M32: #define __RDPID__ 1
 // CHECK_ICX_M32: #define __RDRND__ 1
 // CHECK_ICX_M32: #define __RDSEED__ 1
-// CHECK_ICX_M32: #define __RTM__ 1
 // CHECK_ICX_M32: #define __SGX__ 1
 // CHECK_ICX_M32: #define __SHA__ 1
 // CHECK_ICX_M32: #define __SSE2__ 1
@@ -1293,7 +1280,6 @@
 // CHECK_ICX_M64: #define __RDPID__ 1
 // CHECK_ICX_M64: #define __RDRND__ 1
 // CHECK_ICX_M64: #define __RDSEED__ 1
-// CHECK_ICX_M64: #define __RTM__ 1
 // CHECK_ICX_M64: #define __SGX__ 1
 // CHECK_ICX_M64: #define __SHA__ 1
 // CHECK_ICX_M64: #define __SSE2__ 1
Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -169,7 +169,6 @@
 if (Kind != CK_SkylakeServer) // SKX inherits all SKL features, except SGX
   setFeatureEnabledImpl(Features, "sgx", true);
 setFeatureEnabledImpl(Features, "clflushopt", true);
-setFeatureEnabledImpl(Features, "rtm", true);
 setFeatureEnabledImpl(Features, "aes

[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-10 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira created this revision.
thiagomacieira added reviewers: mgorny, erichkeane.
Herald added subscribers: cfe-commits, srhines.

/usr/lib/os-release is the official path of /etc/os-release (the latter is 
usually a symlink to the former)


Repository:
  rC Clang

https://reviews.llvm.org/D53125

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  lib/Driver/ToolChains/Linux.cpp
  unittests/Driver/DistroTest.cpp

Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,19 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectClearLinux) {
+  vfs::InMemoryFileSystem ClearLinuxFileSystem;
+  ClearLinuxFileSystem.addFile("/usr/lib/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("NAME=\"Clear Linux OS\"\n"
+   "VERSION=1\n"
+   "ID=clear-linux-os\n"
+   "VERSION_ID=25530\n"
+   "PRETTY_NAME=\"Clear Linux OS\"\n"
+   "ANSI_COLOR=\"1;35\"\n"
+   "HOME_URL=\"https://clearlinux.org\"\n";
+   "SUPPORT_URL=\"https://clearlinux.org\"\n";
+   "BUG_REPORT_URL=\"mailto:d...@lists.clearlinux.org\"\n"
+   "PRIVACY_POLICY_URL=\"http://www.intel.com/privacy\"\n";));
+}
+
 } // end anonymous namespace
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -229,16 +229,19 @@
 
   Distro Distro(D.getVFS());
 
-  if (Distro.IsAlpineLinux()) {
+  if (Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("now");
   }
 
-  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
+  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("relro");
   }
 
+  if (Distro.IsClearLinux())
+ExtraOpts.push_back("--copy-dt-needed-entries");
+
   if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
   StringRef::npos)
 // With devtoolset on RHEL, we want to add a bin directory that is relative
@@ -283,7 +286,7 @@
   ExtraOpts.push_back("--build-id");
 #endif
 
-  if (IsAndroid || Distro.IsOpenSUSE())
+  if (IsAndroid || Distro.IsOpenSUSE() || Distro.IsClearLinux())
 ExtraOpts.push_back("--enable-new-dtags");
 
   // The selection of paths to try here is designed to match the patterns which
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -136,6 +136,19 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  File = VFS.getBufferForFile("/usr/lib/os-release");
+  if (File) {
+StringRef Data = File.get()->getBuffer();
+SmallVector Lines;
+Data.split(Lines, "\n");
+Distro::DistroType Version = Distro::UnknownDistro;
+for (StringRef Line : Lines)
+  if (Version == Distro::UnknownDistro && Line.startswith("ID="))
+Version = llvm::StringSwitch(Line.substr(3))
+  .Case("clear-linux-os", Distro::ClearLinux);
+return Version;
+  }
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -28,6 +28,7 @@
 // the first and last known member in the family, e.g. IsRedHat().
 AlpineLinux,
 ArchLinux,
+ClearLinux,
 DebianLenny,
 DebianSqueeze,
 DebianWheezy,
@@ -122,6 +123,10 @@
 return DistroVal == AlpineLinux;
   }
 
+  bool IsClearLinux() const {
+return DistroVal == ClearLinux;
+  }
+
   /// @}
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-10 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira updated this revision to Diff 169151.
thiagomacieira added a comment.

Oops, add the missing portion of the unit test (the part that actually tests).


https://reviews.llvm.org/D53125

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  lib/Driver/ToolChains/Linux.cpp
  unittests/Driver/DistroTest.cpp

Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,19 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectClearLinux) {
+  vfs::InMemoryFileSystem ClearLinuxFileSystem;
+  ClearLinuxFileSystem.addFile("/usr/lib/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("NAME=\"Clear Linux OS\"\n"
+   "VERSION=1\n"
+   "ID=clear-linux-os\n"
+   "VERSION_ID=25530\n"
+   "PRETTY_NAME=\"Clear Linux OS\"\n"
+   "ANSI_COLOR=\"1;35\"\n"
+   "HOME_URL=\"https://clearlinux.org\"\n";
+   "SUPPORT_URL=\"https://clearlinux.org\"\n";
+   "BUG_REPORT_URL=\"mailto:d...@lists.clearlinux.org\"\n"
+   "PRIVACY_POLICY_URL=\"http://www.intel.com/privacy\"\n";));
+}
+
 } // end anonymous namespace
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -229,16 +229,19 @@
 
   Distro Distro(D.getVFS());
 
-  if (Distro.IsAlpineLinux()) {
+  if (Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("now");
   }
 
-  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
+  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("relro");
   }
 
+  if (Distro.IsClearLinux())
+ExtraOpts.push_back("--copy-dt-needed-entries");
+
   if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
   StringRef::npos)
 // With devtoolset on RHEL, we want to add a bin directory that is relative
@@ -283,7 +286,7 @@
   ExtraOpts.push_back("--build-id");
 #endif
 
-  if (IsAndroid || Distro.IsOpenSUSE())
+  if (IsAndroid || Distro.IsOpenSUSE() || Distro.IsClearLinux())
 ExtraOpts.push_back("--enable-new-dtags");
 
   // The selection of paths to try here is designed to match the patterns which
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -136,6 +136,19 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  File = VFS.getBufferForFile("/usr/lib/os-release");
+  if (File) {
+StringRef Data = File.get()->getBuffer();
+SmallVector Lines;
+Data.split(Lines, "\n");
+Distro::DistroType Version = Distro::UnknownDistro;
+for (StringRef Line : Lines)
+  if (Version == Distro::UnknownDistro && Line.startswith("ID="))
+Version = llvm::StringSwitch(Line.substr(3))
+  .Case("clear-linux-os", Distro::ClearLinux);
+return Version;
+  }
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -28,6 +28,7 @@
 // the first and last known member in the family, e.g. IsRedHat().
 AlpineLinux,
 ArchLinux,
+ClearLinux,
 DebianLenny,
 DebianSqueeze,
 DebianWheezy,
@@ -122,6 +123,10 @@
 return DistroVal == AlpineLinux;
   }
 
+  bool IsClearLinux() const {
+return DistroVal == ClearLinux;
+  }
+
   /// @}
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-10 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira updated this revision to Diff 169152.

https://reviews.llvm.org/D53125

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  lib/Driver/ToolChains/Linux.cpp
  unittests/Driver/DistroTest.cpp

Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,27 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectClearLinux) {
+  vfs::InMemoryFileSystem ClearLinuxFileSystem;
+  ClearLinuxFileSystem.addFile("/usr/lib/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("NAME=\"Clear Linux OS\"\n"
+   "VERSION=1\n"
+   "ID=clear-linux-os\n"
+   "VERSION_ID=25530\n"
+   "PRETTY_NAME=\"Clear Linux OS\"\n"
+   "ANSI_COLOR=\"1;35\"\n"
+   "HOME_URL=\"https://clearlinux.org\"\n";
+   "SUPPORT_URL=\"https://clearlinux.org\"\n";
+   "BUG_REPORT_URL=\"mailto:d...@lists.clearlinux.org\"\n"
+   "PRIVACY_POLICY_URL=\"http://www.intel.com/privacy\"\n";));
+
+  Distro ClearLinux{ClearLinuxFileSystem};
+  ASSERT_EQ(Distro(Distro::ClearLinux), ClearLinux);
+  ASSERT_TRUE(ClearLinux.IsClearLinux());
+  ASSERT_FALSE(ClearLinux.IsUbuntu());
+  ASSERT_FALSE(ClearLinux.IsRedhat());
+  ASSERT_FALSE(ClearLinux.IsOpenSUSE());
+  ASSERT_FALSE(ClearLinux.IsDebian());
+}
+
 } // end anonymous namespace
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -229,16 +229,19 @@
 
   Distro Distro(D.getVFS());
 
-  if (Distro.IsAlpineLinux()) {
+  if (Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("now");
   }
 
-  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
+  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("relro");
   }
 
+  if (Distro.IsClearLinux())
+ExtraOpts.push_back("--copy-dt-needed-entries");
+
   if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
   StringRef::npos)
 // With devtoolset on RHEL, we want to add a bin directory that is relative
@@ -283,7 +286,7 @@
   ExtraOpts.push_back("--build-id");
 #endif
 
-  if (IsAndroid || Distro.IsOpenSUSE())
+  if (IsAndroid || Distro.IsOpenSUSE() || Distro.IsClearLinux())
 ExtraOpts.push_back("--enable-new-dtags");
 
   // The selection of paths to try here is designed to match the patterns which
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -136,6 +136,19 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  File = VFS.getBufferForFile("/usr/lib/os-release");
+  if (File) {
+StringRef Data = File.get()->getBuffer();
+SmallVector Lines;
+Data.split(Lines, "\n");
+Distro::DistroType Version = Distro::UnknownDistro;
+for (StringRef Line : Lines)
+  if (Version == Distro::UnknownDistro && Line.startswith("ID="))
+Version = llvm::StringSwitch(Line.substr(3))
+  .Case("clear-linux-os", Distro::ClearLinux);
+return Version;
+  }
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -28,6 +28,7 @@
 // the first and last known member in the family, e.g. IsRedHat().
 AlpineLinux,
 ArchLinux,
+ClearLinux,
 DebianLenny,
 DebianSqueeze,
 DebianWheezy,
@@ -122,6 +123,10 @@
 return DistroVal == AlpineLinux;
   }
 
+  bool IsClearLinux() const {
+return DistroVal == ClearLinux;
+  }
+
   /// @}
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-11 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira added inline comments.



Comment at: lib/Driver/Distro.cpp:139
 
+  File = VFS.getBufferForFile("/usr/lib/os-release");
+  if (File) {

mgorny wrote:
> Technically speaking, the spec says you are supposed to read 
> `/etc/os-release` first and fall back to `/usr/lib/os-release` only if the 
> former does not exist.
You're right, I'll adapt.


https://reviews.llvm.org/D53125



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-11 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira updated this revision to Diff 169236.
thiagomacieira added a comment.

Updated to check for /etc/os-release first and /usr/lib/os-release if that fails


https://reviews.llvm.org/D53125

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  lib/Driver/ToolChains/Linux.cpp
  unittests/Driver/DistroTest.cpp

Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,27 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectClearLinux) {
+  vfs::InMemoryFileSystem ClearLinuxFileSystem;
+  ClearLinuxFileSystem.addFile("/usr/lib/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("NAME=\"Clear Linux OS\"\n"
+   "VERSION=1\n"
+   "ID=clear-linux-os\n"
+   "VERSION_ID=25530\n"
+   "PRETTY_NAME=\"Clear Linux OS\"\n"
+   "ANSI_COLOR=\"1;35\"\n"
+   "HOME_URL=\"https://clearlinux.org\"\n";
+   "SUPPORT_URL=\"https://clearlinux.org\"\n";
+   "BUG_REPORT_URL=\"mailto:d...@lists.clearlinux.org\"\n"
+   "PRIVACY_POLICY_URL=\"http://www.intel.com/privacy\"\n";));
+
+  Distro ClearLinux{ClearLinuxFileSystem};
+  ASSERT_EQ(Distro(Distro::ClearLinux), ClearLinux);
+  ASSERT_TRUE(ClearLinux.IsClearLinux());
+  ASSERT_FALSE(ClearLinux.IsUbuntu());
+  ASSERT_FALSE(ClearLinux.IsRedhat());
+  ASSERT_FALSE(ClearLinux.IsOpenSUSE());
+  ASSERT_FALSE(ClearLinux.IsDebian());
+}
+
 } // end anonymous namespace
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -229,16 +229,19 @@
 
   Distro Distro(D.getVFS());
 
-  if (Distro.IsAlpineLinux()) {
+  if (Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("now");
   }
 
-  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
+  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("relro");
   }
 
+  if (Distro.IsClearLinux())
+ExtraOpts.push_back("--copy-dt-needed-entries");
+
   if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
   StringRef::npos)
 // With devtoolset on RHEL, we want to add a bin directory that is relative
@@ -283,7 +286,7 @@
   ExtraOpts.push_back("--build-id");
 #endif
 
-  if (IsAndroid || Distro.IsOpenSUSE())
+  if (IsAndroid || Distro.IsOpenSUSE() || Distro.IsClearLinux())
 ExtraOpts.push_back("--enable-new-dtags");
 
   // The selection of paths to try here is designed to match the patterns which
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -136,6 +136,21 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  File = VFS.getBufferForFile("/etc/os-release");
+  if (!File)
+File = VFS.getBufferForFile("/usr/lib/os-release");
+  if (File) {
+StringRef Data = File.get()->getBuffer();
+SmallVector Lines;
+Data.split(Lines, "\n");
+Distro::DistroType Version = Distro::UnknownDistro;
+for (StringRef Line : Lines)
+  if (Version == Distro::UnknownDistro && Line.startswith("ID="))
+Version = llvm::StringSwitch(Line.substr(3))
+  .Case("clear-linux-os", Distro::ClearLinux);
+return Version;
+  }
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -28,6 +28,7 @@
 // the first and last known member in the family, e.g. IsRedHat().
 AlpineLinux,
 ArchLinux,
+ClearLinux,
 DebianLenny,
 DebianSqueeze,
 DebianWheezy,
@@ -122,6 +123,10 @@
 return DistroVal == AlpineLinux;
   }
 
+  bool IsClearLinux() const {
+return DistroVal == ClearLinux;
+  }
+
   /// @}
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-15 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira marked an inline comment as done.
thiagomacieira added inline comments.



Comment at: lib/Driver/Distro.cpp:148
+for (StringRef Line : Lines)
+  if (Version == Distro::UnknownDistro && Line.startswith("ID="))
+Version = llvm::StringSwitch(Line.substr(3))

I'm changing this so we can detect Clear-derived distributions.


https://reviews.llvm.org/D53125



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-15 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira updated this revision to Diff 169779.
thiagomacieira added a comment.

Update detection: as of Clear Linux 25620, /usr/lib/os-relaese contains 
ID_LIKE=clear-linux-os, which allows detecting not only Clear itself, but also 
Linux distributions derived from it (Clear Linux mixes).


https://reviews.llvm.org/D53125

Files:
  include/clang/Driver/Distro.h
  lib/Driver/Distro.cpp
  lib/Driver/ToolChains/Linux.cpp
  unittests/Driver/DistroTest.cpp

Index: unittests/Driver/DistroTest.cpp
===
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,28 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectClearLinux) {
+  vfs::InMemoryFileSystem ClearLinuxFileSystem;
+  ClearLinuxFileSystem.addFile("/usr/lib/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("NAME=\"Clear Linux OS\"\n"
+   "VERSION=1\n"
+   "ID=clear-linux-os\n"
+   "ID_LIKE=clear-linux-os\n"
+   "VERSION_ID=25530\n"
+   "PRETTY_NAME=\"Clear Linux OS\"\n"
+   "ANSI_COLOR=\"1;35\"\n"
+   "HOME_URL=\"https://clearlinux.org\"\n";
+   "SUPPORT_URL=\"https://clearlinux.org\"\n";
+   "BUG_REPORT_URL=\"mailto:d...@lists.clearlinux.org\"\n"
+   "PRIVACY_POLICY_URL=\"http://www.intel.com/privacy\"\n";));
+
+  Distro ClearLinux{ClearLinuxFileSystem};
+  ASSERT_EQ(Distro(Distro::ClearLinux), ClearLinux);
+  ASSERT_TRUE(ClearLinux.IsClearLinux());
+  ASSERT_FALSE(ClearLinux.IsUbuntu());
+  ASSERT_FALSE(ClearLinux.IsRedhat());
+  ASSERT_FALSE(ClearLinux.IsOpenSUSE());
+  ASSERT_FALSE(ClearLinux.IsDebian());
+}
+
 } // end anonymous namespace
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -229,17 +229,20 @@
 
   Distro Distro(D.getVFS());
 
-  if (Distro.IsAlpineLinux() || Triple.isAndroid()) {
+  if (Distro.IsAlpineLinux() || Distro.IsClearLinux() || Triple.isAndroid()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("now");
   }
 
   if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() ||
-  Triple.isAndroid()) {
+  Distro.IsClearLinux() || Triple.isAndroid()) {
 ExtraOpts.push_back("-z");
 ExtraOpts.push_back("relro");
   }
 
+  if (Distro.IsClearLinux())
+ExtraOpts.push_back("--copy-dt-needed-entries");
+
   if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
   StringRef::npos)
 // With devtoolset on RHEL, we want to add a bin directory that is relative
@@ -287,7 +290,7 @@
   ExtraOpts.push_back("--build-id");
 #endif
 
-  if (IsAndroid || Distro.IsOpenSUSE())
+  if (IsAndroid || Distro.IsOpenSUSE() || Distro.IsClearLinux())
 ExtraOpts.push_back("--enable-new-dtags");
 
   // The selection of paths to try here is designed to match the patterns which
Index: lib/Driver/Distro.cpp
===
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -137,6 +137,21 @@
   if (VFS.exists("/etc/arch-release"))
 return Distro::ArchLinux;
 
+  File = VFS.getBufferForFile("/etc/os-release");
+  if (!File)
+File = VFS.getBufferForFile("/usr/lib/os-release");
+  if (File) {
+StringRef Data = File.get()->getBuffer();
+SmallVector Lines;
+Data.split(Lines, "\n");
+Distro::DistroType Version = Distro::UnknownDistro;
+for (StringRef Line : Lines)
+  if (Version == Distro::UnknownDistro && Line.startswith("ID_LIKE="))
+Version = llvm::StringSwitch(Line.substr(7))
+  .Case("clear-linux-os", Distro::ClearLinux);
+return Version;
+  }
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -28,6 +28,7 @@
 // the first and last known member in the family, e.g. IsRedHat().
 AlpineLinux,
 ArchLinux,
+ClearLinux,
 DebianLenny,
 DebianSqueeze,
 DebianWheezy,
@@ -122,6 +123,10 @@
 return DistroVal == AlpineLinux;
   }
 
+  bool IsClearLinux() const {
+return DistroVal == ClearLinux;
+  }
+
   /// @}
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits