Repository navigation
fix: use unsigned bitfields for portable bytecode cache struct layout - #141
Conversation
|
/build-preview |
|
🔄 Preview build started Release tag: |
WalkthroughReplaced enum/OptionSet-typed members with raw byte storage and added casts/wrappers when exposing or serializing those values in Changes
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
…rtable serialization CachedFunctionExecutable and CachedCodeBlock in CachedTypes.cpp are serialized as raw memory bytes for the JSC bytecode cache. These structs contain bitfields of mixed types (unsigned, CodeFeatures, etc.) which are packed differently by MSVC-style (clang-cl) vs GCC-style (Clang/GCC) compilers. This makes bytecode generated on macOS/Linux crash when loaded on Windows. Adding __attribute__((gcc_struct)) to just these two structs forces GCC-compatible layout regardless of compiler, making the bytecode cache format portable across all platforms. This is more targeted than a global -mno-ms-bitfields flag which would break MSVC ABI compatibility for all of WebKit.
|
This may have been caused by a newer build being triggered for the same PR. |
31b7cc2 to
481ba51
Compare
|
/build-preview |
|
🔄 Preview build started Release tag: |
|
✅ Preview build completed Release: autobuild-preview-pr-141-481ba51a |
|
nice |
-mno-ms-bitfields for clang-cl to fix cross-platform bytecode cache__attribute__((gcc_struct)) on bytecode cache structs for portable serialization
|
So it seems clang-cl does not support gcc_structs, yet this change fixed the cross compiling bytecode crash. Need to investigate more |
__attribute__((gcc_struct)) on bytecode cache structs for portable serialization|
/build-preview |
|
🔄 Preview build started Release tag: |
Replace enum/OptionSet/typedef fields with unsigned bitfields to ensure consistent struct layout across MSVC and GCC packing rules. The issue: mixing different-sized types (uint8_t, uint16_t, enums) with unsigned bitfields causes different packing on Windows vs macOS/Linux. This breaks cross-platform bytecode serialization. The fix: use `unsigned m_field : N` for all bitfields. This keeps all fields in the same unsigned bitfield sequence, ensuring consistent layout. Test results (test struct with mixed types): - OriginalLayout: macOS=8, Windows=12 (DIFFERENT) - FixedLayout: macOS=8, Windows=8 (SAME) Co-Authored-By: Claude <[email protected]>
16a168c to
9899e38
Compare
|
/build-preview |
|
This may have been caused by a newer build being triggered for the same PR. |
|
🔄 Preview build started Release tag: |
|
✅ Preview build completed Release: autobuild-preview-pr-141-9899e383 |
Summary
Fixes cross-platform bytecode serialization crash when bytecode generated on macOS/Linux is loaded on Windows (e.g.,
bun build --compile --bytecode --target=bun-windows-x64).Root cause
The
CachedFunctionExecutableandCachedCodeBlockstructs contain fields with different types mixed together:SourceParseMode(enum : uint8_t)OptionSet<CodeGenerationMode>(class wrapping uint8_t)CodeFeatures(typedef uint16_t)LexicallyScopedFeatures(typedef uint8_t)unsignedbitfieldsMSVC and GCC have different struct packing rules when mixing different-sized types. This causes layout mismatches:
Fix
Replace all non-unsigned bitfield types with
unsigned : Nbitfields:SourceParseMode m_sourceParseMode→unsigned m_sourceParseMode : 8OptionSet<CodeGenerationMode> m_codeGenerationMode→unsigned m_codeGenerationMode : 8CodeFeatures m_features : 14→unsigned m_features : 14LexicallyScopedFeatures m_lexicallyScopedFeatures : 2→unsigned m_lexicallyScopedFeatures : 2Accessors cast back to original types. This ensures consistent layout across all platforms.
Why not
__attribute__((gcc_struct))?The initial approach tried using
gcc_structto force GCC-compatible layout, but clang-cl (LLVM 19) doesn't support this attribute and silently ignores it.Test plan
🤖 Generated with Claude Code