Skip to content

Conversation

@lfmeadow
Copy link
Contributor

This can happen in static destructors when called after the
runtime is already shutdown (e.g., by ompt_finalize_tool). Even
though it is technically an error to call omp_destroy_lock after
shutdown, the application doesn't necessarily know that omp_destroy_lock
was already called. This is safe becaues all indirect locks are
destoryed in __kmp_cleanup_indirect_user_locks so the return
value will always be valid or a nullptr, not garbage.

@github-actions
Copy link

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 the openmp:libomp OpenMP host runtime label Jun 25, 2025
@lfmeadow
Copy link
Contributor Author

@TerryLWilmarth @jpeyton52 could you please review this? I realize it is a point fix but it addresses a use case in RAJA and seems like a nice user-friendly thing to do. It shows up with AMD's rocprof-sdk which implements its own OMPT client tool.
I can easily add a lit test.

Copy link
Contributor

@TerryLWilmarth TerryLWilmarth left a comment

Choose a reason for hiding this comment

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

LGTM
@hansangbae Does this look okay to you too?

@hansangbae
Copy link
Contributor

Looks fine to me.

@lfmeadow
Copy link
Contributor Author

lfmeadow commented Jun 25, 2025

Can someone please approve the workflow?

@github-actions
Copy link

github-actions bot commented Jun 25, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@jprotze jprotze left a comment

Choose a reason for hiding this comment

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

Can you add a test case for this?

@lfmeadow
Copy link
Contributor Author

Can you add a test case for this?

Will do.

@jprotze
Copy link
Collaborator

jprotze commented Jun 25, 2025

Thanks! Also, thanks for working on this and coming up with a fix! Some performance tool folks also complained to me about this before.

@lfmeadow
Copy link
Contributor Author

Thanks! Also, thanks for working on this and coming up with a fix! Some performance tool folks also complained to me about this before.

You're welcome. Yes, it came from RAJA . There are probably some others lurking but this one seemed to be likely enough that it was worth a point fix.

  This can happen in static destructors when called after the
  runtime is already shutdown (e.g., by ompt_finalize_tool). Even
  though it is technically an error to call omp_destroy_lock after
  shutdown, the application doesn't necessarily know that omp_destroy_lock
  was already called. This is safe becaues all indirect locks are
  destoryed in __kmp_cleanup_indirect_user_locks so the return
  value will always be valid or a nullptr, not garbage.
@lfmeadow lfmeadow force-pushed the openmp-avoid-segv-omp_destroy_lock branch from 6619553 to 511cfaf Compare June 25, 2025 18:18
@lfmeadow
Copy link
Contributor Author

@jprotze OK, test is added and I fixed the formatting issue. I guess there's another workflow approval required.

Copy link
Collaborator

@jprotze jprotze left a comment

Choose a reason for hiding this comment

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

Lgtm

@jprotze jprotze merged commit aec8867 into llvm:main Jun 25, 2025
7 checks passed
@github-actions
Copy link

@lfmeadow 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!

@lfmeadow lfmeadow deleted the openmp-avoid-segv-omp_destroy_lock branch June 25, 2025 19:36
@kwk
Copy link
Contributor

kwk commented Jun 26, 2025

It looks like the test ompt/misc/lock_double_destroy.cpp that was added with this PR fails in our build on fedora-rawhide-i386 and fedora-42-i386 with the following output. (This was discovered here).

FAIL: libomp :: ompt/misc/lock_double_destroy.cpp (141 of 402, 5 of 5 attempts)
******************** TEST 'libomp :: ompt/misc/lock_double_destroy.cpp' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/./bin/clang++ -fopenmp   -I /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/src -I /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test -L /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -I /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt -std=c++17 /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/misc/lock_double_destroy.cpp -o /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/test/ompt/misc/Output/lock_double_destroy.cpp.tmp -lm -latomic && /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/test/ompt/misc/Output/lock_double_destroy.cpp.tmp | tee /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/test/ompt/misc/Output/lock_double_destroy.cpp.tmp.out | /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/./bin/FileCheck /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/misc/lock_double_destroy.cpp
# executed command: /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/./bin/clang++ -fopenmp -I /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/src -I /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test -L /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -I /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt -std=c++17 /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/misc/lock_double_destroy.cpp -o /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/test/ompt/misc/Output/lock_double_destroy.cpp.tmp -lm -latomic
# .---command stderr------------
# | In file included from /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/misc/lock_double_destroy.cpp:3:
# | /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/callback.h:829:18: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
# |   829 |     event_name = "ompt_event_section_begin";
# |       |                  ^
# | /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/callback.h:833:18: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
# |   833 |     event_name = "ompt_event_ws_loop_chunk_begin";
# |       |                  ^
# | /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/callback.h:837:18: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
# |   837 |     event_name = "ompt_event_taskloop_chunk_begin";
# |       |                  ^
# | /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/callback.h:841:18: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
# |   841 |     event_name = "ompt_event_distribute_chunk_begin";
# |       |                  ^
# | /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/callback.h:845:18: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
# |   845 |     event_name = "ompt_ws_loop_iteration_begin";
# |       |                  ^
# | 5 warnings generated.
# `-----------------------------
# executed command: /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/test/ompt/misc/Output/lock_double_destroy.cpp.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11
# executed command: tee /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/runtimes/runtimes-bins/openmp/runtime/test/ompt/misc/Output/lock_double_destroy.cpp.tmp.out
# executed command: /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/./bin/FileCheck /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/misc/lock_double_destroy.cpp
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/llvm/redhat-linux-build/./bin/FileCheck /builddir/build/BUILD/llvm-21.0.0_pre20250626.g2f9eee849f7d74-build/llvm-project-2f9eee849f7d7414c447d26625517edc34437138/openmp/runtime/test/ompt/misc/lock_double_destroy.cpp
# `-----------------------------
# error: command failed with exit status: 2

--

********************

@jprotze
Copy link
Collaborator

jprotze commented Jun 26, 2025

@kwk: I'm wondering, why this only fails for this specific test, but not for ompt/misc/interoperability.cpp
Since this seems to be an issue with compiling callback.h with the C++ frontend, I would expect that the other test also fails. As a quick fix, we can create callback.c, which includes callback.h, compile it separately into an object file and link it into the test.

anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…#145625)

This can happen in static destructors when called after the
  runtime is already shutdown (e.g., by ompt_finalize_tool). Even
  though it is technically an error to call omp_destroy_lock after
shutdown, the application doesn't necessarily know that omp_destroy_lock
  was already called. This is safe becaues all indirect locks are
  destoryed in __kmp_cleanup_indirect_user_locks so the return
  value will always be valid or a nullptr, not garbage.
@jprotze
Copy link
Collaborator

jprotze commented Jun 27, 2025

The C++ related output are just warnings.
The test fails due to segfault in openmp/runtime/src/kmp_csupport.cpp:2665. I can reproduce this on ubuntu 24.04 in a standalone build with system clang. (gdb) p *(void**)user_lock prints 0. I don't have time to dig deeper into the issue before next week, so I suggest to disable the test by adding // REQUIRES: needs-fix to the test for now and fix the test pipelines.

jprotze added a commit that referenced this pull request Jun 27, 2025
The test added with PR #145625 fails with certain build configurations of
libomp, disabling the test until the issue in the runtime is fixed.
@jprotze
Copy link
Collaborator

jprotze commented Jun 27, 2025

I pushed this change as 23384cd with the goal to enable the test when similar fixes as implemented in this PR are applied to the other code paths in __kmpc_destroy_lock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

openmp:libomp OpenMP host runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants