Skip to content

Conversation

@adurang
Copy link
Contributor

@adurang adurang commented Oct 9, 2025

On Windows, for a reason I don't fully understand boolean bits get extra padding (even when asking for packed structures) in the structures that messes the offsets between the compiler and the runtime.

Also, "weak" works differently on Windows than Linux (i.e., the "local" routine has preference) which causes it to crash as we don't really have an alternate implementation of __kmpc_omp_wait_deps. Given this, it doesn't make sense to mark it as "weak" for Linux either.

@llvmbot llvmbot added the offload label Oct 9, 2025
@adurang adurang requested a review from jplehr October 9, 2025 13:26
@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2025

@llvm/pr-subscribers-offload

Author: Alex Duran (adurang)

Changes

On Windows, for a reason I don't fully understand boolean bits get extra padding (even when asking for packed structures) in the structures that messes the offsets between the compiler and the runtime.

Also, "weak" works differently on Windows than Linux (i.e., the "local" routine has preference) which causes it to crash as we don't really have an alternate implementation of __kmpc_omp_wait_deps. Given this, it doesn't either make sense to mark it as "weak" for Linux either.


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

2 Files Affected:

  • (modified) offload/include/OpenMP/InteropAPI.h (+6-6)
  • (modified) offload/libomptarget/OpenMP/InteropAPI.cpp (+1-2)
diff --git a/offload/include/OpenMP/InteropAPI.h b/offload/include/OpenMP/InteropAPI.h
index 53ac4be2e2e98..8c06ba36fc3f3 100644
--- a/offload/include/OpenMP/InteropAPI.h
+++ b/offload/include/OpenMP/InteropAPI.h
@@ -25,8 +25,8 @@ typedef enum kmp_interop_type_t {
 } kmp_interop_type_t;
 
 struct interop_attrs_t {
-  bool inorder : 1;
-  int reserved : 31;
+  uint32_t inorder : 1;
+  uint32_t reserved : 31;
 
   /// Check if the supported attributes are compatible with the current
   ///   attributes. Only if an attribute is supported can the value be true,
@@ -44,15 +44,15 @@ struct interop_spec_t {
 };
 
 struct interop_flags_t {
-  bool implicit : 1; // dispatch (true) or interop (false)
-  bool nowait : 1;   // has nowait flag
-  int reserved : 30;
+  uint32_t implicit : 1; // dispatch (true) or interop (false)
+  uint32_t nowait : 1;   // has nowait flag
+  uint32_t reserved : 30;
 };
 
 struct interop_ctx_t {
   uint32_t version; // version of the interface (current is 0)
   interop_flags_t flags;
-  int gtid;
+  int32_t gtid;
 };
 
 struct dep_pack_t {
diff --git a/offload/libomptarget/OpenMP/InteropAPI.cpp b/offload/libomptarget/OpenMP/InteropAPI.cpp
index c55ef2c2e672c..d6ef17c06355c 100644
--- a/offload/libomptarget/OpenMP/InteropAPI.cpp
+++ b/offload/libomptarget/OpenMP/InteropAPI.cpp
@@ -22,8 +22,7 @@ extern "C" {
 
 void __kmpc_omp_wait_deps(ident_t *loc_ref, int32_t gtid, int32_t ndeps,
                           kmp_depend_info_t *dep_list, int32_t ndeps_noalias,
-                          kmp_depend_info_t *noalias_dep_list)
-    __attribute__((weak));
+                          kmp_depend_info_t *noalias_dep_list);
 
 } // extern "C"
 

void __kmpc_omp_wait_deps(ident_t *loc_ref, int32_t gtid, int32_t ndeps,
kmp_depend_info_t *dep_list, int32_t ndeps_noalias,
kmp_depend_info_t *noalias_dep_list)
__attribute__((weak));
Copy link
Contributor

Choose a reason for hiding this comment

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

So it was marked as weak but didn't provide any definition in libomptarget (apart from the one in libomp)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems so. The ones in other places (like InternalTypes.h) also have "weak" but no definition. I have no idea who decided to do it like this but I think all "weak" attributes should probably removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so too. I don't see why these attributes are needed without a definition in libomptarget. If it's not linked to libomp, or another lib providing this symbol, there will be a linking error anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you prefer to do it on this PR or a sepparate one?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to know other opinions before, to confirm this is not necessary.

CC @jhuber6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ping? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so weak extern symbols are defined as nullptr and not a linker error in ELF. This might be trying to prevent that? I don't really know for sure what it's trying to do. There's no check on this function so if it wasn't defined this code would segfault. I'm just going to assume it's not needed, since we should always link liboimp w/ libomptarget` anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the comment!

Maybe it's better to remove these weak attributes in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can do a follow-up for other functions specified as weak. Also, to gather them in one place, for some reason they're scattered here and there...

void __kmpc_omp_wait_deps(ident_t *loc_ref, int32_t gtid, int32_t ndeps,
kmp_depend_info_t *dep_list, int32_t ndeps_noalias,
kmp_depend_info_t *noalias_dep_list)
__attribute__((weak));
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so weak extern symbols are defined as nullptr and not a linker error in ELF. This might be trying to prevent that? I don't really know for sure what it's trying to do. There's no check on this function so if it wasn't defined this code would segfault. I'm just going to assume it's not needed, since we should always link liboimp w/ libomptarget` anyways.

@adurang adurang merged commit 9ba54ca into llvm:main Oct 17, 2025
11 checks passed
@adurang adurang deleted the interop_win_fix branch October 17, 2025 09:08
adurang added a commit that referenced this pull request Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants