aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2021-05-11 15:16:00 -0700
committerSam Clegg <sbc@chromium.org>2021-05-12 13:43:37 -0700
commitcd01430ff13b5441bc71e6dc3c4e688052f7be82 (patch)
tree4d2d3c0c677a8ab97cd151aa7ef6024fcf4394b4 /llvm/lib/Object/WasmObjectFile.cpp
parent3041b16f7322a0392810e4a14b13cacac1929ad8 (diff)
downloadllvm-cd01430ff13b5441bc71e6dc3c4e688052f7be82.zip
llvm-cd01430ff13b5441bc71e6dc3c4e688052f7be82.tar.gz
llvm-cd01430ff13b5441bc71e6dc3c4e688052f7be82.tar.bz2
[lld][WebAssembly] Allow data symbols to extend past end of segment
This fixes a bug with string merging with string symbols that contain NULLs, as is the case in the `merge-string.s` test. The bug only showed when we run with `--relocatable` and then try read the resulting object back in. In this case we would end up with string symbols that extend past the end of the segment in which they live. The problem comes from the fact that sections which are flagged as string mergable assume that all strings are NULL terminated. The merging algorithm will drop trailing chars that follow a NULL since they are essentially unreachable. However, the "size" attribute (in the symbol table) of such a truncated symbol is not updated resulting a symbol size that can overlap the end of the segment. I verified that this can happen in ELF too given the right conditions and the its harmless enough. In practice Strings that contain embedded null should not be part of a mergable section. Differential Revision: https://reviews.llvm.org/D102281
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index df64a46..8004c5e 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -637,9 +637,12 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
object_error::parse_failed);
auto Offset = readVaruint64(Ctx);
auto Size = readVaruint64(Ctx);
- if (Offset + Size > DataSegments[Index].Data.Content.size())
- return make_error<GenericBinaryError>("invalid data symbol offset",
- 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;