Commit fa7dc18
Enable empty base alignment on Environment to make HV32 build on Windows
Summary:
In Callable.h, we assert the invariant that the offset of
`parentEnvironment_` and `size_` in `Environment` is the same as
`parentEnvironment` and `size` in `SHEnvironment`, respectively.
However, this is not always true with MSVC (Clang with enforce the
same layout on Windows).
`Environment` inherits from `VariableSizeRuntimeCell` and
`TrailingObjects<Environment, GCHermesValue>` (with this order).
With HV32 release mode, `VariableSizeRuntimeCell` has 4 bytes,
`TrailingObjects<Environment, GCHermesValue>` has 0 bytes and has an
`alignas(8)` specifier.
The default memory layout is:
0: base class VariableSizeRuntimeCell
4: padding
8: parentEnvironment_ (if casting to TrailingObjects, the address is here)
12: size_
16: trailing objects of GCHermesValue
The reason is that MSVC does remove the empty class's storage (so
`TrailingObjects` occupies 0 byte), but it still enforces that the
empty base class still has a unique address. And due to the
`alignas(8)` specifier, it has to add 4 padding bytes to make the
address aligned to 8 bytes.
With the `__declspec(empty_bases)` attribute, the memory layout is:
0: base class VariableSizeRuntimeCell
4: parentEnvironment_
8: size_
12: padding
16: trailing objects of GCHermesValue
This is the same as SHEnvironment.
Reviewed By: tmikov
Differential Revision: D87686988
fbshipit-source-id: 014b2aeda05750c78e5d8a160249c43ce91ccf3f1 parent e595577 commit fa7dc18
1 file changed
+18
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
28 | 45 | | |
29 | 46 | | |
30 | 47 | | |
| |||
0 commit comments