forked from codership/galera
-
Notifications
You must be signed in to change notification settings - Fork 20
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
macos: fix missing pthread mutex init after calloc #21
Open
sitano
wants to merge
1
commit into
MariaDB:mariadb-4.x
Choose a base branch
from
sitano:ivan/fix_gcs_group_mutex_init
base: mariadb-4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This reminds me of the recent MDEV-34625 and MariaDB/server#3408. I understood that macOS would use a
clang
based compiler by default.I think that use of placement
new
after a call to acalloc
like operation may lead to surprises when using GCC 6 or later, if the constructor is expecting that some fields were already initialized by a previous write. GCC 6 and later could optimize away such pre-constructor writes, thanks to-flifetime-dse
.That macOS (as well as AIX) are not happy with zero initialization for
pthread_mutex_t
bit me in MariaDB/server#3433.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.
MacOS uses Clang yes. But MDEV-34625 IMHO is different. Moreover, the Godbolt example does not look correct - it is fine that the
memset
in https://gcc.godbolt.org/z/5n87z1raG is optimized out because it is expected (I suppose) that after a class constructor is called all class variables are initialized. Thus, the compiler may conclude that if we havevoid *buf = malloc(size S); s = new (buf) buf;
is equivalent toS *s = new S;
.But it is different if you have
malloc()
buf size bigger than the memory that the constructor() is expected to touch:https://gcc.godbolt.org/z/Y43YW7vKj
became
call calloc
in assembly orrep stosq
. So memset is Not eliminated in this case and will not be eliminated in the case of gcs_core_t* core = GU_CALLOC (1, gcs_core_t);
as far assizeof(gcs_core_t) >> gcs_group_t
.it does not eliminate calloc() even if
-flifetime-dse=0
(try saving *buf to external volatile var) (default is 2) (https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html).if you still think it is not safe, I can offer that we could replace the mutex there instead of
gu::Mutex memb_mtx_
we could writegu_mutex_t mutable value_
and init without calling class constructors. WDYT?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.
I think its forbidden by the spec (speculating) - constructor must init all class fields
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.
Yes, it is UB, with no doubt. If all fields of
gu::Mutex
are initialized by the constructor, then there should be no issue with the GCC-flifetime-dse
on any platform.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.
from what we can see in gu_mutex.hpp they all are init-ed