New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Wasm-GC] Use correct offsets when generating code for struct gets and sets in B3 and Air #10490
Conversation
EWS run on previous version of this PR (hash 1803922) |
1803922
to
9521d87
Compare
EWS run on previous version of this PR (hash 9521d87) |
9521d87
to
3633d03
Compare
EWS run on previous version of this PR (hash 3633d03) |
self().emitLoad(structBase, JSWebAssemblyStruct::offsetOfPayload(), payload); | ||
|
||
uint32_t fieldOffset = fixupPointerPlusOffset(payload, *structType.getFieldOffset(fieldIndex)); | ||
// Add offset(data) to get structBase.m_payload.m_storage.data() | ||
uint32_t fieldOffset = JSWebAssemblyStruct::offsetOfPayloadData() + fixupPointerPlusOffset(payload, *structType.getFieldOffset(fieldIndex)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be inside the fixup check in case it overflows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getFieldOffset should be offsetOfField, and should include the wasm struct offset of payload data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change, but as a result, I had to change JSWebAssemblyStruct::fieldPointer()
to explicitly subtract the offset of the payload data, since StructType::offsetOfField()
now returns an offset relative to m_payload.m_storage
, but fieldPointer()
uses m_payload.data()
as the base. I tried replacing m_payload.data()
with m_payload.storage()
, but couldn't get the casts to work while preserving the const return value of the method. It's kind of ugly, but if you have any suggestions, let me know.
self().emitLoad(structBase, JSWebAssemblyStruct::offsetOfPayload(), payload); | ||
// Add offset(data) to get structBase.m_payload.m_storage.data() | ||
uint32_t fieldOffset = JSWebAssemblyStruct::offsetOfPayloadData() + fixupPointerPlusOffset(payload, *structType.getFieldOffset(fieldIndex)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
3633d03
to
0b39d7c
Compare
EWS run on previous version of this PR (hash 0b39d7c) |
EWS run on previous version of this PR (hash 3cfc57e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me
@@ -69,7 +69,8 @@ JSWebAssemblyStruct* JSWebAssemblyStruct::tryCreate(JSGlobalObject* globalObject | |||
|
|||
const uint8_t* JSWebAssemblyStruct::fieldPointer(uint32_t fieldIndex) const | |||
{ | |||
return m_payload.data() + *structType()->getFieldOffset(fieldIndex); | |||
// offsetOfField() returns an offset relative to `m_payload`; subtract offsetOfData() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just make a separate getter for this
EWS run on current version of this PR (hash 848946b) |
β¦d sets in B3 and Air https://bugs.webkit.org/show_bug.cgi?id=252719 Reviewed by Tadeu Zagallo and Justin Michaud. The generated code for struct get and set operations was using the wrong offsets and overwriting the header for the struct object's `m_payload.storage` field. Triggering the bug requires a function call where the callee returns a struct and the caller performs a `struct.get` on the result, and the callee is interpreted while the caller is compiled (or vice versa). * JSTests/wasm/gc/bug252719.js: Added. (module): (testIntFields): * Source/JavaScriptCore/wasm/WasmAirIRGeneratorBase.h: (JSC::Wasm::ExpressionType>::addStructGet): (JSC::Wasm::ExpressionType>::addStructSet): * Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::emitStructSet): (JSC::Wasm::B3IRGenerator::addStructGet): * Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp: (JSC::Wasm::StructType::StructType): * Source/JavaScriptCore/wasm/WasmTypeDefinition.h: (JSC::Wasm::StructType::offsetOfField const): (JSC::Wasm::StructType::offsetOfField): (JSC::Wasm::StructType::getFieldOffset const): Deleted. (JSC::Wasm::StructType::getFieldOffset): Deleted. * Source/JavaScriptCore/wasm/js/JSWebAssemblyStruct.cpp: (JSC::JSWebAssemblyStruct::fieldPointer const): * Source/JavaScriptCore/wasm/js/JSWebAssemblyStruct.h: Canonical link: https://commits.webkit.org/261899@main
848946b
to
2e2ee48
Compare
Committed 261899@main (2e2ee48): https://commits.webkit.org/261899@main Reviewed commits have been landed. Closing PR #10490 and removing active labels. |
2e2ee48
848946b