diff options
author | Derek Schuff <dschuff@chromium.org> | 2023-07-25 14:13:05 -0700 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2023-07-27 15:43:51 -0700 |
commit | 1b21067cf247c62c2442daa7ee2d3915249d1ee2 (patch) | |
tree | 799411b3f5b269dc5f896fe80b295e8036110558 /llvm/lib/Object/WasmObjectFile.cpp | |
parent | edf2e0e075e8562ca6a57a3614fbb2b65077e375 (diff) | |
download | llvm-1b21067cf247c62c2442daa7ee2d3915249d1ee2.zip llvm-1b21067cf247c62c2442daa7ee2d3915249d1ee2.tar.gz llvm-1b21067cf247c62c2442daa7ee2d3915249d1ee2.tar.bz2 |
[WebAssembly][Objcopy] Write output section headers identically to inputs
Previously when objcopy generated section headers, it padded the LEB
that encodes the section size out to 5 bytes, matching the behavior of
clang. This is correct, but results in a binary that differs from the
input. This can sometimes have undesirable consequences (e.g. breaking
source maps).
This change makes the object reader remember the size of the LEB
encoding in the section header, so that llvm-objcopy can reproduce it
exactly. For sections not read from an object file (e.g. that
llvm-objcopy is adding itself), pad to 5 bytes.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D155535
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index a72242b..11b9b57 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); |