aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2022-06-17 13:09:43 -0700
committerDerek Schuff <dschuff@chromium.org>2022-06-23 13:56:17 -0700
commit5a082d9c1c14df5cee5a45683aee524e9b57a662 (patch)
treec101cdb749968ecf8589682e9f415ad5df46fb36 /llvm/lib/Object/WasmObjectFile.cpp
parent40aace59cc58ca438060cf4dfd97ba01ff4f0ebc (diff)
downloadllvm-5a082d9c1c14df5cee5a45683aee524e9b57a662.zip
llvm-5a082d9c1c14df5cee5a45683aee524e9b57a662.tar.gz
llvm-5a082d9c1c14df5cee5a45683aee524e9b57a662.tar.bz2
[WebAssembly][Object] Remove requirement that objects must have code sections
When parsing name and linking sections, we currently require that the object must have a code section (it seems that this was intended to verify section ordering). However it can be useful for binaries to have their code sections stripped out (e.g. if we just want the debug info). In that case we need the rest of the known sections (so e.g. we know how many functions there are, to verify the name section) but not the actual code. I've removed the restriction completely. I think this is OK because the section-parsing code already checks function and global indices in many places for validity and will return appropriate errors if the relevant sections are missing. Also we can't just replace the requirement of seeing a code section with a requirement that we see a function or global section, because a binary may just not have any functions or globals. But there's only an problem if the name or linking section tries to name a nonexistent function. Part of a fix for https://github.com/emscripten-core/emscripten/issues/13084 Differential Revision: https://reviews.llvm.org/D128094
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp16
1 files changed, 3 insertions, 13 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index cc80ae9..ce816b0 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -451,10 +451,6 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
llvm::DenseSet<uint64_t> SeenFunctions;
llvm::DenseSet<uint64_t> SeenGlobals;
llvm::DenseSet<uint64_t> SeenSegments;
- if (Functions.size() && !SeenCodeSection) {
- return make_error<GenericBinaryError>("names must come after code section",
- object_error::parse_failed);
- }
while (Ctx.Ptr < Ctx.End) {
uint8_t Type = readUint8(Ctx);
@@ -474,7 +470,7 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
return make_error<GenericBinaryError>(
"function named more than once", object_error::parse_failed);
if (!isValidFunctionIndex(Index) || Name.empty())
- return make_error<GenericBinaryError>("invalid name entry",
+ return make_error<GenericBinaryError>("invalid function name entry",
object_error::parse_failed);
if (isDefinedFunctionIndex(Index))
@@ -485,7 +481,7 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
return make_error<GenericBinaryError>("global named more than once",
object_error::parse_failed);
if (!isValidGlobalIndex(Index) || Name.empty())
- return make_error<GenericBinaryError>("invalid name entry",
+ return make_error<GenericBinaryError>("invalid global name entry",
object_error::parse_failed);
} else {
nameType = wasm::NameType::DATA_SEGMENT;
@@ -493,7 +489,7 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
return make_error<GenericBinaryError>(
"segment named more than once", object_error::parse_failed);
if (Index > DataSegments.size())
- return make_error<GenericBinaryError>("invalid named data segment",
+ return make_error<GenericBinaryError>("invalid data segment name entry",
object_error::parse_failed);
}
DebugNames.push_back(wasm::WasmDebugName{nameType, Index, Name});
@@ -519,11 +515,6 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) {
HasLinkingSection = true;
- if (Functions.size() && !SeenCodeSection) {
- return make_error<GenericBinaryError>(
- "linking data must come after code section",
- object_error::parse_failed);
- }
LinkingData.Version = readVaruint32(Ctx);
if (LinkingData.Version != wasm::WasmMetadataVersion) {
@@ -1410,7 +1401,6 @@ Error WasmObjectFile::parseStartSection(ReadContext &Ctx) {
}
Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) {
- SeenCodeSection = true;
CodeSection = Sections.size();
uint32_t FunctionCount = readVaruint32(Ctx);
if (FunctionCount != Functions.size()) {