Skip to content

[OpenMP] avoid segv for a lock that has already been destroyed #145625

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lfmeadow
Copy link

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.

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
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
Author

lfmeadow commented Jun 25, 2025

Can someone please approve the workflow?

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

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.

5 participants