diff options
author | Sam Clegg <sbc@chromium.org> | 2023-10-03 13:16:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-03 13:16:16 -0700 |
commit | afe957ea9552dac35ed21c4160b1ef63439c49cb (patch) | |
tree | 5b3613a2a9869b4dc1182720a459a90e7dd988aa /llvm/lib/Object/WasmObjectFile.cpp | |
parent | be66a2f66bac159256e45ac74629625de27ed603 (diff) | |
download | llvm-afe957ea9552dac35ed21c4160b1ef63439c49cb.zip llvm-afe957ea9552dac35ed21c4160b1ef63439c49cb.tar.gz llvm-afe957ea9552dac35ed21c4160b1ef63439c49cb.tar.bz2 |
[WebAssembly] Allow absolute symbols in the linking section (symbol table) (#67493)
Fixes a crash in `-Wl,-emit-relocs` where the linker was not able to
write linker-synthetic absolute symbols to the symbol table.
This change adds a new symbol flag (`WASM_SYMBOL_ABS`), which means that
the symbol's offset is absolute and not relative to a given segment.
Such symbols include `__stack_low` and `__stack_low`.
Note that wasm object files never contains such symbols, only binaries
linked with `-Wl,-emit-relocs`.
Fixes: #67111
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index e9471ad..0982c7e 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -723,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 segment 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; |