Bug 1501703: Move the custom section read before finishing a wasm module's metadata; r=luke

--HG--
extra : rebase_source : 0384cec0612899e5778876aa0264871dfacffc96
extra : amend_source : 56ba7c68842e503aae67525efa030c13e631188c
This commit is contained in:
Benjamin Bouvier 2018-10-24 17:28:27 +02:00
Родитель 2699579fa0
Коммит a5b3df32ff
2 изменённых файлов: 29 добавлений и 23 удалений

Просмотреть файл

@ -978,7 +978,7 @@ ModuleGenerator::finishCodeTier()
return js::MakeUnique<CodeTier>(std::move(metadataTier_), std::move(segment));
}
bool
SharedMetadata
ModuleGenerator::finishMetadata(const Bytes& bytecode)
{
// Finish initialization of Metadata, which is only needed for constructing
@ -1005,14 +1005,14 @@ ModuleGenerator::finishMetadata(const Bytes& bytecode)
const size_t numFuncTypes = env_->funcTypes.length();
if (!metadata_->debugFuncArgTypes.resize(numFuncTypes)) {
return false;
return nullptr;
}
if (!metadata_->debugFuncReturnTypes.resize(numFuncTypes)) {
return false;
return nullptr;
}
for (size_t i = 0; i < numFuncTypes; i++) {
if (!metadata_->debugFuncArgTypes[i].appendAll(env_->funcTypes[i]->args())) {
return false;
return nullptr;
}
metadata_->debugFuncReturnTypes[i] = env_->funcTypes[i]->ret();
}
@ -1026,7 +1026,12 @@ ModuleGenerator::finishMetadata(const Bytes& bytecode)
memcpy(metadata_->debugHash, hash, sizeof(ModuleHash));
}
return true;
MOZ_ASSERT_IF(env_->nameCustomSectionIndex, !!metadata_->namePayload);
// Metadata shouldn't be mutably modified after finishMetadata().
SharedMetadata metadata = metadata_;
metadata_ = nullptr;
return metadata;
}
SharedModule
@ -1046,23 +1051,6 @@ ModuleGenerator::finishModule(const ShareableBytes& bytecode,
return nullptr;
}
if (!finishMetadata(bytecode.bytes)) {
return nullptr;
}
StructTypeVector structTypes;
for (TypeDef& td : env_->types) {
if (td.isStructType() && !structTypes.append(std::move(td.structType()))) {
return nullptr;
}
}
MutableCode code = js_new<Code>(std::move(codeTier), *metadata_, std::move(jumpTables),
std::move(structTypes));
if (!code || !code->initialize(*linkData_)) {
return nullptr;
}
// Copy over data from the Bytecode, which is going away at the end of
// compilation.
@ -1105,6 +1093,24 @@ ModuleGenerator::finishModule(const ShareableBytes& bytecode,
metadata_->namePayload = customSections[*env_->nameCustomSectionIndex].payload;
}
SharedMetadata metadata = finishMetadata(bytecode.bytes);
if (!metadata) {
return nullptr;
}
StructTypeVector structTypes;
for (TypeDef& td : env_->types) {
if (td.isStructType() && !structTypes.append(std::move(td.structType()))) {
return nullptr;
}
}
MutableCode code = js_new<Code>(std::move(codeTier), *metadata, std::move(jumpTables),
std::move(structTypes));
if (!code || !code->initialize(*linkData_)) {
return nullptr;
}
// See Module debugCodeClaimed_ comments for why we need to make a separate
// debug copy.

Просмотреть файл

@ -202,7 +202,7 @@ class MOZ_STACK_CLASS ModuleGenerator
bool finishCodegen();
bool finishMetadataTier();
UniqueCodeTier finishCodeTier();
bool finishMetadata(const Bytes& bytecode);
SharedMetadata finishMetadata(const Bytes& bytecode);
bool isAsmJS() const { return env_->isAsmJS(); }
Tier tier() const { return env_->tier(); }