-
Notifications
You must be signed in to change notification settings - Fork 14
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
Use valid address in pthread_setspecific to silence warnings #162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
thread_setup_unix.c
Outdated
@@ -9,6 +9,9 @@ static pthread_mutex_t *mutex_buf = NULL; | |||
|
|||
static pthread_key_t destructor_key; | |||
|
|||
/* Used in pthread_setspecific. See https://github.com/microsoft/go/issues/1305. */ | |||
static char stub; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to exist at the global scope, or could static char stub;
or char stub;
be declared just before the call?
If there's no difference, I think putting the declaration inside thread_id
would be a bit clearer. And IMO putting it on the stack (if possible) raises the fewest questions from a reader's perspective. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks putting the variable in the function scope also works, and it does look clearer. I'll keep the static
keyword, though, I would rather not pass a pointer to a stack-allocated variable that can be used outside the function frame, just in case it is used somewhere 😅.
Co-authored-by: Davis Goodin <[email protected]>
* use valid address in pthread_setspecific to silence warnings * Update thread_setup_unix.c Co-authored-by: Davis Goodin <[email protected]> * use local variable instead of global --------- Co-authored-by: Davis Goodin <[email protected]> (cherry picked from commit 6f4d87d)
…168) * use valid address in pthread_setspecific to silence warnings * Update thread_setup_unix.c Co-authored-by: Davis Goodin <[email protected]> * use local variable instead of global --------- Co-authored-by: Davis Goodin <[email protected]> (cherry picked from commit 6f4d87d)
Building with a newer glibc (probably since 2.34) causes the following warning:
The is caused by the
access
attribute annotation ofpthread_setspecific
, which was recently added.GCC defines the none mode of access as:
The access mode none specifies that the pointer to which it applies is not used to access the referenced object at all. Unless the pointer is null the pointed-to object must exist and have at least the size as denoted by the size-index argument. The object need not be initialized. The mode is intended to be used as a means to help validate the expected object size, for example in functions that call __builtin_object_size. See Object Size Checking.
We are passing
(void*)1
as a NULL pointer, which doesn't meet thenone
access requirements. This PR fixes that by using a static stub char pointer.Fixes microsoft/go#1305.