Skip to content

Add check for SYS_gettid support #119742

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

Closed
wants to merge 1 commit into from
Closed

Conversation

apeskov
Copy link
Contributor

@apeskov apeskov commented Dec 12, 2024

To improve compatibility with old glibc version which lack syscall(SYS_gettid) will use pthread_self() as a fallback.

To improve compatibility with old glibc version which lack SYS_gettid
will use pthread_self() as a fallback.
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
Copy link
Member

llvmbot commented Dec 12, 2024

@llvm/pr-subscribers-llvm-support

Author: Alexander Peskov (apeskov)

Changes

To improve compatibility with old glibc version which lack syscall(SYS_gettid) will use pthread_self() as a fallback.


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

1 Files Affected:

  • (modified) llvm/lib/Support/Unix/Threading.inc (+1-1)
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index c7b4c7af3b9f33..368e3cf1c5bd8f 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -140,7 +140,7 @@ uint64_t llvm::get_threadid() {
   return uint64_t(getthrid());
 #elif defined(__ANDROID__)
   return uint64_t(gettid());
-#elif defined(__linux__)
+#elif defined(__linux__) && defined(SYS_gettid)
   return uint64_t(syscall(SYS_gettid));
 #else
   return uint64_t(pthread_self());

@apeskov
Copy link
Contributor Author

apeskov commented Dec 12, 2024

@brad0 @devnexen
Could you please take a look on this change?

Copy link
Contributor

@brad0 brad0 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 better to change SYS_gettid to __NR_gettid.

I posted a PR here.

#120007

@apeskov
Copy link
Contributor Author

apeskov commented Dec 16, 2024

Ok, __NR_gettid will suite me as well. Thanks!

Your PR already passed some checks so I will not update this one.

@brad0 brad0 closed this Dec 18, 2024
@apeskov apeskov deleted the ap/check-gettid branch January 13, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants