Skip to content

Commit fd1aba0

Browse files
joyeecheungStefanStojanovic
authored andcommitted
deps: V8: cherry-pick 99ebeac9c548
Original commit message: [torque] Fix C++ object layout assertions for MSVC STL The assertions generated for @cppObjectLayoutDefinition classes assume that the first field of a derived class starts at sizeof(Parent) and that sizeof(Class) == the packed size computed by Torque. Both assumptions break when compiling with the MSVC STL, which stores std::atomic<T> with alignas(sizeof(T)). Under the Microsoft C++ ABI an alignas() is a required alignment that #pragma pack cannot lower, so the std::atomic bit fields of Map force Map, and in turn the pack(1) ExtendedMap, to align by 4 bytes. After rounding up, sizeof(ExtendedMap) == sizeof(Map) + 4 == kSize + 3 so static_assert(kSize == sizeof(ExtendedMap)) fails. The base subobject size is not rounded up however, so JSInterceptorMap places its first field at sizeof(Map) + 1 rather than sizeof(ExtendedMap), and static_assert(kFlagsOffset == offsetof(JSInterceptorMap, flags_)) fails as well. Fix this by: - Using the packed parent size that Torque already knows as the offset of the first derived field instead of sizeof(Parent). - Relaxing the assertion to only require that sizeof(Class) does not exceed kSize by alignof(Class) or more, so that any extra bytes fit into the alignment padding. Co-Authored-By: StefanStojanovic <stefan.stojanovic@janeasystems.com> Refs: #65161 Bug: 531344950 Change-Id: I16811484a8ff3d1bff187bab950ac71b6ea7f297 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8486028 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Igor Sheludko <ishell@chromium.org> Commit-Queue: Joyee Cheung <joyee@igalia.com> Cr-Commit-Position: refs/heads/main@{#110223} Refs: v8/v8@99ebeac Co-Authored-By: StefanStojanovic <stefan.stojanovic@janeasystems.com> Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com> Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com> PR-URL: #66537 Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent f0273ed commit fd1aba0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎common.gypi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
# Reset this number to 0 on major V8 upgrades.
4646
# Increment by one for each non-official patch applied to deps/v8.
47-
'v8_embedder_string': '-node.1',
47+
'v8_embedder_string': '-node.2',
4848

4949
##### V8 defaults for Node.js #####
5050

‎deps/v8/src/torque/implementation-visitor.cc‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4029,6 +4029,11 @@ class ClassFieldOffsetGenerator : public FieldOffsetsGenerator {
40294029
std::string parent_name = use_templates ? "P" : parent->name();
40304030

40314031
if (type->IsLayoutDefinedInCpp()) {
4032+
if (parent) {
4033+
if (std::optional<size_t> packed_size = parent->size().SingleValue()) {
4034+
return std::to_string(*packed_size);
4035+
}
4036+
}
40324037
return "sizeof(" + parent_name + ")";
40334038
}
40344039

@@ -4117,7 +4122,8 @@ void CppClassGenerator::GenerateCppObjectLayoutDefinitionAsserts() {
41174122
<< "::" << f.name_and_type.name << " in C++ do not match\");\n";
41184123
}
41194124
if (!type_->IsAbstract() && type_->HasStaticSize()) {
4120-
impl_ << " static_assert(kSize == sizeof(" + name_ + "));\n";
4125+
impl_ << " static_assert(kSize <= sizeof(" + name_ + ") && sizeof(" +
4126+
name_ + ") < kSize + alignof(" + name_ + "));\n";
41214127
}
41224128

41234129
impl_ << "};\n\n";

0 commit comments

Comments
 (0)