-
Notifications
You must be signed in to change notification settings - Fork 900
Fix offset detection in attr_subsys_construct #10343
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
Conversation
It appears that GCC starting from GCC 11 optimizes out the offset detection. By moving the pointers used for testing out of the function into TU scope we can suppress that optimization. Signed-off-by: Joseph Schuchart <[email protected]>
This makes the code thread-unsafe, does it not? That seems unacceptable. There must be a better solution. |
The following is a smaller change, and permits diff --git a/ompi/attribute/attribute.c b/ompi/attribute/attribute.c
index c46b913f6d..2f3a63cc36 100644
--- a/ompi/attribute/attribute.c
+++ b/ompi/attribute/attribute.c
@@ -581,7 +581,7 @@ int ompi_attr_put_ref(void)
static void attr_subsys_construct(attr_subsys_t *subsys)
{
int ret;
- void *bogus = (void*) 1;
+ static const void *bogus = (void*) 1;
int *p = (int *) &bogus;
subsys->keyval_hash = OBJ_NEW(opal_hash_table_t); |
This still feels like the wrong answer though, since I can't help but wonder if this code is UB and GCC is right to do horrible things to it. |
Where did you get the impression this made the code non thread safe? |
Static globals are not thread safe unless constant. If constant, add that to declaration, as I showed already in my proposed patch. |
Working on an implementation that uses a union instead, to avoid this nail-curling mess. Will report back. |
@devreal do we have to compute |
I don't think we should keep this implementation, even if we could figure out the offsets without causing UB. It just seems awfully shaky. A much cleaner way is to use C unions and select the right member based on the |
Superseded by #10344, closing. |
It appears that GCC starting from GCC 11 optimizes out the offset detection. By moving the pointers used for testing out of the function into TU scope we can suppress that optimization.
I have to admit that I am not sure I understand why we do this detection in the first place. There might be a better fix so I'm putting this PR out for review and discussion.
Fixes #10339
Signed-off-by: Joseph Schuchart [email protected]