Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

devreal
Copy link
Contributor

@devreal devreal commented Apr 29, 2022

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]

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]>
@jeffhammond
Copy link
Contributor

This makes the code thread-unsafe, does it not? That seems unacceptable. There must be a better solution.

@jeffhammond
Copy link
Contributor

The following is a smaller change, and permits const on the static data, which seems safer.

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

@jeffhammond
Copy link
Contributor

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.

@jeffhammond
Copy link
Contributor

03d9750 and 3e6c5bb are the only two commits that could have caused the problem.

@ggouaillardet
Copy link
Contributor

Where did you get the impression this made the code non thread safe?
The change only impacts the scope of some read-only data.

@jeffhammond
Copy link
Contributor

Static globals are not thread safe unless constant. If constant, add that to declaration, as I showed already in my proposed patch.

@devreal
Copy link
Contributor Author

devreal commented Apr 30, 2022

Working on an implementation that uses a union instead, to avoid this nail-curling mess. Will report back.

@ggouaillardet
Copy link
Contributor

@devreal do we have to compute *_pos programmatically at runtime?
I mean could we simply macro define these values based on pointer sizes and endianness that are known at runtime?

@devreal
Copy link
Contributor Author

devreal commented May 1, 2022

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 set_from field. II put up a PR at #10344.

@devreal
Copy link
Contributor Author

devreal commented May 3, 2022

Superseded by #10344, closing.

@devreal devreal closed this May 3, 2022
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.

attribute functions lead to application segfault
3 participants