Skip to content

[Driver] Fix _XOPEN_SOURCE definition on Solaris #137141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2025

Conversation

rorth
Copy link
Collaborator

@rorth rorth commented Apr 24, 2025

Since commit 613a077, flang doesn't build any longer on Solaris/amd64:

flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~

That patch led to the version of quadmath.h deep inside /usr/gcc/<N> to be found, thus HAS_QUADMATHLIB is defined. However, the struct HostRuntimeLibrary<__float128, LibraryVersion::Libm> template is guarded by _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600, while clang only predefines _XOPEN_SOURCE=500.

This code dates back to commit 0c1941c back in 2012. Currently, this is long obsolete and gcc prefefines _XOPEN_SOURCE=600 instead since GCC 4.6 back in 2011.

This patch follows that.

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

Since commit 613a077, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match requi
red type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>` to
be found, thus `HAS_QUADMATHLIB` is defined.  However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is guarded
by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while `clang`
only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941c
back in 2012.  Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
@rorth rorth requested a review from MaskRay April 24, 2025 08:44
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 24, 2025

@llvm/pr-subscribers-clang

Author: Rainer Orth (rorth)

Changes

Since commit 613a077, flang doesn't build any longer on Solaris/amd64:

flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory&lt;F, F{std::acos}&gt;::Create("acos"),
      |                          ^~~~~~~~~

That patch led to the version of quadmath.h deep inside /usr/gcc/&lt;N&gt; to be found, thus HAS_QUADMATHLIB is defined. However, the struct HostRuntimeLibrary&lt;__float128, LibraryVersion::Libm&gt; template is guarded by _POSIX_C_SOURCE &gt;= 200112L || _XOPEN_SOURCE &gt;= 600, while clang only predefines _XOPEN_SOURCE=500.

This code dates back to commit 0c1941c back in 2012. Currently, this is long obsolete and gcc prefefines _XOPEN_SOURCE=600 instead since GCC 4.6 back in 2011.

This patch follows that.

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


Full diff: https://github.com/llvm/llvm-project/pull/137141.diff

1 Files Affected:

  • (modified) clang/lib/Basic/Targets/OSTargets.h (+1-8)
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index a88c851797aab..d148b38d03c7c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -618,14 +618,7 @@ class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
     DefineStd(Builder, "unix", Opts);
     Builder.defineMacro("__svr4__");
     Builder.defineMacro("__SVR4");
-    // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
-    // newer, but to 500 for everything else.  feature_test.h has a check to
-    // ensure that you are not using C99 with an old version of X/Open or C89
-    // with a new version.
-    if (Opts.C99)
-      Builder.defineMacro("_XOPEN_SOURCE", "600");
-    else
-      Builder.defineMacro("_XOPEN_SOURCE", "500");
+    Builder.defineMacro("_XOPEN_SOURCE", "600");
     if (Opts.CPlusPlus) {
       Builder.defineMacro("__C99FEATURES__");
       Builder.defineMacro("_FILE_OFFSET_BITS", "64");

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I have limited internet access between April 20th and May 4th, and my response time may be delayed..)

@rorth rorth merged commit e71c8ea into llvm:main Apr 26, 2025
14 checks passed
jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
Since commit 613a077, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>`
to be found, thus `HAS_QUADMATHLIB` is defined. However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is
guarded by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while
`clang` only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941c
back in 2012. Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
@rorth rorth added this to the LLVM 20.X Release milestone May 2, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status May 2, 2025
@rorth
Copy link
Collaborator Author

rorth commented May 2, 2025

/cherry-pick e71c8ea

@rorth
Copy link
Collaborator Author

rorth commented May 2, 2025

This patch is required to build flang on Solaris/amd64. Until very recently, a 2-stage build of main with flang included worked with clang-20 as build compiler since flang was only built in stage 2 and the freshly built clang-21 does include the patch.. However, now flang is built in stage 1 already, so the stage 1 compiler needs to include this patch, too, to avoid the build breaking again.

IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Since commit 613a077, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>`
to be found, thus `HAS_QUADMATHLIB` is defined. However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is
guarded by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while
`clang` only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941c
back in 2012. Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Since commit 613a077, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>`
to be found, thus `HAS_QUADMATHLIB` is defined. However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is
guarded by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while
`clang` only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941c
back in 2012. Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Since commit 613a077, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>`
to be found, thus `HAS_QUADMATHLIB` is defined. However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is
guarded by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while
`clang` only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941c
back in 2012. Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
Since commit 613a077, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>`
to be found, thus `HAS_QUADMATHLIB` is defined. However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is
guarded by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while
`clang` only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941c
back in 2012. Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
@tstellar
Copy link
Collaborator

Was there a backport PR created for this change?

@tstellar tstellar moved this from Needs Triage to Needs Pull Request in LLVM Release Status May 10, 2025
@rorth
Copy link
Collaborator Author

rorth commented May 10, 2025

No. However, I got an error for the /cherry-pick that looks like some weird internal error to me, not a failed merge attempt or some such.

@llvmbot
Copy link
Member

llvmbot commented May 10, 2025

Failed to cherry-pick: `

https://github.com/llvm/llvm-project/actions/runs/14947694098

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

@rorth
Copy link
Collaborator Author

rorth commented May 15, 2025

Drats, I'd hoped the markup would inhibit the cherry pick directive from being picked up.

I've now dropped the patch into local LLVM 20.1.5 builds on both amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11. It applied cleanly and introduced no regressions. I'll try a regular cherry pick again: maybe it finally works this time.

@rorth
Copy link
Collaborator Author

rorth commented May 15, 2025

/cherry-pick e71c8ea

@llvmbot
Copy link
Member

llvmbot commented May 15, 2025

/pull-request #140044

@llvmbot llvmbot moved this from Needs Backport PR to Done in LLVM Release Status May 15, 2025
swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request May 27, 2025
Since commit 613a077, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>`
to be found, thus `HAS_QUADMATHLIB` is defined. However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is
guarded by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while
`clang` only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941c
back in 2012. Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

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

(cherry picked from commit e71c8ea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
Development

Successfully merging this pull request may close these issues.

4 participants