[PATCH] D155775: [HIP][Clang][Driver][RFC] Add driver support for C++ Parallel Algorithm Offload

2023-10-04 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D155775#4652872 , @AlexVlx wrote:

> In D155775#4652851 , @ro wrote:
>
>> In D155775#4652785 , @AlexVlx 
>> wrote:
>>
>>> In D155775#4652780 , @dyung wrote:
>>>
 
>>
>>
>>
 At this point, would it be easier to add a REQUIRES line for the target 
 the test should support rather than just whack-a-mole for the targets it 
 does not?
>>>
>>> Oh, it definitely would be MUCH easier to add a `REQUIRES` line, however 
>>> I'd have had to have thought about that, which I did not, so thank you for 
>>> the wake up call. I'll update this in a few minutes.
>>
>> Unfortunately, this is still not done after almost a day, leaving quite a 
>> number of buildbots broken.  Please fix or revert.
>
> Apologies, do you have an indication of which buildbots are still broken due 
> to this change, after the most recent commit? The ones I was initially aware 
> of, as well as those brought up here appear to pass at the moment, and 
> glancing through the currently failing builds didn’t point to this as being 
> the culprit (I could’ve simply missed it). Thank you!

At least the Solaris/sparcv9 and Solaris/amd64 buildbots are still affected.  
However, `XFAIL`ing a long list of targets when it's known that particular 
targets/target properties are required for the test to `PASS` is fundamentally 
wrong!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155775

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


[PATCH] D155775: [HIP][Clang][Driver][RFC] Add driver support for C++ Parallel Algorithm Offload

2023-10-04 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D155775#4652785 , @AlexVlx wrote:

> In D155775#4652780 , @dyung wrote:
>
>> 



>> At this point, would it be easier to add a REQUIRES line for the target the 
>> test should support rather than just whack-a-mole for the targets it does 
>> not?
>
> Oh, it definitely would be MUCH easier to add a `REQUIRES` line, however I'd 
> have had to have thought about that, which I did not, so thank you for the 
> wake up call. I'll update this in a few minutes.

Unfortunately, this is still not done after almost a day, leaving quite a 
number of buildbots broken.  Please fix or revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155775

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


[PATCH] D159222: [clang] Consistently use isOSSolaris()

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bc7b753a5cd: [clang] Consistently use isOSSolaris() 
(authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159222

Files:
  clang/lib/Basic/Targets/Sparc.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1838,7 +1838,7 @@
 
   StringRef Suff64 = "/64";
   // Solaris uses platform-specific suffixes instead of /64.
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 switch (TargetTriple.getArch()) {
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
@@ -2220,7 +2220,7 @@
 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 const llvm::Triple , SmallVectorImpl ,
 StringRef SysRoot) {
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 // Solaris is a special case.
 // The GCC installation is under
 //   /usr/gcc/./lib/gcc//../
@@ -2422,7 +2422,7 @@
   using std::begin;
   using std::end;
 
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
 "sparc-sun-solaris2.11"};
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -998,7 +998,7 @@
 
   // Solaris ld defaults to --export-dynamic behaviour but doesn't support
   // the option, so don't try to pass it.
-  if (TC.getTriple().getOS() == llvm::Triple::Solaris && !LinkerIsGnuLd)
+  if (TC.getTriple().isOSSolaris() && !LinkerIsGnuLd)
 return true;
   SmallString<128> SanRT(TC.getCompilerRT(Args, Sanitizer));
   if (llvm::sys::fs::exists(SanRT + ".syms")) {
Index: clang/lib/Basic/Targets/Sparc.cpp
===
--- clang/lib/Basic/Targets/Sparc.cpp
+++ clang/lib/Basic/Targets/Sparc.cpp
@@ -141,7 +141,7 @@
 void SparcV8TargetInfo::getTargetDefines(const LangOptions ,
  MacroBuilder ) const {
   SparcTargetInfo::getTargetDefines(Opts, Builder);
-  if (getTriple().getOS() == llvm::Triple::Solaris)
+  if (getTriple().isOSSolaris())
 Builder.defineMacro("__sparcv8");
   else {
 switch (getCPUGeneration(CPU)) {
@@ -168,7 +168,7 @@
   Builder.defineMacro("__sparcv9");
   Builder.defineMacro("__arch64__");
   // Solaris doesn't need these variants, but the BSDs do.
-  if (getTriple().getOS() != llvm::Triple::Solaris) {
+  if (!getTriple().isOSSolaris()) {
 Builder.defineMacro("__sparc64__");
 Builder.defineMacro("__sparc_v9__");
 Builder.defineMacro("__sparcv9__");


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1838,7 +1838,7 @@
 
   StringRef Suff64 = "/64";
   // Solaris uses platform-specific suffixes instead of /64.
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 switch (TargetTriple.getArch()) {
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
@@ -2220,7 +2220,7 @@
 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 const llvm::Triple , SmallVectorImpl ,
 StringRef SysRoot) {
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 // Solaris is a special case.
 // The GCC installation is under
 //   /usr/gcc/./lib/gcc//../
@@ -2422,7 +2422,7 @@
   using std::begin;
   using std::end;
 
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
 "sparc-sun-solaris2.11"};
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -998,7 +998,7 @@
 
   // Solaris ld defaults to --export-dynamic behaviour but doesn't support
   // the option, so don't try to pass it.
-  if (TC.getTriple().getOS() == llvm::Triple::Solaris && !LinkerIsGnuLd)
+  if (TC.getTriple().isOSSolaris() && !LinkerIsGnuLd)
 return true;
   SmallString<128> SanRT(TC.getCompilerRT(Args, Sanitizer));
   if (llvm::sys::fs::exists(SanRT + ".syms")) {
Index: 

[PATCH] D85309: [Driver] Support GNU ld on Solaris

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd39a9e3b4d4a: [Driver] Support GNU ld on Solaris (authored 
by ro).

Changed prior to commit:
  https://reviews.llvm.org/D85309?vs=554946=555463#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85309

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/Driver/hip-link-bundle-archive.hip
  clang/test/Driver/solaris-ld-sanitizer.c
  clang/test/Driver/solaris-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  flang/test/Driver/linker-flags.f90
  llvm/cmake/modules/AddLLVM.cmake

Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -282,9 +282,9 @@
 # ld64's implementation of -dead_strip breaks tools that use plugins.
 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
  LINK_FLAGS " -Wl,-dead_strip")
-  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
 # Support for ld -z discard-unused=sections was only added in
-# Solaris 11.4.
+# Solaris 11.4.  GNU ld ignores it, but warns every time.
 include(LLVMCheckLinkerFlag)
 llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
 if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
@@ -1281,7 +1281,10 @@
 # the size of the exported symbol table, but on other platforms we can do
 # it without any trouble.
 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
-if (APPLE)
+# CMake doesn't set CMAKE_EXE_EXPORTS_${lang}_FLAG on Solaris, so
+# ENABLE_EXPORTS has no effect.  While Solaris ld defaults to -rdynamic
+# behaviour, GNU ld needs it.
+if (APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
   set_property(TARGET ${target} APPEND_STRING PROPERTY
 LINK_FLAGS " -rdynamic")
 endif()
Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -10,7 +10,7 @@
 !   'oldnames' on Windows, but they are not needed when compiling
 !   Fortran code and they might bring in additional dependencies.
 !   Make sure they're not added.
-! RUN: %flang -### -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
+! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
 
 ! Compiler invocation to generate the object file
 ! CHECK-LABEL: {{.*}} "-emit-obj"
Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
===
--- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
+++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
@@ -2,13 +2,14 @@
 /// allow this test to also run on Windows (which can't be done for the
 /// debuginfo variant).
 
-// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %}
+// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %} %if target={{.*-solaris.*}} %{ -fuse-ld= %}
 // RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB-NO-G
 // RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC-NO-G
 // RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC-NO-G
 // RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL-NO-G
 
-/// Solaris ld -S has different semantics.
+/// Solaris ld -S has different semantics, so enforce -fuse-ld= for
+/// configurations that default to GNU ld.
 // XFAIL: target={{.*solaris.*}}
 
 // CHECK: AddressSanitizer: global-buffer-overflow
Index: compiler-rt/cmake/config-ix.cmake
===
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -1,4 +1,5 @@
 include(CMakePushCheckState)
+include(AddLLVM)
 include(LLVMCheckCompilerLinkerFlag)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
@@ -196,7 +197,7 @@
 llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
 llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
 

[PATCH] D159352: [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ro marked an inline comment as done.
Closed by commit rGb1b1f364d633: [Driver] Dont default to DWARF 2 on 
Solaris (authored by ro).

Changed prior to commit:
  https://reviews.llvm.org/D159352?vs=555335=555443#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159352

Files:
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/CodeGen/dwarf-version.c
  clang/test/Driver/clang-g-opts.c
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -193,8 +193,8 @@
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 
2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
-// RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-tables-only -g %s --target=i386-pc-solaris 2>&1 \
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLTO_NO %s
 //
@@ -212,8 +212,8 @@
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-directives-only -g %s -target 
x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
-// RUN: %clang -### -c -gline-directives-only -g %s -target i386-pc-solaris 
2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-directives-only -g %s --target=i386-pc-solaris 
2>&1 \
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-directives-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLIO_NO %s
 
Index: clang/test/Driver/clang-g-opts.c
===
--- clang/test/Driver/clang-g-opts.c
+++ clang/test/Driver/clang-g-opts.c
@@ -27,8 +27,8 @@
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
-// RUN: %clang -### -S %s -g0 -g -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g0 -g --target=i386-pc-solaris 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G %s
 
 // CHECK-WITHOUT-G-NOT: -debug-info-kind
 // CHECK-WITH-G: "-debug-info-kind=constructor"
Index: clang/test/CodeGen/dwarf-version.c
===
--- clang/test/CodeGen/dwarf-version.c
+++ clang/test/CodeGen/dwarf-version.c
@@ -4,6 +4,8 @@
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-5 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang --target=i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
+// RUN: %clang --target=i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 
 // The -isysroot is used as a hack to avoid LIT messing with the SDKROOT
 // environment variable which indirecty overrides the version in the target
@@ -13,8 +15,6 @@
 
 // RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 // RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER4
-// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER2
-// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 
 // Check which debug info formats we use on Windows. By default, in an MSVC
 // environment, we should use codeview. You can enable dwarf, which implicitly
Index: clang/lib/Driver/ToolChains/Solaris.h
===
--- clang/lib/Driver/ToolChains/Solaris.h
+++ clang/lib/Driver/ToolChains/Solaris.h
@@ -63,7 +63,6 @@
llvm::opt::ArgStringList ) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
 
   const char *getDefaultLinker() const override {
 // clang currently uses Solaris ld-only options.


Index: clang/test/Driver/debug-options.c

[PATCH] D159352: [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added inline comments.



Comment at: clang/test/CodeGen/dwarf-version.c:7
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5

MaskRay wrote:
> Switch to `--target=` while moving lines.
Two questions:
- Wouldn't it be better to keep the style consistent across a file, rather than 
introduce a mix?
- I guess it's ok to just commit the patch with such a slight revision without 
re-uploading it to Phabricator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159352

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


[PATCH] D159352: [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

`clang` currently defaults to DWARF 2 on Solaris.  This dates back to LLVM 
3.8.0.  I suspect this is related to `gcc/config/sol2.cc` 
(`solaris_override_options`) doing the same unless `HAVE_LD_EH_FRAME_CIEV3`.  
The latter is 1 on both Solaris 11.3 and 11.4, so the workaround has become 
irrelevant these days.

This patch removes the Solaris override, adjusting affected testcases 
accordingly.

Tested on `amd64-pc-solaris2.11` (`Release` and `Debug` builds) and 
`sparcv9-sun-solaris2.11` (`Release` build).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159352

Files:
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/CodeGen/dwarf-version.c
  clang/test/Driver/clang-g-opts.c
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -195,7 +195,7 @@
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 
2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLTO_NO %s
 //
@@ -214,7 +214,7 @@
 // RUN: %clang -### -c -gline-directives-only -g %s -target 
x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-directives-only -g %s -target i386-pc-solaris 
2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-directives-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLIO_NO %s
 
Index: clang/test/Driver/clang-g-opts.c
===
--- clang/test/Driver/clang-g-opts.c
+++ clang/test/Driver/clang-g-opts.c
@@ -28,7 +28,7 @@
 // RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g0 -g -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G %s
 
 // CHECK-WITHOUT-G-NOT: -debug-info-kind
 // CHECK-WITH-G: "-debug-info-kind=constructor"
Index: clang/test/CodeGen/dwarf-version.c
===
--- clang/test/CodeGen/dwarf-version.c
+++ clang/test/CodeGen/dwarf-version.c
@@ -4,6 +4,8 @@
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-5 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 
 // The -isysroot is used as a hack to avoid LIT messing with the SDKROOT
 // environment variable which indirecty overrides the version in the target
@@ -13,8 +15,6 @@
 
 // RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 // RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER4
-// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER2
-// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 
 // Check which debug info formats we use on Windows. By default, in an MSVC
 // environment, we should use codeview. You can enable dwarf, which implicitly
Index: clang/lib/Driver/ToolChains/Solaris.h
===
--- clang/lib/Driver/ToolChains/Solaris.h
+++ clang/lib/Driver/ToolChains/Solaris.h
@@ -66,7 +66,6 @@
llvm::opt::ArgStringList ) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
 
   const char *getDefaultLinker() const override;
 


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -195,7 +195,7 @@
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 

[PATCH] D85309: [Driver] Support GNU ld on Solaris

2023-08-31 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/test/Driver/hip-link-bundle-archive.hip:59
 // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
-// RUN:   --target=x86_64-pc-windows-msvc \
+// RUN:   --target=x86_64-pc-windows-msvc -fuse-ld= \
 // RUN:   -nogpuinc -nogpulib %s -fgpu-rdc -L%t -lhipBundled2 \

MaskRay wrote:
> Any idea why `-fuse-ld=` is now needed?
I've tried to explain it in the change description, but just noticed the 
filename is wrong:

When LLVM is built with `-DCLANG_DEFAULT_LINKER=gld` on Solaris, `MSVC.cpp` 
`visualstudio::Linker::ConstructJob` sets `Linker` to `gld`.  Ultimately, 
`GetProgramPath(Linker)` is called, resulting in a search for `gld`, which 
exists in `/usr/bin/gld` on Solaris.  With `-fuse-ld=`, this doesn't happen and 
the expected `link` is returned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85309

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


[PATCH] D85309: [Driver] Support GNU ld on Solaris

2023-08-31 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 554946.
ro marked an inline comment as done.
ro added a comment.

Move `isLinkerGnuLd` to `Solaris.{h,cpp}` and into `solaris` namespace to make 
it unambigously clear where to use it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85309

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/Driver/hip-link-bundle-archive.hip
  clang/test/Driver/solaris-ld-sanitizer.c
  clang/test/Driver/solaris-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  flang/test/Driver/linker-flags.f90
  llvm/cmake/modules/AddLLVM.cmake

Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -282,9 +282,9 @@
 # ld64's implementation of -dead_strip breaks tools that use plugins.
 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
  LINK_FLAGS " -Wl,-dead_strip")
-  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
 # Support for ld -z discard-unused=sections was only added in
-# Solaris 11.4.
+# Solaris 11.4.  GNU ld ignores it, but warns every time.
 include(LLVMCheckLinkerFlag)
 llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
 if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
@@ -1288,7 +1288,10 @@
 # the size of the exported symbol table, but on other platforms we can do
 # it without any trouble.
 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
-if (APPLE)
+# CMake doesn't set CMAKE_EXE_EXPORTS_${lang}_FLAG on Solaris, so
+# ENABLE_EXPORTS has no effect.  While Solaris ld defaults to -rdynamic
+# behaviour, GNU ld needs it.
+if (APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
   set_property(TARGET ${target} APPEND_STRING PROPERTY
 LINK_FLAGS " -rdynamic")
 endif()
Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -10,7 +10,7 @@
 !   'oldnames' on Windows, but they are not needed when compiling
 !   Fortran code and they might bring in additional dependencies.
 !   Make sure they're not added.
-! RUN: %flang -### -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
+! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
 
 ! Compiler invocation to generate the object file
 ! CHECK-LABEL: {{.*}} "-emit-obj"
Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
===
--- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
+++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
@@ -2,13 +2,14 @@
 /// allow this test to also run on Windows (which can't be done for the
 /// debuginfo variant).
 
-// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %}
+// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %} %if target={{.*-solaris.*}} %{ -fuse-ld= %}
 // RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB-NO-G
 // RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC-NO-G
 // RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC-NO-G
 // RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL-NO-G
 
-/// Solaris ld -S has different semantics.
+/// Solaris ld -S has different semantics, so enforce -fuse-ld= for
+/// configurations that default to GNU ld.
 // XFAIL: target={{.*solaris.*}}
 
 // CHECK: AddressSanitizer: global-buffer-overflow
Index: compiler-rt/cmake/config-ix.cmake
===
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -1,4 +1,5 @@
 include(CMakePushCheckState)
+include(AddLLVM)
 include(LLVMCheckCompilerLinkerFlag)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
@@ -196,7 +197,7 @@
 llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
 llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
 
-if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND 

[PATCH] D85309: [Driver] Support GNU ld on Solaris

2023-08-31 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:305
 
+bool tools::isLinkerGnuLd(const ToolChain , const ArgList ) {
+  // Only used if targetting Solaris.

MaskRay wrote:
> I suppose that this should be in a Solaris specific file to indicate that 
> it's not for other systems.
> 
> GNU ld is almost ubiquitous on Linux and is almost always available at 
> /usr/bin/ld (with very few distributions using others linkers by default or 
> providing an option).
> 
> Detecting linker to affect driver decisions is we Linux are very wary of. We 
> are nervous even trying to do some stuff only related to lld.
> 
> We likely don't want this function to be in CommonArgs to lure other 
> contributors to use.
> I suppose that this should be in a Solaris specific file to indicate that 
> it's not for other systems.

Indeed.  I've moved it to `Solaris.{h,cpp}` now.  In fact, initially i'd tried 
to assert a Solaris target in `isLinkerGnuLd`, but that cannot work because in 
some cases the function is called in common code, even though the result is 
only used on Solaris.

I briefly thought about generalizing both `IsLinkerGnuLd` and `IsLinkerLLD` 
into a common
```
enum LinkerFlavour getLinkerFlavor();
```
but doing this for all possible configs seemed like a can of worms I'd rather 
not open.

> GNU ld is almost ubiquitous on Linux and is almost always available at 
> /usr/bin/ld (with very few distributions using others linkers by default or 
> providing an option).
> 
> Detecting linker to affect driver decisions is we Linux are very wary of. We 
> are nervous even trying to do some stuff only related to lld.

I saw: that code is only used on Darwin, it seems, and I'd like to avoid 
touching that.

> We likely don't want this function to be in CommonArgs to lure other 
> contributors to use.

Apart from the move to `Solaris.h`, I've also moved it into the `solaris` 
namespace to make things completely obvious.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85309

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


[PATCH] D159222: [clang] Consistently use isOSSolaris()

2023-08-30 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: jrtc27, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

While looking over the Solaris GNU ld patch (D85309 
), I noticed that we weren't using 
`isOSSolaris()` consistenly in `clang`.  This patch fixes this.

This patch is on top of D85309 .

Tested on `amd64-pc-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159222

Files:
  clang/lib/Basic/Targets/Sparc.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1838,7 +1838,7 @@
 
   StringRef Suff64 = "/64";
   // Solaris uses platform-specific suffixes instead of /64.
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 switch (TargetTriple.getArch()) {
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
@@ -2220,7 +2220,7 @@
 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 const llvm::Triple , SmallVectorImpl ,
 StringRef SysRoot) {
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 // Solaris is a special case.
 // The GCC installation is under
 //   /usr/gcc/./lib/gcc//../
@@ -2422,7 +2422,7 @@
   using std::begin;
   using std::end;
 
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
 "sparc-sun-solaris2.11"};
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -999,7 +999,7 @@
 
   // Solaris ld defaults to --export-dynamic behaviour but doesn't support
   // the option, so don't try to pass it.
-  if (TC.getTriple().getOS() == llvm::Triple::Solaris && !LinkerIsGnuLd)
+  if (TC.getTriple().isOSSolaris() && !LinkerIsGnuLd)
 return true;
   SmallString<128> SanRT(TC.getCompilerRT(Args, Sanitizer));
   if (llvm::sys::fs::exists(SanRT + ".syms")) {
Index: clang/lib/Basic/Targets/Sparc.cpp
===
--- clang/lib/Basic/Targets/Sparc.cpp
+++ clang/lib/Basic/Targets/Sparc.cpp
@@ -141,7 +141,7 @@
 void SparcV8TargetInfo::getTargetDefines(const LangOptions ,
  MacroBuilder ) const {
   SparcTargetInfo::getTargetDefines(Opts, Builder);
-  if (getTriple().getOS() == llvm::Triple::Solaris)
+  if (getTriple().isOSSolaris())
 Builder.defineMacro("__sparcv8");
   else {
 switch (getCPUGeneration(CPU)) {
@@ -168,7 +168,7 @@
   Builder.defineMacro("__sparcv9");
   Builder.defineMacro("__arch64__");
   // Solaris doesn't need these variants, but the BSDs do.
-  if (getTriple().getOS() != llvm::Triple::Solaris) {
+  if (!getTriple().isOSSolaris()) {
 Builder.defineMacro("__sparc64__");
 Builder.defineMacro("__sparc_v9__");
 Builder.defineMacro("__sparcv9__");


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1838,7 +1838,7 @@
 
   StringRef Suff64 = "/64";
   // Solaris uses platform-specific suffixes instead of /64.
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 switch (TargetTriple.getArch()) {
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
@@ -2220,7 +2220,7 @@
 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 const llvm::Triple , SmallVectorImpl ,
 StringRef SysRoot) {
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 // Solaris is a special case.
 // The GCC installation is under
 //   /usr/gcc/./lib/gcc//../
@@ -2422,7 +2422,7 @@
   using std::begin;
   using std::end;
 
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
+  if (TargetTriple.isOSSolaris()) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
 "sparc-sun-solaris2.11"};
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -999,7 +999,7 @@
 
   // Solaris ld defaults to --export-dynamic behaviour but doesn't support
   // the option, so don't try to pass it.
-  if (TC.getTriple().getOS() == llvm::Triple::Solaris && 

[PATCH] D85309: [Driver] Support GNU ld on Solaris

2023-08-30 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 554711.
ro retitled this revision from "[WIP][clang][Driver] Support GNU ld on Solaris" 
to "[Driver] Support GNU ld on Solaris".
ro added a comment.
Herald added subscribers: llvm-commits, Sanitizers, Enna1, ormris.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
Herald added projects: Sanitizers, LLVM, Flang, All.

This is a major revison of the original WIP patch that should be (close to) 
ready.  Major differences are:

- Linker selection is dynamic now: one can switch between Solaris ld and GNU ld 
at runtime, with the default selectable with `-DCLANG_DEFAULT_LINKER`.
- Testcases have been adjusted to test both variants in case there are 
differences.
- The `compiler-rt/cmake/config-ix.cmake` and 
`llvm/cmake/modules/AddLLVM.cmake` changes to restrict the tests to Solaris ld 
are necessary because GNU accepts unknown `-z` options, but warns every time 
they are used, creating a lot of noise.  Since there seems to be no way to 
check for those warnings in `llvm_check_compiler_linker_flag` or 
`llvm_check_compiler_linker_flag`, I restrict the cmake tests to Solaris ld in 
the first place.
- The changes to `clang/test/Driver/hip-link-bundle-archive.hip` and 
`flang/test/Driver/linker-flags.f90` are required to handle the 
`-DCLANG_DEFAULT_LINKER=gld` case: when this is passed to `cmake`, the 
`WebAssembly.cpp` `getLinkerPath` returns `/usr/bin/gld` instead of the 
expected `link`.
- `compiler-rt/test/asan/TestCases/global-location-nodebug.cpp` needs to 
enforce the Solaris ld, otherwise the test would `XPASS` with GNU ld which has 
the `-S` semantics expected by the test.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` with both 
`-DCLANG_DEFAULT_LINKER=gld` and the default, and `x86_64-pc-linux-gnu`.  No 
regressions in either case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85309

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/Driver/hip-link-bundle-archive.hip
  clang/test/Driver/solaris-ld-sanitizer.c
  clang/test/Driver/solaris-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  flang/test/Driver/linker-flags.f90
  llvm/cmake/modules/AddLLVM.cmake

Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -282,9 +282,9 @@
 # ld64's implementation of -dead_strip breaks tools that use plugins.
 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
  LINK_FLAGS " -Wl,-dead_strip")
-  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+  elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
 # Support for ld -z discard-unused=sections was only added in
-# Solaris 11.4.
+# Solaris 11.4.  GNU ld ignores it, but warns every time.
 include(LLVMCheckLinkerFlag)
 llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
 if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
@@ -1288,7 +1288,10 @@
 # the size of the exported symbol table, but on other platforms we can do
 # it without any trouble.
 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
-if (APPLE)
+# CMake doesn't set CMAKE_EXE_EXPORTS_${lang}_FLAG on Solaris, so
+# ENABLE_EXPORTS has no effect.  While Solaris ld defaults to -rdynamic
+# behaviour, GNU ld needs it.
+if (APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
   set_property(TARGET ${target} APPEND_STRING PROPERTY
 LINK_FLAGS " -rdynamic")
 endif()
Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -10,7 +10,7 @@
 !   'oldnames' on Windows, but they are not needed when compiling
 !   Fortran code and they might bring in additional dependencies.
 !   Make sure they're not added.
-! RUN: %flang -### -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
+! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
 
 ! Compiler invocation to generate the object file
 ! CHECK-LABEL: {{.*}} "-emit-obj"
Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
===
--- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
+++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
@@ 

[PATCH] D158955: [Driver] Improve legibility of ld -z options on Solaris

2023-08-28 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG779353e576ea: [Driver] Improve legibility of ld -z options 
on Solaris (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158955

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c
  clang/test/Driver/solaris-ld.c

Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -16,7 +16,7 @@
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
-// CHECK-LD-SPARC32-SAME: "-zignore" "-latomic" "-zrecord"
+// CHECK-LD-SPARC32-SAME: "-z" "ignore" "-latomic" "-z" "record"
 // CHECK-LD-SPARC32-SAME: "-lgcc_s"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- clang/test/Driver/solaris-ld-sanitizer.c
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -6,49 +6,49 @@
 // RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
-// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+// CHECK-LD-SPARC32-NOT: "-z" "relax=transtls"
 
 /// Check sparc-sun-solaris2.11, 32bit
 // RUN: %clang -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
-// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+// CHECK-LD-SPARC32-NOT: "-z" "relax=transtls"
 
 /// Check sparc-sun-solaris2.11, 64bit
 // RUN: %clang -m64 --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
-// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+// CHECK-LD-SPARC64-NOT: "-z" "relax=transtls"
 
 /// Check sparc-sun-solaris2.11, 64bit
 // RUN: %clang -m64 -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
-// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+// CHECK-LD-SPARC64-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 32bit
 // RUN: %clang --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
-// CHECK-LD-X32-NOT: -zrelax=transtls
+// CHECK-LD-X32-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 32bit
 // RUN: %clang -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
-// CHECK-LD-X32-NOT: -zrelax=transtls
+// CHECK-LD-X32-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 64bit
 // RUN: %clang -m64 --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
-// CHECK-LD-X64-NOT: -zrelax=transtls
+// CHECK-LD-X64-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 64bit
 // RUN: %clang -m64 -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
-// CHECK-LD-X64-UBSAN: -zrelax=transtls
+// CHECK-LD-X64-UBSAN: "-z" "relax=transtls"
 
 /// General tests that the ld -z now workaround is only applied on
 /// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to
@@ -58,10 +58,10 @@
 // RUN: %clang -fsanitize=address -shared-libasan --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN-SHARED %s
-// CHECK-LD-X32-ASAN-SHARED: -znow
+// CHECK-LD-X32-ASAN-SHARED: "-z" "now"
 
 /// Check i386-pc-solaris2.11, 32bit, static libclang_rt.asan
 // RUN: %clang -fsanitize=address --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   

[PATCH] D158959: [clang-tidy] Disambiguate calls to log

2023-08-27 Thread Rainer Orth via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG03dff0d4acaf: [clang-tidy] Disambiguate calls to log 
(authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158959

Files:
  clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp


Index: clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -214,10 +214,12 @@
   Iterations = ceil(float(InitValue - EndValue) / ConstantValue);
   break;
 case (BO_MulAssign):
-  Iterations = 1 + (log(EndValue) - log(InitValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)EndValue) - log((double)InitValue)) /
+   log((double)ConstantValue);
   break;
 case (BO_DivAssign):
-  Iterations = 1 + (log(InitValue) - log(EndValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)InitValue) - log((double)EndValue)) /
+   log((double)ConstantValue);
   break;
 default:
   // All other operators are not handled; assume large bounds.


Index: clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -214,10 +214,12 @@
   Iterations = ceil(float(InitValue - EndValue) / ConstantValue);
   break;
 case (BO_MulAssign):
-  Iterations = 1 + (log(EndValue) - log(InitValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)EndValue) - log((double)InitValue)) /
+   log((double)ConstantValue);
   break;
 case (BO_DivAssign):
-  Iterations = 1 + (log(InitValue) - log(EndValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)InitValue) - log((double)EndValue)) /
+   log((double)ConstantValue);
   break;
 default:
   // All other operators are not handled; assume large bounds.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158959: [clang-tidy] Disambiguate calls to log

2023-08-27 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: PiotrZSL.
Herald added subscribers: carlosgalvezp, pengfei, zzheng, fedor.sergeev, 
xazax.hun, jyknight.
Herald added a reviewer: njames93.
Herald added a project: All.
ro requested review of this revision.
Herald added a project: clang-tools-extra.

c8644b18f570be9d26d83cdeeb2369cd3cbddaf1 
 broke the 
Solaris/amd64  and 
Solaris/sparcv9  
buildbots:

  FAILED: 
tools/clang/tools/extra/clang-tidy/altera/CMakeFiles/obj.clangTidyAlteraModule.dir/UnrollLoopsCheck.cpp.o
  [...]
  
/vol/llvm/src/llvm-project/dist/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp:217:25:
 error: call to 'log' is ambiguous 
217 |   Iterations = 1 + (log(EndValue) - log(InitValue)) / 
log(ConstantValue);
| ^~~
  /usr/include/iso/math_iso.h:60:15: note: candidate function
 60 | extern double log __P((double));
|   ^
  /usr/include/iso/math_iso.h:158:15: note: candidate function
158 | inline float log(float __X) { return __logf(__X); }
|  ^
  /usr/include/iso/math_iso.h:193:21: note: candidate function
193 | inline long double log(long double __X) { return __logl(__X); 
}
|^

Fixed by disambituating the calls with `double` casts.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.

Will commit shortly to unbreak the bots.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158959

Files:
  clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp


Index: clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -214,10 +214,12 @@
   Iterations = ceil(float(InitValue - EndValue) / ConstantValue);
   break;
 case (BO_MulAssign):
-  Iterations = 1 + (log(EndValue) - log(InitValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)EndValue) - log((double)InitValue)) /
+   log((double)ConstantValue);
   break;
 case (BO_DivAssign):
-  Iterations = 1 + (log(InitValue) - log(EndValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)InitValue) - log((double)EndValue)) /
+   log((double)ConstantValue);
   break;
 default:
   // All other operators are not handled; assume large bounds.


Index: clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -214,10 +214,12 @@
   Iterations = ceil(float(InitValue - EndValue) / ConstantValue);
   break;
 case (BO_MulAssign):
-  Iterations = 1 + (log(EndValue) - log(InitValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)EndValue) - log((double)InitValue)) /
+   log((double)ConstantValue);
   break;
 case (BO_DivAssign):
-  Iterations = 1 + (log(InitValue) - log(EndValue)) / log(ConstantValue);
+  Iterations = 1 + (log((double)InitValue) - log((double)EndValue)) /
+   log((double)ConstantValue);
   break;
 default:
   // All other operators are not handled; assume large bounds.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158955: [Driver] Improve legibility of ld -z options on Solaris

2023-08-27 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: pengfei, fedor.sergeev, emaste.
Herald added a project: All.
ro requested review of this revision.

Following the lead of the Linux code, this patch passes the `ld -z` options as 
two separate args on Solaris, improving legibility.  For lack of a variadic 
`std::push_back`, `getAsNeededOption` had to be changed to `addAsNeededOption`, 
matching other `add*Options` functions, changing callers accordingly.  The 
additional args are also used in a WIP revision of the Solaris GNU ld patch 
D85309 , which will allow runtime selection of 
the linker to use.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158955

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c
  clang/test/Driver/solaris-ld.c

Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -16,7 +16,7 @@
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
-// CHECK-LD-SPARC32-SAME: "-zignore" "-latomic" "-zrecord"
+// CHECK-LD-SPARC32-SAME: "-z" "ignore" "-latomic" "-z" "record"
 // CHECK-LD-SPARC32-SAME: "-lgcc_s"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- clang/test/Driver/solaris-ld-sanitizer.c
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -6,49 +6,49 @@
 // RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
-// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+// CHECK-LD-SPARC32-NOT: "-z" "relax=transtls"
 
 /// Check sparc-sun-solaris2.11, 32bit
 // RUN: %clang -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
-// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+// CHECK-LD-SPARC32-NOT: "-z" "relax=transtls"
 
 /// Check sparc-sun-solaris2.11, 64bit
 // RUN: %clang -m64 --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
-// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+// CHECK-LD-SPARC64-NOT: "-z" "relax=transtls"
 
 /// Check sparc-sun-solaris2.11, 64bit
 // RUN: %clang -m64 -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
-// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+// CHECK-LD-SPARC64-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 32bit
 // RUN: %clang --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
-// CHECK-LD-X32-NOT: -zrelax=transtls
+// CHECK-LD-X32-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 32bit
 // RUN: %clang -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
-// CHECK-LD-X32-NOT: -zrelax=transtls
+// CHECK-LD-X32-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 64bit
 // RUN: %clang -m64 --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
-// CHECK-LD-X64-NOT: -zrelax=transtls
+// CHECK-LD-X64-NOT: "-z" "relax=transtls"
 
 /// Check i386-pc-solaris2.11, 64bit
 // RUN: %clang -m64 -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
-// CHECK-LD-X64-UBSAN: -zrelax=transtls
+// CHECK-LD-X64-UBSAN: "-z" "relax=transtls"
 
 /// General tests that the ld -z now workaround is only applied on
 /// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to
@@ -58,10 +58,10 @@
 // RUN: %clang -fsanitize=address -shared-libasan 

[PATCH] D158206: [Driver] Add PIE support on Solaris

2023-08-18 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ro marked an inline comment as done.
Closed by commit rG62945bb81116: [Driver] Add PIE support on Solaris (authored 
by ro).

Changed prior to commit:
  https://reviews.llvm.org/D158206?vs=551539=551598#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158206

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtbeginS.o
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtbeginS.o
  clang/test/Driver/solaris-ld.c

Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -106,6 +106,33 @@
 // CHECK-SPARC32-SHARED-NOT: "-lgcc"
 // CHECK-SPARC32-SHARED-NOT: "-lm"
 
+// Check the right ld flags are present with -pie.
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PIE %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -nopie \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+
+// Check that -shared/-r/-static disable PIE.
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -shared -pie \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -r -pie \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -static -pie \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+
+// CHECK-PIE: "-z" "type=pie"
+// CHECK-NOPIE-NOT: "-z" "type=pie"
+
 // -r suppresses default -l and crt*.o, values-*.o like -nostdlib.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -r 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
@@ -115,6 +142,28 @@
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o
 
+// Check that crt{begin,end}S.o is linked with -shared/-pie.
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -shared \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -nopie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTS %s
+// CHECK-CRTS: crtbeginS.o
+// CHECK-CRTS: crtendS.o
+// CHECK-NOCRTS-NOT: crtbeginS.o
+// CHECK-NOCRTS-NOT: crtendS.o
+
 // Check that crtfastmath.o is linked with -ffast-math.
 
 // Check sparc-sun-solaris2.11, 32bit
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -47,11 +47,24 @@
  Exec, CmdArgs, Inputs, Output));
 }
 
+static bool getPIE(const ArgList , const ToolChain ) {
+  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
+  Args.hasArg(options::OPT_r))
+return false;
+
+  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+   options::OPT_nopie);
+  if (!A)
+return TC.isPIEDefault(Args);
+  return A->getOption().matches(options::OPT_pie);
+}
+
 void solaris::Linker::ConstructJob(Compilation , const JobAction ,
const InputInfo ,
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
+  const bool IsPIE = getPIE(Args, getToolChain());
   ArgStringList CmdArgs;
 
   // Demangle C++ names in errors
@@ -62,6 +75,11 @@
 CmdArgs.push_back("_start");
   }
 
+  if (IsPIE) {
+CmdArgs.push_back("-z");
+

[PATCH] D158206: [Driver] Add PIE support on Solaris

2023-08-18 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added inline comments.



Comment at: clang/lib/Driver/ToolChains/Solaris.cpp:136
+const char *crtbegin = nullptr;
+if (Args.hasArg(options::OPT_shared) || IsPIE)
+  crtbegin = "crtbeginS.o";

MaskRay wrote:
> Q: Interesting. If -shared used crtbegin.o before, how did it work?
> 
> On Linux, using GCC crtbegin.o (compiled with `-fno-PIC` or similar non-PIC 
> option) will cause:
> ```
> ld.lld: error: relocation R_X86_64_32S cannot be used against local symbol; 
> recompile with -fPIC
> >>> defined in /usr/lib/gcc/x86_64-linux-gnu/12/crtbegin.o
> >>> referenced by crtstuff.c
> >>>   /usr/lib/gcc/x86_64-linux-gnu/12/crtbegin.o:(.text+0x7)
> 
> ld.lld: error: relocation R_X86_64_32 cannot be used against symbol 
> '_ITM_deregisterTMCloneTable'; recompile with -fPIC
> >>> defined in /usr/lib/gcc/x86_64-linux-gnu/12/crtbegin.o
> >>> referenced by crtstuff.c
> >>>   /usr/lib/gcc/x86_64-linux-gnu/12/crtbegin.o:(.text+0xE)
> 
> ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; 
> recompile with -fPIC
> >>> defined in /usr/lib/gcc/x86_64-linux-gnu/12/crtbegin.o
> >>> referenced by crtstuff.c
> >>>   /usr/lib/gcc/x86_64-linux-gnu/12/crtbegin.o:(.text+0x18)
> ```
When the Solaris crts were reworked for Solaris 11.4 back in 2015, the were 
intentionally built as PIC to avoid issues just like that.



Comment at: clang/test/Driver/solaris-ld.c:110
+// Check the right ld flags are present with -pie.
+// RUN: %clang -### %s -pie 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \

MaskRay wrote:
> ro wrote:
> > MaskRay wrote:
> > > The convention is to put `2>&1` at the end of the command, aka before `|`
> > I've changed just the newly added tests.  There are a few others, but I've 
> > left the as is for now to avoid cluttering the patch with unrelated changes.
> Ultra nit: you may pack --target=sparc-sun-solaris2.11 on the first line to 
> make the commands compacter, like `%clang --target=sparc-sun-solaris2.11 -### 
> %s` below.
> 
Good point, done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158206

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


[PATCH] D158207: [Driver] Link with crtbeginS.o/crtendS.o on Solaris

2023-08-18 Thread Rainer Orth via Phabricator via cfe-commits
ro abandoned this revision.
ro added a comment.

Merged into  D158206 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158207

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


[PATCH] D158206: [Driver] Add PIE support on Solaris

2023-08-18 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 551539.
ro marked 2 inline comments as done.
ro edited the summary of this revision.
ro added a comment.
Herald added a subscriber: jrtc27.

- Merged D158207 .
- Incorporate review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158206

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtbeginS.o
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtbeginS.o
  clang/test/Driver/solaris-ld.c

Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -106,6 +106,38 @@
 // CHECK-SPARC32-SHARED-NOT: "-lgcc"
 // CHECK-SPARC32-SHARED-NOT: "-lm"
 
+// Check the right ld flags are present with -pie.
+// RUN: %clang -### %s -pie \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PIE %s
+// RUN: %clang -### %s -nopie \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+
+// Check that -shared/-r/-static disable PIE.
+// RUN: %clang -### %s -shared -pie \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+// RUN: %clang -### %s -r -pie \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+// RUN: %clang -### %s -static -pie \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+
+// CHECK-PIE: "-z" "type=pie"
+// CHECK-NOPIE-NOT: "-z" "type=pie"
+
 // -r suppresses default -l and crt*.o, values-*.o like -nostdlib.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -r 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
@@ -115,6 +147,28 @@
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o
 
+// Check that crt{begin,end}S.o is linked with -shared/-pie.
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -shared \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -nopie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTS %s
+// CHECK-CRTS: crtbeginS.o
+// CHECK-CRTS: crtendS.o
+// CHECK-NOCRTS-NOT: crtbeginS.o
+// CHECK-NOCRTS-NOT: crtendS.o
+
 // Check that crtfastmath.o is linked with -ffast-math.
 
 // Check sparc-sun-solaris2.11, 32bit
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -47,11 +47,24 @@
  Exec, CmdArgs, Inputs, Output));
 }
 
+static bool getPIE(const ArgList , const ToolChain ) {
+  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
+  Args.hasArg(options::OPT_r))
+return false;
+
+  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+   options::OPT_nopie);
+  if (!A)
+return TC.isPIEDefault(Args);
+  return A->getOption().matches(options::OPT_pie);
+}
+
 void solaris::Linker::ConstructJob(Compilation , const JobAction ,
const InputInfo ,
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
+  const bool IsPIE = getPIE(Args, getToolChain());
   ArgStringList CmdArgs;
 
   // Demangle C++ names in errors
@@ -62,6 +75,11 @@
 CmdArgs.push_back("_start");
   }
 
+  if (IsPIE) {
+CmdArgs.push_back("-z");
+

[PATCH] D158206: [Driver] Add PIE support on Solaris

2023-08-18 Thread Rainer Orth via Phabricator via cfe-commits
ro marked 2 inline comments as done.
ro added a comment.

In D158206#4596471 , @MaskRay wrote:

>> I'll submit a follow-up patch to make use of crtbeginS.o and crtendS.o 
>> shortly.
>
> I think this patch should make this change, so that the change is correct on 
> itself.

Ok, done.  I'll update with the merge patch once another round of testing has 
finished.




Comment at: clang/lib/Driver/ToolChains/Solaris.cpp:55
const char *LinkingOutput) const {
+  const bool IsPIE =
+  !Args.hasArg(options::OPT_shared) &&

MaskRay wrote:
> On Linux, `clang -r` `-static` also disable the linker option `-pie`.
> `-static-pie` is handled as a special case which also disables the regular 
> `-pie` code path.
I've taken `Gnu.cpp` (`getPIE`), removing the `-static-pie` handling.

Solaris supports neither `-static` (no `libc.a` etc. since Solaris 10) nor 
`-static-pie`.  Given that `gcc` silently ignores that, I'm doing the same.



Comment at: clang/test/Driver/solaris-ld.c:110
+// Check the right ld flags are present with -pie.
+// RUN: %clang -### %s -pie 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \

MaskRay wrote:
> The convention is to put `2>&1` at the end of the command, aka before `|`
I've changed just the newly added tests.  There are a few others, but I've left 
the as is for now to avoid cluttering the patch with unrelated changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158206

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


[PATCH] D158207: [Driver] Link with crtbeginS.o/crtendS.o on Solaris

2023-08-17 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: pengfei, jrtc27, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

`clang` doesn't currently use `crtbeginS.o` and `crtendS.o` on Solaris with 
`-pie` or `-shared`.  This patch fixes that.  It depends on D158206 
 for the `IsPIE` definition.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and 
`x86_64-pc-linux-gnu`.

Both this one and D158206  might be 
candidates for LLVM 17.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158207

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtbeginS.o
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtbeginS.o
  clang/test/Driver/solaris-ld.c


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -129,6 +129,28 @@
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o
 
+// Check that crt{begin,end}S.o is linked with -shared/-pie.
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -shared \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -nopie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTS %s
+// CHECK-CRTS: crtbeginS.o
+// CHECK-CRTS: crtendS.o
+// CHECK-NOCRTS-NOT: crtbeginS.o
+// CHECK-NOCRTS-NOT: crtendS.o
+
 // Check that crtfastmath.o is linked with -ffast-math.
 
 // Check sparc-sun-solaris2.11, 32bit
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -119,8 +119,13 @@
   values_xpg = "values-xpg4.o";
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
-CmdArgs.push_back(
-Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
+
+const char *crtbegin = nullptr;
+if (Args.hasArg(options::OPT_shared) || IsPIE)
+  crtbegin = "crtbeginS.o";
+else
+  crtbegin = "crtbegin.o";
+
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(crtbegin)));
 // Add crtfastmath.o if available and fast math is enabled.
 getToolChain().addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
@@ -177,8 +182,12 @@
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
-CmdArgs.push_back(
-Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
+if (Args.hasArg(options::OPT_shared) || IsPIE)
+  CmdArgs.push_back(
+  Args.MakeArgString(getToolChain().GetFilePath("crtendS.o")));
+else
+  CmdArgs.push_back(
+  Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
   }


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -129,6 +129,28 @@
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o
 
+// Check that crt{begin,end}S.o is linked with -shared/-pie.
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -shared \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -nopie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \

[PATCH] D158206: [Driver] Add PIE support on Solaris

2023-08-17 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: pengfei, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

`clang` currently lacks PIE support on Solaris.  This patch fixes this.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and 
`x86_64-pc-linux-gnu`.

I'll submit a follow-up patch to make use of `crtbeginS.o` and `crtendS.o` 
shortly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158206

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld.c


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -106,6 +106,20 @@
 // CHECK-SPARC32-SHARED-NOT: "-lgcc"
 // CHECK-SPARC32-SHARED-NOT: "-lm"
 
+// Check the right ld flags are present with -pie.
+// RUN: %clang -### %s -pie 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-PIE %s
+// RUN: %clang -### %s -nopie 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+// CHECK-PIE: "-ztype=pie"
+// CHECK-NOPIE-NOT: "-ztype=pie'
+
 // -r suppresses default -l and crt*.o, values-*.o like -nostdlib.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -r 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -52,6 +52,9 @@
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
+  const bool IsPIE =
+  !Args.hasArg(options::OPT_shared) &&
+  (Args.hasArg(options::OPT_pie) || getToolChain().isPIEDefault(Args));
   ArgStringList CmdArgs;
 
   // Demangle C++ names in errors
@@ -62,6 +65,9 @@
 CmdArgs.push_back("_start");
   }
 
+  if (IsPIE)
+CmdArgs.push_back("-ztype=pie");
+
   if (Args.hasArg(options::OPT_static)) {
 CmdArgs.push_back("-Bstatic");
 CmdArgs.push_back("-dn");


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -106,6 +106,20 @@
 // CHECK-SPARC32-SHARED-NOT: "-lgcc"
 // CHECK-SPARC32-SHARED-NOT: "-lm"
 
+// Check the right ld flags are present with -pie.
+// RUN: %clang -### %s -pie 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-PIE %s
+// RUN: %clang -### %s -nopie 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-NOPIE %s
+// CHECK-PIE: "-ztype=pie"
+// CHECK-NOPIE-NOT: "-ztype=pie'
+
 // -r suppresses default -l and crt*.o, values-*.o like -nostdlib.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -r 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -52,6 +52,9 @@
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
+  const bool IsPIE =
+  !Args.hasArg(options::OPT_shared) &&
+  (Args.hasArg(options::OPT_pie) || getToolChain().isPIEDefault(Args));
   ArgStringList CmdArgs;
 
   // Demangle C++ names in errors
@@ -62,6 +65,9 @@
 CmdArgs.push_back("_start");
   }
 
+  if (IsPIE)
+CmdArgs.push_back("-ztype=pie");
+
   if (Args.hasArg(options::OPT_static)) {
 CmdArgs.push_back("-Bstatic");
 CmdArgs.push_back("-dn");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-16 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGae84ad15efd7: [Driver] Select newest GCC installation on 
Solaris (authored by ro).

Changed prior to commit:
  https://reviews.llvm.org/D157275?vs=550226=550651#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157275

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -168,6 +168,155 @@
 S);
 }
 
+TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  const char *EmptyFiles[] = {
+  // Sort entries so the latest version doesn't come first.
+  "/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/32/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/32/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/sparcv8plus/"
+  "crtbegin.o",
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/32/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/amd64/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/sparcv9/crtbegin.o",
+  };
+
+  for (const char *Path : EmptyFiles)
+InMemoryFileSystem->addFile(Path, 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "i386-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  "Selected multilib: 32;@m32\n",
+  S);
+  }
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "amd64-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  "Selected multilib: .;@m64\n",
+  S);
+  }
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  

[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-15 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 550226.
ro marked an inline comment as done.
ro added a comment.
Herald added a subscriber: ormris.

- Simplify `SolarisPrefixes` sorting.
- Switch to unitest`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157275

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -168,6 +168,155 @@
 S);
 }
 
+TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  const char *EmptyFiles[] = {
+  // Sort entries so the latest version doesn't come first.
+  "/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/32/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/32/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/sparcv8plus/"
+  "crtbegin.o",
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/32/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/amd64/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/sparcv9/crtbegin.o",
+  };
+
+  for (const char *Path : EmptyFiles)
+InMemoryFileSystem->addFile(Path, 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "i386-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  "Selected multilib: 32;@m32\n",
+  S);
+  }
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "amd64-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  "Selected multilib: .;@m64\n",
+  S);
+  }
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  

[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-15 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added a comment.

In D157275#4585184 , @MaskRay wrote:

> Thanks for the update. Regarding testing, it seems that unittests will be 
> more convenience than creating so many placeholder files in `Inputs/`. 
> `clang/unittests/Driver/ToolChainTest.cpp` `TEST(ToolChainTest, 
> VFSGCCInstallation)` has an example for Linux. You can add another for 
> Solaris.

TBH, I'm quite sceptical about the unittest framework here: we already have 
2300+ empty files in `clang/test/Driver`, so adding 12 more shouldn't be such a 
big deal.  With a real in-filesystem tree, I can quickly test various 
scenarious with `clang -v --sysroot`, while this isn't possible with the 
unittest framework (which I find way harder to read).  I'm adding the unittest 
nonetheless, but would prefer to keep the `lit`-based test instead.




Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2258
 
-  Prefixes.push_back(CandidatePrefix);
+  SolarisPrefixes.push_back(CandidatePrefix);
 }

MaskRay wrote:
> It's better to use https://en.wikipedia.org/wiki/Schwartzian_transform here 
> to avoid calling `llvm::sys::path::filename` and 
> `Generic_GCC::GCCVersion::Parse` in the comparator. Then the comparator is 
> just `A < B` and can just be removed.
This is way shorter and efficient indeed.  Patch updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157275

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


[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-14 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 549925.
ro added a comment.
Herald added a subscriber: mgrang.

Updated based on discussions in Issue #53709:

- Sort Solaris GCC prefixes in reverse version order so the latest version is 
picked.
- Update testcase to match.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.

I'm seeing weird testsuite failures in 2-stage builds on Solaris/amd64 with gcc 
12, but not with clang 16, which I don't yet understand.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157275

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/sparcv8plus/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/amd64/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/sparcv9/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/crtbegin.o
  clang/test/Driver/solaris-multi-gcc-search.test


Index: clang/test/Driver/solaris-multi-gcc-search.test
===
--- /dev/null
+++ clang/test/Driver/solaris-multi-gcc-search.test
@@ -0,0 +1,51 @@
+/// Check that clang uses the latest available Solaris GCC installation.
+
+/// Check sparc-sun-solaris2.11, 32-bit
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC %s
+// CHECK-SPARC: Found candidate GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARC-NEXT: Selected GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARC-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC-NEXT: Selected multilib: sparcv8plus;@m32
+
+/// Check i386-pc-solaris2.11, 32-bit
+// RUN: %clang -v 2>&1 --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-I386 %s
+// CHECK-I386: Found candidate GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-I386-NEXT: Selected GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-I386-NEXT: Candidate multilib: .;@m64
+// CHECK-I386-NEXT: Candidate multilib: 32;@m32
+// CHECK-I386-NEXT: Selected multilib: 32;@m32
+
+/// Check sparcv9-sun-solaris2.11, 64-bit
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARCV9 %s
+// CHECK-SPARCV9: Found candidate GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARCV9-NEXT: Selected GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARCV9-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARCV9-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARCV9-NEXT: Selected multilib: .;@m64
+
+/// Check x86_64-pc-solaris2.11, 64-bit
+// RUN: %clang -v 2>&1 --target=x86_64-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-X86_64 %s
+
+/// Check amd64-pc-solaris2.11, 64-bit
+// RUN: %clang -v 2>&1 --target=amd64-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-X86_64 %s
+// CHECK-X86_64: Found candidate GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-X86_64-NEXT: Selected GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-X86_64-NEXT: Candidate multilib: .;@m64
+// CHECK-X86_64-NEXT: Candidate multilib: 32;@m32
+// CHECK-X86_64-NEXT: Selected multilib: .;@m64
Index: 

[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-08 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2193
 // Skip other prefixes once a GCC installation is found.
-if (Version > VersionZero)
+// Solaris GCC installations live in separate Prefixes per Version
+// (/usr/gcc/) that arrive in directory order, so check all

MaskRay wrote:
> Adding a Solaris special case here seems strange.
> 
> Do you know what the typical `Prefixes` values are on Solaris? Is it possible 
> to remove some elements as a special case for Solaris instead?
Agreed.  This patch in its current form is just meant as a stop-gap measure to 
unbreak basic Solaris functionality while avoiding to affect other targets.

I've described the value of `Prefixes` on Solaris in the Issue: its an array of 
`/usr/gcc/` for each installed version of GCC, however in directory order 
and thus random.  The exact set is variable since every version can be 
installed or uninstalled at any time, old versions get deprecated and removed, 
and new ones added over time.

My fundamental problem here is that I haven't yet been able to reproduce the 
failure your original patch is meant to fix, so I don't really know what to 
guard against.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157275

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


[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-07 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: pengfei, jrtc27, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

As described in Issue #53709 
, since 
28d58d8fe2094af6902dee7b4d68ec30a3e9d737 
 `clang` 
doesn't find the latest of several parallel GCC installations on Solaris, but 
only the first in directory order, which is pretty random.

Since this breaks basic functionality of the Solaris port, this patch restores 
scanning all prefixes for GCC installations.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and 
`x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157275

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/sparcv8plus/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/amd64/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/sparcv9/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/crtbegin.o
  clang/test/Driver/solaris-multi-gcc-search.test


Index: clang/test/Driver/solaris-multi-gcc-search.test
===
--- /dev/null
+++ clang/test/Driver/solaris-multi-gcc-search.test
@@ -0,0 +1,60 @@
+/// Check that clang uses the latest available Solaris GCC installation.
+
+/// Check sparc-sun-solaris2.11, 32-bit
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC %s
+// CHECK-SPARC-DAG: Found candidate GCC installation: 
{{.*}}4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3
+// CHECK-SPARC-DAG: Found candidate GCC installation: 
{{.*}}7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0
+// CHECK-SPARC-DAG: Found candidate GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARC: Selected GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARC-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC-NEXT: Selected multilib: sparcv8plus;@m32
+
+/// Check i386-pc-solaris2.11, 32-bit
+// RUN: %clang -v 2>&1 --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-I386 %s
+// CHECK-I386-DAG: Found candidate GCC installation: 
{{.*}}4.7/lib/gcc/i386-pc-solaris2.11/4.7.3
+// CHECK-I386-DAG: Found candidate GCC installation: 
{{.*}}7/lib/gcc/x86_64-pc-solaris2.11/7.5.0
+// CHECK-I386-DAG: Found candidate GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-I386: Selected GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-I386-NEXT: Candidate multilib: .;@m64
+// CHECK-I386-NEXT: Candidate multilib: 32;@m32
+// CHECK-I386-NEXT: Selected multilib: 32;@m32
+
+/// Check sparcv9-sun-solaris2.11, 64-bit
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARCV9 %s
+// CHECK-SPARCV9-DAG: Found candidate GCC installation: 
{{.*}}4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3
+// CHECK-SPARCV9-DAG: Found candidate GCC installation: 
{{.*}}7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0
+// CHECK-SPARCV9-DAG: Found candidate GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARCV9: Selected GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARCV9-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARCV9-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARCV9-NEXT: Selected multilib: .;@m64
+

[PATCH] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43dfe0f08eca: [Driver] Allow for sparcv8plus subdir with 
Solaris/SPARC GCC (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157013

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/solaris-sparc-gcc-search.test

Index: clang/test/Driver/solaris-sparc-gcc-search.test
===
--- /dev/null
+++ clang/test/Driver/solaris-sparc-gcc-search.test
@@ -0,0 +1,56 @@
+/// Check that clang can handle both old-style (32) and new-style (sparcv8plus)
+/// 32-bit sparc multilib subdirs.
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC48 %s
+// CHECK-SPARC32-GCC48: Selected GCC installation: {{.*}}4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC32-GCC48-NEXT: Selected multilib: .;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC10 %s
+// CHECK-SPARC32-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC32-GCC10-NEXT: Selected multilib: 32;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC11 %s
+// CHECK-SPARC32-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC32-GCC11-NEXT: Selected multilib: sparcv8plus;@m32
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC48 %s
+// CHECK-SPARC64-GCC48: Selected GCC installation: {{.*}}gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC64-GCC48-NEXT: Selected multilib: sparcv9;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC10 %s
+// CHECK-SPARC64-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC64-GCC10-NEXT: Selected multilib: .;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC11 %s
+// CHECK-SPARC64-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC64-GCC11-NEXT: Selected multilib: .;@m64
Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -20,6 +20,7 @@
 ".hipi",
 ".hlsl",
 ".yaml",
+".test",
 ]
 config.substitutions = list(config.substitutions)
 config.substitutions.insert(
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ 

[PATCH] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/test/Driver/lit.local.cfg:23
 ".yaml",
+".test",
 ]

MaskRay wrote:
> Instead of adding a new extension, you can just name your test `.c`?
I could, but went for  `.test` instead because the `clang` invocations don't 
need input.

Besides, there's still the issue of the existing `crash-report-null.test` 
that's currently ignored.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157013

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


[PATCH] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: pengfei, jrtc27, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

Since GCC 11, the bundled Solaris/SPARC GCC uses the `sparcv8plus` subdirectory 
for 32-bit objects, just like upstream GCC.  Before that, it used `32` instead 
from a local patch.

Since `clang` doesn't know about that `sparcv8plus` subdirectory, it wouldn't 
properly use GCC 11+ installations.

The new `solaris-sparc-gcc-search.test` testcase wasn't run initially (like the 
existing `crash-report-null.test`) because the `.test` suffix wasn't handled.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and 
`x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157013

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/solaris-sparc-gcc-search.test

Index: clang/test/Driver/solaris-sparc-gcc-search.test
===
--- /dev/null
+++ clang/test/Driver/solaris-sparc-gcc-search.test
@@ -0,0 +1,56 @@
+/// Check that clang can handle both old-style (32) and new-style (sparcv8plus)
+/// 32-bit sparc multilib subdirs.
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC48 %s
+// CHECK-SPARC32-GCC48: Selected GCC installation: {{.*}}4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC32-GCC48-NEXT: Selected multilib: .;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC10 %s
+// CHECK-SPARC32-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC32-GCC10-NEXT: Selected multilib: 32;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC11 %s
+// CHECK-SPARC32-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC32-GCC11-NEXT: Selected multilib: sparcv8plus;@m32
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC48 %s
+// CHECK-SPARC64-GCC48: Selected GCC installation: {{.*}}gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC64-GCC48-NEXT: Selected multilib: sparcv9;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC10 %s
+// CHECK-SPARC64-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC64-GCC10-NEXT: Selected multilib: .;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC11 %s
+// CHECK-SPARC64-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC64-GCC11-NEXT: Selected multilib: .;@m64
Index: clang/test/Driver/lit.local.cfg

[PATCH] D155736: Fix __cfi_check not aligned to 4k on relocatable files with no executable code

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

It seems this patch broke the Solaris/amd64 buildbot 
:

  FAIL: Clang::cfi-check-fail.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155736

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


[PATCH] D156861: [Driver] Remove references to Solaris 12

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd0dc887d7ed2: [Driver] Remove references to Solaris 12 
(authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156861

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2407,13 +2407,11 @@
   if (TargetTriple.getOS() == llvm::Triple::Solaris) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
-"sparc-sun-solaris2.11", "sparc-sun-solaris2.12"};
+"sparc-sun-solaris2.11"};
 static const char *const SolarisSparcV9Triples[] = {
-"sparcv9-sun-solaris2.11", "sparcv9-sun-solaris2.12"};
-static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11",
-"i386-pc-solaris2.12"};
-static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11",
-   
"x86_64-pc-solaris2.12"};
+"sparcv9-sun-solaris2.11"};
+static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11"};
+static const char *const SolarisX86_64Triples[] = 
{"x86_64-pc-solaris2.11"};
 LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 switch (TargetTriple.getArch()) {


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2407,13 +2407,11 @@
   if (TargetTriple.getOS() == llvm::Triple::Solaris) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
-"sparc-sun-solaris2.11", "sparc-sun-solaris2.12"};
+"sparc-sun-solaris2.11"};
 static const char *const SolarisSparcV9Triples[] = {
-"sparcv9-sun-solaris2.11", "sparcv9-sun-solaris2.12"};
-static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11",
-"i386-pc-solaris2.12"};
-static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11",
-   "x86_64-pc-solaris2.12"};
+"sparcv9-sun-solaris2.11"};
+static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11"};
+static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11"};
 LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 switch (TargetTriple.getArch()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156861: [Driver] Remove references to Solaris 12

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D156861#4555280 , @MaskRay wrote:

> While you are modifying the lines `static const char ...[]` should look 
> better than `static const char *const SolarisX86Triples[]`

While this would certainly avoid the ugly formatting, it doesn't compile.  
Besides, I'd rather avoid using different styles just a few lines apart.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156861

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


[PATCH] D156363: [Driver] -###: exit with code 1 if hasErrorOccurred

2023-08-02 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D156363#4554884 , @MaskRay wrote:

> In D156363#4554812 , @jhuber6 wrote:
>
>> 



>> Probably because we're not specifying the `--target=` I'll add that in my 
>> fix for AMDGPU I'm working on and see if it solves the problem.
>
> Thank you for fixing these tests. I agree that clang_f_opts.c:117 with 
> `-flto` needs a `--target=`, to not cause this error on 
> `amd64-pc-solaris2.11'`.
> This should be the only line. I unfortunately did not catch this because I do 
> not have access to a target using `HasNativeLLVMSupport` == false`.

Confirmed: adding `-target x86_64-unknown-linux` to both `clang_f_opts.c:117` 
and `lto.c:19` let both tests `PASS` on `amd64-pc-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156363

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


[PATCH] D156363: [Driver] -###: exit with code 1 if hasErrorOccurred

2023-08-02 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D156363#4553043 , @ro wrote:

> It seems the latest commit of this patch has (re-)introduced two failures on 
> the Solaris/amd64 buildbot 
> :
>
>   FAIL: Clang::clang_f_opts.c
>   FAIL: Clang::lto.c
>
> I cannot really make sense of that.

I think I found it: running the matching '*.script' files under `bash -x` shows 
the tests ending with:

- for `clang_f_lto.c`:

  + : 'RUN: at line 117'
  + /var/llvm/local-amd64-debug-stage2/tools/clang/stage2-bins/bin/clang -### 
-flto -forder-file-instrumentation 
/vol/llvm/src/llvm-project/local/clang/test/Driver/clang_f_opts.c
  + /var/llvm/local-amd64-debug-stage2/tools/clang/stage2-bins/bin/FileCheck 
-check-prefix=CHECK-ORDERFILE-INSTR-LTO 
/vol/llvm/src/llvm-project/local/clang/test/Driver/clang_f_opts.c

- for `lto.c`, it's similar:

  + : 'RUN: at line 19'
  + /var/llvm/local-amd64-debug-stage2/tools/clang/stage2-bins/bin/clang 
/vol/llvm/src/llvm-project/local/clang/test/Driver/lto.c -flto -save-temps -###
  ro@niers 79 > 
/var/llvm/local-amd64-debug-stage2/tools/clang/stage2-bins/bin/clan

Manually re-running `clang` gives

  clang: error: 'amd64-pc-solaris2.11': unable to pass LLVM bit-code files to 
linker

in both cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156363

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


[PATCH] D156363: [Driver] -###: exit with code 1 if hasErrorOccurred

2023-08-02 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

It seems the latest commit of this patch has (re-)introduced two failures on 
the Solaris/amd64 buildbot 
:

  FAIL: Clang::clang_f_opts.c
  FAIL: Clang::lto.c

I cannot really make sense of that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156363

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


[PATCH] D156861: [Driver] Remove references to Solaris 12

2023-08-02 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added a subscriber: fedor.sergeev.
Herald added a project: All.
ro requested review of this revision.

Solaris 12 was re-christened as Solaris 11.4 while still in beta, so all 
references are long obsolete and can be removed.

Tested on `amd64-pc-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156861

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2407,13 +2407,11 @@
   if (TargetTriple.getOS() == llvm::Triple::Solaris) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
-"sparc-sun-solaris2.11", "sparc-sun-solaris2.12"};
+"sparc-sun-solaris2.11"};
 static const char *const SolarisSparcV9Triples[] = {
-"sparcv9-sun-solaris2.11", "sparcv9-sun-solaris2.12"};
-static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11",
-"i386-pc-solaris2.12"};
-static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11",
-   
"x86_64-pc-solaris2.12"};
+"sparcv9-sun-solaris2.11"};
+static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11"};
+static const char *const SolarisX86_64Triples[] = 
{"x86_64-pc-solaris2.11"};
 LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 switch (TargetTriple.getArch()) {


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2407,13 +2407,11 @@
   if (TargetTriple.getOS() == llvm::Triple::Solaris) {
 static const char *const SolarisLibDirs[] = {"/lib"};
 static const char *const SolarisSparcV8Triples[] = {
-"sparc-sun-solaris2.11", "sparc-sun-solaris2.12"};
+"sparc-sun-solaris2.11"};
 static const char *const SolarisSparcV9Triples[] = {
-"sparcv9-sun-solaris2.11", "sparcv9-sun-solaris2.12"};
-static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11",
-"i386-pc-solaris2.12"};
-static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11",
-   "x86_64-pc-solaris2.12"};
+"sparcv9-sun-solaris2.11"};
+static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11"};
+static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11"};
 LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
 switch (TargetTriple.getArch()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156325: [Driver] Link shared asan runtime lib with -z now on Solaris/x86

2023-07-27 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6b5149aa442e: [Driver] Link shared asan runtime lib with -z 
now on Solaris/x86 (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156325

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- clang/test/Driver/solaris-ld-sanitizer.c
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -49,3 +49,19 @@
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
 // CHECK-LD-X64-UBSAN: -zrelax=transtls
+
+/// General tests that the ld -z now workaround is only applied on
+/// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to
+/// make these tests independent of the host system.
+
+/// Check i386-pc-solaris2.11, 32bit, shared libclang_rt.asan
+// RUN: %clang -fsanitize=address -shared-libasan --target=i386-pc-solaris2.11 
%s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN-SHARED %s
+// CHECK-LD-X32-ASAN-SHARED: -znow
+
+/// Check i386-pc-solaris2.11, 32bit, static libclang_rt.asan
+// RUN: %clang -fsanitize=address --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN %s
+// CHECK-LD-X32-ASAN-NOT: -znow
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
 CmdArgs.push_back("-zrelax=transtls");
 }
+// Avoid AsanInitInternal cycle, Issue #64126.
+if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
+SA.needsAsanRt())
+  CmdArgs.push_back("-znow");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- clang/test/Driver/solaris-ld-sanitizer.c
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -49,3 +49,19 @@
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
 // CHECK-LD-X64-UBSAN: -zrelax=transtls
+
+/// General tests that the ld -z now workaround is only applied on
+/// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to
+/// make these tests independent of the host system.
+
+/// Check i386-pc-solaris2.11, 32bit, shared libclang_rt.asan
+// RUN: %clang -fsanitize=address -shared-libasan --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN-SHARED %s
+// CHECK-LD-X32-ASAN-SHARED: -znow
+
+/// Check i386-pc-solaris2.11, 32bit, static libclang_rt.asan
+// RUN: %clang -fsanitize=address --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN %s
+// CHECK-LD-X32-ASAN-NOT: -znow
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || 

[PATCH] D156325: [Driver] Link shared asan runtime lib with -z now on Solaris/x86

2023-07-27 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 544660.
ro added a comment.

Add testcases.

Re-tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156325

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- clang/test/Driver/solaris-ld-sanitizer.c
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -49,3 +49,19 @@
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
 // CHECK-LD-X64-UBSAN: -zrelax=transtls
+
+/// General tests that the ld -z now workaround is only applied on
+/// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to
+/// make these tests independent of the host system.
+
+/// Check i386-pc-solaris2.11, 32bit, shared libclang_rt.asan
+// RUN: %clang -fsanitize=address -shared-libasan --target=i386-pc-solaris2.11 
%s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN-SHARED %s
+// CHECK-LD-X32-ASAN-SHARED: -znow
+
+/// Check i386-pc-solaris2.11, 32bit, static libclang_rt.asan
+// RUN: %clang -fsanitize=address --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN %s
+// CHECK-LD-X32-ASAN-NOT: -znow
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
 CmdArgs.push_back("-zrelax=transtls");
 }
+// Avoid AsanInitInternal cycle, Issue #64126.
+if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
+SA.needsAsanRt())
+  CmdArgs.push_back("-znow");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- clang/test/Driver/solaris-ld-sanitizer.c
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -49,3 +49,19 @@
 // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
 // CHECK-LD-X64-UBSAN: -zrelax=transtls
+
+/// General tests that the ld -z now workaround is only applied on
+/// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to
+/// make these tests independent of the host system.
+
+/// Check i386-pc-solaris2.11, 32bit, shared libclang_rt.asan
+// RUN: %clang -fsanitize=address -shared-libasan --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN-SHARED %s
+// CHECK-LD-X32-ASAN-SHARED: -znow
+
+/// Check i386-pc-solaris2.11, 32bit, static libclang_rt.asan
+// RUN: %clang -fsanitize=address --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32-ASAN %s
+// CHECK-LD-X32-ASAN-NOT: -znow
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
 

[PATCH] D156325: [Driver] Link shared asan runtime lib with -z now on Solaris/x86

2023-07-27 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D156325#4537237 , @MaskRay wrote:

> This needs a clang/test/Driver test.

Indeed, I forgot.  Added now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156325

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


[PATCH] D156325: [Driver] Link shared asan runtime lib with -z now on Solaris/x86

2023-07-26 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: vitalybuka, MaskRay.
ro added a project: clang.
Herald added a subscriber: fedor.sergeev.
Herald added a project: All.
ro requested review of this revision.

As detailed in Issue #64126, several asan tests `FAIL` due to a cycle in 
`AsanInitInternal`.  This can by avoided by disabling lazy binding with `ld -z 
now`.

Tested on `amd64-pc-solaris2.11.`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156325

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp


Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
 CmdArgs.push_back("-zrelax=transtls");
 }
+// Avoid AsanInitInternal cycle, Issue #64126.
+if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
+SA.needsAsanRt())
+  CmdArgs.push_back("-znow");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,


Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
 CmdArgs.push_back("-zrelax=transtls");
 }
+// Avoid AsanInitInternal cycle, Issue #64126.
+if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
+SA.needsAsanRt())
+  CmdArgs.push_back("-znow");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141596: [Driver] Add crtfastmath.o on Solaris if appropriate

2023-01-13 Thread Rainer Orth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c4a70f8f6f3: [Driver] Add crtfastmath.o on Solaris if 
appropriate (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141596

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtfastmath.o
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtfastmath.o
  
clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64/crtfastmath.o
  
clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/crtfastmath.o
  clang/test/Driver/solaris-ld.c


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -114,3 +114,57 @@
 // CHECK-RELOCATABLE-NOT: "-l
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o
+
+// Check that crtfastmath.o is linked with -ffast-math.
+
+// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-SPARC32 %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-SPARC32 %s
+// CHECK-CRTFASTMATH-SPARC32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-SPARC32: 
"[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-SPARC32-NOT: crtfastmath.o
+
+// Check sparc-pc-solaris2.11, 64bit
+// RUN: %clang -m64 --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-SPARC64 %s
+// RUN: %clang -m64 --target=sparc-sun-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-SPARC64 %s
+// CHECK-CRTFASTMATH-SPARC64: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-SPARC64: 
"[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-SPARC64-NOT: crtfastmath.o
+
+// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang --target=i386-pc-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-X32 %s
+// RUN: %clang --target=i386-pc-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-X32 %s
+// CHECK-CRTFASTMATH-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-X32: 
"[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-X32-NOT: crtfastmath.o
+
+// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 --target=i386-pc-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-X64 %s
+// RUN: %clang -m64 --target=i386-pc-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-X64 %s
+// CHECK-CRTFASTMATH-X64: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-X64: 
"[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-X64-NOT: crtfastmath.o
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -115,6 +115,8 @@
 Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
+// Add crtfastmath.o if available and fast math is enabled.
+getToolChain().addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
 
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -114,3 +114,57 @@
 // CHECK-RELOCATABLE-NOT: "-l
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // 

[PATCH] D141596: [Driver] Add crtfastmath.o on Solaris if appropriate

2023-01-12 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: jrtc27, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

`Flang :: Driver/fast_math.f90` `FAIL`s on Solaris because `crtfastmath.o` is 
missing from the link line.

This patch adds it as appropriate.

Tested on `amd64-pc-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141596

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtfastmath.o
  
clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtfastmath.o
  
clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64/crtfastmath.o
  
clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/crtfastmath.o
  clang/test/Driver/solaris-ld.c


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -114,3 +114,57 @@
 // CHECK-RELOCATABLE-NOT: "-l
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o
+
+// Check that crtfastmath.o is linked with -ffast-math.
+
+// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-SPARC32 %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-SPARC32 %s
+// CHECK-CRTFASTMATH-SPARC32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-SPARC32: 
"[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-SPARC32-NOT: crtfastmath.o
+
+// Check sparc-pc-solaris2.11, 64bit
+// RUN: %clang -m64 --target=sparc-sun-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-SPARC64 %s
+// RUN: %clang -m64 --target=sparc-sun-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-SPARC64 %s
+// CHECK-CRTFASTMATH-SPARC64: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-SPARC64: 
"[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-SPARC64-NOT: crtfastmath.o
+
+// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang --target=i386-pc-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-X32 %s
+// RUN: %clang --target=i386-pc-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-X32 %s
+// CHECK-CRTFASTMATH-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-X32: 
"[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-X32-NOT: crtfastmath.o
+
+// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 --target=i386-pc-solaris2.11 -### %s \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOCRTFASTMATH-X64 %s
+// RUN: %clang -m64 --target=i386-pc-solaris2.11 -### %s -ffast-math \
+// RUN:--gcc-toolchain="" \
+// RUN:--sysroot=%S/Inputs/solaris_x86_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRTFASTMATH-X64 %s
+// CHECK-CRTFASTMATH-X64: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-CRTFASTMATH-X64: 
"[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64{{/|}}crtfastmath.o"
+// CHECK-NOCRTFASTMATH-X64-NOT: crtfastmath.o
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -115,6 +115,8 @@
 Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
+// Add crtfastmath.o if available and fast math is enabled.
+getToolChain().addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
 
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ 

[PATCH] D129156: Add -fpass-plugin option to Flang

2022-11-24 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D129156#3949194 , @awarzynski 
wrote:

> 



> Sorry that you are hitting this - things like this happen, sadly. I think 
> that the easiest to resolve it would be to tweak the expected error so that 
> it works on Solaris as well as other popular platforms. Given that you might 
> be the only person able to test on Solaris, would you be able to upload 
> something for  a review? Thanks!

No worries, especially given that this seems to be the first test ever to check 
the `Could not load library` error message.

I've just submitted a patch that works on Linux and Solaris (all that I can 
easily test): D138663 .


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

https://reviews.llvm.org/D129156

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


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-11-24 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

This introduced a new failure on Solaris:

  FAIL: Flang :: Driver/pass-plugin-not-found.f90

Running the failing command manually shows:

  error: unable to load plugin 'X.Y': 'Could not load library 'X.Y': ld.so.1: 
flang-new: X.Y: open failed: No such file or directory'

while the test currently expects

  error: unable to load plugin 'X.Y': 'Could not load library 'X.Y': X.Y: 
cannot open shared object file: No such file or directory'

This expectation is unjustified, I believe: the message is produced by 
`PassPlugin::Load` -> `sys::DynamicLibrary::getPermanentLibrary` -> 
`HandleSet::DLOpen` -> `::dlerror`.  Obviously the output of the last is 
system-dependent; I don't think we can put any requirements on it (maybe not 
even the exact wording of the `No such file or directory` part.


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

https://reviews.llvm.org/D129156

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


[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-10 Thread Rainer Orth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e56821bac02: [Linux] Hack around Linux/sparc 
bits/stdio-ldbl.h (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -874,6 +874,9 @@
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines 
-check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT -check-prefix SPARC-DEFAULT-CXX %s
 //
@@ -997,6 +1000,7 @@
 // SPARC:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
+// SPARC-LINUX:#define __NO_INLINE__ 1
 // SPARC:#define __POINTER_WIDTH__ 32
 // SPARC-DEFAULT:#define __PTRDIFF_TYPE__ int
 // SPARC-NETOPENBSD:#define __PTRDIFF_TYPE__ long int
@@ -1380,6 +1384,11 @@
 // SPARCV9:#define __SIZEOF_POINTER__ 8
 // SPARCV9:#define __UINTPTR_TYPE__ long unsigned int
 //
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc64-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC64-LINUX %s
+// SPARC64-LINUX:#define __NO_INLINE__ 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-openbsd < 
/dev/null | FileCheck -match-full-lines -check-prefix SPARC64-OBSD %s
 // SPARC64-OBSD:#define __INT64_TYPE__ long long int
 // SPARC64-OBSD:#define __INTMAX_C_SUFFIX__ LL
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,9 @@
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+// Work around Issue #47994 until glibc PR build/27558 is fixed.
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -874,6 +874,9 @@
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc-unknown-linux-gnu -O < /dev/null | FileCheck -match-full-lines -check-prefix SPARC-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT -check-prefix SPARC-DEFAULT-CXX %s
 //
@@ -997,6 +1000,7 @@
 // SPARC:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
+// SPARC-LINUX:#define __NO_INLINE__ 1
 // SPARC:#define __POINTER_WIDTH__ 32
 // SPARC-DEFAULT:#define __PTRDIFF_TYPE__ int
 // SPARC-NETOPENBSD:#define __PTRDIFF_TYPE__ long int
@@ -1380,6 +1384,11 @@
 // SPARCV9:#define __SIZEOF_POINTER__ 8
 // SPARCV9:#define __UINTPTR_TYPE__ long unsigned int
 //
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc64-unknown-linux-gnu -O < /dev/null | FileCheck -match-full-lines 

[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-09 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 459017.
ro added a comment.

Add comment, tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -874,6 +874,9 @@
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT %s
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines 
-check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix 
SPARC -check-prefix SPARC-DEFAULT -check-prefix SPARC-DEFAULT-CXX %s
 //
@@ -997,6 +1000,7 @@
 // SPARC:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
+// SPARC-LINUX:#define __NO_INLINE__ 1
 // SPARC:#define __POINTER_WIDTH__ 32
 // SPARC-DEFAULT:#define __PTRDIFF_TYPE__ int
 // SPARC-NETOPENBSD:#define __PTRDIFF_TYPE__ long int
@@ -1380,6 +1384,11 @@
 // SPARCV9:#define __SIZEOF_POINTER__ 8
 // SPARCV9:#define __UINTPTR_TYPE__ long unsigned int
 //
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc64-unknown-linux-gnu -O < /dev/null | 
FileCheck -match-full-lines -check-prefix SPARC64-LINUX %s
+// SPARC64-LINUX:#define __NO_INLINE__ 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-openbsd < 
/dev/null | FileCheck -match-full-lines -check-prefix SPARC64-OBSD %s
 // SPARC64-OBSD:#define __INT64_TYPE__ long long int
 // SPARC64-OBSD:#define __INTMAX_C_SUFFIX__ LL
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,9 @@
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+// Work around Issue #47994 until glibc PR build/27558 is fixed.
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -874,6 +874,9 @@
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc-unknown-linux-gnu -O < /dev/null | FileCheck -match-full-lines -check-prefix SPARC-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT -check-prefix SPARC-DEFAULT-CXX %s
 //
@@ -997,6 +1000,7 @@
 // SPARC:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
+// SPARC-LINUX:#define __NO_INLINE__ 1
 // SPARC:#define __POINTER_WIDTH__ 32
 // SPARC-DEFAULT:#define __PTRDIFF_TYPE__ int
 // SPARC-NETOPENBSD:#define __PTRDIFF_TYPE__ long int
@@ -1380,6 +1384,11 @@
 // SPARCV9:#define __SIZEOF_POINTER__ 8
 // SPARCV9:#define __UINTPTR_TYPE__ long unsigned int
 //
+// Check that clang defines __NO_INLINE__ unconditionally (even at -O) to
+// work around Issue #47994.
+// RUN: %clang_cc1 -E -dM -triple=sparc64-unknown-linux-gnu -O < /dev/null | FileCheck -match-full-lines -check-prefix SPARC64-LINUX %s
+// SPARC64-LINUX:#define __NO_INLINE__ 1
+//
 // RUN: %clang_cc1 -E 

[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-09 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D133405#3779190 , @MaskRay wrote:

> So, sparc64 gcc does seem to define the macro by default. (I am using Debian 
> testing and can't tell whether it's distro setting or upstream default) 
> ¯\_(ツ)_/¯
>
>   % sparc64-linux-gnu-gcc -E -dM -xc /dev/null -nostdinc | grep NO_INLINE
>   #define __NO_INLINE__ 1

True, as does `clang`.  However, both define it only at `-O0`.  This is common 
upstream behaviour in both cases.

The following reduced testcase demonstrates the issue:

  $ cat vfprintf-ldbl.c 
  struct _IO_FILE;
  typedef struct _IO_FILE FILE;
  extern FILE *stdout;
  typedef __builtin_va_list __gnuc_va_list;
  extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
 __gnuc_va_list __arg);
  extern int __inline __attribute__ ((__gnu_inline__))
  vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
  {
return vfprintf (stdout, __fmt, __arg);
  }
  extern __typeof (vfprintf) vfprintf __asm ("" "_nldbl" "vfprintf");

makes `clang` choke

  $ clang -c vfprintf-ldbl.c
  vfprintf-ldbl.c:12:28: error: cannot apply asm label to function after its 
first use
  extern __typeof (vfprintf) vfprintf __asm ("" "_nldbl" "vfprintf");
 ^   ~~
  1 error generated.

while gcc compiles this without issues.

> This needs a test in `clang/test/Preprocessor/init.c` (find `SPARC`) with a 
> comment linking to the canonical place to discuss the glibc problem 
> (@zatrazz).

Done now and tested on `sparcv9-sun-solaris2.11`.  Will also test on 
`sparc64-unknown-linux-gnu` once the currently running release build is 
finished (this box is **slow**).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

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


[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-08 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D133405#3776096 , @MaskRay wrote:

> It's not a compiler's job to define this workaround...

Yes and no: GCC successfully does it via its `fixincludes` mechanism.  
Unfortunately, LLVM doesn't provide something similar and doesn't even known 
about the GCC `include-fixed` directory, which could be used as a fallback.  
Sometimes OS headers **are** broken and remain so for a long time.  While one 
can throw hands up in disgust, this doesn't make the problem go away.  If I own 
the machine, I can patch/hack system headers as need be, but that's not an 
option on shared systems where I have to live with what's installed.

> If a platform want to provide a built-in macro, you can use 
> https://clang.llvm.org/docs/UsersManual.html#configuration-files and add 
> `-D__NO_INLINE__` there.
> To avoid magic behaviors, `${triple}-clang` loads `${triple}.cfg` while 
> `clang` doesn't (see 
> https://discourse.llvm.org/t/configuration-files/42529/24)

That's nice in some controlled circumstances where I can control e.g. the 
`clang` command used, but doesn't help in others like a release build with 
`test-release.sh` where I don't have that control.  I fully understand Jörg's 
argument in that thread that implicit changes from some hidden config 
file/environment variable are a maintenance nightmare and to be avoided at all 
cost.

> See also 
> https://discourse.llvm.org/t/rfc-adding-a-default-file-location-to-config-file-support/63606
>  (I am somewhat concerned with `clang` loading a config).
> But if you make `clang` a shell script that executes 
> `sparc64-pc-linux-gnu-clang` or the like, I think it should be fine.

Again, that would be ok for an installed `clang`, but while doing a release 
build, such a script wouldn't be used at all.

On top of all that, defining `__NO_INLINE__` globally to hack around a header 
bug is way too large a hammer: it has more effects than it should, which is why 
I called it a hack to allow making some progess at all, nothing to be included 
upstream.  I merely wanted to document what I'd changed in the Linux/sparc64 
release builds rather than only vaguely referring to my hack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133405

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


[PATCH] D133407: [Driver] Support non-canonical triples with new runtime lib layout

2022-09-07 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: StephenFan, abidh, jrtc27, fedor.sergeev, 
kristof.beyls, jyknight.
Herald added a project: All.
ro requested review of this revision.

This is the companion patch to D133406 , 
intended to get the ideas of `clang` of `compiler-rt` where runtime libs are 
located with `-DLLVM_ENABLE_RUNTIMES` in sync.  Both patches were necessary to 
run the release builds/tests for Solaris/amd64 and Linux/sparc64.

Tested on `amd64-pc-solaris2.11` and `sparc64-unknown-linux-gnu`.

This patch is **not** ready for prime time: right now it causes two regressions:

  Clang :: Driver/baremetal.cpp
  Clang :: Driver/print-libgcc-file-name-clangrt.c

where the patched driver uses `-triple thumbv7m-vendor-none-eabi` instead of 
the expected `armv7m-vendor-none-eabi`.  I have not yet tried to investigate 
this in detail, just wanted to get the patch out for reference.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133407

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/Scrt1.o
  clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/crti.o
  clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/crtn.o
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/crtbeginS.o
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/crtendS.o
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/libgcc.a
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/libgcc_s.so
  clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libc.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libdl.so
  clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libm.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libpthread.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libresolv.so
  
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/librt.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/sparcv9-unknown-linux-gnu/libclang_rt.ubsan_standalone.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-pc-solaris2.11/libclang_rt.ubsan_standalone.a
  clang/test/Driver/noncanon-per-target-runtime-dir.c
  clang/test/Driver/runtime-layout.c

Index: clang/test/Driver/runtime-layout.c
===
--- /dev/null
+++ clang/test/Driver/runtime-layout.c
@@ -0,0 +1,56 @@
+/// Check that clang's idea of runtime dir layout matches e.g. compiler-rt's.
+
+/// Classical runtime layout.
+// RUN: mkdir -p %t-classic/lib/sunos
+
+/// Canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+/// Non-canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=amd64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+/// Canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i386-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+/// Non-canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i686-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-classic \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-CLASSIC %s
+
+// RUNTIME-DIR-CLASSIC: {{.*}}/lib/sunos
+
+/// New runtime layout.
+
+// RUN: mkdir -p %t-runtime/lib/x86_64-pc-solaris2.11
+
+/// Canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-X86_64 %s
+
+/// Non-canonical triple, 64-bit.
+// RUN: %clang -print-runtime-dir --target=amd64-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-X86_64 %s
+
+// RUNTIME-DIR-X86_64: {{.*}}/lib/x86_64-pc-solaris2.11
+
+// RUN: mkdir -p %t-runtime/lib/i386-pc-solaris2.11
+
+/// Canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i386-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-I386 %s
+
+/// Non-canonical triple, 32-bit.
+// RUN: %clang -print-runtime-dir --target=i686-pc-solaris2.11 \
+// RUN:   -resource-dir=%t-runtime \
+// RUN:   | FileCheck --check-prefix=RUNTIME-DIR-I386 %s
+
+// RUNTIME-DIR-I386: {{.*}}/lib/i386-pc-solaris2.11
Index: clang/test/Driver/noncanon-per-target-runtime-dir.c
===
--- /dev/null
+++ clang/test/Driver/noncanon-per-target-runtime-dir.c
@@ -0,0 +1,20 @@
+/// 

[PATCH] D133405: [Linux] Hack around Linux/sparc

2022-09-07 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: glaubitz, MaskRay.
Herald added subscribers: StephenFan, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I've been using this hack to work around the Linux/sparc64 compile failure 
described in Issue #47994 , 
especially since the underlying glibc PR build/27558 
 doesn't seem to be 
making progress and some fix is required to have LLVM build on 
`sparc64-unknown-linux-gnu` at all, as evidenced on the buildbot.

I don't expect this patch to be commited, just posting for reference.

Tested on `sparc64-unknown-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133405

Files:
  clang/lib/Basic/Targets/OSTargets.h


Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,8 @@
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)


Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,8 @@
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+if (Triple.isSPARC())
+  Builder.defineMacro("__NO_INLINE__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130688: [Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux

2022-08-18 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D130688#3731653 , @glaubitz wrote:

> In D130688#3731619 , @ro wrote:
>
>> In D130688#3731611 , @glaubitz 
>> wrote:
>>
>>> 
>>
>>
>>
>>> Yeah, someone from the LEON community should comment whether they would be 
>>> OK to default to V9 on all Linux targets. I don't really want to omit 
>>> Gentoo here which still support Linux on SPARC.
>>
>> How could they?  LEON is V8 (with extensions) only!
>
> Well, they could patch LLVM locally. I assume they don't use the pristine 
> upstream sources anyway in such custom setups.

Why should they need to?  AFAICS all the LEON CPU support is upstream already, 
so why break upstream for them without need?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130688

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


[PATCH] D130688: [Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux

2022-08-18 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D130688#3731611 , @glaubitz wrote:

> 



> Yeah, someone from the LEON community should comment whether they would be OK 
> to default to V9 on all Linux targets. I don't really want to omit Gentoo 
> here which still support Linux on SPARC.

How could they?  LEON is V8 (with extensions) only!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130688

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


[PATCH] D130688: [Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux

2022-08-18 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

It's almost three weeks since the last comments.  Any suggestions on how to 
proceed with this patch?  Given that the original issue (atomics not inlined 
with `-m32`) is now worked around by always linking with `--as-needed -latomic 
--no-as-needed`, the patch is no longer needed to fix build failures.  However, 
it still would make a nice and cheap optimization on distros that require v9 
CPUs, if we can figure out how to reliably identify them.  Maybe someone from 
the LEON community could chime in?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130688

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


[PATCH] D130566: [Driver] Default to DWARF 4 on Linux/sparc64

2022-07-29 Thread Rainer Orth via Phabricator via cfe-commits
ro abandoned this revision.
ro added a comment.

Nick Clifton just commited a fix both to the binutils 2.39 branch and master.  
So the workaround certainly isn't necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130566

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


[PATCH] D130688: [Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux

2022-07-29 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D130688#3686512 , @MaskRay wrote:

> Making the behavior different for different Linux distributions is not great, 
> but if it matches the practice, I think it is fine.

It's the best we can do in `clang`, I fear, due to the compiler's desire to 
decide as much as possible at runtime.  GCC is way more static here, and 
whoever builds it can decide on the default CPU with `--with-cpu=v9` e.g. at 
configure time.

> I don't know Sparc enough to suggest anything for 32-bit, though...

An alternative would be to just check the host CPU with `getHostCPUName` as 
updated by D130272 .  That CPU name then 
needs to be checked if it supports the V9 ISA.  That could be done using 
`getCPUGeneration(CPU) == CG_V9` in `clang/lib/Basic/Targets/Sparc.h`.  
However, `SparcTargetInfo` (or `TargetInfo` in general) is not currently used 
inside the driver code.

Of course, this only works in the native case, but that's true for distro 
checks, too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130688

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


[PATCH] D130273: [clang][Driver] Handle SPARC -mcpu=native etc.

2022-07-29 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf3714884ae4: [clang][Driver] Handle SPARC -mcpu=native etc. 
(authored by ro).

Changed prior to commit:
  https://reviews.llvm.org/D130273?vs=448290=448529#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130273

Files:
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp
  clang/lib/Driver/ToolChains/Arch/Sparc.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/sparc-march.c
  clang/test/Driver/sparc-mcpu.c
  clang/test/Driver/sparc-mtune.c

Index: clang/test/Driver/sparc-mtune.c
===
--- /dev/null
+++ clang/test/Driver/sparc-mtune.c
@@ -0,0 +1,21 @@
+// RUN: %clang -target sparcv9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9 %s
+// SPARCV9: "-cc1"{{.*}} "-triple" "sparcv9"
+
+// RUN: %clang -target sparc64 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC64 %s
+// SPARC64: "-cc1"{{.*}} "-triple" "sparc64"
+
+// RUN: %clang -target sparcv9 -mtune=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_V9 %s
+// SPARCV9_V9: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-tune-cpu" "v9"
+
+// RUN: %clang -target sparcv9 -mtune=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_US %s
+// SPARCV9_US: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-tune-cpu" "ultrasparc"
+
+// RUN: %clang -target sparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC %s
+// SPARC: "-cc1"{{.*}} "-triple" "sparc"
+
+// RUN: %clang -target sparc -mtune=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_V9 %s
+// SPARC_V9: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-tune-cpu" "v9"
+
+// RUN: %clang -target sparc -mtune=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_US %s
+// SPARC_US: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-tune-cpu" "ultrasparc"
+
Index: clang/test/Driver/sparc-mcpu.c
===
--- /dev/null
+++ clang/test/Driver/sparc-mcpu.c
@@ -0,0 +1,21 @@
+// RUN: %clang -target sparcv9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9 %s
+// SPARCV9: "-cc1"{{.*}} "-triple" "sparcv9"
+
+// RUN: %clang -target sparc64 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC64 %s
+// SPARC64: "-cc1"{{.*}} "-triple" "sparc64"
+
+// RUN: %clang -target sparcv9 -mcpu=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_V9 %s
+// SPARCV9_V9: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-target-cpu" "v9"
+
+// RUN: %clang -target sparcv9 -mcpu=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_US %s
+// SPARCV9_US: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-target-cpu" "ultrasparc"
+
+// RUN: %clang -target sparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC %s
+// SPARC: "-cc1"{{.*}} "-triple" "sparc"
+
+// RUN: %clang -target sparc -mcpu=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_V9 %s
+// SPARC_V9: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-target-cpu" "v9"
+
+// RUN: %clang -target sparc -mcpu=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_US %s
+// SPARC_US: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-target-cpu" "ultrasparc"
+
Index: clang/test/Driver/sparc-march.c
===
--- /dev/null
+++ clang/test/Driver/sparc-march.c
@@ -0,0 +1,4 @@
+// RUN: %clang -target sparcv9 -march=v9 -### -c %s 2>&1 | FileCheck %s
+// RUN: %clang -target sparc64 -march=v9 -### -c %s 2>&1 | FileCheck %s
+// RUN: %clang -target sparc -march=v9 -### -c %s 2>&1 | FileCheck %s
+// CHECK: error: unsupported option '-march=' for target
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -12,6 +12,7 @@
 #include "Arch/M68k.h"
 #include "Arch/Mips.h"
 #include "Arch/PPC.h"
+#include "Arch/Sparc.h"
 #include "Arch/SystemZ.h"
 #include "Arch/VE.h"
 #include "Arch/X86.h"
@@ -431,15 +432,15 @@
 
   case llvm::Triple::bpfel:
   case llvm::Triple::bpfeb:
-  case llvm::Triple::sparc:
-  case llvm::Triple::sparcel:
-  case llvm::Triple::sparcv9:
 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
   return A->getValue();
-if (T.getArch() == llvm::Triple::sparc && T.isOSSolaris())
-  return "v9";
 return "";
 
+  case llvm::Triple::sparc:
+  case llvm::Triple::sparcel:
+  case llvm::Triple::sparcv9:
+return sparc::getSparcTargetCPU(D, Args, T);
+
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 return x86::getX86TargetCPU(D, Args, T);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2213,6 +2213,18 @@
 CmdArgs.push_back("-mfloat-abi");
 

[PATCH] D130569: [Driver] Use libatomic for 32-bit SPARC atomics support on Linux

2022-07-29 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9b1897bbd0e3: [Driver] Use libatomic for 32-bit SPARC 
atomics support on Linux (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130569

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/linux-ld.c


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1007,6 +1007,7 @@
 // CHECK-SPARCV8: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV8: "-m" "elf32_sparc"
 // CHECK-SPARCV8: "-dynamic-linker" 
"{{(/usr/sparc-unknown-linux-gnu)?}}/lib/ld-linux.so.2"
+// CHECK-SPARCV8: "--push-state" "--as-needed" "-latomic" "--pop-state"
 //
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=sparcel-unknown-linux-gnu \
@@ -1021,6 +1022,7 @@
 // CHECK-SPARCV9: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV9: "-m" "elf64_sparc"
 // CHECK-SPARCV9: "-dynamic-linker" 
"{{(/usr/sparcv9-unknown-linux-gnu)?}}/lib{{(64)?}}/ld-linux.so.2"
+// CHECK-SPARCV9-NOT: "-latomic"
 
 // Test linker invocation on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,16 @@
 
   AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+  // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+  // forcibly link with libatomic as a workaround.
+  // TODO: Issue #41880 and D118021.
+  if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+CmdArgs.push_back("--push-state");
+CmdArgs.push_back("--as-needed");
+CmdArgs.push_back("-latomic");
+CmdArgs.push_back("--pop-state");
+  }
+
   if (WantPthread && !isAndroid)
 CmdArgs.push_back("-lpthread");
 


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1007,6 +1007,7 @@
 // CHECK-SPARCV8: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV8: "-m" "elf32_sparc"
 // CHECK-SPARCV8: "-dynamic-linker" "{{(/usr/sparc-unknown-linux-gnu)?}}/lib/ld-linux.so.2"
+// CHECK-SPARCV8: "--push-state" "--as-needed" "-latomic" "--pop-state"
 //
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=sparcel-unknown-linux-gnu \
@@ -1021,6 +1022,7 @@
 // CHECK-SPARCV9: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV9: "-m" "elf64_sparc"
 // CHECK-SPARCV9: "-dynamic-linker" "{{(/usr/sparcv9-unknown-linux-gnu)?}}/lib{{(64)?}}/ld-linux.so.2"
+// CHECK-SPARCV9-NOT: "-latomic"
 
 // Test linker invocation on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,16 @@
 
   AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+  // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+  // forcibly link with libatomic as a workaround.
+  // TODO: Issue #41880 and D118021.
+  if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+CmdArgs.push_back("--push-state");
+CmdArgs.push_back("--as-needed");
+CmdArgs.push_back("-latomic");
+CmdArgs.push_back("--pop-state");
+  }
+
   if (WantPthread && !isAndroid)
 CmdArgs.push_back("-lpthread");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130688: [Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux

2022-07-28 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/Sparc.cpp:139
+  if (Triple.getArch() == llvm::Triple::sparc &&
+  (Triple.isOSSolaris() || Distro(D.getVFS(), Triple).IsDebian()))
 return "v9";

glaubitz wrote:
> Can we do it "IsLinux()" instead of "IsDebian()"?
> 
> I think Gentoo should profit from this change as well.
No, for the reason I mentioned: there are Linux distributions with SPARC 
support that **don't support SPARC v9**, like [[ 
https://www.gaisler.com/index.php/products/operating-systems/linux | LEON Linux 
]].  Solaris is easy here because it's v9-only.

LLVM explicitly has extensive LEON support, so we shouldn't break it there!

I don't really known which Linux distributions which are considered supported 
by current LLVM, have SPARC support at all and require v9 CPUs.  That's for the 
community to tell.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130688

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


[PATCH] D130566: [Driver] Default to DWARF 4 on Linux/sparc64

2022-07-28 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D130566#3682923 , @dblaikie wrote:

>> This is all extremely weird, but until the error shows up again, I'll put 
>> this patch on hold (not yet abandoning since there seems to be no way to 
>> unabandon if necessary).
>
> You can abandon and then "reclaim" the revision to reopen it and continue 
> work.

Ah, I missed that: the reclaim action is only offered for abandoned patches, I 
assume.  Thanks.

In D130566#3683174 , @MaskRay wrote:

> I accepted this because this seems a major showstopper and we want to resolve 
> it for the upcoming major release
> But I just recall that clang 14.0.0 has defaulted to DWARF v5 for most ELF 
> operating systems on all architectures, including Sparc.
> I think we need more justification to downgrade the DWARV version.

Fully agreed.  However, clang 14.0.0 was in a way worse shape on Debian/sparc64 
(wouldn't even build), so we wouldn't have noticed.  Solaris/sparcv9 wouldn't 
notice either since it uses the native linker, not GNU ld.

>> So far, I had only seen it with the GNU ld 2.38.50 bundled with Debian 
>> 11/sparc64, but couldn't reproduce on Ubuntu 20.04/x86_64 (neither bundled 
>> GNU ld 2.34, nor self-compiled 2.38.90)
>
> Thanks for the additional note. Seems worth investigating whether it is an 
> issue which should be addressed on GNU ld side.
> binutils 2.39 will be released on 2022-08-06 
> (https://sourceware.org/pipermail/binutils/2022-July/121656.html) and such a 
> regression style issue should be worked on quickly.

Indeed.  However, I won't be able to spend much time on this: Linux/sparc64 is 
only tangential to my work (as a vehicle to test SPARC patches where I want to 
make sure they don't break that target).  I've got enough to do testing 
binutils 2.39 on Solaris ;-)

That said, I've now filed binutils PR binutils PR ld/29424 
.  The binutils 
maintainers can now decide what the want to do about this, if anything.

> The binutils code does suggest it doesn't handle the DWARF v5 features, but I 
> am curious why older releases don't have the problem.

They might if one tried.  However, the bundled GNU ld is already 2.38.50.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130566

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


[PATCH] D130273: [clang][Driver] Handle SPARC -mcpu=native etc.

2022-07-28 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 448290.
ro marked 3 inline comments as done.
ro edited the summary of this revision.
ro added a comment.

- Incorporate review comments.
- Add testcases.
- Reject `-march`, matching GCC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130273

Files:
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp
  clang/lib/Driver/ToolChains/Arch/Sparc.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/sparc-march.c
  clang/test/Driver/sparc-mcpu.c
  clang/test/Driver/sparc-mtune.c

Index: clang/test/Driver/sparc-mtune.c
===
--- /dev/null
+++ clang/test/Driver/sparc-mtune.c
@@ -0,0 +1,21 @@
+// RUN: %clang -target sparcv9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9 %s
+// SPARCV9: "-cc1"{{.*}} "-triple" "sparcv9"
+
+// RUN: %clang -target sparc64 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC64 %s
+// SPARC64: "-cc1"{{.*}} "-triple" "sparc64"
+
+// RUN: %clang -target sparcv9 -mtune=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_V9 %s
+// SPARCV9_V9: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-tune-cpu" "v9"
+
+// RUN: %clang -target sparcv9 -mtune=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_US %s
+// SPARCV9_US: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-tune-cpu" "ultrasparc"
+
+// RUN: %clang -target sparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC %s
+// SPARC: "-cc1"{{.*}} "-triple" "sparc"
+
+// RUN: %clang -target sparc -mtune=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_V9 %s
+// SPARC_V9: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-tune-cpu" "v9"
+
+// RUN: %clang -target sparc -mtune=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_US %s
+// SPARC_US: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-tune-cpu" "ultrasparc"
+
Index: clang/test/Driver/sparc-mcpu.c
===
--- /dev/null
+++ clang/test/Driver/sparc-mcpu.c
@@ -0,0 +1,21 @@
+// RUN: %clang -target sparcv9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9 %s
+// SPARCV9: "-cc1"{{.*}} "-triple" "sparcv9"
+
+// RUN: %clang -target sparc64 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC64 %s
+// SPARC64: "-cc1"{{.*}} "-triple" "sparc64"
+
+// RUN: %clang -target sparcv9 -mcpu=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_V9 %s
+// SPARCV9_V9: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-target-cpu" "v9"
+
+// RUN: %clang -target sparcv9 -mcpu=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_US %s
+// SPARCV9_US: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-target-cpu" "ultrasparc"
+
+// RUN: %clang -target sparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC %s
+// SPARC: "-cc1"{{.*}} "-triple" "sparc"
+
+// RUN: %clang -target sparc -mcpu=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_V9 %s
+// SPARC_V9: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-target-cpu" "v9"
+
+// RUN: %clang -target sparc -mcpu=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_US %s
+// SPARC_US: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-target-cpu" "ultrasparc"
+
Index: clang/test/Driver/sparc-march.c
===
--- /dev/null
+++ clang/test/Driver/sparc-march.c
@@ -0,0 +1,4 @@
+// RUN: %clang -target sparcv9 -march=v9 -### -c %s 2>&1 | FileCheck %s
+// RUN: %clang -target sparc64 -march=v9 -### -c %s 2>&1 | FileCheck %s
+// RUN: %clang -target sparc -march=v9 -### -c %s 2>&1 | FileCheck %s
+// CHECK: error: unsupported option '-march=' for target
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -12,6 +12,7 @@
 #include "Arch/M68k.h"
 #include "Arch/Mips.h"
 #include "Arch/PPC.h"
+#include "Arch/Sparc.h"
 #include "Arch/SystemZ.h"
 #include "Arch/VE.h"
 #include "Arch/X86.h"
@@ -431,14 +432,14 @@
 
   case llvm::Triple::bpfel:
   case llvm::Triple::bpfeb:
+if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
+  return A->getValue();
+return "";
+
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel:
   case llvm::Triple::sparcv9:
-if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
-  return A->getValue();
-if (T.getArch() == llvm::Triple::sparc && T.isOSSolaris())
-  return "v9";
-return "";
+return sparc::getSparcTargetCPU(D, Args, T);
 
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2205,6 +2205,18 @@
 CmdArgs.push_back("-mfloat-abi");
 CmdArgs.push_back("hard");
   }
+
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
+

[PATCH] D130688: [Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux

2022-07-28 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: glaubitz, MaskRay, jrtc27.
ro added a project: clang.
Herald added subscribers: StephenFan, pengfei, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

This is the Debian/sparc64 equivalent of D86621 
: since that distro only supports SPARC V9 
CPUs, it should default to `-mcpu=v9`, among others to allow inlining of 
atomics even in 32-bit code.

Tested on `sparc64-pc-linux-gnu`, `sparcv9-sun-solaris2.11`, and 
`x86_64-pc-linux-gnu`.

There's currently one issue, though: while this is the right thing for 
Debian/sparc64 (I don't think Debian/sparc which ran on non-V9 CPUs is 
supported any longer), it's wrong for current Linux distributions for 32-bit 
CPUs (LEON Linux AFAIK, there may be others).  While the driver can 
distringuish between Debian and non-Debian distributions for that, I've found 
no way to do so in the testsuite.  Thus, 
`clang/test/Preprocessor/predefined-arch-macros.c` currently `FAIL`s the 
`CHECK_SPARC` tests: it needs to check for `__sparc_v9__` on Debian, but keep 
`__sparcv8` on others.  Any suggestions on how to handle this?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130688

Files:
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp


Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "Sparc.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -134,7 +135,8 @@
 return std::string(CPUName);
   }
 
-  if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
+  if (Triple.getArch() == llvm::Triple::sparc &&
+  (Triple.isOSSolaris() || Distro(D.getVFS(), Triple).IsDebian()))
 return "v9";
   return "";
 }


Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Sparc.h"
+#include "clang/Driver/Distro.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -134,7 +135,8 @@
 return std::string(CPUName);
   }
 
-  if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
+  if (Triple.getArch() == llvm::Triple::sparc &&
+  (Triple.isOSSolaris() || Distro(D.getVFS(), Triple).IsDebian()))
 return "v9";
   return "";
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130569: [Driver] Use libatomic for 32-bit SPARC atomics support on Linux

2022-07-28 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 448253.
ro marked 2 inline comments as done.
ro added a comment.

- Switch to `--push-state`/`--pop-state`.
- Add testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130569

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/linux-ld.c


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1007,6 +1007,7 @@
 // CHECK-SPARCV8: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV8: "-m" "elf32_sparc"
 // CHECK-SPARCV8: "-dynamic-linker" 
"{{(/usr/sparc-unknown-linux-gnu)?}}/lib/ld-linux.so.2"
+// CHECK-SPARCV8: "--push-state" "--as-needed" "-latomic" "--pop-state"
 //
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=sparcel-unknown-linux-gnu \
@@ -1021,6 +1022,7 @@
 // CHECK-SPARCV9: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV9: "-m" "elf64_sparc"
 // CHECK-SPARCV9: "-dynamic-linker" 
"{{(/usr/sparcv9-unknown-linux-gnu)?}}/lib{{(64)?}}/ld-linux.so.2"
+// CHECK-SPARCV9-NOT: "-latomic"
 
 // Test linker invocation on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,16 @@
 
   AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+  // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+  // forcibly link with libatomic as a workaround.
+  // TODO: Issue #41880 and D118021.
+  if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+CmdArgs.push_back("--push-state");
+CmdArgs.push_back("--as-needed");
+CmdArgs.push_back("-latomic");
+CmdArgs.push_back("--pop-state");
+  }
+
   if (WantPthread && !isAndroid)
 CmdArgs.push_back("-lpthread");
 


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1007,6 +1007,7 @@
 // CHECK-SPARCV8: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV8: "-m" "elf32_sparc"
 // CHECK-SPARCV8: "-dynamic-linker" "{{(/usr/sparc-unknown-linux-gnu)?}}/lib/ld-linux.so.2"
+// CHECK-SPARCV8: "--push-state" "--as-needed" "-latomic" "--pop-state"
 //
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=sparcel-unknown-linux-gnu \
@@ -1021,6 +1022,7 @@
 // CHECK-SPARCV9: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV9: "-m" "elf64_sparc"
 // CHECK-SPARCV9: "-dynamic-linker" "{{(/usr/sparcv9-unknown-linux-gnu)?}}/lib{{(64)?}}/ld-linux.so.2"
+// CHECK-SPARCV9-NOT: "-latomic"
 
 // Test linker invocation on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,16 @@
 
   AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+  // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+  // forcibly link with libatomic as a workaround.
+  // TODO: Issue #41880 and D118021.
+  if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+CmdArgs.push_back("--push-state");
+CmdArgs.push_back("--as-needed");
+CmdArgs.push_back("-latomic");
+CmdArgs.push_back("--pop-state");
+  }
+
   if (WantPthread && !isAndroid)
 CmdArgs.push_back("-lpthread");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130569: [Driver] Use libatomic for 32-bit SPARC atomics support on Linux

2022-07-28 Thread Rainer Orth via Phabricator via cfe-commits
ro marked 2 inline comments as done.
ro added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:634
 
+  // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+  // forcibly link with libatomic as a workaround.

MaskRay wrote:
> `// TODO ...` and attach a bug link
It's split between the original bug report and a patch review: I only noticed 
later (when `compiler-rt` started to make use of 64-bit atomics) that those 
aren't implemented by `clang -m32 -mcpu=v9`.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:637
+  if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+CmdArgs.push_back("--as-needed");
+CmdArgs.push_back("-latomic");

MaskRay wrote:
> Such --as-needed usage is a bit fragile if clang driver in the future passes 
> `--as-needed`  in the beginning. Better to use --push-state if you have a 
> not-too-old ld.
Good point: I initially fell into that trap in D130571 when I added 
`--as-needed -latomic --no-as-needed` to `SANITIZER_COMMON_LINK_FLAGS`: it got 
added early to the link line, before the objects using atomics, and had no 
effect.  Only then did Iearn that `target_link_libraries` accepts not only 
library names, but also linker flags.

As for `--push-state`, it was introduced in GNU `ld` 2.25 back in 2014, to it's 
save to assume it's present.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130569

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


[PATCH] D130566: [Driver] Default to DWARF 4 on Linux/sparc64

2022-07-27 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D130566#3681129 , @dblaikie wrote:

>> During a build on Debian 11/sparc64, several binaries fail to link with
>>
>>   /usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 
>> 0x23
>
> What's the linker doing parsing DWARF? Any idea what feature this is? And why 
> is it SPARC-specific? Or is it true of other targets on the same Debian 
> version?

I have no idea, actually.  The code in question is `bfd/dwarf2.c` 
(`read_attribute_value`), who's comment states:

  /* Read and fill in the value of attribute ATTR as described by FORM.
 Read data starting from INFO_PTR, but never at or beyond INFO_PTR_END.
 Returns an updated INFO_PTR taking into account the amount of data read.  
*/

So far, I had only seen it with the GNU `ld` 2.38.50 bundled with Debian 
11/sparc64, but couldn't reproduce on Ubuntu 20.04/x86_64 (neither bundled GNU 
`ld`  2.34, nor self-compiled 2.38.90).  Things got even weirder when I tried 
to create a minimal testcase for a binutils bug report: I'd initially seen the 
error when linking `Sanitizer-sparc-Test`.  However, at that time the link also 
failed due to D130571 .  I got the `unhandled 
FORM value` error several times, probably for several different input objects.  
However, when adding `-latomic` to the link, the link did succeed without 
issues.

I've since ran a full build with all pending patches, just without this one, 
and didn't see the DWARF error again.  This is all extremely weird, but until 
the error shows up again, I'll put this patch on hold (not yet abandoning since 
there seems to be no way to unabandon if necessary).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130566

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


[PATCH] D130566: [Driver] Default to DWARF 4 on Linux/sparc64

2022-07-26 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D130566#3679480 , @glaubitz wrote:

> Interesting and thanks for catching this! How did you discover this issue? Is 
> there any particular program that fails to build due to this issue?

Sure: many programs fail to link during `ninja check-all` for this problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130566

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


[PATCH] D130569: [Driver] Use libatomic for 32-bit SPARC atomics support on Linux [clang-linux-sparc-libatomic.patch, submitted 2022-07-26]

2022-07-26 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: glaubitz, jrtc27, MaskRay, efriedma.
ro added a project: clang.
Herald added subscribers: StephenFan, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

This is the Linux/sparc64 equivalent to D118021 
, necessary to provide an external 
implementation of atomics on 32-bit SPARC which LLVM cannot inline even with 
`-mcpu=v9` or an equivalent default.

Tested on `sparc64-unknown-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130569

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,14 @@
 
   AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+  // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+  // forcibly link with libatomic as a workaround.
+  if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+CmdArgs.push_back("--as-needed");
+CmdArgs.push_back("-latomic");
+CmdArgs.push_back("--no-as-needed");
+  }
+
   if (WantPthread && !isAndroid)
 CmdArgs.push_back("-lpthread");
 


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,14 @@
 
   AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+  // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+  // forcibly link with libatomic as a workaround.
+  if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+CmdArgs.push_back("--as-needed");
+CmdArgs.push_back("-latomic");
+CmdArgs.push_back("--no-as-needed");
+  }
+
   if (WantPthread && !isAndroid)
 CmdArgs.push_back("-lpthread");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130566: [Driver] Default to DWARF 4 on Linux/sparc64

2022-07-26 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: glaubitz, MaskRay.
ro added a project: clang.
Herald added subscribers: jsji, StephenFan, pengfei, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

During a build on Debian 11/sparc64, several binaries fail to link with

  /usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x23

`/usr/bin/ld` is `GNU ld (GNU Binutils for Debian) 2.38.50.20220707`.  `0x23 is 
`DW_FORM_rnglistx` which isn't handled even by GNU binutils master.  Building 
with `-gdwarf-4` avoids this.

Tested on `sparc64-unknown-linux-gnu`.

For comparison's sake, I've tried a build on Ubuntu 20.04/x86_64 with GNU `ld` 
2.38.90, which isn't affected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130566

Files:
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -325,7 +325,7 @@
 }
 
 unsigned Linux::GetDefaultDwarfVersion() const {
-  if (getTriple().isAndroid())
+  if (getTriple().isAndroid() || getTriple().isSPARC())
 return 4;
   return ToolChain::GetDefaultDwarfVersion();
 }


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -325,7 +325,7 @@
 }
 
 unsigned Linux::GetDefaultDwarfVersion() const {
-  if (getTriple().isAndroid())
+  if (getTriple().isAndroid() || getTriple().isSPARC())
 return 4;
   return ToolChain::GetDefaultDwarfVersion();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130273: [clang][Driver] Handle SPARC -mcpu=native etc.

2022-07-22 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D130273#3670623 , @MaskRay wrote:

> I notice that in gcc, -march/-mtune/-mcpu are handled in gcc/config/* and 
> every port may have somewhat different behaviors. E.g. x86 and aarch64 are 
> different (and I suspect x86 has the weird behavior).

Right: e.g. `gcc` on SPARC doesn't support `-march` at all.  I've made no 
changes to `clang` here, i.e. the option is silently ignored.  I believe it's 
important to keep that compatibility so `clang` command lines can be passed to 
`gcc` or vice versa.

> Have you checked that whether this matches GCC? We need some 
> clang/test/Driver tests for `"-cc1"{{.*}} "-target-cpu" "..."`

Not in every detail, especially since the `gcc` driver just passes `-mcpu` etc. 
on to `cc1` which handles them itself, so it's not really easy to see what 
happens.

I'll add some tests, though.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2226
+
+std::string TuneCPU;
+if (Name == "native")

MaskRay wrote:
> ```
> std::string TuneCPU(Name == "native" ? ... : ...)
> if (!TuneCPU.empty()) {
>   ...
> ```
I'm not sure about this: I tried that variant, but I don't really think it's 
clearer than what I have now:
```
std::string TuneCPU(Name == "native"
? std::string(llvm::sys::getHostCPUName()
: std::string(Name)));
```
My code was taken from `AddSystemZTargetArgs` directly below and it would seem 
a bit weird if they differ in style.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130273

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


[PATCH] D130273: [clang][Driver] Handle SPARC -mcpu=native etc.

2022-07-21 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: MaskRay, glaubitz, jrtc27.
ro added a project: clang.
Herald added subscribers: StephenFan, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

To make use of SPARC support in `getHostCPUName` as implemented by D130272 
, this patch uses it to handle `-mcpu=native` 
and `-mtune=native`.

Tested on `sparcv9-sun-solaris2.11` and checking that those options are passed 
on as `-target-cpu` resp. `-tune-cpu` as expected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130273

Files:
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp
  clang/lib/Driver/ToolChains/Arch/Sparc.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp

Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -12,6 +12,7 @@
 #include "Arch/M68k.h"
 #include "Arch/Mips.h"
 #include "Arch/PPC.h"
+#include "Arch/Sparc.h"
 #include "Arch/SystemZ.h"
 #include "Arch/VE.h"
 #include "Arch/X86.h"
@@ -431,14 +432,14 @@
 
   case llvm::Triple::bpfel:
   case llvm::Triple::bpfeb:
+if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
+  return A->getValue();
+return "";
+
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel:
   case llvm::Triple::sparcv9:
-if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
-  return A->getValue();
-if (T.getArch() == llvm::Triple::sparc && T.isOSSolaris())
-  return "v9";
-return "";
+return sparc::getSparcTargetCPU(D, Args, T);
 
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2219,6 +2219,21 @@
 CmdArgs.push_back("-mfloat-abi");
 CmdArgs.push_back("hard");
   }
+
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
+StringRef Name = A->getValue();
+
+std::string TuneCPU;
+if (Name == "native")
+  TuneCPU = std::string(llvm::sys::getHostCPUName());
+else
+  TuneCPU = std::string(Name);
+
+if (!TuneCPU.empty()) {
+  CmdArgs.push_back("-tune-cpu");
+  CmdArgs.push_back(Args.MakeArgString(TuneCPU));
+}
+  }
 }
 
 void Clang::AddSystemZTargetArgs(const ArgList ,
Index: clang/lib/Driver/ToolChains/Arch/Sparc.h
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.h
+++ clang/lib/Driver/ToolChains/Arch/Sparc.h
@@ -28,6 +28,9 @@
 
 FloatABI getSparcFloatABI(const Driver , const llvm::opt::ArgList );
 
+std::string getSparcTargetCPU(const Driver , const llvm::opt::ArgList ,
+  const llvm::Triple );
+
 void getSparcTargetFeatures(const Driver , const llvm::opt::ArgList ,
 std::vector );
 const char *getSparcAsmModeForCPU(llvm::StringRef Name,
Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -12,6 +12,7 @@
 #include "clang/Driver/Options.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -113,6 +114,28 @@
   return ABI;
 }
 
+std::string sparc::getSparcTargetCPU(const Driver , const ArgList ,
+ const llvm::Triple ) {
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
+StringRef CPUName = A->getValue();
+
+if (CPUName == "native") {
+  std::string CPU = std::string(llvm::sys::getHostCPUName());
+  if (!CPU.empty() && CPU != "generic")
+return CPU;
+  else
+return "";
+}
+
+return std::string(CPUName);
+  }
+
+  if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
+return "v9";
+  else
+return "";
+}
+
 void sparc::getSparcTargetFeatures(const Driver , const ArgList ,
std::vector ) {
   sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-22 Thread Rainer Orth via Phabricator via cfe-commits
ro abandoned this revision.
ro added a comment.

Superceded by D119829  and D120048 
.  If absolutely necessary, D120059 
 could be revived if Illumos cannot implement 
`dlpi_tls_modid`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D119829: [Driver] Support Solaris/amd64 GetTls

2022-02-22 Thread Rainer Orth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb1fc966d2e41: [Driver] Support Solaris/amd64 GetTls 
(authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119829

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- /dev/null
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -0,0 +1,51 @@
+/// General tests that the ld -z relax=transtls workaround is only applied
+/// on Solaris/amd64. Note that we use sysroot to make these tests
+/// independent of the host system.
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 
2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -m64 --target=sparc-sun-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -m64 -fsanitize=undefined --target=sparc-sun-solaris2.11 %s 
-### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
+// CHECK-LD-X64-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 
2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
+// CHECK-LD-X64-UBSAN: -zrelax=transtls
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -14,6 +14,8 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "clang/Driver/ToolChain.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -145,8 +147,18 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
-if (NeedsSanitizerDeps)
+if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
+
+  // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
+  // However, ld -z relax=transtls is available since Solaris 11.2, but not
+  // in Illumos.
+  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
+  if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
+  (SA.needsAsanRt() || SA.needsStatsRt() ||
+   (SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
+CmdArgs.push_back("-zrelax=transtls");
+}
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- /dev/null
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -0,0 +1,51 @@
+/// General tests that the ld -z relax=transtls workaround is only applied
+/// on Solaris/amd64. Note that we use sysroot to make these tests
+/// independent of the host system.
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// 

[PATCH] D119829: [Driver] Support Solaris/amd64 GetTls

2022-02-19 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 410083.
ro added a comment.

Testcase formatting improvements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119829

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- /dev/null
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -0,0 +1,51 @@
+/// General tests that the ld -z relax=transtls workaround is only applied
+/// on Solaris/amd64. Note that we use sysroot to make these tests
+/// independent of the host system.
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 
2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -m64 --target=sparc-sun-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -m64 -fsanitize=undefined --target=sparc-sun-solaris2.11 %s 
-### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 --target=i386-pc-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
+// CHECK-LD-X64-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 
2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
+// CHECK-LD-X64-UBSAN: -zrelax=transtls
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -14,6 +14,8 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "clang/Driver/ToolChain.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -145,8 +147,18 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
-if (NeedsSanitizerDeps)
+if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
+
+  // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
+  // However, ld -z relax=transtls is available since Solaris 11.2, but not
+  // in Illumos.
+  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
+  if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
+  (SA.needsAsanRt() || SA.needsStatsRt() ||
+   (SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
+CmdArgs.push_back("-zrelax=transtls");
+}
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {


Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- /dev/null
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -0,0 +1,51 @@
+/// General tests that the ld -z relax=transtls workaround is only applied
+/// on Solaris/amd64. Note that we use sysroot to make these tests
+/// independent of the host system.
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 32bit

[PATCH] D119829: [Driver] Support Solaris/amd64 GetTls

2022-02-19 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/test/Driver/solaris-ld-sanitizer.c:6
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang %s -### 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \

MaskRay wrote:
> The first line is now shorter. You can move --target= above.
> 
> For me, the number of lines of a test counts and sometimes compacter RUN 
> lines improve readability.
Depends: on long lines, crucial information can be harder to find.  I moved 
`--target=` up, but kept the distinguishing `-m64`/`-fsanitize=` in front.  
Unfortunately, that causes some of the lines to be longer than 80 characters.

However, the `--gcc-toolchain=` and `--sysroot=` lines could easily be joined.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119829

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


[PATCH] D119829: [Driver] Support Solaris/amd64 GetTls

2022-02-18 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 409881.
ro marked 2 inline comments as done.
ro added a comment.

Test fixes as per review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119829

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c

Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- /dev/null
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -0,0 +1,67 @@
+/// General tests that the ld -z relax=transtls workaround is only applied
+/// on Solaris/amd64. Note that we use sysroot to make these tests
+/// independent of the host system.
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang %s -### 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -fsanitize=undefined %s -### 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -m64 %s -### 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+/// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -m64 -fsanitize=undefined %s -### 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang %s -### 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang -fsanitize=undefined %s -### 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 %s -### 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
+// CHECK-LD-X64-NOT: -zrelax=transtls
+
+/// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -m64 -fsanitize=undefined %s -### 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
+// CHECK-LD-X64-UBSAN: -zrelax=transtls
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -14,6 +14,8 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "clang/Driver/ToolChain.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -145,8 +147,18 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
-if (NeedsSanitizerDeps)
+if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
+
+  // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
+  // However, ld -z relax=transtls is available since Solaris 11.2, but not
+  // in Illumos.
+  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
+  if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
+  (SA.needsAsanRt() || SA.needsStatsRt() ||
+   (SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
+CmdArgs.push_back("-zrelax=transtls");
+}
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119829: [Driver] Support Solaris/amd64 GetTls

2022-02-18 Thread Rainer Orth via Phabricator via cfe-commits
ro marked 2 inline comments as done.
ro added inline comments.



Comment at: clang/test/Driver/solaris-ld-sanitizer.c:1
+// General tests that the ld -z relax=transtls workaround is only applied
+// on Solaris/amd64. Note that we use sysroot to make these tests

MaskRay wrote:
> Optional: some folks prefer an alternative comment marker (`///` for C, `##` 
> for assembly, etc) for non-RUN non-CHECK comments. It makes the comments 
> stand out (they may render differently in an editor). Many tests have 
> check-prefix typos and if we teach lit or FileCheck to catch such typos, we 
> can let them skip `///` lines to avoid false positives.
Seems quite sensible: patch amended.



Comment at: clang/test/Driver/solaris-ld-sanitizer.c:6
+// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \

MaskRay wrote:
> Remove -no-canonical-prefixes . See some cleanup advice on D119309.
Done, as well as `-o %t.o`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119829

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


[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-17 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91605#3329375 , @ro wrote:

> 



> As an experiment, I've tried to use `GetStaticTlsBoundary` instead.  It does 
> indeed work on recent Solaris 11.4 and the resulting patch is at D120048 
> .  I'm pretty certain that support for 
> Solaris 11.3/Illumos which lack `dlpi_tls_modid` using `dlinfo(RTLD_SELF, 
> RTLD_DI_LINKMAP)` can be added on top of that one, unbreaking the Illumos 
> build.  This would avoid considerable duplication of the `dl_iterate_phdr` 
> code, which is certainly a nice benefit.  I'll experiment with that route 
> later.

Now posted as D120059 .  It this approach is 
acceptable, the series of D119829 , D120048 
, and D120059 
 will supercede this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-17 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91605#3322312 , @ro wrote:

> In D91605#3321554 , @MaskRay wrote:
>
>> `GetTls` is about the static TLS block size. It consists of the main 
>> executable's TLS, and initially loaded shared objects' TLS, `struct 
>> pthread`, and padding.
>> Solaris should be able to just use the code path like FreeBSD, Linux musl, 
>> and various unpopular architectures of Linux glibc:
>>
>>   #elif SANITIZER_FREEBSD || SANITIZER_LINUX
>> uptr align;
>> GetStaticTlsBoundary(addr, size, );
>
> Not unconditionally, unfortunally: as the comment above `GetSizeFromHdr` 
> explains, `dlpi_tls_modid` was only introduced in an update to Solaris 11.4 
> FCS (which is sort of a problem), but isn't present in 11.3 (don't reallly 
> care) and Illumos (this would break compilation for them).  OTOH my solution 
> is successfully being used in GCC's `libphobos` on Solaris 11.3, 11.4, and 
> most likely Illumos, too.  I'd rather not burn the Illumos bridge if it can 
> be avoided.

As an experiment, I've tried to use `GetStaticTlsBoundary` instead.  It does 
indeed work on recent Solaris 11.4 and the resulting patch is at D120048 
.  I'm pretty certain that support for 
Solaris 11.3/Illumos which lack `dlpi_tls_modid` using `dlinfo(RTLD_SELF, 
RTLD_DI_LINKMAP)` can be added on top of that one, unbreaking the Illumos 
build.  This would avoid considerable duplication of the `dl_iterate_phdr` 
code, which is certainly a nice benefit.  I'll experiment with that route later.

I know now why I did the present patch the way it is: `GetStaticTlsBoundary` 
was only introduced months after I submitted this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-15 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91605#3321556 , @MaskRay wrote:

> The Clang driver change should be in a separate patch with clang/test/Driver 
> tests.

Done now: D119829 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D119829: [Driver] Support Solaris/amd64 GetTls

2022-02-15 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: fedor.sergeev, jyknight.
ro requested review of this revision.

This is the driver part of D91605 , a 
workaround to allow direct calls to `__tls_get_addr` on Solaris/amd64.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

This adds a testcase to the original submission.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119829

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld-sanitizer.c

Index: clang/test/Driver/solaris-ld-sanitizer.c
===
--- /dev/null
+++ clang/test/Driver/solaris-ld-sanitizer.c
@@ -0,0 +1,67 @@
+// General tests that the ld -z relax=transtls workaround is only applied
+// on Solaris/amd64. Note that we use sysroot to make these tests
+// independent of the host system.
+
+// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+// Check sparc-sun-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
+// CHECK-LD-SPARC32-NOT: -zrelax=transtls
+
+// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+// Check sparc-sun-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
+// CHECK-LD-SPARC64-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 32bit
+// RUN: %clang -no-canonical-prefixes -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
+// CHECK-LD-X32-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
+// CHECK-LD-X64-NOT: -zrelax=transtls
+
+// Check i386-pc-solaris2.11, 64bit
+// RUN: %clang -no-canonical-prefixes -m64 -fsanitize=undefined %s -### -o %t.o 2>&1 \
+// RUN: --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_x86_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
+// CHECK-LD-X64-UBSAN: -zrelax=transtls
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -14,6 +14,8 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "clang/Driver/ToolChain.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -145,8 +147,18 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
-if (NeedsSanitizerDeps)
+if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
+
+  // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
+  // However, ld -z relax=transtls is available since Solaris 11.2, but not
+  // in Illumos.
+  const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
+  if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
+  (SA.needsAsanRt() || SA.needsStatsRt() ||
+   (SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
+CmdArgs.push_back("-zrelax=transtls");
+}
   }
 
   if 

[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-15 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91605#3321554 , @MaskRay wrote:

> `GetTls` is about the static TLS block size. It consists of the main 
> executable's TLS, and initially loaded shared objects' TLS, `struct pthread`, 
> and padding.
> Solaris should be able to just use the code path like FreeBSD, Linux musl, 
> and various unpopular architectures of Linux glibc:
>
>   #elif SANITIZER_FREEBSD || SANITIZER_LINUX
> uptr align;
> GetStaticTlsBoundary(addr, size, );

Not unconditionally, unfortunally: as the comment above `GetSizeFromHdr` 
explains, `dlpi_tls_modid` was only introduced in an update to Solaris 11.4 FCS 
(which is sort of a problem), but isn't present in 11.3 (don't reallly care) 
and Illumos (this would break compilation for them).  OTOH my solution is 
successfully being used in GCC's `libphobos` on Solaris 11.3, 11.4, and most 
likely Illumos, too.  I'd rather not burn the Illumos bridge if it can be 
avoided.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-14 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

@vitalybuka , @MaskRay could I persuade you to review the revision version 
which should be much less controversial and completely Solaris-specific?  
Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

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


[PATCH] D91605: [sanitizers] Implement GetTls on Solaris

2022-02-14 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 408389.
ro added a subscriber: nikic.
ro added a comment.

Since the build-time check for the `ld -z relax=transtls` option was met with 
massive resistance and was only necessary for Illumos anyway, this revision 
just uses it unconditionally.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

The Illumos community will have to provide a way to somehow distinguish the two 
OSes.  The configure triple is still the same, and the `uname -o` output 
(`Solaris` vs. `illumos` seems to be hardcoded in the `uname` command and not 
be available programmatically.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91605

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_solaris.h

Index: compiler-rt/lib/sanitizer_common/sanitizer_solaris.h
===
--- /dev/null
+++ compiler-rt/lib/sanitizer_common/sanitizer_solaris.h
@@ -0,0 +1,63 @@
+//===-- sanitizer_solaris.h -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of Sanitizer runtime. It contains Solaris-specific
+// definitions.
+//
+//===--===//
+
+#ifndef SANITIZER_SOLARIS_H
+#define SANITIZER_SOLARIS_H
+
+#include "sanitizer_internal_defs.h"
+
+#if SANITIZER_SOLARIS
+
+#include 
+
+namespace __sanitizer {
+
+// Beginning of declaration from OpenSolaris/Illumos
+// $SRC/cmd/sgs/include/rtld.h.
+struct Rt_map {
+  Link_map rt_public;
+  const char *rt_pathname;
+  ulong_t rt_padstart;
+  ulong_t rt_padimlen;
+  ulong_t rt_msize;
+  uint_t rt_flags;
+  uint_t rt_flags1;
+  ulong_t rt_tlsmodid;
+};
+
+// Structure matching the Solaris 11.4 struct dl_phdr_info used to determine
+// presence of dlpi_tls_modid field at runtime.  Cf. Solaris 11.4
+// dl_iterate_phdr(3C), Example 2.
+struct dl_phdr_info_test {
+  ElfW(Addr) dlpi_addr;
+  const char *dlpi_name;
+  const ElfW(Phdr) * dlpi_phdr;
+  ElfW(Half) dlpi_phnum;
+  u_longlong_t dlpi_adds;
+  u_longlong_t dlpi_subs;
+  size_t dlpi_tls_modid;
+  void *dlpi_tls_data;
+};
+
+struct TLS_index {
+  unsigned long ti_moduleid;
+  unsigned long ti_tlsoffset;
+};
+
+extern "C" void *__tls_get_addr(TLS_index *);
+
+}  // namespace __sanitizer
+
+#endif  // SANITIZER_SOLARIS
+
+#endif  // SANITIZER_SOLARIS_H
Index: compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
===
--- compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -27,6 +27,7 @@
 #include "sanitizer_linux.h"
 #include "sanitizer_placement_new.h"
 #include "sanitizer_procmaps.h"
+#include "sanitizer_solaris.h"
 
 #if SANITIZER_NETBSD
 #define _RTLD_SOURCE  // for __lwp_gettcb_fast() / __lwp_getprivate_fast()
@@ -62,6 +63,7 @@
 #endif
 
 #if SANITIZER_SOLARIS
+#include 
 #include 
 #include 
 #endif
@@ -444,6 +446,39 @@
   void **);
 #endif
 
+#if SANITIZER_SOLARIS
+// dlpi_tls_modid is only available since Solaris 11.4 SRU 10.  Use
+// dlinfo(RTLD_DI_LINKMAP) instead which works on both Solaris 11.3 and Illumos.
+
+static size_t main_tls_modid;
+
+int GetSizeFromHdr(struct dl_phdr_info *info, size_t size, void *data) {
+  const ElfW(Phdr) *hdr = info->dlpi_phdr;
+  const ElfW(Phdr) *last_hdr = hdr + info->dlpi_phnum;
+
+  // With the introduction of dlpi_tls_modid, the tlsmodid of the executable
+  // was changed to 1 to match other implementations.
+  if (size >= offsetof(dl_phdr_info_test, dlpi_tls_modid))
+main_tls_modid = 1;
+  else
+main_tls_modid = 0;
+
+  for (; hdr != last_hdr; ++hdr) {
+if (hdr->p_type == PT_TLS) {
+  Rt_map *map;
+
+  dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, );
+
+  if (map->rt_tlsmodid == main_tls_modid) {
+*(uptr *)data = hdr->p_memsz;
+return -1;
+  }
+}
+  }
+  return 0;
+}
+#endif  // SANITIZER_SOLARIS
+
 #if !SANITIZER_GO
 static void GetTls(uptr *addr, uptr *size) {
 #if SANITIZER_ANDROID
@@ -538,9 +573,15 @@
 }
   }
 #elif SANITIZER_SOLARIS
-  // FIXME
   *addr = 0;
   *size = 0;
+  // Find size (p_memsz) of TLS block of the main program.
+  dl_iterate_phdr(GetSizeFromHdr, size);
+
+  if (*size != 0) {
+TLS_index ti = {(unsigned long)main_tls_modid, 0};
+*addr = (uptr)__tls_get_addr();
+  }
 #else
 #error "Unknown OS"
 #endif
Index: clang/lib/Driver/ToolChains/Solaris.cpp

[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-10 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6afa9e6b0d9: [Driver] Use libatomic for 32-bit SPARC 
atomics support (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld.c


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -17,6 +17,7 @@
 // CHECK-LD-SPARC32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-SPARC32-SAME: "-zignore" "-latomic" "-zrecord"
 // CHECK-LD-SPARC32-SAME: "-lgcc_s"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
@@ -40,6 +41,7 @@
 // CHECK-LD-SPARC64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9"
 // CHECK-LD-SPARC64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../../sparcv9"
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/lib/sparcv9"
+// CHECK-LD-SPARC64-NOT:  "-latomic"
 // CHECK-LD-SPARC64-SAME: "-lgcc_s"
 // CHECK-LD-SPARC64-SAME: "-lc"
 // CHECK-LD-SPARC64-SAME: "-lgcc"
@@ -63,6 +65,7 @@
 // CHECK-LD-X32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4"
 // CHECK-LD-X32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/../../.."
 // CHECK-LD-X32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-X32-NOT:  "-latomic"
 // CHECK-LD-X32-SAME: "-lgcc_s"
 // CHECK-LD-X32-SAME: "-lc"
 // CHECK-LD-X32-SAME: "-lgcc"
@@ -86,6 +89,7 @@
 // CHECK-LD-X64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64"
 // CHECK-LD-X64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/../../../amd64"
 // CHECK-LD-X64-SAME: "-L[[SYSROOT]]/usr/lib/amd64"
+// CHECK-LD-X64-NOT:  "-latomic"
 // CHECK-LD-X64-SAME: "-lgcc_s"
 // CHECK-LD-X64-SAME: "-lc"
 // CHECK-LD-X64-SAME: "-lgcc"
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@
   CmdArgs.push_back("-lssp_nonshared");
   CmdArgs.push_back("-lssp");
 }
+// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+// forcibly link with libatomic as a workaround.
+if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), true));
+  CmdArgs.push_back("-latomic");
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), false));
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -117,6 +117,8 @@
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+const char *getAsNeededOption(const ToolChain , bool as_needed);
+
 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList );
 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList );
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -756,7 +756,7 @@
   return false;
 }
 
-static const char *getAsNeededOption(const ToolChain , bool as_needed) {
+const char *tools::getAsNeededOption(const ToolChain , bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
 


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -17,6 +17,7 @@
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-SPARC32-SAME: "-zignore" "-latomic" "-zrecord"
 // CHECK-LD-SPARC32-SAME: "-lgcc_s"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
@@ -40,6 +41,7 @@
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9"
 // CHECK-LD-SPARC64-SAME: 

[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-10 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/test/Driver/solaris-ld.c:46
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/lib/sparcv9"
+// CHECK-LD-SPARC64-NOT:  "-zignore"
+// CHECK-LD-SPARC64-NOT:  "-latomic"

ro wrote:
> MaskRay wrote:
> > Such NOT patterns are usually inadequate and may go stale pretty easily, 
> > since technically the patterns can occur in many places.
> > 
> > One idea is to use --implicit-check-not; another is to enumerate all 
> > options and use the `{{^}}` style I picked in linux-cross.cpp, but perhaps 
> > your style is good enough if we can remember these library after after -L 
> > and before -lgcc_s
> > Such NOT patterns are usually inadequate and may go stale pretty easily, 
> > since technically the patterns can occur in many places.
> 
> I wondered so myself: while this is currently the only instance of 
> `-zignore`/`-zrecord`, `-lgcc_s` requires similar treatment.
> 
> > One idea is to use --implicit-check-not; another is to enumerate all 
> > options and use the `{{^}}` style I picked in linux-cross.cpp, but perhaps 
> > your style is good enough if we can remember these library after after -L 
> > and before -lgcc_s
> 
> I'll check those.  However, it occured to me that the crucial check is that 
> `-latomic` isn't added at all, `-zignore`/`-zrecord` or no, so maybe just 
> check for that and avoid the issue for the moment.
In the end, I've decided to go for the simple `*-NOT: "-latomic" form: it's 
simple and robust, which is all the more important since this patch needs to go 
into the `release/14.x` branch, too.

Going forward, I thing going for the `linux-cross.cpp` style is best.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

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


[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-10 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 407455.
ro marked an inline comment as done.
ro added a comment.

Simplify test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld.c


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -17,6 +17,7 @@
 // CHECK-LD-SPARC32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-SPARC32-SAME: "-zignore" "-latomic" "-zrecord"
 // CHECK-LD-SPARC32-SAME: "-lgcc_s"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
@@ -40,6 +41,7 @@
 // CHECK-LD-SPARC64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9"
 // CHECK-LD-SPARC64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../../sparcv9"
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/lib/sparcv9"
+// CHECK-LD-SPARC64-NOT:  "-latomic"
 // CHECK-LD-SPARC64-SAME: "-lgcc_s"
 // CHECK-LD-SPARC64-SAME: "-lc"
 // CHECK-LD-SPARC64-SAME: "-lgcc"
@@ -63,6 +65,7 @@
 // CHECK-LD-X32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4"
 // CHECK-LD-X32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/../../.."
 // CHECK-LD-X32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-X32-NOT:  "-latomic"
 // CHECK-LD-X32-SAME: "-lgcc_s"
 // CHECK-LD-X32-SAME: "-lc"
 // CHECK-LD-X32-SAME: "-lgcc"
@@ -86,6 +89,7 @@
 // CHECK-LD-X64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64"
 // CHECK-LD-X64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/../../../amd64"
 // CHECK-LD-X64-SAME: "-L[[SYSROOT]]/usr/lib/amd64"
+// CHECK-LD-X64-NOT:  "-latomic"
 // CHECK-LD-X64-SAME: "-lgcc_s"
 // CHECK-LD-X64-SAME: "-lc"
 // CHECK-LD-X64-SAME: "-lgcc"
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@
   CmdArgs.push_back("-lssp_nonshared");
   CmdArgs.push_back("-lssp");
 }
+// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+// forcibly link with libatomic as a workaround.
+if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), true));
+  CmdArgs.push_back("-latomic");
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), false));
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -117,6 +117,8 @@
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+const char *getAsNeededOption(const ToolChain , bool as_needed);
+
 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList );
 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList );
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -756,7 +756,7 @@
   return false;
 }
 
-static const char *getAsNeededOption(const ToolChain , bool as_needed) {
+const char *tools::getAsNeededOption(const ToolChain , bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
 


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -17,6 +17,7 @@
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-SPARC32-SAME: "-zignore" "-latomic" "-zrecord"
 // CHECK-LD-SPARC32-SAME: "-lgcc_s"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
@@ -40,6 +41,7 @@
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9"
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../../sparcv9"
 // CHECK-LD-SPARC64-SAME: 

[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-10 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added inline comments.



Comment at: clang/test/Driver/solaris-ld.c:20
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-SPARC32-SAME: "-zignore"
+// CHECK-LD-SPARC32-SAME: "-latomic"

MaskRay wrote:
> If they are consecutive.
The are, patch amended.



Comment at: clang/test/Driver/solaris-ld.c:46
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/lib/sparcv9"
+// CHECK-LD-SPARC64-NOT:  "-zignore"
+// CHECK-LD-SPARC64-NOT:  "-latomic"

MaskRay wrote:
> Such NOT patterns are usually inadequate and may go stale pretty easily, 
> since technically the patterns can occur in many places.
> 
> One idea is to use --implicit-check-not; another is to enumerate all options 
> and use the `{{^}}` style I picked in linux-cross.cpp, but perhaps your style 
> is good enough if we can remember these library after after -L and before 
> -lgcc_s
> Such NOT patterns are usually inadequate and may go stale pretty easily, 
> since technically the patterns can occur in many places.

I wondered so myself: while this is currently the only instance of 
`-zignore`/`-zrecord`, `-lgcc_s` requires similar treatment.

> One idea is to use --implicit-check-not; another is to enumerate all options 
> and use the `{{^}}` style I picked in linux-cross.cpp, but perhaps your style 
> is good enough if we can remember these library after after -L and before 
> -lgcc_s

I'll check those.  However, it occured to me that the crucial check is that 
`-latomic` isn't added at all, `-zignore`/`-zrecord` or no, so maybe just check 
for that and avoid the issue for the moment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

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


[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-09 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 407120.
ro added a comment.

Add tests in `solaris-ld.c`.

Spot-checked by running the single test with `llvm-lit` on 
`sparcv9-sun-solaris2.11`,
`amd64-solaris2.11`, and `x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/Driver/solaris-ld.c


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -17,6 +17,9 @@
 // CHECK-LD-SPARC32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-SPARC32-SAME: "-zignore"
+// CHECK-LD-SPARC32-SAME: "-latomic"
+// CHECK-LD-SPARC32-SAME: "-zrecord"
 // CHECK-LD-SPARC32-SAME: "-lgcc_s"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
@@ -40,6 +43,9 @@
 // CHECK-LD-SPARC64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9"
 // CHECK-LD-SPARC64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../../sparcv9"
 // CHECK-LD-SPARC64-SAME: "-L[[SYSROOT]]/usr/lib/sparcv9"
+// CHECK-LD-SPARC64-NOT:  "-zignore"
+// CHECK-LD-SPARC64-NOT:  "-latomic"
+// CHECK-LD-SPARC64-NOT:  "-zrecord"
 // CHECK-LD-SPARC64-SAME: "-lgcc_s"
 // CHECK-LD-SPARC64-SAME: "-lc"
 // CHECK-LD-SPARC64-SAME: "-lgcc"
@@ -63,6 +69,9 @@
 // CHECK-LD-X32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4"
 // CHECK-LD-X32-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/../../.."
 // CHECK-LD-X32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-X32-NOT:  "-zignore"
+// CHECK-LD-X32-NOT:  "-latomic"
+// CHECK-LD-X32-NOT:  "-zrecord"
 // CHECK-LD-X32-SAME: "-lgcc_s"
 // CHECK-LD-X32-SAME: "-lc"
 // CHECK-LD-X32-SAME: "-lgcc"
@@ -86,6 +95,9 @@
 // CHECK-LD-X64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64"
 // CHECK-LD-X64-SAME: 
"-L[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/../../../amd64"
 // CHECK-LD-X64-SAME: "-L[[SYSROOT]]/usr/lib/amd64"
+// CHECK-LD-X64-NOT:  "-zignore"
+// CHECK-LD-X64-NOT:  "-latomic"
+// CHECK-LD-X64-NOT:  "-zrecord"
 // CHECK-LD-X64-SAME: "-lgcc_s"
 // CHECK-LD-X64-SAME: "-lc"
 // CHECK-LD-X64-SAME: "-lgcc"
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@
   CmdArgs.push_back("-lssp_nonshared");
   CmdArgs.push_back("-lssp");
 }
+// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+// forcibly link with libatomic as a workaround.
+if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), true));
+  CmdArgs.push_back("-latomic");
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), false));
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -117,6 +117,8 @@
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+const char *getAsNeededOption(const ToolChain , bool as_needed);
+
 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList );
 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList );
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -756,7 +756,7 @@
   return false;
 }
 
-static const char *getAsNeededOption(const ToolChain , bool as_needed) {
+const char *tools::getAsNeededOption(const ToolChain , bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
 


Index: clang/test/Driver/solaris-ld.c
===
--- clang/test/Driver/solaris-ld.c
+++ clang/test/Driver/solaris-ld.c
@@ -17,6 +17,9 @@
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2"
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/../../.."
 // CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-SPARC32-SAME: "-zignore"
+// 

[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-09 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D118021#3307079 , @MaskRay wrote:

> This needs some tests, otherwise there is a risk that others may break your 
> changes when refactoring driver code.

I thought it would be enough that any breakage there would cause a large number 
of test failures.  But it's certainly better to avoid problems up from rather 
than reacting afterwards.

> The style I favor most is `test/Driver/linux-cross.cpp`. freebsd.c is not too 
> bad. linux-ld.c is somewhat messy but can give you some idea what to test.
> I'll add a note that zignore isn't tested and that is a problem.

It seemed easiest to add to `solaris-ld.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

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


[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-09 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

Ping^2.  It would be great if this could be reviewed/commited soon: it fixes 
hundreds of testsuite failures, so I'd like to get it into LLVM 14.

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

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


[PATCH] D91607: [clang][Sparc] Fix __builtin_extract_return_addr etc.

2022-02-02 Thread Rainer Orth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGefdd0a29b7eb: [clang][Sparc] Fix 
__builtin_extract_return_addr etc. (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91607

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/builtins-sparc.c


Index: clang/test/CodeGen/builtins-sparc.c
===
--- clang/test/CodeGen/builtins-sparc.c
+++ clang/test/CodeGen/builtins-sparc.c
@@ -1,10 +1,29 @@
 // REQUIRES: sparc-registered-target
 // RUN: %clang_cc1 -triple sparc-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
-// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | 
FileCheck -check-prefix CHECK-V9 %s
 
 void test_eh_return_data_regno(void)
 {
   volatile int res;
-  res = __builtin_eh_return_data_regno(0);  // CHECK: store volatile i32 24
-  res = __builtin_eh_return_data_regno(1);  // CHECK: store volatile i32 25
+  res = __builtin_eh_return_data_regno(0);  // CHECK,CHECKV9: store volatile 
i32 24
+  res = __builtin_eh_return_data_regno(1);  // CHECK,CHECKV9: store volatile 
i32 25
+}
+
+void *test_extract_return_address(void)
+{
+  // CHECK,CHECKV9: getelementptr i8, i8* %0, i32 8
+  return __builtin_extract_return_addr(__builtin_return_address(0));
+}
+
+struct s {
+  void *p;
+};
+
+struct s test_extract_struct_return_address(void)
+{
+  struct s s;
+  // CHECK:getelementptr i8, i8* %0, i32 12
+  // CHECK-V9: getelementptr i8, i8* %0, i32 8
+  s.p = __builtin_extract_return_addr(__builtin_return_address(0));
+  return s;
 }
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9474,6 +9474,28 @@
 public:
   SparcV8TargetCodeGenInfo(CodeGenTypes )
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+int Offset;
+if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+  Offset = 12;
+else
+  Offset = 8;
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, Offset));
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+int Offset;
+if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+  Offset = -12;
+else
+  Offset = -8;
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, Offset));
+  }
 };
 } // end anonymous namespace
 
@@ -9748,6 +9770,18 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
llvm::Value *Address) const override;
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, 8));
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, -8));
+  }
 };
 } // end anonymous namespace
 


Index: clang/test/CodeGen/builtins-sparc.c
===
--- clang/test/CodeGen/builtins-sparc.c
+++ clang/test/CodeGen/builtins-sparc.c
@@ -1,10 +1,29 @@
 // REQUIRES: sparc-registered-target
 // RUN: %clang_cc1 -triple sparc-unknown-unknown -emit-llvm %s -o - | FileCheck %s
-// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix CHECK-V9 %s
 
 void test_eh_return_data_regno(void)
 {
   volatile int res;
-  res = __builtin_eh_return_data_regno(0);  // CHECK: store volatile i32 24
-  res = __builtin_eh_return_data_regno(1);  // CHECK: store volatile i32 25
+  res = __builtin_eh_return_data_regno(0);  // CHECK,CHECKV9: store volatile i32 24
+  res = __builtin_eh_return_data_regno(1);  // CHECK,CHECKV9: store volatile i32 25
+}
+
+void *test_extract_return_address(void)
+{
+  // CHECK,CHECKV9: getelementptr i8, i8* %0, i32 8
+  return __builtin_extract_return_addr(__builtin_return_address(0));
+}
+
+struct s {
+  void *p;
+};
+
+struct s test_extract_struct_return_address(void)
+{
+  struct s s;
+  // CHECK:getelementptr i8, i8* %0, i32 12
+  // CHECK-V9: getelementptr i8, i8* %0, i32 8
+  s.p = 

[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-01 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

Ping? It's been a week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

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


[PATCH] D91607: [clang][Sparc] Fix __builtin_extract_return_addr etc.

2022-02-01 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 404939.
ro added a comment.
Herald added a subscriber: jrtc27.

- Use `CreateGEP`
- Add testcase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91607

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/builtins-sparc.c


Index: clang/test/CodeGen/builtins-sparc.c
===
--- clang/test/CodeGen/builtins-sparc.c
+++ clang/test/CodeGen/builtins-sparc.c
@@ -1,10 +1,29 @@
 // REQUIRES: sparc-registered-target
 // RUN: %clang_cc1 -triple sparc-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
-// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | 
FileCheck -check-prefix CHECK-V9 %s
 
 void test_eh_return_data_regno(void)
 {
   volatile int res;
-  res = __builtin_eh_return_data_regno(0);  // CHECK: store volatile i32 24
-  res = __builtin_eh_return_data_regno(1);  // CHECK: store volatile i32 25
+  res = __builtin_eh_return_data_regno(0);  // CHECK,CHECKV9: store volatile 
i32 24
+  res = __builtin_eh_return_data_regno(1);  // CHECK,CHECKV9: store volatile 
i32 25
+}
+
+void *test_extract_return_address(void)
+{
+  // CHECK,CHECKV9: getelementptr i8, i8* %0, i32 8
+  return __builtin_extract_return_addr(__builtin_return_address(0));
 }
+
+struct s {
+  void *p;
+};
+
+struct s test_extract_struct_return_address(void)
+{
+  struct s s;
+  // CHECK:getelementptr i8, i8* %0, i32 12
+  // CHECK-V9: getelementptr i8, i8* %0, i32 8
+  s.p = __builtin_extract_return_addr(__builtin_return_address(0));
+  return s;
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9472,6 +9472,28 @@
 public:
   SparcV8TargetCodeGenInfo(CodeGenTypes )
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+int Offset;
+if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+  Offset = 12;
+else
+  Offset = 8;
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, Offset));
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+int Offset;
+if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+  Offset = -12;
+else
+  Offset = -8;
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, Offset));
+  }
 };
 } // end anonymous namespace
 
@@ -9746,6 +9768,18 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
llvm::Value *Address) const override;
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, 8));
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override {
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, -8));
+  }
 };
 } // end anonymous namespace
 


Index: clang/test/CodeGen/builtins-sparc.c
===
--- clang/test/CodeGen/builtins-sparc.c
+++ clang/test/CodeGen/builtins-sparc.c
@@ -1,10 +1,29 @@
 // REQUIRES: sparc-registered-target
 // RUN: %clang_cc1 -triple sparc-unknown-unknown -emit-llvm %s -o - | FileCheck %s
-// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix CHECK-V9 %s
 
 void test_eh_return_data_regno(void)
 {
   volatile int res;
-  res = __builtin_eh_return_data_regno(0);  // CHECK: store volatile i32 24
-  res = __builtin_eh_return_data_regno(1);  // CHECK: store volatile i32 25
+  res = __builtin_eh_return_data_regno(0);  // CHECK,CHECKV9: store volatile i32 24
+  res = __builtin_eh_return_data_regno(1);  // CHECK,CHECKV9: store volatile i32 25
+}
+
+void *test_extract_return_address(void)
+{
+  // CHECK,CHECKV9: getelementptr i8, i8* %0, i32 8
+  return __builtin_extract_return_addr(__builtin_return_address(0));
 }
+
+struct s {
+  void *p;
+};
+
+struct s test_extract_struct_return_address(void)
+{
+  struct s s;
+  // CHECK:getelementptr i8, i8* %0, i32 12
+  // CHECK-V9: getelementptr i8, i8* %0, i32 8
+  s.p = __builtin_extract_return_addr(__builtin_return_address(0));
+  

[PATCH] D91607: [clang][Sparc] Fix __builtin_extract_return_addr etc.

2022-02-01 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91607#3285825 , @efriedma wrote:

> In D91607#3283350 , @ro wrote:
>
>> In D91607#3280808 , @efriedma wrote:
>>
>>> Testcase?
>>
>> I thought the 3 testcases adjusted in D91608 
>>  to use `__builtin_extract_return_addr` and 
>> fixed by this patch were enough.  Otherwise, should I just augment 
>> `clang/test/CodeGen/builtins-sparc.c` or better create a new test?
>
> I'd prefer to have coverage in the clang regression tests, so developers can 
> catch regressions and easily check the expected codegen.  builtins-sparc.c is 
> fine.

Understood: this way you don't rely on native builds and can test SPARC V8 
structure return which isn't exercised by the sanitzer tests.

>>> Do you need to ptrtoint/inttoptr?  I would expect that the address is an 
>>> `i8*`, so you can just GEP an appropriate number of bytes.
>>
>> TBH, I know practically nothing about LLVM codegen, so I rely heavily on 
>> guidance.  IIRC this patch was developed by searching for similar code in 
>> `TargetInfo.cpp` and modifying it until it did what I needed.  Is this the 
>> place to read on GEP ?
>
> That's a good starting place for understanding the complexity of GEP... but 
> you don't need that much here. Here, we just want to pass a single index; 
> that's equivalent to pointer addition in C.
>
> You should be able to just drop the calls to CreatePtrToInt and 
> CreateIntToPtr, and replace CreateAdd with CreateGEP.

Cool: I'd been struggling with `CreateConstInBoundsByteGEP` which seemed what I 
need, but had me fighting with conversion between `llvm::Value *` and `Address`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91607

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


[PATCH] D91607: [clang][Sparc] Fix __builtin_extract_return_addr etc.

2022-01-31 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D91607#3280808 , @efriedma wrote:

> Testcase?

I thought the 3 testcases adjusted in D91608  
to use `__builtin_extract_return_addr` and fixed by this patch were enough.  
Otherwise, should I just augment `clang/test/CodeGen/builtins-sparc.c` or 
better create a new test?

> Do you need to ptrtoint/inttoptr?  I would expect that the address is an 
> `i8*`, so you can just GEP an appropriate number of bytes.

TBH, I know practically nothing about LLVM codegen, so I rely heavily on 
guidance.  IIRC this patch was developed by searching for similar code in 
`TargetInfo.cpp` and modifying it until it did what I needed.  Is this the 
place to read on GEP ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91607

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


[PATCH] D91607: [clang][Sparc] Fix __builtin_extract_return_addr etc.

2022-01-28 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

Ping.  This hasn't been reviewed in more than a year and is still required for 
D91608 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91607

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


[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-01-27 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 403607.
ro marked an inline comment as done.
ro added a comment.

Omit `sanitizer_atomic_clang.h` part, belongs to D118021 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Solaris.cpp


Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@
   CmdArgs.push_back("-lssp_nonshared");
   CmdArgs.push_back("-lssp");
 }
+// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+// forcibly link with libatomic as a workaround.
+if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), true));
+  CmdArgs.push_back("-latomic");
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), false));
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -114,6 +114,8 @@
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+const char *getAsNeededOption(const ToolChain , bool as_needed);
+
 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList );
 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList );
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -737,7 +737,7 @@
   return false;
 }
 
-static const char *getAsNeededOption(const ToolChain , bool as_needed) {
+const char *tools::getAsNeededOption(const ToolChain , bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
 


Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@
   CmdArgs.push_back("-lssp_nonshared");
   CmdArgs.push_back("-lssp");
 }
+// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+// forcibly link with libatomic as a workaround.
+if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), true));
+  CmdArgs.push_back("-latomic");
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), false));
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -114,6 +114,8 @@
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+const char *getAsNeededOption(const ToolChain , bool as_needed);
+
 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList );
 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList );
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -737,7 +737,7 @@
   return false;
 }
 
-static const char *getAsNeededOption(const ToolChain , bool as_needed) {
+const char *tools::getAsNeededOption(const ToolChain , bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118021: [Driver] Use libatomic for 32-bit SPARC atomics support

2022-01-27 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 403604.
ro added a comment.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

- Clarify comment.
- Use `__ATOMIC_SEQ_CST`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Solaris.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h


Index: compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
===
--- compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
@@ -74,13 +74,8 @@
 inline bool atomic_compare_exchange_strong(volatile T *a, typename T::Type 
*cmp,
typename T::Type xchg,
memory_order mo) {
-  typedef typename T::Type Type;
-  Type cmpv = *cmp;
-  Type prev;
-  prev = __sync_val_compare_and_swap(>val_dont_use, cmpv, xchg);
-  if (prev == cmpv) return true;
-  *cmp = prev;
-  return false;
+  return __atomic_compare_exchange(>val_dont_use, cmp, , false, mo,
+   __ATOMIC_SEQ_CST);
 }
 
 template
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@
   CmdArgs.push_back("-lssp_nonshared");
   CmdArgs.push_back("-lssp");
 }
+// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+// forcibly link with libatomic as a workaround.
+if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), true));
+  CmdArgs.push_back("-latomic");
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), false));
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -114,6 +114,8 @@
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+const char *getAsNeededOption(const ToolChain , bool as_needed);
+
 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList );
 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList );
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -737,7 +737,7 @@
   return false;
 }
 
-static const char *getAsNeededOption(const ToolChain , bool as_needed) {
+const char *tools::getAsNeededOption(const ToolChain , bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
 


Index: compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
===
--- compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
@@ -74,13 +74,8 @@
 inline bool atomic_compare_exchange_strong(volatile T *a, typename T::Type *cmp,
typename T::Type xchg,
memory_order mo) {
-  typedef typename T::Type Type;
-  Type cmpv = *cmp;
-  Type prev;
-  prev = __sync_val_compare_and_swap(>val_dont_use, cmpv, xchg);
-  if (prev == cmpv) return true;
-  *cmp = prev;
-  return false;
+  return __atomic_compare_exchange(>val_dont_use, cmp, , false, mo,
+   __ATOMIC_SEQ_CST);
 }
 
 template
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@
   CmdArgs.push_back("-lssp_nonshared");
   CmdArgs.push_back("-lssp");
 }
+// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+// forcibly link with libatomic as a workaround.
+if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), true));
+  CmdArgs.push_back("-latomic");
+  CmdArgs.push_back(getAsNeededOption(getToolChain(), false));
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===

  1   2   3   >