Fix HeapMeta alignment on 32-bit platforms using C11 union#451
Open
mstorm wants to merge 1 commit intofacebook:devfrom
Open
Fix HeapMeta alignment on 32-bit platforms using C11 union#451mstorm wants to merge 1 commit intofacebook:devfrom
mstorm wants to merge 1 commit intofacebook:devfrom
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR addresses alignment issues for
HeapMetaon 32-bit architectures by restructuring it using a C11 anonymous struct within aunion. This enforces a 16-byte size without altering itsalignofrequirement, preventing potential alignment-related crashes on 32-bit systems (wheremalloctypically returns 8-byte aligned addresses).Fixes #342
Type of Change
Test Plan
make libto verify that the static assertionsizeof(HeapMeta) == 16passes across different configurations.make test(1619 tests passed) to ensure no regressions in allocator logic and overall functionality.Test Configuration
Technical Analysis (For Reviewers)
We compared three approaches: (1) Manual
#ifdefpadding, (2)ZL_ALIGNED(16), and (3) C11union.unionapproach generates identical machine code to the original struct. Field access (stp/ldp) and pointer arithmetic remain optimal.ZL_ALIGNED(16), which raisesalignof(HeapMeta)to 16 and could cause runtime assertion failures with 8-byte alignedmallocpointers, theunionapproach keeps the original alignment requirement (8) while guaranteeing the 16-byte size.sizeofalignof