Skip to content
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

Don't emit relax relocs like R_X86_64_REX_GOTPCRELX on X86 target for OPENMP internal vars. #75564

Closed

Conversation

UmeshKalappa0
Copy link

For kernel modules (where -fno-pic and no-pie is implicit ) having "R_X86_64_REX_GOTPCRELX " relocs burden the kernel loader to handle the same like https://godbolt.org/z/hhh7ozojz.

Solution : Mark the OpenMP internal variables with dso_local conditionally for no-pic and no-pie ,then

  1. reset the dso_local for thread_local and weak linkage internal vars.

R_X86_64_REX_GOTPCRELX  for the OPENMP internal vars like
https://godbolt.org/z/hhh7ozojz.

Solution : Mark the OpenMP internal variables with dso_local
conditionally for no-pic and no-pie ,then
a)reset the dso_local for thread_local and weak linkage vars.
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 clang Clang issues not falling into any other category clang:openmp OpenMP related changes to Clang labels Dec 15, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 15, 2023

@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-flang-openmp
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: None (UmeshKalappa0)

Changes

For kernel modules (where -fno-pic and no-pie is implicit ) having "R_X86_64_REX_GOTPCRELX " relocs burden the kernel loader to handle the same like https://godbolt.org/z/hhh7ozojz.

Solution : Mark the OpenMP internal variables with dso_local conditionally for no-pic and no-pie ,then

  1. reset the dso_local for thread_local and weak linkage internal vars.

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

1 Files Affected:

  • (added) clang/test/OpenMP/gomp_critical_dso_local_var.c (+23)
diff --git a/clang/test/OpenMP/gomp_critical_dso_local_var.c b/clang/test/OpenMP/gomp_critical_dso_local_var.c
new file mode 100644
index 00000000000000..915f6773bf67bf
--- /dev/null
+++ b/clang/test/OpenMP/gomp_critical_dso_local_var.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s --check-prefix=DSO_LOCAL
+
+// DSO_LOCAL-DAG: @.gomp_critical_user_.var = common dso_local global [8 x i32] zeroinitializer, align 8
+int omp_critical_test()
+{
+  int sum;
+  int known_sum;
+
+  sum=0;
+#pragma omp parallel
+  {
+    int mysum=0;
+    int i;
+#pragma omp for
+    for (i = 0; i < 1000; i++)
+      mysum = mysum + i;
+#pragma omp critical
+    sum = mysum +sum;
+  }
+  known_sum = 999 * 1000 / 2;
+  return (known_sum == sum);
+}
+

@UmeshKalappa0 UmeshKalappa0 marked this pull request as draft December 15, 2023 07:02
@UmeshKalappa0 UmeshKalappa0 marked this pull request as ready for review December 15, 2023 07:30
@UmeshKalappa0 UmeshKalappa0 self-assigned this Dec 15, 2023
@efriedma-quic
Copy link
Collaborator

Scattering around setDSOLocal(false) makes the logic hard to understand. I'd strongly prefer to fix the initial setting of dso_local when we create the global variable. We can refactor the code to make that work.

@UmeshKalappa0
Copy link
Author

Scattering around setDSOLocal(false) makes the logic hard to understand. I'd strongly prefer to fix the initial setting of dso_local when we create the global variable. We can refactor the code to make that work.

@efriedma-quic ,thank you for the suggestions and was not sure about adding dso_local for openmp weak linkage vars ,but from the weak semantics point ,its ok to add the dso_local for no-pic /no-pie code ,so updated changes accordingly .

@mahtohappy
Copy link
Contributor

Hi @UmeshKalappa0 why did you close this? This is still needed for us internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category flang:openmp mlir:llvm mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants