[clang] [compiler-rt] [libcxx] [llvm] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)

2024-07-31 Thread Rainer Orth via cfe-commits

rorth wrote:

Both bots are working again: thanks for the quick fix.

https://github.com/llvm/llvm-project/pull/96171
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [libcxx] [llvm] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)

2024-07-31 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke the 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/120/builds/485) and 
[Solaris/sparcv9](https://lab.llvm.org/buildbot/#/builders/13/builds/1287) 
buildbots.

https://github.com/llvm/llvm-project/pull/96171
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Have getTargetSubDirPath better match get_compiler_rt_target (PR #100091)

2024-07-31 Thread Rainer Orth via cfe-commits


@@ -766,9 +766,19 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 return {};
   };
 
-  if (auto Path = getPathForTriple(getTriple()))
+  llvm::Triple Triple = getTriple();
+
+  // Try triple as is.
+  if (auto Path = getPathForTriple(Triple))
 return *Path;
 
+  // Match transformations in CompilerRTUtils.cmake:get_compiler_rt_target.

rorth wrote:

It's not, some BSDs prefer the `amd64` form, too.  Besides, 
`get_compiler_rt_target` does it unconditionally, so `clang` should match.

https://github.com/llvm/llvm-project/pull/100091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Have getTargetSubDirPath better match get_compiler_rt_target (PR #100091)

2024-07-29 Thread Rainer Orth via cfe-commits

https://github.com/rorth milestoned 
https://github.com/llvm/llvm-project/pull/100091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Rainer Orth via cfe-commits

https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/100724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Rainer Orth via cfe-commits

rorth wrote:

Right, as is it's just a ugly hack with the underlying problem like to rear its 
ugly head again in the future.

https://github.com/llvm/llvm-project/pull/100724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Rainer Orth via cfe-commits

rorth wrote:

> > Whatever the case, we need at least a short-term solution now: the Solaris 
> > buildbots have been broken for two days now.
> 
> Agreed that we need something in the short term, I'm just trying to find the 
> cleanest "something" under the assumption that this hack will live for a long 
> time. That's why I was hoping we could shove this into CMake somewhere (it's 
> less in everyone's face than the current approach). If we can't do that, then 
> I can live with this approach.

I just don't see how this can be done.  And TBH rather than pile hack upon 
hack, I'd rather spend some time on duplicating what GCC already does in Clang. 
 This will require tons and tons of guidance, though.

> Note: precommit CI failures look unrelated.

I think so: I've seen the same failure in my Linux/x86_64 but not on Solaris.

https://github.com/llvm/llvm-project/pull/100724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Rainer Orth via cfe-commits

rorth wrote:

> Thank you for helping out with this odd edge case! I don't suppose there's a 
> way we can shove this hack into CMake (basically, like a kind of linker 
> script hack)? If so, can we apply it broadly enough so that any use of 
> `time_put` in other TUs will also benefit?

This would have to apply to all instances of `std::tm`, so I cannot say if this 
is feasible at all.  Besides, `clang` on Solaris supports both Solaris `ld` and 
GNU `ld`, which have different linker script syntax, duplicating the code if in 
fact both support the renaming.

This all seems like a waste of time to me.

> (If there are better alternatives than this approach, I'd love to hear about 
> them, this is a pretty gnarly way to go about working around the issue.)

I believe `clang` should something like `g++` to handle the mangling difference 
itself.  On the `g++` side of things, there's the 
`TARGET_CXX_DECL_MANGLING_CONTEXT` target hook, implemented for Solaris in 
`gcc/config/sol2-cxx.cc` (`solaris_cxx_decl_mangling_context`) and applied in 
`gcc/cp/mangle.cc` (`decl_mangling_context`) where it is called as 
`targetm.cxx.decl_mangling_context`.

As I've mentioned before, I've no idea where to do something similar in 
`clang`.  I believe that would be `clang/lib/CodeGen`

Whatever the case, we need at least a short-term solution now: the Solaris 
buildbots have been broken for two days now.


https://github.com/llvm/llvm-project/pull/100724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Rainer Orth via cfe-commits

https://github.com/rorth created 
https://github.com/llvm/llvm-project/pull/100724

The introduction of `std::put_time` in
fad17b43dbc09ac7e0a95535459845f72c2b739a broke the Solaris build:
```
Undefined   first referenced
 symbol in file
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPKSt2tmPKcSB_
 lib/libclangLex.a(PPMacroExpansion.cpp.o)
ld: fatal: symbol referencing errors
```
As discussed in PR #99075, the problem is that GCC mangles `std::tm` as `tm` on 
Solaris for binary compatility, while `clang` doesn't (Issue #33114).

As a stop-gap measure, this patch introduces an `asm` level alias to the same 
effect.

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

>From 139569a6e48ceda0adc9fa8ca8e2d5d238f0712a Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Fri, 26 Jul 2024 11:15:16 +0200
Subject: [PATCH] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp

The introduction of `std::put_time` in
fad17b43dbc09ac7e0a95535459845f72c2b739a broke the Solaris build:
```
Undefined   first referenced
 symbol in file
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPKSt2tmPKcSB_
 lib/libclangLex.a(PPMacroExpansion.cpp.o)
ld: fatal: symbol referencing errors
```
As discussed in PR #99075, the problem is that GCC mangles `std::tm` as
`tm` on Solaris for binary compatility, while `clang` doesn't (Issue

As a stop-gap measure, this patch introduces an `asm` level alias to the
same effect.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Lex/PPMacroExpansion.cpp | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 879f01e87806e..1e31fcc3d731e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1604,6 +1604,16 @@ static bool isTargetVariantEnvironment(const TargetInfo 
,
   return false;
 }
 
+#if defined(__sun__) && defined(__svr4__)
+// GCC mangles std::tm as tm for binary compatibility on Solaris (Issue
+// #33114).  We need to match this to allow the std::put_time calls to link
+// (PR #99075).
+asm("_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
+"RSt8ios_basecPKSt2tmPKcSB_ = "
+"_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
+"RSt8ios_basecPK2tmPKcSB_");
+#endif
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token ) {

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


[clang] [clang] replaced the usage of `asctime` with `std::put_time` (PR #99075)

2024-07-26 Thread Rainer Orth via cfe-commits

rorth wrote:

> > At least in the short term. ISTM that `clang++` may need to do something 
> > along the lines of Bug 33767 (resp. the underlying GCC bug/patch), 
> > otherwise users are in for a nasty surprise.
> 
> Agreed; long-term we need a better solution. Hopefully someone maintaining 
> Solaris support can step in and help there, because this is quite surprising 
> behavior.

The cleaned-up hack is in the final rounds of testing.  Wlll create a PR once 
that's done.

There's no real Solaris maintainer AFAIK: while I do run the buildbots and try 
to keep the port in shape as time allows, I can only do so much.  The Solaris 
GCC maintainership takes enough of my time and splitting it would only be to 
the detriment of both projects.

TBH, I wouldn't even know where to look: I've mostly dealt with `compiler-rt` 
and driver issues so far.

https://github.com/llvm/llvm-project/pull/99075
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] replaced the usage of `asctime` with `std::put_time` (PR #99075)

2024-07-25 Thread Rainer Orth via cfe-commits

rorth wrote:

At least in the short term.  ISTM that `clang++` may need to do something along 
the lines of Bug 33767 (resp. the underlying GCC bug/patch), otherwise users 
are in for a nasty surprise.

https://github.com/llvm/llvm-project/pull/99075
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] replaced the usage of `asctime` with `std::put_time` (PR #99075)

2024-07-25 Thread Rainer Orth via cfe-commits

rorth wrote:

> If you dump the symbols from the STL shared library on the system, is there 
> one for `time_put` at all? If so, what is the mangled symbol it exports?

While the source requires
```
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPKSt2tmPKcSB_

std::time_put > 
>::put(std::ostreambuf_iterator >, std::ios_base&, 
char, std::tm const*, char const*, char const*) const
```
`libstdc++.so.6` only provides
```
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPK2tmPKcSB_

std::time_put > 
>::put(std::ostreambuf_iterator >, std::ios_base&, 
char, tm const*, char const*, char const*) const
```
i.e. `tm const *` instead of `std::tm const *`.
> 
> (As a perhaps terrible idea, could we use the `alias` attribute on a 
> redeclaration to try to force to link against the correct mangling for 
> Solaris only?)

A hack along the lines of
```
asm("_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPKSt2tmPKcSB_
 = 
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPK2tmPKcSB_");
```
at least allows `clang` to link.

https://github.com/llvm/llvm-project/pull/99075
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] replaced the usage of `asctime` with `std::put_time` (PR #99075)

2024-07-25 Thread Rainer Orth via cfe-commits

rorth wrote:

> Aha!
> 
> https://bugs.llvm.org/show_bug.cgi?id=33767

Ah, old sins (from the GCC side no less) keep haunting me.

> We have a mixture of both `std::tm` and `::tm` in here, try switching to 
> using `::tm` and see if that helps.

Unfortunately not: I always get the undefined reference to the `std::tm const 
*` version, no matter what I tried.

https://github.com/llvm/llvm-project/pull/99075
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] replaced the usage of `asctime` with `std::put_time` (PR #99075)

2024-07-24 Thread Rainer Orth via cfe-commits

rorth wrote:

This seems to have broken the 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/120/builds/187) and 
[Solaris/sparcv9](https://lab.llvm.org/buildbot/#/builders/13/builds/1030) 
buildbots.

https://github.com/llvm/llvm-project/pull/99075
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Have getTargetSubDirPath better match get_compiler_rt_target (PR #100091)

2024-07-23 Thread Rainer Orth via cfe-commits

https://github.com/rorth created 
https://github.com/llvm/llvm-project/pull/100091

As explained in [[Driver] Support non-canonical triples with new runtime lib 
layout](https://reviews.llvm.org/D133407), there are massive problems if 
`clang`'s and `compiler-rt`'s ideas of the target triple don't match. This can 
happen e.g. on Solaris/amd64 (`amd64-pc-solaris2.11`, `amd64` being the 
customary name of 64-bit x86 on that target) or Linux/sparc64 
(`sparc64-unknown-linux-gnu`, where `config.sub` returns the `sparc64` form by 
default).

While some adjustments have been made in `compiler-rt` ([[compiler-rt] Handle 
non-canonical triples with new runtime lib
layout](https://reviews.llvm.org/D133406)), the `clang` side is still unfixed 
and the previous patch doesn't work any longer.

As the stop-gap measure, this patch takes two of the adjustments made in 
`CompilerRTUtils.cmake` (`get_compiler_rt_target`) and applies them to 
`ToolChain.cpp` (`getTargetSubDirPath`) which currently takes the target triple 
as is, creating a mismatch between `clang`s idea of the layout of 
`lib/clang//` and where `compiler-rt` actually installs the 
runtime libs.

The tests had to be trimmed massively because `clang -print-runtime-dir` lies 
since PR #87866: when the runtime libs are installed in the projects/classic 
layout, `clang` still emits the nonexisting runtimes layout.

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

>From 4513f179765b432305bf79c71f691fcbb3fdc264 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Tue, 23 Jul 2024 11:36:07 +0200
Subject: [PATCH] [Driver] Have getTargetSubDirPath better match
 get_compiler_rt_target

As explained in [[Driver] Support non-canonical triples with new runtime
lib layout](https://reviews.llvm.org/D133407), there are massive problems
if `clang`'s and `compiler-rt`'s ideas of the target triple don't match.
This can happen e.g. on Solaris/amd64 (`amd64-pc-solaris2.11`, `amd64`
being the customary name of 64-bit x86 on that target) or Linux/sparc64
(`sparc64-unknown-linux-gnu`, where `config.sub` returns the `sparc64` form
by default).

While some adjustments have been made in `compiler-rt` ([[compiler-rt]
Handle non-canonical triples with new runtime lib
layout](https://reviews.llvm.org/D133406)), the `clang` side is still
unfixed and the previous patch doesn't work any longer.

As the stop-gap measure, this patch takes two of the adjustments made in
`CompilerRTUtils.cmake` (`get_compiler_rt_target`) and applies them to
`ToolChain.cpp` (`getTargetSubDirPath`) which currently takes the target
triple as is, creating a mismatch between `clang`s idea of the layout of
`lib/clang//` and where `compiler-rt` actually installs the
runtime libs.

The tests had to be trimmed massively because `clang -print-runtime-dir`
lies since PR #87866: when the runtime libs are installed in the
projects/classic layout, `clang` still emits the nonexisting runtimes
layout.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.
---
 clang/lib/Driver/ToolChain.cpp| 25 -
 .../lib/sparc64-linux-gnu/Scrt1.o |  0
 .../lib/sparc64-linux-gnu/crti.o  |  0
 .../lib/sparc64-linux-gnu/crtn.o  |  0
 .../lib/gcc/sparc64-linux-gnu/12/crtbeginS.o  |  0
 .../lib/gcc/sparc64-linux-gnu/12/crtendS.o|  0
 .../usr/lib/gcc/sparc64-linux-gnu/12/libgcc.a |  0
 .../lib/gcc/sparc64-linux-gnu/12/libgcc_s.so  |  0
 .../usr/lib/sparc64-linux-gnu/libc.so |  0
 .../usr/lib/sparc64-linux-gnu/libdl.so|  0
 .../usr/lib/sparc64-linux-gnu/libm.so |  0
 .../usr/lib/sparc64-linux-gnu/libpthread.so   |  0
 .../usr/lib/sparc64-linux-gnu/libresolv.so|  0
 .../usr/lib/sparc64-linux-gnu/librt.so|  0
 .../libclang_rt.ubsan_standalone.a|  0
 .../libclang_rt.ubsan_standalone.a|  0
 .../Driver/noncanon-per-target-runtime-dir.c  | 20 +++
 clang/test/Driver/runtime-layout.c| 35 +++
 18 files changed, 72 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/Scrt1.o
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/crti.o
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/lib/sparc64-linux-gnu/crtn.o
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/crtbeginS.o
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/crtendS.o
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/libgcc.a
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/gcc/sparc64-linux-gnu/12/libgcc_s.so
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libc.so
 create mode 100644 
clang/test/Driver/Inputs/debian_sparc64_tree/usr/lib/sparc64-linux-gnu/libdl.so
 create mode 100644 

[clang] [clang][Driver] Fix safestack -u ordering (PR #98468)

2024-07-11 Thread Rainer Orth via cfe-commits

https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/98468
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Fix safestack -u ordering (PR #98468)

2024-07-11 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch was already approved in [ [safestack] Various Solaris fixes #98001 
](https://github.com/llvm/llvm-project/pull/98001), therefore I'll commit it 
shortly.

https://github.com/llvm/llvm-project/pull/98468
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Fix safestack -u ordering (PR #98468)

2024-07-11 Thread Rainer Orth via cfe-commits

https://github.com/rorth created https://github.com/llvm/llvm-project/pull/98468

When re-enabling safestack testing on Solaris after the unexplained 
b0260c5b1052f8e3ff1ec77dc42a11f42da762cc, all tests `FAIL`ed to link:

```
Undefined   first referenced
 symbol in file
__safestack_unsafe_stack_ptrbuffer-copy-vla.o
__safestack_init(command line)
ld: fatal: symbol referencing errors
```

The problem is that `-u __safestack_init` was passed to the linker after the 
corresponding version of `libclang_rt.safestack-*.a`.  Since the Solaris linker 
(like Unix linkers for decades) respects the command line argument order 
(unlike e.g. GNU ld which uses GNU getopt), this cannot work.  Fixed by moving 
the `-u` arg further to the front.  Two affected testcases were fixed 
accordingly.

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

>From 88dfd3a550b50333d782a192c19a1e5418ecdf6d Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 11 Jul 2024 13:41:01 +0200
Subject: [PATCH] [clang][Driver] Fix safestack -u ordering

When re-enabling safestack testing on Solaris after the unexplained
b0260c5b1052f8e3ff1ec77dc42a11f42da762cc, all tests `FAIL`ed to link:

```
Undefined   first referenced
 symbol in file
__safestack_unsafe_stack_ptrbuffer-copy-vla.o
__safestack_init(command line)
ld: fatal: symbol referencing errors
```

The problem is that `-u __safestack_init` was passed to the linker after
the corresponding version of `libclang_rt.safestack-*.a`.  Since the
Solaris linker (like Unix linkers for decades) respects the command line
argument order (unlike e.g. GNU ld which uses GNU getopt), this cannot
work.  Fixed by moving the `-u` arg further to the front.  Two affected
testcases were fixed accordingly.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`,
`x86_64-pc-linux-gnu`, and `sparc64-unknown-linux-gnu`.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 ++
 clang/test/Driver/ohos.c   |  2 +-
 clang/test/Driver/sanitizer-ld.c   |  2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 80a2b2bf31183..019df16a909f4 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1534,6 +1534,12 @@ bool tools::addSanitizerRuntimes(const ToolChain , 
const ArgList ,
  RequiredSymbols);
   }
 
+  // -u options must be added before the runtime libs that resolve them.
+  for (auto S : RequiredSymbols) {
+CmdArgs.push_back("-u");
+CmdArgs.push_back(Args.MakeArgString(S));
+  }
+
   // Inject libfuzzer dependencies.
   if (SanArgs.needsFuzzer() && SanArgs.linkRuntimes() &&
   !Args.hasArg(options::OPT_shared)) {
@@ -1566,10 +1572,6 @@ bool tools::addSanitizerRuntimes(const ToolChain , 
const ArgList ,
 addSanitizerRuntime(TC, Args, CmdArgs, RT, false, false);
 AddExportDynamic |= !addSanitizerDynamicList(TC, Args, CmdArgs, RT);
   }
-  for (auto S : RequiredSymbols) {
-CmdArgs.push_back("-u");
-CmdArgs.push_back(Args.MakeArgString(S));
-  }
   // If there is a static runtime with no dynamic list, force all the symbols
   // to be dynamic to be sure we export sanitizer interface functions.
   if (AddExportDynamic)
diff --git a/clang/test/Driver/ohos.c b/clang/test/Driver/ohos.c
index b1ce61e7227b6..8de4e6de57f7f 100644
--- a/clang/test/Driver/ohos.c
+++ b/clang/test/Driver/ohos.c
@@ -95,8 +95,8 @@
 // RUN: | FileCheck %s -check-prefix=CHECK-SAFESTACK
 // CHECK-SAFESTACK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-SAFESTACK: "-fsanitize=safe-stack"
-// CHECK-SAFESTACK: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a"
 // CHECK-SAFESTACK: "__safestack_init"
+// CHECK-SAFESTACK: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a"
 
 // RUN: %clang %s -### --target=arm-liteos \
 // RUN: -fsanitize=address 2>&1 \
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index 48e4ea1f7dcb5..c83066a334001 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -753,8 +753,8 @@
 // CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-SAFESTACK-LINUX-NOT: "-lc"
 // CHECK-SAFESTACK-LINUX-NOT: whole-archive
-// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a"
 // CHECK-SAFESTACK-LINUX: "-u" "__safestack_init"
+// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a"
 // CHECK-SAFESTACK-LINUX: "-lpthread"
 // CHECK-SAFESTACK-LINUX: "-ldl"
 // CHECK-SAFESTACK-LINUX: "-lresolv"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-11 Thread Rainer Orth via cfe-commits

rorth wrote:

> > The problem is that -u __safestack_init was passed to the linker after the 
> > corresponding version of libclang_rt.safestack-*.a. Since the Solaris 
> > linker (like Unix linkers for decades) respect
> 
> I agree this part should be extracted since it affects other systems. Other 
> parts are Solaris specific and since the support is currently broken, it is 
> safe to combine changes. We also don't have Solaris build bots, so the 
> change, if correctly restricted to Solaris, would not cause any problems.

We sure have Solaris buildbots, both 
[Solaris/sparcv9](https://lab.llvm.org/buildbot/#/builders/13) and 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/94).

Actually, two parts of the patch do affect non-Solaris targets:
- The SPARC enablement, which is covered by Linux/sparc64 testing, and
- adding some (otherwise unused) `sanitizer_common` objects to 
`libclang_rt.safestack-*.a`.  This was tested on both Linux/x86_64 and 
Linux/sparc64, and I'm resonably certain that unused objects in an archive lib 
won't affect other targets.

https://github.com/llvm/llvm-project/pull/98001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-10 Thread Rainer Orth via cfe-commits

rorth wrote:

> They look quite independent. Would be possible to split independent fixed 
> into a separate patches?

With the exception of the `-u` reordering, they are all Solaris-only, so I kept 
them together to avoid tons of micro-patches.  I certainly could split them if 
you prefer, something like
- `-u` reordering
- sparc enabling
- add `sanitizer_common` objects
- `pthread stacksize` quirk
- fix `TgKill`
- switch syscalls to `_REAL*`
- re-enable testing

Just let me know.

https://github.com/llvm/llvm-project/pull/98001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Fix Linux/sparc64 -m32 (PR #98124)

2024-07-10 Thread Rainer Orth via cfe-commits

https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/98124
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Fix Linux/sparc64 -m32 (PR #98124)

2024-07-09 Thread Rainer Orth via cfe-commits

https://github.com/rorth created https://github.com/llvm/llvm-project/pull/98124

`clang` currently fails to find a GCC installation on Linux/sparc64 with 
`-m32`.  `strace` reveals that `clang` tries to access 
`/usr/lib/gcc/sparcv9-linux-gnu` (which doesn't exist) instead of 
`/usr/lib/gcc/sparc64-linux-gnu`.

It turns out that 20d497c26fc95c80a1bacb38820d92e5f52bec58 was overeager in 
removing some of the necessary directories.

Fixed by reverting the Linux/sparc* part of the patch.

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

>From 0cfc30c6db46bf61e496824afda7f11b69e2d8ff Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Tue, 9 Jul 2024 09:43:56 +0200
Subject: [PATCH] [clang][Driver] Fix Linux/sparc64 -m32

`clang` currently fails to find a GCC installation on Linux/sparc64 with
`-m32`.  `strace` reveals that `clang` tries to access
`/usr/lib/gcc/sparcv9-linux-gnu` (which doesn't exist) instead of
`/usr/lib/gcc/sparc64-linux-gnu`.

It turns out that 20d497c26fc95c80a1bacb38820d92e5f52bec58 was overeager in
removing some of the necessary directories.

Fixed by reverting the Linux/sparc* part of the patch.

Tested on `sparc64-unknown-linux-gnu`.
---
 clang/lib/Driver/ToolChains/Gnu.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b141e5f2adfab..ff5e4022a2763 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2563,9 +2563,11 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
"riscv64-unknown-elf"};
 
   static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
-  static const char *const SPARCv8Triples[] = {"sparcv8-linux-gnu"};
+  static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",
+   "sparcv8-linux-gnu"};
   static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"};
-  static const char *const SPARCv9Triples[] = {"sparcv9-linux-gnu"};
+  static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu",
+   "sparcv9-linux-gnu"};
 
   static const char *const SystemZLibDirs[] = {"/lib64", "/lib"};
   static const char *const SystemZTriples[] = {

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


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread Rainer Orth via cfe-commits

rorth wrote:

> ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️
> You can test this locally with the following command:
> View the diff from clang-format here.
> 
> ```diff
> diff --git a/compiler-rt/lib/safestack/safestack_platform.h 
> b/compiler-rt/lib/safestack/safestack_platform.h
> index 77eeb9cda6..27e29d6ead 100644
> --- a/compiler-rt/lib/safestack/safestack_platform.h
> +++ b/compiler-rt/lib/safestack/safestack_platform.h
> @@ -13,9 +13,6 @@
>  #ifndef SAFESTACK_PLATFORM_H
>  #define SAFESTACK_PLATFORM_H
>  
> -#include "safestack_util.h"
> -#include "sanitizer_common/sanitizer_platform.h"
> -
>  #include 
>  #include 
>  #include 
> @@ -26,6 +23,9 @@
>  #include 
>  #include 
>  
> +#include "safestack_util.h"
> +#include "sanitizer_common/sanitizer_platform.h"
> +
>  #if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX || \
>SANITIZER_SOLARIS)
>  #  error "Support for your platform has not been implemented"
> ```

I had seen that when running `clang-format-diff.py`, but chose to ignore that 
because it seems unrelated and even somewhat dangerous: there are often cases 
where you need to define some macro **before** including system headers.

https://github.com/llvm/llvm-project/pull/98001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread Rainer Orth via cfe-commits

rorth wrote:

The mentioned patch to switch safestack to use the `sanitizer_common` functions 
instead of their own ones in `sanitizer_platform.h` has to wait until this one 
is approved: AFAIT github doesn't support stacked pull requests.

https://github.com/llvm/llvm-project/pull/98001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-08 Thread Rainer Orth via cfe-commits

https://github.com/rorth created https://github.com/llvm/llvm-project/pull/98001

At the end of the recent flurry of Illumos (and implicitly Solaris) safestack 
patches, the tests were disabled in
b0260c5b1052f8e3ff1ec77dc42a11f42da762cc without explanation.

After re-enabling them, there were many problems on Solaris:

- Every single testcase failed to link:

  ``` Undefined first referenced
   symbol   in file
  __safestack_unsafe_stack_ptrbuffer-copy-vla.o
  __safestack_init(command line)
  ld: fatal: symbol referencing errors
  ```

  The problem is that `-u __safestack_init` was passed to the linker after the 
corresponding version of `libclang_rt.safestack-*.a`.  Since the Solaris linker 
(like Unix linkers for decades) respects the command line argument order 
(unlike e.g. GNU ld which uses GNU getopt), this cannot work.  Fixed by moving 
the `-u` arg further to the front.  Two affected testcases were adjusted 
accordingly.

* While 540fd42c755f20f7b79c6c79493ec36d8cb9b3d3 enabled safestack on Solaris 
unconditionally, it ignored that Solaris also exists on SPARC and forgot to 
enable SPARC support.  This patch fixes that.

- Afterwards, the tests still fail to link with undefined references to 
`__sanitizer_internal_memset` etc.  These are from 
`sanitizer_redefine_builtins.h`.  Definitions live in `sanitizer_libc.cpp.o` 
and were added to the safestack runtime lib as is already the case e.g. for 
asan and ubsan.  Why GNU ld allows the link to complete with those symbols 
undefined is beyond me.

- The `pthread*.c` tests `FAIL` with

  ``` safestack CHECK failed: 
/vol/llvm/src/llvm-project/local/compiler-rt/lib/safestack/safestack.cpp:227 
size ```

  The problem is that `pthread_attr_init` initializes the `stacksize` attribute 
to 0, signifying the default.  Unless explicitly overridded, it stays that way. 
 I think this is allowed by XPG7.  Since safestack cannot deal with this, I set 
`size` to the defaults documented in `pthread_create(3C)`.  Unfortunately, 
there's no macro for those values outside of private `libc` headers.

- The Solaris `syscall` interface isn't stable.  This is not just a theoretical 
concern, but the syscalls have changed incompatibly several times in the past.  
Therefore this patch switches the implementations of `TgKill` (where 
`SYS_lwp_kill` doesn't exist on Solaris 11.4 anyway), `Mmap`, `Munmap`, and 
`Mprotect` to the same `_REAL*` solution already used in 
`sanitizer_solaris.cpp`.  Instead of duplicating what's already in 
`sanitizer_common`, it seems way better to me to just reuse those 
implementations, though.  A subsequent patch does just that.

With those changes, safestack compiles and all tests `PASS`.

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

>From f8de9c3c2dbde4021f0d32a55c8a385221c0f749 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Mon, 8 Jul 2024 10:28:42 +0200
Subject: [PATCH] [safestack] Various Solaris fixes

At the end of the recent flurry of Illumos (and implicitly Solaris)
safestack patches, the tests were disabled in
b0260c5b1052f8e3ff1ec77dc42a11f42da762cc without explanation.

After re-enabling them, there were many problems on Solaris:

- Every single testcase failed to link:

  ```
  Undefined first referenced
   symbol   in file
  __safestack_unsafe_stack_ptrbuffer-copy-vla.o
  __safestack_init(command line)
  ld: fatal: symbol referencing errors
  ```

  The problem is that `-u __safestack_init` was passed to the linker after
  the corresponding version of `libclang_rt.safestack-*.a`.  Since the
  Solaris linker (like Unix linkers for decades) respects the command line
  argument order (unlike e.g. GNU ld which uses GNU getopt), this cannot
  work.  Fixed by moving the `-u` arg further to the front.  Two affected
  testcases were fixed accordingly.

* While 540fd42c755f20f7b79c6c79493ec36d8cb9b3d3 enabled safestack on
  Solaris unconditionally, it ignored that Solaris also exists on SPARC and
  forgot to enable SPARC support.  This patch fixes that.

- Afterwards, the tests still fail to link with undefined references to
  `__sanitizer_internal_memset` etc.  These are from
  `sanitizer_redefine_builtins.h`.  Definitions live in
  `sanitizer_libc.cpp.o` and were added to the safestack runtime lib as is
  already the case e.g. for asan and ubsan.  Why GNU ld allows the link to
  complete with those undefined is beyond me.

- The `pthread*.c` tests `FAIL` with

  ```
  safestack CHECK failed: 
/vol/llvm/src/llvm-project/local/compiler-rt/lib/safestack/safestack.cpp:227 
size
  ```

  The problem is that `pthread_attr_init` initializes the `stacksize`
  attribute to 0, signifying the default.  Unless explicitly overridded, it
  stays that way.  I think this is allowed by XPG7.  Since safestack cannot
  deal with this, I set 

[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

2024-06-29 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke the 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/94/builds/4729) 
buildbot.

For god's sake, can you please either test your Illumos patches on Solaris, too 
(there are Solaris buildbots in the cfarm for exactly such a purpose) and 
finally handle Issue #53919 when it's necessary to distinguish Solaris and 
Illumos.

This happens ever and ever again with your patches and I'm getting pissed off 
by this attitude!

https://github.com/llvm/llvm-project/pull/95648
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] No transitive source location change (PR #86912)

2024-05-01 Thread Rainer Orth via cfe-commits

rorth wrote:

This is certainly a case of unaligned access.  In a local build, I've run the 
first failing `clang` invocation under `truss` (the Solaris syscall tracer).  
For
```
/var/llvm/dist-sparcv9-release-stage2-A-flang-clang18/tools/clang/stage2-bins/bin/clang
 -cc1 -internal-isystem 
/var/llvm/dist-sparcv9-release-stage2-A-flang-clang18/tools/clang/stage2-bins/lib/clang/19/include
 -nostdsysteminc -fmodules -Wno-private-module -fimplicit-module-maps 
-fmodules-cache-path=/var/llvm/dist-sparcv9-release-stage2-A-flang-clang18/tools/clang/stage2-bins/tools/clang/test/APINotes/Output/availability.m.tmp/ModulesCache
 -fapinotes-modules -fsyntax-only -I 
/vol/llvm/src/llvm-project/dist/clang/test/APINotes/Inputs/Headers -F 
/vol/llvm/src/llvm-project/dist/clang/test/APINotes/Inputs/Frameworks 
/vol/llvm/src/llvm-project/dist/clang/test/APINotes/availability.m -verify
```
this reveals
```
14552:  Incurred fault #5, FLTACCESS  %pc = 0x1083824E0
14552:siginfo: SIGBUS BUS_ADRALN addr=0x7F5E7B6C
14552:  Received signal #10, SIGBUS [caught]
14552:siginfo: SIGBUS BUS_ADRALN addr=0x7F5E7B6C
```
`gdb` shows exactly that:
```
Thread 2 received signal SIGBUS, Bus error.
[Switching to Thread 1 (LWP 1)]
0x0001083824e0 in clang::ASTReader::DeclCursorForID(clang::GlobalDeclID, 
clang::SourceLocation&) ()
1: x/i $pc
=> 0x1083824e0 
<_ZN5clang9ASTReader15DeclCursorForIDENS_12GlobalDeclIDERNS_14SourceLocationE+168>:
  ldx  [ %i5 + %i1 ], %o2
(gdb) p/x $i5
$1 = 0x7f5e7b4c
(gdb) p/x $i1
$2 = 0x20
```
The `ldx` insn (Load Extended Word) takes a doubleword address with natural 
(64-bit) alignment.

https://github.com/llvm/llvm-project/pull/86912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-30 Thread Rainer Orth via cfe-commits

rorth wrote:

> I'll revert this. Due to I can't reproduce this. When the bot gets stable, 
> please tell if it is the real problem.

You can reproduce this: the [GCC compile farm](https://portal.cfarm.net/) does 
have a Solaris/sparcv9 system (`cfarm215`) which is perfectly equipped to run 
LLVM builds (I've tried).

I think the stack traces from the bot are a pretty strong indication that your 
patch is the culprit:
```
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang-19  0x0001076d87b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, 
int) + 36
1  clang-19  0x0001076d910c SignalHandler(int) + 896
2  libc.so.1 0x7f0c62a8 __sighndlr + 12
3  libc.so.1 0x7f0b8b50 call_user_handler + 1024
4  libc.so.1 0x7f0b8f10 sigacthandler + 160
5  clang-19  0x0001083824e0 
clang::ASTReader::DeclCursorForID(clang::GlobalDeclID, clang::SourceLocation&) 
+ 168
6  clang-19  0x00010838aca0 
clang::ASTReader::ReadDeclRecord(clang::GlobalDeclID) + 48
7  clang-19  0x0001082fb4ec clang::ASTReader::GetDecl(clang::GlobalDeclID) 
+ 232
8  clang-19  0x0001082cb820 
clang::ASTReader::SetGloballyVisibleDecls(clang::IdentifierInfo*, 
llvm::SmallVectorImpl const&, 
llvm::SmallVectorImpl*) + 252
9  clang-19  0x0001083144a0 clang::ASTReader::finishPendingActions() + 572
10 clang-19  0x000108319e10 clang::ASTReader::FinishedDeserializing() + 92
11 clang-19  0x00010830dbf4 clang::ASTReader::get(llvm::StringRef) + 680
12 clang-19  0x0001078a84fc clang::IdentifierTable::get(llvm::StringRef) + 
84
13 clang-19  0x00010a130fcc clang::Sema::Initialize() + 1208
14 clang-19  0x000109fd1814 clang::Parser::Initialize() + 1260
15 clang-19  0x000109fccb68 clang::ParseAST(clang::Sema&, bool, bool) + 556
16 clang-19  0x0001081b10d8 clang::ASTFrontendAction::ExecuteAction() + 248
17 clang-19  0x0001081b06f8 clang::FrontendAction::Execute() + 92
18 clang-19  0x0001081196c8 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1572
19 clang-19  0x0001082b87b8 
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 684
20 clang-19  0x0001048a2980 cc1_main(llvm::ArrayRef, char 
const*, void*) + 4296
21 clang-19  0x00010489f6f8 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) + 1184
22 clang-19  0x00010489e018 clang_main(int, char**, llvm::ToolContext 
const&) + 4424
23 clang-19  0x0001048aee0c main + 60
24 clang-19  0x00010489c904 _start + 100
/var/llvm/dist-sparcv9-release-stage2-A-flang-clang18/tools/clang/stage2-bins/tools/clang/test/PCH/Output/opencl-extensions.cl.script:
 line 2: 12701 Bus Error   
/var/llvm/dist-sparcv9-release-stage2-A-flang-clang18/tools/clang/stage2-bins/bin/clang
 -cc1 -internal-isystem 
/var/llvm/dist-sparcv9-release-stage2-A-flang-clang18/tools/clang/stage2-bins/lib/clang/19/include
 -nostdsysteminc -include-pch 
/var/llvm/dist-sparcv9-release-stage2-A-flang-clang18/tools/clang/stage2-bins/tools/clang/test/PCH/Output/opencl-extensions.cl.tmp
 -fsyntax-only 
/vol/llvm/src/llvm-project/dist/clang/test/PCH/opencl-extensions.cl -triple 
spir-unknown-unknown
```
One thing I see immediately that this uses a triple the bot is not configured 
to handle.  Nonetheless clang shouldn't die with `SIGBUS` in such as case.

https://github.com/llvm/llvm-project/pull/86912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-30 Thread Rainer Orth via cfe-commits

rorth wrote:

I strongly suspect that this patch badly broke the [Solaris/sparcv9 
buildbot](https://lab.llvm.org/buildbot/#/builders/72/builds/4046): it 
introduced more than 1000 failures.

Please fix or revert.

https://github.com/llvm/llvm-project/pull/86912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-02-13 Thread Rainer Orth via cfe-commits

rorth wrote:

The libcalls per se wouldn't be a problem since on 32-bit Solaris/sparc 
`-latomic` is always linked due to that.  However, the `__sync_*` libcalls 
aren't defined in `libatomic.so`, thus the link failure.

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-02-13 Thread Rainer Orth via cfe-commits

rorth wrote:

Confirmed: reverting the patch locally restores the build.

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Emit atomic IR in place of optimized libcalls. (PR #73176)

2024-02-13 Thread Rainer Orth via cfe-commits

rorth wrote:

I'm pretty certain this patch broke the [Solaris/sparcv9 
buildbot](https://lab.llvm.org/buildbot/#/builders/72/builds/2541).

https://github.com/llvm/llvm-project/pull/73176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-01-26 Thread Rainer Orth via cfe-commits

rorth wrote:

> `embmedany` is already rejected by the driver at the moment:
> 
> ```
> error: unsupported argument 'embmedany' to option '-mcmodel=' for target 
> 'sparc64'
> ```
Seems sensible indeed.
> On the testing issue, however, would compiling LLVM with each of the code 
> models + running codegen tests be enough to at least exercise the relevant 
> parts (and see if there's still issues, etc.)?

I'd run 2-stage builds/tests (either with the existing machinery or by building 
LLVM twice explicitly: once with an external compiler and then again with the 
just-built one).


https://github.com/llvm/llvm-project/pull/79485
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-01-26 Thread Rainer Orth via cfe-commits

rorth wrote:

GCC also supports `-mcmodel=embmedany`.  Maybe it would be good to reject that 
with a clear message?

As for the generated code (not this PR, I'd say), it would certainly be good to 
test that on some larger code base (like LLVM itself) and, preferably, also 
test actual interoperability with GCC. Especially in SPARC support, I have seen 
to many cases where LLVM wouldn't interoperate with itself, let alone GCC.

https://github.com/llvm/llvm-project/pull/79485
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang-tools-extra] [clang] [PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (PR #78285)

2024-01-22 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke both the 
[Solaris/sparcv9](https://lab.llvm.org/buildbot/#/builders/72/builds/2015) and 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/94/builds/394) 
buildbots.

If it really requires recent `lld`, this is guaranteed to not work: `lld` 
hasn't even been ported to Solaris.  Similar issues most likely will exist on 
other targets where the bot either doesn't build `lld` or it isn't supported at 
all.

https://github.com/llvm/llvm-project/pull/78285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CMake] Add support for building on illumos (PR #74930)

2024-01-18 Thread Rainer Orth via cfe-commits

rorth wrote:

I wonder what the current flurry of patdhes to support Illumos is about.  I'd 
originally filed Issue #53919 to make clear what's needed from the Illumos 
project to keep it as an LLVM target, given that they haven't contributed 
either bug reports, code or testing in a long time.  Without that, keeping 
Illumos somehow in a gray zone between supported and unsupported, this doubles 
my workload for Solaris patches:

- Whenever I add or remove a feature, I need to investigate what needs to be 
done on the Illumos side.
- Depending on the outcome, I need to add separate Illumos support code 
whenever it and Solaris differ.
- And ultimately, I need to test all my patches not only on Solaris, but also 
no Illumos.

This could only be avoided if the Illumos guys (or someone else) reliably 
perform those tasks instead.  However, I don't see any contributions from them, 
so the situation hasn't changed since the Issue was filed.

It also means that cleanup that could be done on the Solaris side (I'd like to 
rip out [[sanitizer_common] Support Solaris < 11.4 in 
GetStaticTlsBoundary](https://reviews.llvm.org/D120059) as soon as Solaris 11.3 
support has been ripped out from GCC; 11.4 doesn't need it, but Illumos would 
AFAIK).

I'm perfectly happy to work with them to develop code that works on both 
variants (Illumos and Solaris), but I'm opposed to have untested/barely tested 
code in that creates massive work for me.

https://github.com/llvm/llvm-project/pull/74930
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LLVM][DWARF] Fix accelerator table switching between CU and TU (PR #77511)

2024-01-12 Thread Rainer Orth via cfe-commits

rorth wrote:

However, the patch broke the [Solaris/sparcv9 
buildbot](https://lab.llvm.org/buildbot/#/builders/72/builds/1834):
```
llc: error: unable to get target for 'x86_64-unknown-linux-gnu', see --version 
and --triple.
```
The bot is configured to do a Sparc-only build.

https://github.com/llvm/llvm-project/pull/77511
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [flang] [llvm] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)

2024-01-11 Thread Rainer Orth via cfe-commits

rorth wrote:

Sure: I've just created one slightly changed from the attached patch: [[flang] 
Handle missing LOGIN_NAME_MAX definition in 
runtime](https://github.com/llvm/llvm-project/pull/5)

https://github.com/llvm/llvm-project/pull/74628
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [llvm] [clang-tools-extra] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)

2024-01-10 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke the Solaris build:
```
FAILED: tools/flang/runtime/CMakeFiles/obj.FortranRuntime.dir/extensions.cpp.o 
[...]
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:60:24: error: use 
of undeclared identifier 'LOGIN_NAME_MAX'
   60 |   const int nameMaxLen{LOGIN_NAME_MAX + 1};
  |^
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:61:12: warning: 
variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   61 |   char str[nameMaxLen];
  |^~
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:61:12: note: 
initializer of 'nameMaxLen' is unknown
/vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:60:13: note: 
declared here
   60 |   const int nameMaxLen{LOGIN_NAME_MAX + 1};
  | ^
1 warning and 1 error generated.
```
and
```
FAILED: 
tools/flang/unittests/Runtime/CMakeFiles/FlangRuntimeTests.dir/CommandTest.cpp.o
[...]
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:530:21: 
error: use of undeclared identifier 'LOGIN_NAME_MAX' 
  530 |   const int charLen{LOGIN_NAME_MAX + 2};
  | ^
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:531:14: 
warning: variable length arrays in C++ are a Clang extension 
[-Wvla-cxx-extension]
  531 |   char input[charLen];
  |  ^~~
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:531:14: 
note: initializer of 'charLen' is unknown
/vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:530:13: 
note: declared here
  530 |   const int charLen{LOGIN_NAME_MAX + 2};
  | ^
```
As documented in Solaris `limits.h(3HEAD)` (and exactly matching XPG7), 
`LOGIN_NAME_MAX` not being defined is an allowed configuration:
```
   Runtime Invariant Values (Possibly Indeterminate)
   A definition of one of the symbolic names  in  the  following  list  is
   omitted  fromon specific implementations where the corre-
   sponding value is equal to or greater than the stated minimum,  but  is
   unspecified.

   This  indetermination  might  depend  on the amount of available memory
   space on a specific instance of a specific implementation.  The  actual
   value  supported  by  a  specific  instance  will  be  provided  by the
   sysconf() function.
[...]
   LOGIN_NAME_MAX

   Maximum length of a login name.
```
So the code needs to fall back to `sysconf(_SC_LOGIN_NAME_MAX)` if 
`LOGIN_NAME_MAX` is not defined.

I've used the attached patch to implement this, which allowed the build and 
`ninja check-all` to finish.  I'm uncertain if support for `syscconf() == -1` 
is really necessary, though.
[lnm.txt](https://github.com/llvm/llvm-project/files/13887475/lnm.txt)


https://github.com/llvm/llvm-project/pull/74628
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Warning for _Float16 passed to format specifier '%f' (PR #74439)

2024-01-08 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke the [Solaris/sparcv9 
buildbot](https://lab.llvm.org/buildbot/#/builders/72/builds/1709): the 
new/changed tests `FAIL` with
```
  File 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/SemaCXX/format-strings-scanf.cpp
 Line 25: _Float16 is not supported on this target
1 error generated.
```

https://github.com/llvm/llvm-project/pull/74439
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang-tools-extra] [mlir] [libunwind] [libcxxabi] [llvm] [lldb] [libcxx] [flang] [lld] [libc] [asan] Install `pthread_atfork` (PR #75290)

2023-12-21 Thread Rainer Orth via cfe-commits

rorth wrote:

> I'll give such a patch a try...

That would be something like
```
int internal_fork(void) {
  // Call syscall directly to avoid pthread_atfork handler processing.
  //
  // This is highly unportable on Solaris since syscalls are an implementation
  // detail subject to change.
  return syscall(SYS_forksys, 0, 0);
}
```
Unfortunately, this fails miserably: at least every asan test that invokes the 
`llvm-symbolizer` fails like
```
==4030==Launching Symbolizer process: /usr/bin/llvm-symbolizer --demangle 
--inlines --default-arch=i386 
==4031==Waiting on the process failed (errno 10).
==4031==WARNING: external symbolizer didn't start up correctly!
```
>From all I could learn from the OpenSolaris `libc` code 
>(`lib/libc/port/threads/scalls.c` (`forkx`), it seems that there happens so 
>much processing on `libc`-internal data structures that cannot simply be 
>skipped that there's no reasonable chance to run `fork` without the handlers.  
>Expecting to be able to seems to be hack that may work on some platforms, but 
>not on others.

https://github.com/llvm/llvm-project/pull/75290
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libc] [clang] [lldb] [libcxxabi] [libunwind] [lld] [compiler-rt] [llvm] [clang-tools-extra] [flang] [mlir] [asan] Install `pthread_atfork` (PR #75290)

2023-12-19 Thread Rainer Orth via cfe-commits

rorth wrote:

It took me a bit to notice this snippet in `sanitizer_solaris.cpp`:
```
DECLARE__REAL_AND_INTERNAL(int, fork, void) {
  // TODO(glider): this may call user's pthread_atfork() handlers which is bad.
  return _REAL(fork)();
}
```
which didn't show up in searches for `internal_fork`.

>From what I could learn from `libc` disassembly and the OpenSolaris sources, 
>the only way to avoid the handlers on Solaris is to invoke the syscall 
>directly.  This is highly unportable, however: syscalls are an implemention 
>detail that can (and **does**) change.  There's reasonable hope that this 
>won't happen for the remaining livetime of Solaris 11.4, though.

I'll give such a patch a try...

https://github.com/llvm/llvm-project/pull/75290
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [compiler-rt] [mlir] [llvm] [lld] [flang] [lldb] [libcxx] [libcxxabi] [clang] [libc] [clang-tools-extra] [asan] Install `pthread_atfork` (PR #75290)

2023-12-15 Thread Rainer Orth via cfe-commits

rorth wrote:

Since this patch, all asan tests loop on Solaris.  This had been hidden for a 
bit by an unrelated extended build breakage on the bots, but now every `ninja 
check-all` on the Solaris/amd64 bot times out.  I could trace this to this 
patch.

E.g. when running 
`projects/compiler-rt/test/asan/I386SunOSConfig/TestCases/Output/alloca_big_alignment.cpp.tmp`,
 I get the expected output
```
=
==3==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 
0xfeffd88a at pc 0x0812907d bp 0xfeffd7f4 sp 0xfeffd7ec
WRITE of size 1 at 0xfeffd88a thread T0
```
and afterwards the test loops.  `truss` shows an unending series of
```
22210:  yield() = 0
22210:  yield() = 0
22210:  yield() = 0
```
and `pstack` gives
```
22213:  /var/llvm/local-amd64-release-stage2-A-flang-492214/tools/clang/stage2
 fdfbebc5 yield(0x8139158, 0x8109558, 0x818a580, 0x0, 0x5dd, 0x8139158) + 15
 0810cd32 __sanitizer::FutexWait(__sanitizer::atomic_uint32_t*, unsigned int) 
(0xfe00a000, 0xfdebdd56, 0x805ad7c, 0xfdfa0107, 0xfeffc68c, 0x5) + 12
 080f4952 __asan::InstallAtForkHandler()::$_0::__invoke() (0xfde26fc0, 0x7, 
0xfe010200, 0xfe010140, 0x7, 0x5) + 12
 fdfa49c8 forkx(0x0, 0xfe5ad000, 0x89f, 0xfdfa4b8c) + c8
 fdfa4b9d fork (0x8139158, 0x811563e, 0xfeffc720, 0xfd6007a0, 0x4, 
0x8139158) + 1d
 0810ccd2 __sanitizer::internal_fork() () + 12
```
This seems no wonder given that `sanitizer_common/sanitizer_solaris.cpp` has
```
void FutexWait(atomic_uint32_t *p, u32 cmp) {
  // FIXME: implement actual blocking.
  sched_yield();
}
```
`sanitizer_mac.cpp` is the same, btw., and even `sanitizer_linux.cpp` has
```
#  if !SANITIZER_SOLARIS
void FutexWait(atomic_uint32_t *p, u32 cmp) {
#if SANITIZER_FREEBSD
  _umtx_op(p, UMTX_OP_WAIT_UINT, cmp, 0, 0);
#elif SANITIZER_NETBSD
  sched_yield(); /* No userspace futex-like synchronization */
#else
  internal_syscall(SYSCALL(futex), (uptr)p, FUTEX_WAIT_PRIVATE, cmp, 0, 0, 0);
#endif
}
```
so even NetBSD would be affected.

https://github.com/llvm/llvm-project/pull/75290
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Perf/lexer faster slow get char and size (PR #70543)

2023-10-29 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke builders like 
[Solaris/amd64](https://lab.llvm.org/staging/#/builders/8/builds/761) that 
include `clang-tools-extra`.

https://github.com/llvm/llvm-project/pull/70543
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix -r handling on Solaris (PR #70322)

2023-10-26 Thread Rainer Orth via cfe-commits

https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/70322
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix -r handling on Solaris (PR #70322)

2023-10-26 Thread Rainer Orth via cfe-commits

https://github.com/rorth created https://github.com/llvm/llvm-project/pull/70322

As discussed in [[Driver] Link Flang runtime on 
Solaris](https://github.com/llvm/llvm-project/pull/65644), `clang -r` 
incorrectly passes both `-Bdynamic` and `-e _start` to `ld` which lets the 
linker choke.

This patch fixes this, omitting `-Bdynamic` completely which is the linker 
default.

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

>From 8a98b2f79931cb6e29d2fced5c86cc555667e3ef Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 26 Oct 2023 14:00:50 +0200
Subject: [PATCH] [Driver] Fix -r handling on Solaris

As discussed in [[Driver] Link Flang runtime on
Solaris](https://github.com/llvm/llvm-project/pull/65644), `clang -r`
incorrectly passes both `-Bdynamic` and `-e _start` to `ld` which lets the
linker choke.

This patch fixes this, omitting `-Bdynamic` completely which is the linker
default.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp | 7 +++
 clang/test/Driver/solaris-ld.c  | 1 +
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index ecff8ddc4ee766f..2b1ac5a7f475c5a 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -96,7 +96,8 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (!LinkerIsGnuLd)
 CmdArgs.push_back("-C");
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared,
+   options::OPT_r)) {
 CmdArgs.push_back("-e");
 CmdArgs.push_back("_start");
   }
@@ -114,10 +115,8 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-Bstatic");
 CmdArgs.push_back("-dn");
   } else {
-CmdArgs.push_back("-Bdynamic");
-if (Args.hasArg(options::OPT_shared)) {
+if (!Args.hasArg(options::OPT_r) && Args.hasArg(options::OPT_shared))
   CmdArgs.push_back("-shared");
-}
 
 // libpthread has been folded into libc since Solaris 10, no need to do
 // anything for pthreads. Claim argument to avoid warning.
diff --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 09e6e8b4f07cf91..8f7f168c387214d 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/clang/test/Driver/solaris-ld.c
@@ -177,6 +177,7 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
 // CHECK-RELOCATABLE: "-L
 // CHECK-RELOCATABLE: "-r"
+// CHECK-RELOCATABLE-NOT: "-e"
 // CHECK-RELOCATABLE-NOT: "-l
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o

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


[clang] Let clang-cl support CUDA/HIP (PR #68921)

2023-10-23 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch also broke the [Solaris/amd64 
buildbot](https://lab.llvm.org/staging/#/builders/8/builds/484).  I suspect 
this happens because that one is configured with `-DLLVM_TARGETS_TO_BUILD=X86`, 
thus lacking cuda support.  In fact, when manually building with support for 
all targets, the test `PASS`es. Please fix.

https://github.com/llvm/llvm-project/pull/68921
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits

https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits

https://github.com/rorth updated https://github.com/llvm/llvm-project/pull/65644

>From 31bdd3477d9f54996b71584598bdd75f2cef31db Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 7 Sep 2023 19:19:32 +0200
Subject: [PATCH 1/3] [Driver] Link Flang runtime on Solaris

I noticed that `flang-new` cannot link Fortran executables on Solaris since
the runtime libs are missing.

This patch fixes this, following `Gnu.cpp`.  The `linker-flags.f90` testcase
is augmented to test for this.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp | 8 
 flang/test/Driver/linker-flags.f90  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 36fe12608eefc6c..252c71d3379eab4 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -223,6 +223,14 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below.
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
+  addFortranRuntimeLibs(getToolChain(), CmdArgs);
+  CmdArgs.push_back("-lm");
+}
 if (Args.hasArg(options::OPT_fstack_protector) ||
 Args.hasArg(options::OPT_fstack_protector_strong) ||
 Args.hasArg(options::OPT_fstack_protector_all)) {
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..717dcc7775e2126 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -4,6 +4,7 @@
 
 ! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and

>From bf1b865045ed4f484f24746aa18405d93e760979 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Tue, 17 Oct 2023 20:43:23 +0200
Subject: [PATCH 2/3] Rename `GNU` label to `UNIX` to better match use.

---
 flang/test/Driver/linker-flags.f90 | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 717dcc7775e2126..fd61825eb4023a5 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -2,9 +2,9 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
-! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
 ! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and
@@ -22,12 +22,12 @@
 !   run on any other platform, such as Windows that use a .exe
 !   suffix. Clang's driver will try to resolve the path to the ld
 !   executable and may find the GNU linker from MinGW or Cygwin.
-! GNU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
-! GNU-SAME: "[[object_file]]"
-! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
-! GNU-SAME: -lm
+! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "[[object_file]]"
+! UNIX-SAME: -lFortran_main
+! UNIX-SAME: -lFortranRuntime
+! UNIX-SAME: -lFortranDecimal
+! UNIX-SAME: -lm
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! DARWIN-SAME: "[[object_file]]"

>From 5e7ca991bd8b87b754e982d9836460dc0f31e59f Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Wed, 18 Oct 2023 12:01:15 +0200
Subject: [PATCH 3/3] Use `--target=`.  Join `-l` lines for `UNIX` case.

---
 flang/test/Driver/linker-flags.f90 | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 

[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits


@@ -21,12 +22,12 @@
 !   run on any other platform, such as Windows that use a .exe
 !   suffix. Clang's driver will try to resolve the path to the ld
 !   executable and may find the GNU linker from MinGW or Cygwin.
-! GNU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
-! GNU-SAME: "[[object_file]]"
-! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
-! GNU-SAME: -lm
+! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "[[object_file]]"
+! UNIX-SAME: -lFortran_main

rorth wrote:

Right: they fit nicely even with the double quotes.  To avoid swamping the 
patch with unrelated changes, I've only adjusted the `UNIX` case.

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits


@@ -2,8 +2,9 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX

rorth wrote:

Done: since I'd already touched almost half the instances, I changed them all 
for consistency.

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-17 Thread Rainer Orth via cfe-commits

https://github.com/rorth updated https://github.com/llvm/llvm-project/pull/65644

>From 31bdd3477d9f54996b71584598bdd75f2cef31db Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 7 Sep 2023 19:19:32 +0200
Subject: [PATCH 1/2] [Driver] Link Flang runtime on Solaris

I noticed that `flang-new` cannot link Fortran executables on Solaris since
the runtime libs are missing.

This patch fixes this, following `Gnu.cpp`.  The `linker-flags.f90` testcase
is augmented to test for this.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp | 8 
 flang/test/Driver/linker-flags.f90  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 36fe12608eefc6c..252c71d3379eab4 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -223,6 +223,14 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below.
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
+  addFortranRuntimeLibs(getToolChain(), CmdArgs);
+  CmdArgs.push_back("-lm");
+}
 if (Args.hasArg(options::OPT_fstack_protector) ||
 Args.hasArg(options::OPT_fstack_protector_strong) ||
 Args.hasArg(options::OPT_fstack_protector_all)) {
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..717dcc7775e2126 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -4,6 +4,7 @@
 
 ! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and

>From bf1b865045ed4f484f24746aa18405d93e760979 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Tue, 17 Oct 2023 20:43:23 +0200
Subject: [PATCH 2/2] Rename `GNU` label to `UNIX` to better match use.

---
 flang/test/Driver/linker-flags.f90 | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 717dcc7775e2126..fd61825eb4023a5 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -2,9 +2,9 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
-! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
 ! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and
@@ -22,12 +22,12 @@
 !   run on any other platform, such as Windows that use a .exe
 !   suffix. Clang's driver will try to resolve the path to the ld
 !   executable and may find the GNU linker from MinGW or Cygwin.
-! GNU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
-! GNU-SAME: "[[object_file]]"
-! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
-! GNU-SAME: -lm
+! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "[[object_file]]"
+! UNIX-SAME: -lFortran_main
+! UNIX-SAME: -lFortranRuntime
+! UNIX-SAME: -lFortranDecimal
+! UNIX-SAME: -lm
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! DARWIN-SAME: "[[object_file]]"

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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-16 Thread Rainer Orth via cfe-commits

rorth wrote:

> I feel that we are bike-shedding here a bit. Please prioritise correctness - 
> using `GNU` as a label for Solaris would not be correct. The following would 
> be:
> 
> * duplicating tests with a different label (e.g. `SOLARIS`) would be 
> correct,
> 
> * renaming the current label from `GNU` to e.g. `UNIX` would be correct.
> 
> 
> Unless I am missing something?

I'd go for renaming the label to `UNIX` then: it avoids unnecessary duplication 
and better describes what those cases are about.

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-11 Thread Rainer Orth via cfe-commits

rorth wrote:

> I'd like for this to move forward.

Agreed: AFAICS the only open issue is whether the Solaris test should use the 
`GNU` label as I have done, introduce an new common one (like `UNIX`; there's 
nothing GNU-specific in that test), or really introduce a separate copy of the 
check under a different label per target (my least preference because it makes 
the test hard to read for no gain).

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-11 Thread Rainer Orth via cfe-commits

rorth wrote:

> > I wonder how to proceed with the patch at hand.
> 
> I'm not a Solaris expert, but based on this discussion I'd consider adding 
> support for `-fuse-ld` in Flang. This sort of changes are often as simple as 
> updating Options.td. Same for `-r`.

Support of `-fuse-ld` is not Solaris-specific in any way.  Other targets 
support e.g. `-fuse-ld=[bfd|lld]`.  That would be just another case of Flang 
needing to support common flags.  However, I don't understand how Flang option 
handling is done, unfortunately.  Whatever the case, this is an issue separate 
from this patch: the only reason we were talking about `-r` and friends is that 
my patch guards adding the Flang runtime libs with `! -nostdlib && ! 
-nodefaultlibs && ! -r`, which I believe we have now established is correct.

However, Flang accepts none of those options yet, which it should for 
compatiblity with both `clang++` and `gfortran`.  However, I won't be able to 
deal with any of this: I've quite a number of other issues on my plate.

> One important rule of thumb that I'd stick to:
> 
> * Do whatever Clang, GFortran and GCC do.
> 
> 
> In cases where there's different behavior between these compilers, just go 
> for whatever feels most sensible, but please document your design decision.

Fully agreed: I've now checked that gfortran handles all of `-r`, `-nostdlib`, 
and `-nodefaultlibs`, so I believe `flang-new` should follow suite.


https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-22 Thread Rainer Orth via cfe-commits

rorth wrote:

The different behaviour can easily be seen since Solaris `clang` supports 
linker selection at compile time:
```
$ clang -r -o hello-r.o hello.o -fuse-ld=gld
/usr/gnu/bin/ld: warning: cannot find entry symbol _start; not setting start 
address
$ clang -r -o hello-r.o hello.o
ld: fatal: option '-Bdynamic' is incompatible with building a relocatable object
ld: fatal: option '-e _start' is incompatible with building a relocatable object
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
I'll either fix the Solaris driver code not to pass `-Bdynamic -e _start` with 
`-r` or do a full comparison of `Gnu.cpp` and `Solaris.cpp` to check for 
undesirable differences.

However, for the patch at hand this is moot while
```
$ flang-new -r -o hello-r.o hello.o
flang-new: error: unknown argument: '-r'
```

I wonder how to proceed with the patch at hand.

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-15 Thread Rainer Orth via cfe-commits

rorth wrote:

I'd argue that handling the Flang runtime libs like C++ is the right thing to 
do here.  However, `flang-new` currently rejects all of `-r`, `-nostdlib`, and 
`-nodefaultlibs` on both Linux and Solaris.  On top of that, Solaris `clang` 
doesn't handle `-r` correctly, passing `-e _start -Bdynamic` to `ld`, which 
makes it choke...

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-14 Thread Rainer Orth via cfe-commits


@@ -4,6 +4,7 @@
 
 ! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU

rorth wrote:

@banach-space How should we proceed with this one?  Really introduce separate 
labels for each OS, even if the checks are identical?  Or consolidate labels as 
I suggested?


https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-08 Thread Rainer Orth via cfe-commits

https://github.com/rorth edited https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-08 Thread Rainer Orth via cfe-commits


@@ -4,6 +4,7 @@
 
 ! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU

rorth wrote:

True, but how many more copies of the same patterns do we want?  Add FreeBSD, 
OpenBSD, ... whenever they arrive?  Isn't the common patternwith or without `-lm`?  How about putting the first under 
one label and the `-lm` part under another, used where appropriate?

https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth review_requested 
https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth created 
https://github.com/llvm/llvm-project/pull/65644:

I noticed that `flang-new` cannot link Fortran executables on Solaris since the 
runtime libs are missing.

This patch fixes this, following `Gnu.cpp`.  The `linker-flags.f90` testcase is 
augmented to test for this.

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

>From 31bdd3477d9f54996b71584598bdd75f2cef31db Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 7 Sep 2023 19:19:32 +0200
Subject: [PATCH] [Driver] Link Flang runtime on Solaris

I noticed that `flang-new` cannot link Fortran executables on Solaris since
the runtime libs are missing.

This patch fixes this, following `Gnu.cpp`.  The `linker-flags.f90` testcase
is augmented to test for this.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp | 8 
 flang/test/Driver/linker-flags.f90  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 36fe12608eefc6c..252c71d3379eab4 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -223,6 +223,14 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below.
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
+  addFortranRuntimeLibs(getToolChain(), CmdArgs);
+  CmdArgs.push_back("-lm");
+}
 if (Args.hasArg(options::OPT_fstack_protector) ||
 Args.hasArg(options::OPT_fstack_protector_strong) ||
 Args.hasArg(options::OPT_fstack_protector_all)) {
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..717dcc7775e2126 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -4,6 +4,7 @@
 
 ! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and

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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth review_requested 
https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth review_requested 
https://github.com/llvm/llvm-project/pull/65644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix linking with -lm on Solaris (PR #65632)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/65632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix linking with -lm on Solaris (PR #65632)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth review_requested 
https://github.com/llvm/llvm-project/pull/65632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix linking with -lm on Solaris (PR #65632)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth review_requested 
https://github.com/llvm/llvm-project/pull/65632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix linking with -lm on Solaris (PR #65632)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth created 
https://github.com/llvm/llvm-project/pull/65632:

As noticed in D158846, the Solaris driver deviates from other targets in that 
it links every executable with `-lm`, but doesn't for shared objects. For C 
code, this is unnecessary, while for C++ `libm` is always needed, even for 
shared objects.

This patch fixes this by following the `Gnu.cpp` precedent.  It adjusts the 
`solaris-ld.c` test accordingly, adding some more tests.

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

>From 929f162e99118ecea75684975448d72cfe46b58f Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 7 Sep 2023 18:10:01 +0200
Subject: [PATCH] [Driver] Fix linking with -lm on Solaris

As noticed in D158846, the Solaris driver deviates from other targets in
that it links every executable with `-lm`, but doesn't for shared objects.
For C code, this is unnecessary, while for C++ `libm` is always needed,
even for shared objects.

This patch fixes this by following the `Gnu.cpp` precedent.  It adjusts the
`solaris-ld.c` test accordingly, adding some more tests.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp |  9 ++---
 clang/test/Driver/solaris-ld.c  | 21 -
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 4e002e348eac5f..36fe12608eefc6 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -87,6 +87,7 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
+  const Driver  = getToolChain().getDriver();
   const bool IsPIE = getPIE(Args, getToolChain());
   ArgStringList CmdArgs;
   bool LinkerIsGnuLd = isLinkerGnuLd(getToolChain(), Args);
@@ -217,8 +218,11 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
-if (getToolChain().ShouldLinkCXXStdlib(Args))
-  getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+if (D.CCCIsCXX()) {
+  if (getToolChain().ShouldLinkCXXStdlib(Args))
+getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+  CmdArgs.push_back("-lm");
+}
 if (Args.hasArg(options::OPT_fstack_protector) ||
 Args.hasArg(options::OPT_fstack_protector_strong) ||
 Args.hasArg(options::OPT_fstack_protector_all)) {
@@ -239,7 +243,6 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
   CmdArgs.push_back("-lgcc");
-  CmdArgs.push_back("-lm");
 }
 const SanitizerArgs  = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
diff --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 231e14966ea42f..09e6e8b4f07cf9 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/clang/test/Driver/solaris-ld.c
@@ -26,7 +26,6 @@
 // CHECK-GLD: "--as-needed" "-lgcc_s" "--no-as-needed"
 // CHECK-LD-SPARC32-SAME: "-lc"
 // CHECK-LD-SPARC32-SAME: "-lgcc"
-// CHECK-LD-SPARC32-SAME: "-lm"
 // CHECK-LD-SPARC32-SAME: 
"[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2{{/|}}crtend.o"
 // CHECK-LD-SPARC32-SAME: "[[SYSROOT]]/usr/lib{{/|}}crtn.o"
 
@@ -49,7 +48,6 @@
 // CHECK-LD-SPARC64-SAME: "-lgcc_s"
 // CHECK-LD-SPARC64-SAME: "-lc"
 // CHECK-LD-SPARC64-SAME: "-lgcc"
-// CHECK-LD-SPARC64-SAME: "-lm"
 // CHECK-LD-SPARC64-SAME: 
"[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9{{/|}}crtend.o"
 // CHECK-LD-SPARC64-SAME: "[[SYSROOT]]/usr/lib/sparcv9{{/|}}crtn.o"
 
@@ -72,7 +70,6 @@
 // CHECK-LD-X32-SAME: "-lgcc_s"
 // CHECK-LD-X32-SAME: "-lc"
 // CHECK-LD-X32-SAME: "-lgcc"
-// CHECK-LD-X32-SAME: "-lm"
 // CHECK-LD-X32-SAME: 
"[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4{{/|}}crtend.o"
 // CHECK-LD-X32-SAME: "[[SYSROOT]]/usr/lib{{/|}}crtn.o"
 
@@ -96,7 +93,6 @@
 // CHECK-LD-X64-SAME: "-lgcc_s"
 // CHECK-LD-X64-SAME: "-lc"
 // CHECK-LD-X64-SAME: "-lgcc"
-// CHECK-LD-X64-SAME: "-lm"
 // CHECK-LD-X64-SAME: 
"[[SYSROOT]]/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64{{/|}}crtend.o"
 // CHECK-LD-X64-SAME: "[[SYSROOT]]/usr/lib/amd64{{/|}}crtn.o"
 
@@ -110,7 +106,22 @@
 // CHECK-SPARC32-SHARED-SAME: "-lgcc_s"
 // CHECK-SPARC32-SHARED-SAME: "-lc"
 // CHECK-SPARC32-SHARED-NOT: "-lgcc"
-// CHECK-SPARC32-SHARED-NOT: "-lm"
+
+// Check that libm is only linked with clang++.
+// RUN: %clang -### %s --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
+// RUN:   | FileCheck 

[clang] [Driver] Always use gas with -fno-integrated-as on Solaris (PR #65489)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/65489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Always use gas with -fno-integrated-as on Solaris (PR #65489)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth resolved 
https://github.com/llvm/llvm-project/pull/65489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Always use gas with -fno-integrated-as on Solaris (PR #65489)

2023-09-07 Thread Rainer Orth via cfe-commits


@@ -0,0 +1,11 @@
+/// General tests for assembler invocations on Solaris.
+
+/// Test that clang uses gas on Solaris.
+// RUN: %clang -x assembler %s -### -c -fno-integrated-as \

rorth wrote:

Sure, done.

https://github.com/llvm/llvm-project/pull/65489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Always use gas with -fno-integrated-as on Solaris (PR #65489)

2023-09-07 Thread Rainer Orth via cfe-commits

https://github.com/rorth updated 
https://github.com/llvm/llvm-project/pull/65489:

>From b867ca65e585427a6d02c245d90797a08f6dfc8e Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Wed, 6 Sep 2023 16:35:27 +0200
Subject: [PATCH 1/2] [Driver] Always use gas with -fno-integrated-as on
 Solaris

`clang -fno-integrated-as` doesn't currently work on Solaris: it doesn't
even select between 32 or 64-bit objects.  Besides, Solaris has both the
native assembler (`/usr/bin/as`) and the GNU assembler (`/usr/bin/gas`
resp. `/usr/gnu/bin/as`).  The native sparc and x86 assemblers aren't
compatible with `clang`'s assembler syntax to varying degrees, and the
command line options for `as` and `gas` are completely different.

Therefore this patch chooses to always use `gas` on Solaris, using
`gnutools::Assembler::ConstructJob` to pass the correct options.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Driver/ToolChains/Gnu.cpp |  4 
 clang/lib/Driver/ToolChains/Solaris.cpp | 17 +++--
 clang/lib/Driver/ToolChains/Solaris.h   |  5 ++---
 clang/test/Driver/solaris-as.c  | 11 +++
 4 files changed, 20 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/Driver/solaris-as.c

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index d215dd779217782..7aeb8e29ebc5574 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -700,6 +700,10 @@ void tools::gnutools::Assembler::ConstructJob(Compilation 
,
   unsigned PICLevel;
   bool IsPIE;
   const char *DefaultAssembler = "as";
+  // Enforce GNU as on Solaris; the native assembler's input syntax isn't fully
+  // compatible.
+  if (getToolChain().getTriple().isOSSolaris())
+DefaultAssembler = "gas";
   std::tie(RelocationModel, PICLevel, IsPIE) =
   ParsePICArgs(getToolChain(), Args);
 
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index a22e4c2e47b87e6..30b79b4d90e0118 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -8,6 +8,7 @@
 
 #include "Solaris.h"
 #include "CommonArgs.h"
+#include "Gnu.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
@@ -32,20 +33,8 @@ void solaris::Assembler::ConstructJob(Compilation , const 
JobAction ,
   const InputInfoList ,
   const ArgList ,
   const char *LinkingOutput) const {
-  claimNoWarnArgs(Args);
-  ArgStringList CmdArgs;
-
-  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, 
options::OPT_Xassembler);
-
-  CmdArgs.push_back("-o");
-  CmdArgs.push_back(Output.getFilename());
-
-  for (const auto  : Inputs)
-CmdArgs.push_back(II.getFilename());
-
-  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
-  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
- Exec, CmdArgs, Inputs, Output));
+  // Just call the Gnu version, which enforces gas on Solaris.
+  gnutools::Assembler::ConstructJob(C, JA, Output, Inputs, Args, 
LinkingOutput);
 }
 
 bool solaris::isLinkerGnuLd(const ToolChain , const ArgList ) {
diff --git a/clang/lib/Driver/ToolChains/Solaris.h 
b/clang/lib/Driver/ToolChains/Solaris.h
index fe3e7f3a1f1b994..04b68c5053caa6c 100644
--- a/clang/lib/Driver/ToolChains/Solaris.h
+++ b/clang/lib/Driver/ToolChains/Solaris.h
@@ -19,10 +19,9 @@ namespace tools {
 
 /// solaris -- Directly call Solaris assembler and linker
 namespace solaris {
-class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
+class LLVM_LIBRARY_VISIBILITY Assembler : public gnutools::Assembler {
 public:
-  Assembler(const ToolChain )
-  : Tool("solaris::Assembler", "assembler", TC) {}
+  Assembler(const ToolChain ) : gnutools::Assembler(TC) {}
 
   bool hasIntegratedCPP() const override { return false; }
 
diff --git a/clang/test/Driver/solaris-as.c b/clang/test/Driver/solaris-as.c
new file mode 100644
index 000..bf06dd97cc3862c
--- /dev/null
+++ b/clang/test/Driver/solaris-as.c
@@ -0,0 +1,11 @@
+/// General tests for assembler invocations on Solaris.
+
+/// Test that clang uses gas on Solaris.
+// RUN: %clang -x assembler %s -### -c -fno-integrated-as \
+// RUN: --target=sparc-sun-solaris2.11 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-GAS %s
+// RUN: %clang -x assembler %s -### -c -fno-integrated-as \
+// RUN: --target=sparc-sun-solaris2.11 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-GAS %s
+/// Allow for both "/usr/bin/gas" (native) and "gas" (cross) forms.
+// CHECK-GAS: gas"

>From 1aa6e3767b08b9767bee67c22863c5e170915839 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 7 Sep 2023 11:24:10 +0200
Subject: [PATCH 2/2] Add -Wa, test.

---
 clang/test/Driver/compress-noias.c | 6 

[clang] 1bc7b75 - [clang] Consistently use isOSSolaris()

2023-09-01 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-09-01T21:45:22+02:00
New Revision: 1bc7b753a5cd1599ecf0575d629460ba08f7121e

URL: 
https://github.com/llvm/llvm-project/commit/1bc7b753a5cd1599ecf0575d629460ba08f7121e
DIFF: 
https://github.com/llvm/llvm-project/commit/1bc7b753a5cd1599ecf0575d629460ba08f7121e.diff

LOG: [clang] Consistently use isOSSolaris()

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

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

Differential Revision: https://reviews.llvm.org/D159222

Added: 


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

Removed: 




diff  --git a/clang/lib/Basic/Targets/Sparc.cpp 
b/clang/lib/Basic/Targets/Sparc.cpp
index 8b9e149037..d1a891092b0f5c 100644
--- a/clang/lib/Basic/Targets/Sparc.cpp
+++ b/clang/lib/Basic/Targets/Sparc.cpp
@@ -141,7 +141,7 @@ void SparcTargetInfo::getTargetDefines(const LangOptions 
,
 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 @@ void SparcV9TargetInfo::getTargetDefines(const LangOptions 
,
   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__");

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 37db5a2740011d..1db05b47e11ba6 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -998,7 +998,7 @@ static bool addSanitizerDynamicList(const ToolChain , 
const ArgList ,
 
   // 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")) {

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index f81a9a4982d4ca..d215dd77921778 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1838,7 +1838,7 @@ static bool findBiarchMultilibs(const Driver ,
 
   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 @@ bool 
Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib ) const {
 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 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   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"};



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


[clang] d39a9e3 - [Driver] Support GNU ld on Solaris

2023-09-01 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-09-01T21:42:05+02:00
New Revision: d39a9e3b4d4afc0321fea72b9d6b8a3908c45fc1

URL: 
https://github.com/llvm/llvm-project/commit/d39a9e3b4d4afc0321fea72b9d6b8a3908c45fc1
DIFF: 
https://github.com/llvm/llvm-project/commit/d39a9e3b4d4afc0321fea72b9d6b8a3908c45fc1.diff

LOG: [Driver] Support GNU ld on Solaris

This patch supports GNU ld on Solaris in addition to Solaris ld, the
default.

- Linker selection is dynamic: 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 when LLVM is built with
  `-DCLANG_DEFAULT_LINKER=gld` on Solaris: `MSVC.cpp`
  `visualstudio::Linker::ConstructJob` ultimately calls
  `GetProgramPath("gld")`, 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.

- `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.

Differential Revision: https://reviews.llvm.org/D85309

Added: 


Modified: 
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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4daca7ba5fc9544..37db5a2740011d4 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -22,6 +22,7 @@
 #include "HIPAMD.h"
 #include "Hexagon.h"
 #include "MSP430.h"
+#include "Solaris.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
@@ -993,9 +994,11 @@ static void addSanitizerRuntime(const ToolChain , const 
ArgList ,
 static bool addSanitizerDynamicList(const ToolChain , const ArgList ,
 ArgStringList ,
 StringRef Sanitizer) {
+  bool LinkerIsGnuLd = solaris::isLinkerGnuLd(TC, Args);
+
   // 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)
+  if (TC.getTriple().getOS() == llvm::Triple::Solaris && !LinkerIsGnuLd)
 return true;
   SmallString<128> SanRT(TC.getCompilerRT(Args, Sanitizer));
   if (llvm::sys::fs::exists(SanRT + ".syms")) {
@@ -1011,11 +1014,14 @@ void tools::addAsNeededOption(const ToolChain ,
   bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
+  bool LinkerIsGnuLd = solaris::isLinkerGnuLd(TC, Args);
 
   // While the Solaris 11.2 ld added --as-needed/--no-as-needed as aliases
   // for the native forms -z ignore/-z record, they are missing in Illumos,
   // so always use the native form.
-  if (TC.getTriple().isOSSolaris()) {
+  // GNU ld doesn't support -z ignore/-z record, so don't use them even on
+  // Solaris.
+  if (TC.getTriple().isOSSolaris() && !LinkerIsGnuLd) {
 CmdArgs.push_back("-z");
 CmdArgs.push_back(as_needed ? "ignore" : "record");
   } else {

diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 1a7839d739655d7..a22e4c2e47b87e6 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -16,6 +16,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "clang/Driver/ToolChain.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ 

[clang] b1b1f36 - [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-09-01T20:02:37+02:00
New Revision: b1b1f364d63382637fa5f64871ee06bf74bd0405

URL: 
https://github.com/llvm/llvm-project/commit/b1b1f364d63382637fa5f64871ee06bf74bd0405
DIFF: 
https://github.com/llvm/llvm-project/commit/b1b1f364d63382637fa5f64871ee06bf74bd0405.diff

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

`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).

Differential Revision: https://reviews.llvm.org/D159352

Added: 


Modified: 
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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.h 
b/clang/lib/Driver/ToolChains/Solaris.h
index fbac92c2c0f31c..9023bf7c37c522 100644
--- a/clang/lib/Driver/ToolChains/Solaris.h
+++ b/clang/lib/Driver/ToolChains/Solaris.h
@@ -63,7 +63,6 @@ class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_ELF {
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.

diff  --git a/clang/test/CodeGen/dwarf-version.c 
b/clang/test/CodeGen/dwarf-version.c
index d307eb3f101f8f..850cedf4d14c76 100644
--- a/clang/test/CodeGen/dwarf-version.c
+++ b/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

diff  --git a/clang/test/Driver/clang-g-opts.c 
b/clang/test/Driver/clang-g-opts.c
index 5ee0fe64fe484f..4882eb6068f436 100644
--- a/clang/test/Driver/clang-g-opts.c
+++ b/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"

diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 4dbd7be10982e3..8ffa88d00dff37 100644
--- a/clang/test/Driver/debug-options.c
+++ b/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:

[clang] 779353e - [Driver] Improve legibility of ld -z options on Solaris

2023-08-28 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-28T09:25:47+02:00
New Revision: 779353e576eaa6ababdfc242784484f3656ecfe0

URL: 
https://github.com/llvm/llvm-project/commit/779353e576eaa6ababdfc242784484f3656ecfe0
DIFF: 
https://github.com/llvm/llvm-project/commit/779353e576eaa6ababdfc242784484f3656ecfe0.diff

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

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`.

Differential Revision: https://reviews.llvm.org/D158955

Added: 


Modified: 
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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 3b99389fdbf228..813f80223bd830 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -999,24 +999,30 @@ static bool addSanitizerDynamicList(const ToolChain , 
const ArgList ,
   return false;
 }
 
-const char *tools::getAsNeededOption(const ToolChain , bool as_needed) {
+void tools::addAsNeededOption(const ToolChain ,
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ,
+  bool as_needed) {
   assert(!TC.getTriple().isOSAIX() &&
  "AIX linker does not support any form of --as-needed option yet.");
 
   // While the Solaris 11.2 ld added --as-needed/--no-as-needed as aliases
   // for the native forms -z ignore/-z record, they are missing in Illumos,
   // so always use the native form.
-  if (TC.getTriple().isOSSolaris())
-return as_needed ? "-zignore" : "-zrecord";
-  else
-return as_needed ? "--as-needed" : "--no-as-needed";
+  if (TC.getTriple().isOSSolaris()) {
+CmdArgs.push_back("-z");
+CmdArgs.push_back(as_needed ? "ignore" : "record");
+  } else {
+CmdArgs.push_back(as_needed ? "--as-needed" : "--no-as-needed");
+  }
 }
 
 void tools::linkSanitizerRuntimeDeps(const ToolChain ,
+ const llvm::opt::ArgList ,
  ArgStringList ) {
   // Force linking against the system libraries sanitizers depends on
   // (see PR15823 why this is necessary).
-  CmdArgs.push_back(getAsNeededOption(TC, false));
+  addAsNeededOption(TC, Args, CmdArgs, false);
   // There's no libpthread or librt on RTEMS & Android.
   if (TC.getTriple().getOS() != llvm::Triple::RTEMS &&
   !TC.getTriple().isAndroid() && !TC.getTriple().isOHOSFamily()) {
@@ -1260,8 +1266,10 @@ bool tools::addXRayRuntime(const ToolChain, const 
ArgList , ArgStringLis
   return false;
 }
 
-void tools::linkXRayRuntimeDeps(const ToolChain , ArgStringList ) {
-  CmdArgs.push_back(getAsNeededOption(TC, false));
+void tools::linkXRayRuntimeDeps(const ToolChain ,
+const llvm::opt::ArgList ,
+ArgStringList ) {
+  addAsNeededOption(TC, Args, CmdArgs, false);
   CmdArgs.push_back("-lpthread");
   if (!TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lrt");
@@ -1805,7 +1813,7 @@ static void AddUnwindLibrary(const ToolChain , const 
Driver ,
   !TC.getTriple().isAndroid() &&
   !TC.getTriple().isOSCygMing() && !TC.getTriple().isOSAIX();
   if (AsNeeded)
-CmdArgs.push_back(getAsNeededOption(TC, true));
+addAsNeededOption(TC, Args, CmdArgs, true);
 
   switch (UNW) {
   case ToolChain::UNW_None:
@@ -1839,7 +1847,7 @@ static void AddUnwindLibrary(const ToolChain , const 
Driver ,
   }
 
   if (AsNeeded)
-CmdArgs.push_back(getAsNeededOption(TC, false));
+addAsNeededOption(TC, Args, CmdArgs, false);
 }
 
 static void AddLibgcc(const ToolChain , const Driver ,

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index b1c8441226310c..7585d24c3c0eb6 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -40,12 +40,13 @@ bool addSanitizerRuntimes(const ToolChain , const 
llvm::opt::ArgList ,
   

[clang-tools-extra] 03dff0d - [clang-tidy] Disambiguate calls to log

2023-08-27 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-27T21:15:43+02:00
New Revision: 03dff0d4acafb61bbb3b765507de79c5e5b6681a

URL: 
https://github.com/llvm/llvm-project/commit/03dff0d4acafb61bbb3b765507de79c5e5b6681a
DIFF: 
https://github.com/llvm/llvm-project/commit/03dff0d4acafb61bbb3b765507de79c5e5b6681a.diff

LOG: [clang-tidy] Disambiguate calls to log

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`.

Differential Revision: https://reviews.llvm.org/D158959

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp 
b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
index 37eacf565f199d..532a43bad74127 100644
--- a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -214,10 +214,12 @@ bool UnrollLoopsCheck::hasLargeNumIterations(const Stmt 
*Statement,
   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


[clang] 62945bb - [Driver] Add PIE support on Solaris

2023-08-18 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-18T21:09:37+02:00
New Revision: 62945bb811169ffac7cf22c64b6dd3a3ad8d38f0

URL: 
https://github.com/llvm/llvm-project/commit/62945bb811169ffac7cf22c64b6dd3a3ad8d38f0
DIFF: 
https://github.com/llvm/llvm-project/commit/62945bb811169ffac7cf22c64b6dd3a3ad8d38f0.diff

LOG: [Driver] Add PIE support on Solaris

`clang` currently lacks PIE support on Solaris.  This patch fixes this,
also linking with `crtbeginS.o` and `crtendS.o` for `-pie` and `-shared`.

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

Differential Revision: https://reviews.llvm.org/D158206

Added: 

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

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 86c789f5fcef5c..de5a69e4ca3fd2 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -47,11 +47,24 @@ void solaris::Assembler::ConstructJob(Compilation , const 
JobAction ,
  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 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("_start");
   }
 
+  if (IsPIE) {
+CmdArgs.push_back("-z");
+CmdArgs.push_back("type=pie");
+  }
+
   if (Args.hasArg(options::OPT_static)) {
 CmdArgs.push_back("-Bstatic");
 CmdArgs.push_back("-dn");
@@ -113,8 +131,13 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   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);
   }
@@ -171,8 +194,12 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   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")));
   }

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtbeginS.o
 
b/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtbeginS.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtbeginS.o
 
b/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtbeginS.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 2127ad5ded074b..8d97a5a3695bdc 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/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="" \

[clang] 18252e6 - [Driver][unittest] Unbreak ToolChainTest.cpp compilation with -Werror

2023-08-16 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-16T10:37:14+02:00
New Revision: 18252e6c8e2b1bb9901b5cca9e9a75edfeda2c4e

URL: 
https://github.com/llvm/llvm-project/commit/18252e6c8e2b1bb9901b5cca9e9a75edfeda2c4e
DIFF: 
https://github.com/llvm/llvm-project/commit/18252e6c8e2b1bb9901b5cca9e9a75edfeda2c4e.diff

LOG: [Driver][unittest] Unbreak ToolChainTest.cpp compilation with -Werror

D157275 broke some buildbots that run with -Werror:

https://lab.llvm.org/buildbot#builders/36/builds/36604
https://lab.llvm.org/buildbot#builders/57/builds/29201

Avoid this by using an overlong line rather than appeasing `clang-format`.

Added: 


Modified: 
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index bf61d428448289..ae567abb81a9bb 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -183,8 +183,7 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
   "/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/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",



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


[clang] ae84ad1 - [Driver] Select newest GCC installation on Solaris

2023-08-16 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-16T09:57:59+02:00
New Revision: ae84ad15efd7ef7da95146e900ec72ceadf98058

URL: 
https://github.com/llvm/llvm-project/commit/ae84ad15efd7ef7da95146e900ec72ceadf98058
DIFF: 
https://github.com/llvm/llvm-project/commit/ae84ad15efd7ef7da95146e900ec72ceadf98058.diff

LOG: [Driver] Select newest GCC installation on Solaris

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.

This patch sorts GCC installations in reverse version order so the latest
is picked.

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

Differential Revision: https://reviews.llvm.org/D157275

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index c8fb05d238782e..508ff1d8b9ae12 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2227,6 +2227,7 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 // so we need to find those /usr/gcc/*/lib/gcc libdirs and go with
 // /usr/gcc/ as a prefix.
 
+SmallVector, 8> SolarisPrefixes;
 std::string PrefixDir = concat(SysRoot, "/usr/gcc");
 std::error_code EC;
 for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(PrefixDir, 
EC),
@@ -2244,8 +2245,13 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   if (!D.getVFS().exists(CandidateLibPath))
 continue;
 
-  Prefixes.push_back(CandidatePrefix);
+  SolarisPrefixes.emplace_back(
+  std::make_pair(CandidateVersion, CandidatePrefix));
 }
+// Sort in reverse order so GCCInstallationDetector::init picks the latest.
+std::sort(SolarisPrefixes.rbegin(), SolarisPrefixes.rend());
+for (auto p : SolarisPrefixes)
+  Prefixes.emplace_back(p.second);
 return;
   }
 

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index 8d3853a7b4a6de..bf61d428448289 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -168,6 +168,155 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
 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: 

[clang] 43dfe0f - [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-03T20:01:13+02:00
New Revision: 43dfe0f08ecaf50f986512d0548bd3ac84d1813b

URL: 
https://github.com/llvm/llvm-project/commit/43dfe0f08ecaf50f986512d0548bd3ac84d1813b
DIFF: 
https://github.com/llvm/llvm-project/commit/43dfe0f08ecaf50f986512d0548bd3ac84d1813b.diff

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

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`.

Differential Revision: https://reviews.llvm.org/D157013

Added: 

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/solaris-sparc-gcc-search.test

Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/lit.local.cfg

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 7aa6984ab8f353..485fd67ca53d3e 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1874,6 +1874,12 @@ static bool findBiarchMultilibs(const Driver ,
 .flag("-m64", /*Disallow=*/true)
 .flag("-mx32")
 .makeMultilib();
+  Multilib Alt32sparc = MultilibBuilder()
+.gccSuffix("/sparcv8plus")
+.includeSuffix("/sparcv8plus")
+.flag("-m32")
+.flag("-m64", /*Disallow=*/true)
+.makeMultilib();
 
   // GCC toolchain for IAMCU doesn't have crtbegin.o, so look for libgcc.a.
   FilterNonExistent NonExistent(
@@ -1885,10 +1891,14 @@ static bool findBiarchMultilibs(const Driver ,
   const bool IsX32 = TargetTriple.isX32();
   if (TargetTriple.isArch32Bit() && !NonExistent(Alt32))
 Want = WANT64;
+  if (TargetTriple.isArch32Bit() && !NonExistent(Alt32sparc))
+Want = WANT64;
   else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32))
 Want = WANT64;
   else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64))
 Want = WANT32;
+  else if (TargetTriple.isArch64Bit() && !NonExistent(Alt32sparc))
+Want = WANT64;
   else {
 if (TargetTriple.isArch32Bit())
   Want = NeedsBiarchSuffix ? WANT64 : WANT32;
@@ -1919,6 +1929,7 @@ static bool findBiarchMultilibs(const Driver ,
   Result.Multilibs.push_back(Alt64);
   Result.Multilibs.push_back(Alt32);
   Result.Multilibs.push_back(Altx32);
+  Result.Multilibs.push_back(Alt32sparc);
 
   Result.Multilibs.FilterOut(NonExistent);
 
@@ -1932,7 +1943,8 @@ static bool findBiarchMultilibs(const Driver ,
 
   if (Result.SelectedMultilibs.back() == Alt64 ||
   Result.SelectedMultilibs.back() == Alt32 ||
-  Result.SelectedMultilibs.back() == Altx32)
+  Result.SelectedMultilibs.back() == Altx32 ||
+  Result.SelectedMultilibs.back() == Alt32sparc)
 Result.BiarchSibling = Default;
 
   return true;

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
new file mode 100644

[clang] d0dc887 - [Driver] Remove references to Solaris 12

2023-08-03 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-03T09:54:25+02:00
New Revision: d0dc887d7ed285688004c75de3784cfe94febd34

URL: 
https://github.com/llvm/llvm-project/commit/d0dc887d7ed285688004c75de3784cfe94febd34
DIFF: 
https://github.com/llvm/llvm-project/commit/d0dc887d7ed285688004c75de3784cfe94febd34.diff

LOG: [Driver] Remove references to Solaris 12

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`.

Differential Revision: https://reviews.llvm.org/D156861

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b64fff8b14be8a..7aa6984ab8f353 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2407,13 +2407,11 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   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


[clang] 6b5149a - [Driver] Link shared asan runtime lib with -z now on Solaris/x86

2023-07-27 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-07-27T11:32:48+02:00
New Revision: 6b5149aa442efc10afa00e8864e58a24a9cf5c9f

URL: 
https://github.com/llvm/llvm-project/commit/6b5149aa442efc10afa00e8864e58a24a9cf5c9f
DIFF: 
https://github.com/llvm/llvm-project/commit/6b5149aa442efc10afa00e8864e58a24a9cf5c9f.diff

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

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` and `x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D156325

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 335a5a88cdfac6..86c789f5fcef5c 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   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,

diff  --git a/clang/test/Driver/solaris-ld-sanitizer.c 
b/clang/test/Driver/solaris-ld-sanitizer.c
index caf01919d4671e..d4fe62b5e14943 100644
--- a/clang/test/Driver/solaris-ld-sanitizer.c
+++ b/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



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


[clang] 7c4a70f - [Driver] Add crtfastmath.o on Solaris if appropriate

2023-01-13 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-01-13T10:08:33+01:00
New Revision: 7c4a70f8f6f37c0d22770fa60e079aaf8928a01c

URL: 
https://github.com/llvm/llvm-project/commit/7c4a70f8f6f37c0d22770fa60e079aaf8928a01c
DIFF: 
https://github.com/llvm/llvm-project/commit/7c4a70f8f6f37c0d22770fa60e079aaf8928a01c.diff

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

`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`.

Differential Revision: https://reviews.llvm.org/D141596

Added: 

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

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index c75375ac95f7b..7cc872c717759 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -115,6 +115,8 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 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);

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtfastmath.o
 
b/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtfastmath.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtfastmath.o
 
b/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtfastmath.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64/crtfastmath.o
 
b/clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/amd64/crtfastmath.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/crtfastmath.o
 
b/clang/test/Driver/Inputs/solaris_x86_tree/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4/crtfastmath.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 2193f35ac0545..2127ad5ded074 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/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

[clang] 1e56821 - [Linux] Hack around Linux/sparc

2022-09-10 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2022-09-10T09:37:35+02:00
New Revision: 1e56821bac02a5d3c6249bbf3ef43b8b569d2551

URL: 
https://github.com/llvm/llvm-project/commit/1e56821bac02a5d3c6249bbf3ef43b8b569d2551
DIFF: 
https://github.com/llvm/llvm-project/commit/1e56821bac02a5d3c6249bbf3ef43b8b569d2551.diff

LOG: [Linux] Hack around Linux/sparc 

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.

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

Differential Revision: https://reviews.llvm.org/D133405

Added: 


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

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 54e66b5bd9e1f..c75f7d9fbafeb 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -388,6 +388,9 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 } 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)

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index e3a24824ff190..028f3448f8bda 100644
--- a/clang/test/Preprocessor/init.c
+++ b/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



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


[clang] bf37148 - [clang][Driver] Handle SPARC -mcpu=native etc.

2022-07-29 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2022-07-29T09:27:09+02:00
New Revision: bf3714884ae4b4a0301bc6af78e8b4deff12558b

URL: 
https://github.com/llvm/llvm-project/commit/bf3714884ae4b4a0301bc6af78e8b4deff12558b
DIFF: 
https://github.com/llvm/llvm-project/commit/bf3714884ae4b4a0301bc6af78e8b4deff12558b.diff

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

To make use of SPARC support in `getHostCPUName` as implemented by D130272
, this patch uses it to handle
`-mcpu=native` and `-mtune=native`.  To match GCC, this patch rejects
`-march` instead of silently treating it as a no-op.

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

Differential Revision: https://reviews.llvm.org/D130273

Added: 
clang/test/Driver/sparc-march.c
clang/test/Driver/sparc-mcpu.c
clang/test/Driver/sparc-mtune.c

Modified: 
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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 70ba8eb2a7d0..2c9d65e7714a 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/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,30 @@ sparc::FloatABI sparc::getSparcFloatABI(const Driver ,
   return ABI;
 }
 
+std::string sparc::getSparcTargetCPU(const Driver , const ArgList ,
+ const llvm::Triple ) {
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+<< A->getSpelling() << Triple.getTriple();
+return "";
+  }
+
+  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;
+  return "";
+}
+return std::string(CPUName);
+  }
+
+  if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
+return "v9";
+  return "";
+}
+
 void sparc::getSparcTargetFeatures(const Driver , const ArgList ,
std::vector ) {
   sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);

diff  --git a/clang/lib/Driver/ToolChains/Arch/Sparc.h 
b/clang/lib/Driver/ToolChains/Arch/Sparc.h
index d12a9a70e264..44658c4259c6 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.h
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.h
@@ -28,6 +28,9 @@ enum class FloatABI {
 
 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,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e94a4e814510..f41d6f4228b6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2213,6 +2213,18 @@ void Clang::AddSparcTargetArgs(const ArgList ,
 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);
+
+CmdArgs.push_back("-tune-cpu");
+CmdArgs.push_back(Args.MakeArgString(TuneCPU));
+  }
 }
 
 void Clang::AddSystemZTargetArgs(const ArgList ,

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 05afa712a809..77ce0395cf3c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/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 @@ std::string tools::getCPUName(const Driver , const 
ArgList ,
 
   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 

[clang] 9b1897b - [Driver] Use libatomic for 32-bit SPARC atomics support on Linux

2022-07-29 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2022-07-29T09:19:38+02:00
New Revision: 9b1897bbd0e3a6e9ef099e74c3d3ed35428c0460

URL: 
https://github.com/llvm/llvm-project/commit/9b1897bbd0e3a6e9ef099e74c3d3ed35428c0460
DIFF: 
https://github.com/llvm/llvm-project/commit/9b1897bbd0e3a6e9ef099e74c3d3ed35428c0460.diff

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

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`.

Differential Revision: https://reviews.llvm.org/D130569

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 34396b0b59c2..f203cae1d329 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,16 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
 
   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");
 

diff  --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c
index d7c58431fa76..e76b35d6137c 100644
--- a/clang/test/Driver/linux-ld.c
+++ b/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 \



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


[clang] b1fc966 - [Driver] Support Solaris/amd64 GetTls

2022-02-22 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2022-02-22T20:14:33+01:00
New Revision: b1fc966d2e4176e640cda52c7148f565e93bedd0

URL: 
https://github.com/llvm/llvm-project/commit/b1fc966d2e4176e640cda52c7148f565e93bedd0
DIFF: 
https://github.com/llvm/llvm-project/commit/b1fc966d2e4176e640cda52c7148f565e93bedd0.diff

LOG: [Driver] Support Solaris/amd64 GetTls

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`.

Differential Revision: https://reviews.llvm.org/D119829

Added: 
clang/test/Driver/solaris-ld-sanitizer.c

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 24f18b92dd66..2d40598bfc1c 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/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 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   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)) {

diff  --git a/clang/test/Driver/solaris-ld-sanitizer.c 
b/clang/test/Driver/solaris-ld-sanitizer.c
new file mode 100644
index ..caf01919d467
--- /dev/null
+++ b/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



___
cfe-commits mailing 

[clang] a6afa9e - [Driver] Use libatomic for 32-bit SPARC atomics support

2022-02-10 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2022-02-10T12:40:32+01:00
New Revision: a6afa9e6b0d9a08ecc878e62343a2af80ff30435

URL: 
https://github.com/llvm/llvm-project/commit/a6afa9e6b0d9a08ecc878e62343a2af80ff30435
DIFF: 
https://github.com/llvm/llvm-project/commit/a6afa9e6b0d9a08ecc878e62343a2af80ff30435.diff

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

Even after D86621 , `clang -m32` on
Solaris/sparcv9 doesn't inline atomics with 8-byte operands, unlike `gcc`.
This leads to many link failures in the testsuite (undefined references to
`__atomic_load_8` and `__sync_val_compare_and_swap_8`.  Until a proper
codegen fix can be implemented, this patch works around the first of those
by linking with `-latomic`.

Tested on `sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D118021

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 40364d23c5599..71f5bd7cb2820 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -756,7 +756,7 @@ static bool addSanitizerDynamicList(const ToolChain , 
const ArgList ,
   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.");
 

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 646fa76949b78..23012dc247e41 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -117,6 +117,8 @@ bool addOpenMPRuntime(llvm::opt::ArgStringList , 
const ToolChain ,
   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 );
 

diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 4d1af094f4814..24f18b92dd661 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -132,6 +132,13 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   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)) {

diff  --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 59d03c4d82253..d40e5dac2da9e 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/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: 

[clang] efdd0a2 - [clang][Sparc] Fix __builtin_extract_return_addr etc.

2022-02-02 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2022-02-02T19:20:02+01:00
New Revision: efdd0a29b7eb6f3b6ca3fe9182a6c1085806c73a

URL: 
https://github.com/llvm/llvm-project/commit/efdd0a29b7eb6f3b6ca3fe9182a6c1085806c73a
DIFF: 
https://github.com/llvm/llvm-project/commit/efdd0a29b7eb6f3b6ca3fe9182a6c1085806c73a.diff

LOG: [clang][Sparc] Fix __builtin_extract_return_addr etc.

While investigating the failures of `symbolize_pc.cpp` and
`symbolize_pc_inline.cpp` on SPARC (both Solaris and Linux), I noticed that
`__builtin_extract_return_addr` is a no-op in `clang` on all targets, while
`gcc` has non-default implementations for arm, mips, s390, and sparc.

This patch provides the SPARC implementation.  For background see
`SparcISelLowering.cpp` (`SparcTargetLowering::LowerReturn_32`), the SPARC
psABI p.3-12, `%i7` and p.3-16/17, and SCD 2.4.1, p.3P-10, `%i7` and
p.3P-15.

Tested (after enabling the `sanitizer_common` tests on SPARC) on
`sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D91607

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 8a0150218a7a..9af3004ebcc5 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -9474,6 +9474,28 @@ class SparcV8TargetCodeGenInfo : public 
TargetCodeGenInfo {
 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 @@ class SparcV9TargetCodeGenInfo : public 
TargetCodeGenInfo {
 
   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
 

diff  --git a/clang/test/CodeGen/builtins-sparc.c 
b/clang/test/CodeGen/builtins-sparc.c
index 92cc7677e21f..343a1c521526 100644
--- a/clang/test/CodeGen/builtins-sparc.c
+++ b/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;
 }



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


[clang] a382a74 - [clang] Fix libclang linking on Solaris

2021-08-07 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2021-08-07T21:14:15+02:00
New Revision: a382a746275b4a1eb1867331efa2319c614305d8

URL: 
https://github.com/llvm/llvm-project/commit/a382a746275b4a1eb1867331efa2319c614305d8
DIFF: 
https://github.com/llvm/llvm-project/commit/a382a746275b4a1eb1867331efa2319c614305d8.diff

LOG: [clang] Fix libclang linking on Solaris

Linking `libclang.so` is currently broken on Solaris:

  ld: fatal: option --version-script requires option -z 
gnu-version-script-compat to be specified

While Solaris `ld` supports a considerable subset of `--version-script`,
there are some elements of the syntax that aren't.

The fix is equivalent to D78510 .

Additionally, use of C-style comments is a GNU extension
that can easily be avoided by using `#` as comment character, which is
supported by GNU `ld`, `gold`, and `lld`.

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

Differential Revision: https://reviews.llvm.org/D107559

Added: 


Modified: 
clang/tools/libclang/CMakeLists.txt
clang/tools/libclang/libclang.map

Removed: 




diff  --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 8cc0fc622174a..7148bdccfba48 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -162,6 +162,11 @@ if(ENABLE_SHARED)
   endif()
   if (USE_VERSION_SCRIPT)
 target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
+# but requires a special option to enable it.
+if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+  target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
+endif()
 # Ensure that libclang.so gets rebuilt when the linker script changes.
 set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
  OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)

diff  --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index aee46b1448457..716e2474966d5 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -1,10 +1,8 @@
-/* If you add a symbol to this file, make sure to add it with the correct
- * version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
- * symbols with the version LLVM_14.
- * On platforms where versions scripts are not used, this file will be used to
- * generate a list of exports for libclang.so
- */
-
+# If you add a symbol to this file, make sure to add it with the correct
+# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
+# symbols with the version LLVM_14.
+# On platforms where versions scripts are not used, this file will be used to
+# generate a list of exports for libclang.so
 
 LLVM_13 {
   global:
@@ -407,10 +405,9 @@ LLVM_13 {
   local: *;
 };
 
-/* Example of how to add a new symbol version entry.  If you do add a new 
symbol
- * version, please update the example to depend on the version you added.
- * LLVM_X {
- * global:
- *clang_newsymbol;
- * };
- */
+# Example of how to add a new symbol version entry.  If you do add a new symbol
+# version, please update the example to depend on the version you added.
+# LLVM_X {
+# global:
+#   clang_newsymbol;
+# };



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


[clang] 76e85ae - [clang][Sparc] Default to -mcpu=v9 for Sparc V8 on Solaris

2020-09-11 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2020-09-11T09:53:19+02:00
New Revision: 76e85ae268f8e64540703b0d1710d27ef0d36040

URL: 
https://github.com/llvm/llvm-project/commit/76e85ae268f8e64540703b0d1710d27ef0d36040
DIFF: 
https://github.com/llvm/llvm-project/commit/76e85ae268f8e64540703b0d1710d27ef0d36040.diff

LOG: [clang][Sparc] Default to -mcpu=v9 for Sparc V8 on Solaris

As reported in Bug 42535, `clang` doesn't inline atomic ops on 32-bit
Sparc, unlike `gcc` on Solaris.  In a 1-stage build with `gcc`, only two
testcases are affected (currently `XFAIL`ed), while in a 2-stage build more
than 100 tests `FAIL` due to this issue.

The reason for this `gcc`/`clang` difference is that `gcc` on 32-bit
Solaris/SPARC defaults to `-mpcu=v9` where atomic ops are supported, unlike
with `clang`'s default of `-mcpu=v8`.  This patch changes `clang` to use
`-mcpu=v9` on 32-bit Solaris/SPARC, too.

Doing so uncovered two bugs:

`clang -m32 -mcpu=v9` chokes with any Solaris system headers included:

  /usr/include/sys/isa_defs.h:461:2: error: "Both _ILP32 and _LP64 are defined"
  #error "Both _ILP32 and _LP64 are defined"

While `clang` currently defines `__sparcv9` in a 32-bit `-mcpu=v9`
compilation, neither `gcc` nor Studio `cc` do.  In fact, the Studio 12.6
`cc(1)` man page clearly states:

These predefinitions are valid in all modes:
  [...]
   __sparcv8 (SPARC)
   __sparcv9 (SPARC -m64)

At the same time, the patch defines `__GCC_HAVE_SYNC_COMPARE_AND_SWAP_[1248]`
for a 32-bit Sparc compilation with any V9 cpu.  I've also changed
`MaxAtomicInlineWidth` for V9, matching what `gcc` does and the Oracle
Developer Studio 12.6: C User's Guide documents (Ch. 3, Support for Atomic
Types, 3.1 Size and Alignment of Atomic C Types).

The two testcases that had been `XFAIL`ed for Bug 42535 are un-`XFAIL`ed
again.

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

Differential Revision: https://reviews.llvm.org/D86621

Added: 


Modified: 
clang/lib/Basic/Targets/Sparc.cpp
clang/lib/Basic/Targets/Sparc.h
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Preprocessor/predefined-arch-macros.c
compiler-rt/test/profile/Posix/instrprof-gcov-parallel.test
compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/Sparc.cpp 
b/clang/lib/Basic/Targets/Sparc.cpp
index 48f36c5ba1c6..5eeb77406c34 100644
--- a/clang/lib/Basic/Targets/Sparc.cpp
+++ b/clang/lib/Basic/Targets/Sparc.cpp
@@ -147,19 +147,20 @@ void SparcTargetInfo::getTargetDefines(const LangOptions 
,
 void SparcV8TargetInfo::getTargetDefines(const LangOptions ,
  MacroBuilder ) const {
   SparcTargetInfo::getTargetDefines(Opts, Builder);
-  switch (getCPUGeneration(CPU)) {
-  case CG_V8:
+  if (getTriple().getOS() == llvm::Triple::Solaris)
 Builder.defineMacro("__sparcv8");
-if (getTriple().getOS() != llvm::Triple::Solaris)
+  else {
+switch (getCPUGeneration(CPU)) {
+case CG_V8:
+  Builder.defineMacro("__sparcv8");
   Builder.defineMacro("__sparcv8__");
-break;
-  case CG_V9:
-Builder.defineMacro("__sparcv9");
-if (getTriple().getOS() != llvm::Triple::Solaris) {
+  break;
+case CG_V9:
+  Builder.defineMacro("__sparcv9");
   Builder.defineMacro("__sparcv9__");
   Builder.defineMacro("__sparc_v9__");
+  break;
 }
-break;
   }
   if (getTriple().getVendor() == llvm::Triple::Myriad) {
 std::string MyriadArchValue, Myriad2Value;
@@ -227,6 +228,12 @@ void SparcV8TargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__myriad2__", Myriad2Value);
 Builder.defineMacro("__myriad2", Myriad2Value);
   }
+  if (getCPUGeneration(CPU) == CG_V9) {
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+  }
 }
 
 void SparcV9TargetInfo::getTargetDefines(const LangOptions ,

diff  --git a/clang/lib/Basic/Targets/Sparc.h b/clang/lib/Basic/Targets/Sparc.h
index d24cf15d7cd6..07844abafe11 100644
--- a/clang/lib/Basic/Targets/Sparc.h
+++ b/clang/lib/Basic/Targets/Sparc.h
@@ -166,10 +166,15 @@ class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public 
SparcTargetInfo {
   PtrDiffType = SignedLong;
   break;
 }
-// Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
-// on up to 64 bits.
+// Up to 32 bits (V8) or 64 bits (V9) are lock-free atomic, but we're
+// willing to do atomic ops on up to 64 bits.
 MaxAtomicPromoteWidth = 64;
-MaxAtomicInlineWidth = 32;
+if (getCPUGeneration(CPU) == CG_V9)
+  MaxAtomicInlineWidth = 64;
+else
+  // FIXME: This isn't correct for plain V8 which lacks CAS,
+  

[clang] f59bec7 - [clang][Driver] Default to /usr/bin/ld on Solaris

2020-08-13 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2020-08-13T22:42:58+02:00
New Revision: f59bec7acb8228fc215fca3ee1e524c38083c50b

URL: 
https://github.com/llvm/llvm-project/commit/f59bec7acb8228fc215fca3ee1e524c38083c50b
DIFF: 
https://github.com/llvm/llvm-project/commit/f59bec7acb8228fc215fca3ee1e524c38083c50b.diff

LOG: [clang][Driver] Default to /usr/bin/ld on Solaris

`clang` currently requires the native linker on Solaris:

  - It passes `-C` to `ld` which GNU `ld` doesn't understand.

  - To use `gld`, one needs to pass the correct `-m EMU` option to select
the right emulation.  Solaris `ld` cannot handle that option.

So far I've worked around this by passing `-DCLANG_DEFAULT_LINKER=/usr/bin/ld`
to `cmake`.  However, if someone forgets this, it depends on the user's
`PATH` whether or not `clang` finds the correct linker, which doesn't make
for a good user experience.

While it would be nice to detect the linker flavor at runtime, this is more
involved.  Instead, this patch defaults to `/usr/bin/ld` on Solaris.  This
doesn't work on its own, however: a link fails with

  clang-12: error: unable to execute command: Executable 
"x86_64-pc-solaris2.11-/usr/bin/ld" doesn't exist!

I avoid this by leaving absolute paths alone in `ToolChain::GetLinkerPath`.

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

Differential Revision: https://reviews.llvm.org/D84029

Added: 
clang/test/Driver/solaris-ld-sld.c

Modified: 
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Solaris.h
llvm/utils/lit/lit/llvm/config.py

Removed: 




diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 2984537c23b4..7be83cade93a 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -568,8 +568,13 @@ std::string ToolChain::GetLinkerPath() const {
   }
   // If we're passed -fuse-ld= with no argument, or with the argument ld,
   // then use whatever the default system linker is.
-  if (UseLinker.empty() || UseLinker == "ld")
-return GetProgramPath(getDefaultLinker());
+  if (UseLinker.empty() || UseLinker == "ld") {
+const char *DefaultLinker = getDefaultLinker();
+if (llvm::sys::path::is_absolute(DefaultLinker))
+  return std::string(DefaultLinker);
+else
+  return GetProgramPath(DefaultLinker);
+  }
 
   // Extending -fuse-ld= to an absolute or relative path is unexpected. 
Checking
   // for the linker flavor is brittle. In addition, prepending "ld." or "ld64."

diff  --git a/clang/lib/Driver/ToolChains/Solaris.h 
b/clang/lib/Driver/ToolChains/Solaris.h
index b79e626ef38d..fbac92c2c0f3 100644
--- a/clang/lib/Driver/ToolChains/Solaris.h
+++ b/clang/lib/Driver/ToolChains/Solaris.h
@@ -65,6 +65,11 @@ class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_ELF {
   SanitizerMask getSupportedSanitizers() const override;
   unsigned GetDefaultDwarfVersion() const override { return 2; }
 
+  const char *getDefaultLinker() const override {
+// clang currently uses Solaris ld-only options.
+return "/usr/bin/ld";
+  }
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;

diff  --git a/clang/test/Driver/solaris-ld-sld.c 
b/clang/test/Driver/solaris-ld-sld.c
new file mode 100644
index ..f65153784b76
--- /dev/null
+++ b/clang/test/Driver/solaris-ld-sld.c
@@ -0,0 +1,7 @@
+// REQUIRES: system-solaris
+
+// Check that clang invokes the native ld.
+
+// RUN: test -f /usr/gnu/bin/ld && env PATH=/usr/gnu/bin %clang -o %t.o %s
+
+int main() { return 0; }

diff  --git a/llvm/utils/lit/lit/llvm/config.py 
b/llvm/utils/lit/lit/llvm/config.py
index db557a7b1fef..e9fd75e0a5fa 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -59,6 +59,8 @@ def __init__(self, lit_config, config):
 features.add('system-netbsd')
 elif platform.system() == 'AIX':
 features.add('system-aix')
+elif platform.system() == 'SunOS':
+features.add('system-solaris')
 
 # Native compilation: host arch == default triple arch
 # Both of these values should probably be in every site config (e.g. as



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


[clang] 7109494 - [clang][Driver] Don't hardcode --as-needed/--no-as-needed on Illumos

2020-08-06 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2020-08-06T10:47:16+02:00
New Revision: 710949482edb96a329104317164909979f2387aa

URL: 
https://github.com/llvm/llvm-project/commit/710949482edb96a329104317164909979f2387aa
DIFF: 
https://github.com/llvm/llvm-project/commit/710949482edb96a329104317164909979f2387aa.diff

LOG: [clang][Driver] Don't hardcode --as-needed/--no-as-needed on Illumos

`ninja check-all` currently fails on Illumos:

  [84/716] Generating default/Asan-i386-inline-Test
  FAILED: projects/compiler-rt/lib/asan/tests/default/Asan-i386-inline-Test
  cd /var/llvm/dist-amd64-release/projects/compiler-rt/lib/asan/tests && 
/var/llvm/dist-amd64-release/./bin/clang 
ASAN_INST_TEST_OBJECTS.gtest-all.cc.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_globals_test.cpp.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_interface_test.cpp.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_internal_interface_test.cpp.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_test.cpp.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_oob_test.cpp.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_mem_test.cpp.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_str_test.cpp.i386-inline.o 
ASAN_INST_TEST_OBJECTS.asan_test_main.cpp.i386-inline.o -o 
/var/llvm/dist-amd64-release/projects/compiler-rt/lib/asan/tests/default/./Asan-i386-inline-Test
 -g --driver-mode=g++ -fsanitize=address -m32
  ld: fatal: unrecognized option '--no-as-needed'
  ld: fatal: use the -z help option for usage information
  clang-11: error: linker command failed with exit code 1 (use -v to see 
invocation)

`clang` unconditionally passes `--as-needed`/`--no-as-needed` to the
linker.  This works on Solaris 11.[34] which added a couple of option
aliases to the native linker to improve compatibility with GNU `ld`.
Illumos `ld` didn't do this, so one needs to use the corresponding
native options `-z ignore`/`-z record` instead.

Because this works on both Solaris and Illumos, the current patch always
passes the native options on Solaris.  This isn't fully correct, however:
when using GNU `ld` on Solaris (not yet supported; I'm working on that),
one still needs `--as-needed` instead.

I'm hardcoding this decision because a generic detection via a `cmake` test
is hard: many systems have their own implementation of `getDefaultLinker`
and `cmake` would have to duplicate the information encoded there.
Besides, it would still break when `-fuse-ld` is used.

Tested on `amd64-pc-solaris2.11` (Solaris 11.4 and OpenIndiana 2020.04),
`sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D84412

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index acde6d9e2111..bb88dd405c67 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -630,6 +630,16 @@ static bool addSanitizerDynamicList(const ToolChain , 
const ArgList ,
   return false;
 }
 
+static const char *getAsNeededOption(const ToolChain , bool as_needed) {
+  // While the Solaris 11.2 ld added --as-needed/--no-as-needed as aliases
+  // for the native forms -z ignore/-z record, they are missing in Illumos,
+  // so always use the native form.
+  if (TC.getTriple().isOSSolaris())
+return as_needed ? "-zignore" : "-zrecord";
+  else
+return as_needed ? "--as-needed" : "--no-as-needed";
+}
+
 void tools::linkSanitizerRuntimeDeps(const ToolChain ,
  ArgStringList ) {
   // Fuchsia never needs these.  Any sanitizer runtimes with system
@@ -639,7 +649,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain ,
 
   // Force linking against the system libraries sanitizers depends on
   // (see PR15823 why this is necessary).
-  CmdArgs.push_back("--no-as-needed");
+  CmdArgs.push_back(getAsNeededOption(TC, false));
   // There's no libpthread or librt on RTEMS & Android.
   if (TC.getTriple().getOS() != llvm::Triple::RTEMS &&
   !TC.getTriple().isAndroid()) {
@@ -836,7 +846,7 @@ bool tools::addXRayRuntime(const ToolChain, const 
ArgList , ArgStringLis
 }
 
 void tools::linkXRayRuntimeDeps(const ToolChain , ArgStringList ) {
-  CmdArgs.push_back("--no-as-needed");
+  CmdArgs.push_back(getAsNeededOption(TC, false));
   CmdArgs.push_back("-lpthread");
   if (!TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lrt");
@@ -1261,7 +1271,7 @@ static void AddUnwindLibrary(const ToolChain , const 
Driver ,
   bool AsNeeded = LGT == LibGccType::UnspecifiedLibGcc &&
   !TC.getTriple().isAndroid() && !TC.getTriple().isOSCygMing();
   if (AsNeeded)
-CmdArgs.push_back("--as-needed");
+CmdArgs.push_back(getAsNeededOption(TC, true));
 
   switch (UNW) {
   case ToolChain::UNW_None:
@@ -1289,7 +1299,7 @@ static void AddUnwindLibrary(const ToolChain , const 
Driver ,
   }
 
   if (AsNeeded)
-

r367866 - [Driver] Properly use values-X[ca].o, values-xpg[46].o on Solaris

2019-08-05 Thread Rainer Orth via cfe-commits
Author: ro
Date: Mon Aug  5 07:06:16 2019
New Revision: 367866

URL: http://llvm.org/viewvc/llvm-project?rev=367866=rev
Log:
[Driver] Properly use values-X[ca].o, values-xpg[46].o on Solaris

Builtins-*-sunos :: compiler_rt_logbf_test.c currently FAILs on Solaris, both 
SPARC and
x86, 32 and 64-bit.

It turned out that this is due to different behaviour of logb depending on the C
standard compiled for, as documented on logb(3M):

  RETURN VALUES
 Upon successful completion, these functions return the exponent of x.
  
 If x is subnormal:
  
 o  For SUSv3-conforming applications compiled with the c99 com-
piler  driver  (see standards(7)), the exponent of x as if x
were normalized is returned.
  
 o  Otherwise, if compiled with the cc compiler  driver,  -1022,
-126,  and  -16382  are  returned  for  logb(), logbf(), and
logbl(), respectively.

Studio c99 and gcc control this by linking with the appropriate version of 
values-xpg[46].o, but clang uses neither of those.

The following patch fixes this by following what gcc does, as corrected some 
time ago in

  Fix use of Solaris values-Xc.o (PR target/40411)
  https://gcc.gnu.org/ml/gcc-patches/2018-01/msg02350.html and
  https://gcc.gnu.org/ml/gcc-patches/2018-01/msg02384.html.

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

Differential Revision: https://reviews.llvm.org/D64793

Added:
cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-Xa.o
cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-Xc.o
cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-xpg4.o
cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-xpg6.o
cfe/trunk/test/Driver/Inputs/solaris_x86_tree/usr/lib/values-Xa.o
cfe/trunk/test/Driver/Inputs/solaris_x86_tree/usr/lib/values-Xc.o
cfe/trunk/test/Driver/Inputs/solaris_x86_tree/usr/lib/values-xpg4.o
cfe/trunk/test/Driver/Inputs/solaris_x86_tree/usr/lib/values-xpg6.o
cfe/trunk/test/Driver/solaris-ld-values.c
cfe/trunk/test/Driver/solaris-ld-values.cpp
Modified:
cfe/trunk/lib/Driver/ToolChains/Solaris.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Solaris.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Solaris.cpp?rev=367866=367865=367866=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Solaris.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Solaris.cpp Mon Aug  5 07:06:16 2019
@@ -8,6 +8,7 @@
 
 #include "Solaris.h"
 #include "CommonArgs.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
@@ -86,8 +87,28 @@ void solaris::Linker::ConstructJob(Compi
   Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
 
 
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
+
+const Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
+bool HaveAnsi = false;
+const LangStandard *LangStd = nullptr;
+if (Std) {
+  HaveAnsi = Std->getOption().matches(options::OPT_ansi);
+  if (!HaveAnsi)
+LangStd = LangStandard::getLangStandardForName(Std->getValue());
+}
+
+const char *values_X = "values-Xa.o";
+// Use values-Xc.o for -ansi, -std=c*, -std=iso9899:199409.
+if (HaveAnsi || (LangStd && !LangStd->isGNUMode()))
+  values_X = "values-Xc.o";
+
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(values_X)));
+
+const char *values_xpg = "values-xpg6.o";
+// Use values-xpg4.o for -std=c90, -std=gnu90, -std=iso9899:199409.
+if (LangStd && LangStd->getLanguage() == Language::C && !LangStd->isC99())
+  values_xpg = "values-xpg4.o";
 CmdArgs.push_back(
-Args.MakeArgString(getToolChain().GetFilePath("values-Xa.o")));
+Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }

Added: cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-Xa.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-Xa.o?rev=367866=auto
==
(empty)

Added: cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-Xc.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-Xc.o?rev=367866=auto
==
(empty)

Added: cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-xpg4.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/solaris_sparc_tree/usr/lib/values-xpg4.o?rev=367866=auto

r367864 - Move LangStandard*, InputKind::Language to Basic

2019-08-05 Thread Rainer Orth via cfe-commits
Author: ro
Date: Mon Aug  5 06:59:26 2019
New Revision: 367864

URL: http://llvm.org/viewvc/llvm-project?rev=367864=rev
Log:
Move LangStandard*, InputKind::Language to Basic

This patch is a prerequisite for using LangStandard from Driver in
https://reviews.llvm.org/D64793.

It moves LangStandard* and InputKind::Language to Basic.  It is mostly
mechanical, with only a few changes of note:

- enum Language has been changed into enum class Language : uint8_t to
  avoid a clash between OpenCL in enum Language and OpenCL in enum
  LangFeatures and not to increase the size of class InputKind.

- Now that getLangStandardForName, which is currently unused, also checks
  both canonical and alias names, I've introduced a helper getLangKind
  which factors out a code pattern already used 3 times.

The patch has been tested on x86_64-pc-solaris2.11, sparcv9-sun-solaris2.11,
and x86_64-pc-linux-gnu.

There's a companion patch for lldb which uses LangStandard.h
(https://reviews.llvm.org/D65717).

While polly includes isl which in turn uses InputKind::C, that part of the
code isn't even built inside the llvm tree.  I've posted a patch to allow
for both InputKind::C and Language::C upstream
(https://groups.google.com/forum/#!topic/isl-development/6oEvNWOSQFE).

Differential Revision: https://reviews.llvm.org/D65562

Added:
cfe/trunk/include/clang/Basic/LangStandard.h
  - copied, changed from r367863, 
cfe/trunk/include/clang/Frontend/LangStandard.h
cfe/trunk/include/clang/Basic/LangStandards.def
  - copied, changed from r367863, 
cfe/trunk/include/clang/Frontend/LangStandards.def
cfe/trunk/lib/Basic/LangStandards.cpp
  - copied, changed from r367863, cfe/trunk/lib/Frontend/LangStandards.cpp
Removed:
cfe/trunk/include/clang/Frontend/LangStandard.h
cfe/trunk/include/clang/Frontend/LangStandards.def
cfe/trunk/lib/Frontend/LangStandards.cpp
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CompilerInvocation.h
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/Basic/CMakeLists.txt
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CMakeLists.txt
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Frontend/FrontendOptions.cpp
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp
cfe/trunk/unittests/Frontend/CodeGenActionTest.cpp
cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
cfe/trunk/unittests/Frontend/OutputStreamTest.cpp

Copied: cfe/trunk/include/clang/Basic/LangStandard.h (from r367863, 
cfe/trunk/include/clang/Frontend/LangStandard.h)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangStandard.h?p2=cfe/trunk/include/clang/Basic/LangStandard.h=cfe/trunk/include/clang/Frontend/LangStandard.h=367863=367864=367864=diff
==
--- cfe/trunk/include/clang/Frontend/LangStandard.h (original)
+++ cfe/trunk/include/clang/Basic/LangStandard.h Mon Aug  5 06:59:26 2019
@@ -6,16 +6,37 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_FRONTEND_LANGSTANDARD_H
-#define LLVM_CLANG_FRONTEND_LANGSTANDARD_H
+#ifndef LLVM_CLANG_BASIC_LANGSTANDARD_H
+#define LLVM_CLANG_BASIC_LANGSTANDARD_H
 
 #include "clang/Basic/LLVM.h"
-#include "clang/Frontend/FrontendOptions.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace clang {
 
-namespace frontend {
+/// The language for the input, used to select and validate the language
+/// standard and possible actions.
+enum class Language : uint8_t {
+  Unknown,
+
+  /// Assembly: we accept this only so that we can preprocess it.
+  Asm,
+
+  /// LLVM IR: we accept this so that we can run the optimizer on it,
+  /// and compile it to assembly or object code.
+  LLVM_IR,
+
+  ///@{ Languages that the frontend can parse and compile.
+  C,
+  CXX,
+  ObjC,
+  ObjCXX,
+  OpenCL,
+  CUDA,
+  RenderScript,
+  HIP,
+  ///@}
+};
 
 enum LangFeatures {
   LineComment = (1 << 0),
@@ -35,22 +56,20 @@ enum LangFeatures {
   OpenCL = (1 << 14)
 };
 
-}
-
 /// LangStandard - Information about the properties of a particular language
 /// standard.
 struct LangStandard {
   enum Kind {
 #define LANGSTANDARD(id, name, lang, desc, features) \
 lang_##id,
-#include "clang/Frontend/LangStandards.def"
+#include "clang/Basic/LangStandards.def"
 lang_unspecified
   };
 
   const char *ShortName;
   const char *Description;
   unsigned Flags;
-  InputKind::Language Language;
+  clang::Language Language;
 
 public:
   /// 

r367351 - [Driver] Support -fsanitize=function on Solaris/x86

2019-07-30 Thread Rainer Orth via cfe-commits
Author: ro
Date: Tue Jul 30 13:04:53 2019
New Revision: 367351

URL: http://llvm.org/viewvc/llvm-project?rev=367351=rev
Log:
[Driver] Support -fsanitize=function on Solaris/x86

UBSan-Standalone-x86_64 :: TestCases/TypeCheck/Function/function.cpp currently
FAILs on Solaris/x86_64:

  clang-9: error: unsupported option '-fsanitize=function' for target 
'x86_64-pc-solaris2.11'

AFAICS, there's nothing more to do then enable that sanitizer in the driver 
(for x86 only),
which is what this patch does, together with updating another testcase.

Tested on x86_64-pc-solaris2.11.

Differential Revision: https://reviews.llvm.org/D64488

Modified:
cfe/trunk/lib/Driver/ToolChains/Solaris.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/lib/Driver/ToolChains/Solaris.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Solaris.cpp?rev=367351=367350=367351=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Solaris.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Solaris.cpp Tue Jul 30 13:04:53 2019
@@ -177,6 +177,7 @@ Solaris::Solaris(const Driver , const
 
 SanitizerMask Solaris::getSupportedSanitizers() const {
   const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+  const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   // FIXME: Omit X86_64 until 64-bit support is figured out.
   if (IsX86) {
@@ -184,6 +185,8 @@ SanitizerMask Solaris::getSupportedSanit
 Res |= SanitizerKind::PointerCompare;
 Res |= SanitizerKind::PointerSubtract;
   }
+  if (IsX86 || IsX86_64)
+Res |= SanitizerKind::Function;
   Res |= SanitizerKind::Vptr;
   return Res;
 }

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=367351=367350=367351=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Tue Jul 30 13:04:53 2019
@@ -727,6 +727,9 @@
 // RUN: %clang -target x86_64--netbsd -fsanitize=scudo %s -### 2>&1 | 
FileCheck %s -check-prefix=SCUDO-NETBSD
 // SCUDO-NETBSD: "-fsanitize=scudo"
 
+// RUN: %clang -target i386--solaris -fsanitize=function %s -### 2>&1 | 
FileCheck %s -check-prefix=FUNCTION-SOLARIS
+// RUN: %clang -target x86_64--solaris -fsanitize=function %s -### 2>&1 | 
FileCheck %s -check-prefix=FUNCTION-SOLARIS
+// FUNCTION-SOLARIS: "-fsanitize=function"
 
 
 // RUN: %clang -target x86_64-scei-ps4 -fsanitize=function 
-fsanitize=undefined %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-FSAN-UBSAN-PS4


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


r367305 - [Driver] Define _FILE_OFFSET_BITS=64 on Solaris

2019-07-30 Thread Rainer Orth via cfe-commits
Author: ro
Date: Tue Jul 30 03:38:41 2019
New Revision: 367305

URL: http://llvm.org/viewvc/llvm-project?rev=367305=rev
Log:
[Driver] Define _FILE_OFFSET_BITS=64 on Solaris

make check-all currently fails on x86_64-pc-solaris2.11 when building with GCC 
9:

  Undefined   first referenced
   symbol in file
  _ZN11__sanitizer14internal_lseekEimi 
SANITIZER_TEST_OBJECTS.sanitizer_libc_test.cc.i386.o
  _ZN11__sanitizer23MapWritableFileToMemoryEPvmim 
SANITIZER_TEST_OBJECTS.sanitizer_libc_test.cc.i386.o
  ld: fatal: symbol referencing errors
  clang-9: error: linker command failed with exit code 1 (use -v to see 
invocation)
  make[3]: *** 
[projects/compiler-rt/lib/sanitizer_common/tests/CMakeFiles/TSanitizer-i386-Test.dir/build.make:92:
 projects/compiler-rt/lib/sanitizer_common/tests/Sanitizer-i386-Test] Error 1

While e.g. __sanitizer::internal_lseek is defined in sanitizer_solaris.cc, g++ 9
predefines _FILE_OFFSET_BITS=64 while clang++ currently does not.

This patch resolves this inconsistency by following the gcc lead, which allows
make check-all to finish successfully.

There's one caveat: gcc defines _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE for 
C++ only, while clang has long been doing it for
all languages.  I'd like to keep it this way because those macros do is to make
declarations of fseek/ftello (_LARGEFILE_SOURCE) resp. the 64-bit versions
of largefile functions (*64 with _LARGEFILE64_SOURCE) visible additionally.
However, _FILE_OFFSET_BITS=64 changes all affected functions to be 
largefile-aware.
I'd like to restrict this to C++, just like gcc does.

To avoid a similar inconsistence with host compilers that don't predefine 
_FILE_OFFSET_BITS=64
(e.g. clang < 9, gcc < 9), this needs a compantion patch 
https://reviews.llvm.org/D64483.

Tested on x86_64-pc-solaris2.11.

Differential Revision: https://reviews.llvm.org/D64482

Modified:
cfe/trunk/lib/Basic/Targets/OSTargets.h

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=367305=367304=367305=diff
==
--- cfe/trunk/lib/Basic/Targets/OSTargets.h (original)
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h Tue Jul 30 03:38:41 2019
@@ -622,8 +622,11 @@ protected:
   Builder.defineMacro("_XOPEN_SOURCE", "600");
 else
   Builder.defineMacro("_XOPEN_SOURCE", "500");
-if (Opts.CPlusPlus)
+if (Opts.CPlusPlus) {
   Builder.defineMacro("__C99FEATURES__");
+  Builder.defineMacro("_FILE_OFFSET_BITS", "64");
+}
+// GCC restricts the next two to C++.
 Builder.defineMacro("_LARGEFILE_SOURCE");
 Builder.defineMacro("_LARGEFILE64_SOURCE");
 Builder.defineMacro("__EXTENSIONS__");


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


r366820 - [clang, test] Fix Clang :: Headers/max_align.c on 64-bit SPARC

2019-07-23 Thread Rainer Orth via cfe-commits
Author: ro
Date: Tue Jul 23 09:24:00 2019
New Revision: 366820

URL: http://llvm.org/viewvc/llvm-project?rev=366820=rev
Log:
[clang, test] Fix Clang :: Headers/max_align.c on 64-bit SPARC

Clang :: Headers/max_align.c currently FAILs on 64-bit SPARC:

  error: 'error' diagnostics seen but not expected: 
File /vol/llvm/src/clang/dist/test/Headers/max_align.c Line 12: 
static_assert failed due to requirement '8 == _Alignof(max_align_t)' ""
  1 error generated.

This happens because SuitableAlign isn't defined for SPARCv9 unlike SPARCv8
(which uses the default of 64 bits).  gcc's sparc/sparc.h has

  #define BIGGEST_ALIGNMENT (TARGET_ARCH64 ? 128 : 64)

This patch sets SuitableAlign to match and updates the corresponding testcase.

Tested on sparcv9-sun-solaris2.11.

Differential Revision: https://reviews.llvm.org/D64487

Modified:
cfe/trunk/lib/Basic/Targets/Sparc.h
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/lib/Basic/Targets/Sparc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/Sparc.h?rev=366820=366819=366820=diff
==
--- cfe/trunk/lib/Basic/Targets/Sparc.h (original)
+++ cfe/trunk/lib/Basic/Targets/Sparc.h Tue Jul 23 09:24:00 2019
@@ -208,6 +208,7 @@ public:
 // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
+SuitableAlign = 128;
 LongDoubleFormat = ::APFloat::IEEEquad();
 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
   }

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=366820=366819=366820=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Tue Jul 23 09:24:00 2019
@@ -9599,6 +9599,7 @@
 // X86-64-DECLSPEC: #define __declspec{{.*}}
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-none < /dev/null 
| FileCheck -match-full-lines -check-prefix SPARCV9 %s
+// SPARCV9:#define __BIGGEST_ALIGNMENT__ 16
 // SPARCV9:#define __INT64_TYPE__ long int
 // SPARCV9:#define __INTMAX_C_SUFFIX__ L
 // SPARCV9:#define __INTMAX_TYPE__ long int


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


r366305 - [Driver] Enable __cxa_atexit on Solaris

2019-07-17 Thread Rainer Orth via cfe-commits
Author: ro
Date: Wed Jul 17 01:37:00 2019
New Revision: 366305

URL: http://llvm.org/viewvc/llvm-project?rev=366305=rev
Log:
[Driver] Enable __cxa_atexit on Solaris

Starting with Solaris 11.4 (which is now the required minimal version), Solaris 
does
support __cxa_atexit.  This patch reflects that.

One might consider removing the affected tests altogether instead of inverting 
them,
as is done on other targets.

Besides, this lets two ASan tests PASS:

  AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
  AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc

Tested on x86_64-pc-solaris2.11 and sparcv9-sun-solaris2.11.

Differential Revision: https://reviews.llvm.org/D64491

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/cxa-atexit.cpp
cfe/trunk/test/Driver/solaris-opts.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=366305=366304=366305=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Jul 17 01:37:00 2019
@@ -4749,7 +4749,6 @@ void Clang::ConstructJob(Compilation ,
   if (!Args.hasFlag(
   options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
   !RawTriple.isOSWindows() &&
-  RawTriple.getOS() != llvm::Triple::Solaris &&
   TC.getArch() != llvm::Triple::xcore &&
   ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||

Modified: cfe/trunk/test/Driver/cxa-atexit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cxa-atexit.cpp?rev=366305=366304=366305=diff
==
--- cfe/trunk/test/Driver/cxa-atexit.cpp (original)
+++ cfe/trunk/test/Driver/cxa-atexit.cpp Wed Jul 17 01:37:00 2019
@@ -19,7 +19,7 @@
 // RUN: %clang -### -target sparc-sun-solaris -c %s -o /dev/null 2>&1 | 
FileCheck %s -check-prefix CHECK-SOLARIS
 
 // CHECK-WINDOWS: "-fno-use-cxa-atexit"
-// CHECK-SOLARIS: "-fno-use-cxa-atexit"
+// CHECK-SOLARIS-NOT: "-fno-use-cxa-atexit"
 // CHECK-HEXAGON-NOT: "-fno-use-cxa-atexit"
 // CHECK-XCORE: "-fno-use-cxa-atexit"
 // CHECK-MTI: "-fno-use-cxa-atexit"

Modified: cfe/trunk/test/Driver/solaris-opts.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/solaris-opts.c?rev=366305=366304=366305=diff
==
--- cfe/trunk/test/Driver/solaris-opts.c (original)
+++ cfe/trunk/test/Driver/solaris-opts.c Wed Jul 17 01:37:00 2019
@@ -1,4 +1,4 @@
 // RUN: %clang %s --target=sparc-sun-solaris2.11 -### -o %t.o 2>&1 | FileCheck 
%s
 
-// CHECK: "-fno-use-cxa-atexit"
+// CHECK-NOT: "-fno-use-cxa-atexit"
 


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


  1   2   >