aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index a72242bc4ac2..0982c7e2efbb 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -268,7 +268,11 @@ static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx,
Section.Offset = Ctx.Ptr - Ctx.Start;
Section.Type = readUint8(Ctx);
LLVM_DEBUG(dbgs() << "readSection type=" << Section.Type << "\n");
+ // When reading the section's size, store the size of the LEB used to encode
+ // it. This allows objcopy/strip to reproduce the binary identically.
+ const uint8_t *PreSizePtr = Ctx.Ptr;
uint32_t Size = readVaruint32(Ctx);
+ Section.HeaderSecSizeEncodingLen = Ctx.Ptr - PreSizePtr;
if (Size == 0)
return make_error<StringError>("zero length section",
object_error::parse_failed);
@@ -719,17 +723,21 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
Info.Name = readString(Ctx);
if (IsDefined) {
auto Index = readVaruint32(Ctx);
- if (Index >= DataSegments.size())
- return make_error<GenericBinaryError>("invalid data symbol index",
- object_error::parse_failed);
auto Offset = readVaruint64(Ctx);
auto Size = readVaruint64(Ctx);
- size_t SegmentSize = DataSegments[Index].Data.Content.size();
- if (Offset > SegmentSize)
- return make_error<GenericBinaryError>(
- "invalid data symbol offset: `" + Info.Name + "` (offset: " +
- Twine(Offset) + " segment size: " + Twine(SegmentSize) + ")",
- object_error::parse_failed);
+ if (!(Info.Flags & wasm::WASM_SYMBOL_ABSOLUTE)) {
+ if (static_cast<size_t>(Index) >= DataSegments.size())
+ return make_error<GenericBinaryError>(
+ "invalid data segment index: " + Twine(Index),
+ object_error::parse_failed);
+ size_t SegmentSize = DataSegments[Index].Data.Content.size();
+ if (Offset > SegmentSize)
+ return make_error<GenericBinaryError>(
+ "invalid data symbol offset: `" + Info.Name +
+ "` (offset: " + Twine(Offset) +
+ " segment size: " + Twine(SegmentSize) + ")",
+ object_error::parse_failed);
+ }
Info.DataRef = wasm::WasmDataReference{Index, Offset, Size};
}
break;