fix(compile): use 8-byte header for embedded section to ensure bytecode alignment (#25377)

## Summary
- Change the size header in embedded Mach-O and PE sections from `u32`
(4 bytes) to `u64` (8 bytes)
- Ensures the data payload starts at an 8-byte aligned offset, which is
required for the bytecode cache

## Test plan
- [x] Test standalone compilation on macOS
- [ ] Test standalone compilation on Windows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Dylan Conway
2025-12-06 16:37:09 -08:00
committed by GitHub
parent cde167cacd
commit 5eb2145b31
5 changed files with 37 additions and 32 deletions

View File

@@ -119,7 +119,7 @@ pub const StandaloneModuleGraph = struct {
};
const Macho = struct {
pub extern "C" fn Bun__getStandaloneModuleGraphMachoLength() ?*align(1) u32;
pub extern "C" fn Bun__getStandaloneModuleGraphMachoLength() ?*align(1) u64;
pub fn getData() ?[]const u8 {
if (Bun__getStandaloneModuleGraphMachoLength()) |length| {
@@ -127,8 +127,10 @@ pub const StandaloneModuleGraph = struct {
return null;
}
// BlobHeader has 8 bytes size (u64), so data starts at offset 8.
const data_offset = @sizeOf(u64);
const slice_ptr: [*]const u8 = @ptrCast(length);
return slice_ptr[4..][0..length.*];
return slice_ptr[data_offset..][0..length.*];
}
return null;
@@ -136,7 +138,7 @@ pub const StandaloneModuleGraph = struct {
};
const PE = struct {
pub extern "C" fn Bun__getStandaloneModuleGraphPELength() u32;
pub extern "C" fn Bun__getStandaloneModuleGraphPELength() u64;
pub extern "C" fn Bun__getStandaloneModuleGraphPEData() ?[*]u8;
pub fn getData() ?[]const u8 {