Skip to content

Conversation

linuxrocks123
Copy link
Contributor

Flang currently doesn't build in debug mode on GCC 15 due to missing dynamic libraries in some CMakeLists.txt files, and OpenMP doesn't link in debug mode due to the atomic library pulling in libstdc++ despite an incomplete attempt in the CMakeLists.txt to disable glibcxx assertions. This PR fixes these issues and allows Flang and the OpenMP runtime to build and link on GCC 15 in debug mode.

Copy link

github-actions bot commented Aug 5, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir openmp:libomp OpenMP host runtime labels Aug 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Patrick Simmons (linuxrocks123)

Changes

Flang currently doesn't build in debug mode on GCC 15 due to missing dynamic libraries in some CMakeLists.txt files, and OpenMP doesn't link in debug mode due to the atomic library pulling in libstdc++ despite an incomplete attempt in the CMakeLists.txt to disable glibcxx assertions. This PR fixes these issues and allows Flang and the OpenMP runtime to build and link on GCC 15 in debug mode.


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

3 Files Affected:

  • (modified) flang/lib/Optimizer/Builder/CMakeLists.txt (+1)
  • (modified) flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt (+2)
  • (modified) openmp/runtime/src/CMakeLists.txt (+1-1)
diff --git a/flang/lib/Optimizer/Builder/CMakeLists.txt b/flang/lib/Optimizer/Builder/CMakeLists.txt
index 31ae395805faf..eb4413887e67e 100644
--- a/flang/lib/Optimizer/Builder/CMakeLists.txt
+++ b/flang/lib/Optimizer/Builder/CMakeLists.txt
@@ -49,6 +49,7 @@ add_flang_library(FIRBuilder
   FIRDialectSupport
   FIRSupport
   FortranEvaluate
+  FortranSupport
   HLFIRDialect
 
   MLIR_DEPS
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
index cc74273d9c5d9..3775a13e31e95 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
@@ -27,6 +27,8 @@ add_flang_library(HLFIRTransforms
   FIRSupport
   FIRTransforms
   FlangOpenMPTransforms
+  FortranEvaluate
+  FortranSupport
   HLFIRDialect
 
   LINK_COMPONENTS
diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index 569061c6494b8..9a2d490bdd65d 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -168,7 +168,7 @@ endif()
 # Disable libstdc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, to
 # avoid an unwanted dependency on libstdc++.so.
 if(NOT WIN32)
-  add_definitions(-U_GLIBCXX_ASSERTIONS)
+  add_definitions(-U_GLIBCXX_ASSERTIONS -D_GLIBCXX_NO_ASSERTIONS)
 endif()
 
 # Add the OpenMP library

@linuxrocks123
Copy link
Contributor Author

@LU-JOHN do you mind reviewing?

@vzakhari
Copy link
Contributor

vzakhari commented Aug 6, 2025

Flang changes look good to me. Thanks!

@linuxrocks123 linuxrocks123 changed the title Correctly Link Flang Dynamic Libraries and Disable libstdc++ Assertions Fix GCC 15 Debug Build Aug 6, 2025
@linuxrocks123 linuxrocks123 changed the title Fix GCC 15 Debug Build Fix Debug Build Using GCC 15 Aug 6, 2025
@LU-JOHN
Copy link
Contributor

LU-JOHN commented Aug 6, 2025

Looks good.

@klausler klausler removed their request for review August 21, 2025 21:21
@ronlieb ronlieb requested review from ronlieb and klausler August 21, 2025 21:21
Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

LGTM, but with a grain of salt, as I'm not /the/ expert on build system issues.

@ronlieb ronlieb merged commit 304373f into llvm:main Aug 21, 2025
9 checks passed
Copy link

@linuxrocks123 Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@klausler klausler removed their request for review August 21, 2025 22:30
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 21, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building flang-rt,flang,openmp at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/11941

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libarcher :: races/task-taskwait-nested.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang -fopenmp  -gdwarf-4 -O1 -fsanitize=thread  -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src   /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp -latomic && env TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1' /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp 2>&1 | tee /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp.log | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c
# executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang -fopenmp -gdwarf-4 -O1 -fsanitize=thread -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp -latomic
# note: command had no output on stdout or stderr
# executed command: env TSAN_OPTIONS=ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp
# note: command had no output on stdout or stderr
# executed command: tee /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp.log
# note: command had no output on stdout or stderr
# executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c
# .---command stderr------------
# | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c:54:16: error: CHECK-NEXT: is not on the line after the previous match
# | // CHECK-NEXT: #0 {{.*}}task-taskwait-nested.c:34
# |                ^
# | <stdin>:10:2: note: 'next' match was here
# |  #0 .omp_outlined..1 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c:34:12 (task-taskwait-nested.c.tmp+0x128061)
# |  ^
# | <stdin>:3:17: note: previous match ended here
# |  Write of size 4 at 0x7fffffffe770 by main thread:
# |                 ^
# | <stdin>:4:1: note: non-matching line after previous match is here
# |  #0 main.omp_outlined_debug__ /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c:44:8 (task-taskwait-nested.c.tmp+0x127fc2)
# | ^
# | 
# | Input file: <stdin>
# | Check file: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |          .
# |          .
# |          .
# |          5:  #1 main.omp_outlined /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c:24:1 (task-taskwait-nested.c.tmp+0x127fc2) 
# |          6:  #2 __kmp_invoke_microtask <null> (libomp.so+0xec578) 
# |          7:  #3 main /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c:24:1 (task-taskwait-nested.c.tmp+0x1281a7) 
# |          8:  
# |          9:  Previous write of size 4 at 0x7fffffffe770 by thread T1: 
# |         10:  #0 .omp_outlined..1 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c:34:12 (task-taskwait-nested.c.tmp+0x128061) 
# | next:54      !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                           error: match on wrong line
# |         11:  #1 .omp_task_entry. /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c:29:1 (task-taskwait-nested.c.tmp+0x128061) 
# |         12:  #2 __kmp_invoke_task(int, kmp_task*, kmp_taskdata*) kmp_tasking.cpp (libomp.so+0x86fae) 
# |         13:  
# |         14:  As if synchronized via sleep: 
# |         15:  #0 usleep /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:386:3 (task-taskwait-nested.c.tmp+0xa02a7) 
...

@dpalermo
Copy link
Contributor

dpalermo commented Aug 22, 2025

Don't add this option by default as it will expose backend errors when building for the AMDGPU:

add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-O2>)

dpalermo added a commit that referenced this pull request Aug 22, 2025
dpalermo added a commit that referenced this pull request Aug 22, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Aug 22, 2025
Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

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

It would be good if you could have explained which change fixes which gcc 15 error. If you would like to fix multiple unrelated build problems, consider multiple PRs.

Comment on lines +186 to +188
add_definitions(-U_GLIBCXX_ASSERTIONS -D_GLIBCXX_NO_ASSERTIONS)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-O2>)
Copy link
Member

@Meinersbur Meinersbur Aug 22, 2025

Choose a reason for hiding this comment

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

  1. -U_GLIBCXX_ASSERTIONS and -fno-exceptions are already added in AddFlangRT.cmake. _GLIBCXX_NO_ASSERTIONS should not be necessary, but could be an alternative to -U_GLIBCXX_ASSERTIONS
  2. We prefer modern CMake style
  3. Adding -O2 overrides the choice of CMAKE_BUILD_TYPE. What optimization level to use should be left to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Meinersbur

Re 2: A suggested alternative syntax would be helpful in understanding what you are suggesting.
Re 3: I don't like forcing -O2 either, but I don't see an alternative to making the DCE happen that's necessary to get rid of the offending undefined symbol.

Copy link
Member

Choose a reason for hiding this comment

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

target_compile_options and target_compile_definitions. See AddFlangRT.cmake. _GLIBCXX_ASSERTIONS and -fno-exceptions are already handled there. If there are any issus with those, it should be fixed in AddFlangRT.cmake, not here.

Copy link
Contributor Author

@linuxrocks123 linuxrocks123 Aug 28, 2025

Choose a reason for hiding this comment

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

@Meinersbur after checking again, I can verify that -fno-exceptions is present in compile_commands.json in the current master, so there's no need for a line adding it in this PR. -O2 must still be added, or else the build succeeds but the Fortran compiler cannot create executables because its runtime library has an undefined symbol.

Meinersbur added a commit that referenced this pull request Aug 26, 2025
In contrast to linking a static library, when linking a shared library
all referenced symbols must be available in either the objects files,
static libraries, or shared libraries passed to the linker command line
and cannot be deferred to when building the executable.

Fixes #150027

Same fix as included in #152223, but with only the changes necessary to
fix #150027 (which is unrelated to GCC 15)
Meinersbur added a commit that referenced this pull request Aug 27, 2025
Since GCC 15.1, libstdc++ enabled assertions/hardening by default in
non-optimized (-O0) builds [1]. That is, _GLIBCXX_ASSERTIONS is defined
in the libstdc++ headers itself so defining/undefining it on the
compiler command line no longer has an effect in non-optimized builds.
As the commit message[2] suggests, define _GLIBCXX_NO_ASSERTIONS
instead.

For libstdc++ headers before 15.1, -U_GLIBCXX_ASSERTIONS still has to be
on the command line as well.

Defining _GLIBCXX_NO_ASSERTIONS was previously proposed in #152223

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112808
[2] gcc-mirror/gcc@361d230
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category openmp:libomp OpenMP host runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants