aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-09-11 18:37:24 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-12-08 17:35:11 +0000
commit8a4dda33d67586ca2624f2a38417baa03a533a7f (patch)
treeea87f69d4341b5a653c3747ebbdbedd7b41da233 /contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
parent06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (diff)
parent8092e001bcd76c0b9fec2311f3a515aa60d2ed07 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp b/contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
index fdcd441cc798..bfab25ce8097 100644
--- a/contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
+++ b/contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
@@ -29,16 +29,19 @@ Writer::SectionHeader Writer::createSectionHeader(const Section &S,
SectionSize = S.Contents.size();
if (HasName)
SectionSize += getULEB128Size(S.Name.size()) + S.Name.size();
- // Pad the LEB value out to 5 bytes to make it a predictable size, and
- // match the behavior of clang.
- encodeULEB128(SectionSize, OS, 5);
+ // If we read this section from an object file, use its original size for the
+ // padding of the LEB value to avoid changing the file size. Otherwise, pad
+ // out to 5 bytes to make it predictable, and match the behavior of clang.
+ unsigned HeaderSecSizeEncodingLen =
+ S.HeaderSecSizeEncodingLen ? *S.HeaderSecSizeEncodingLen : 5;
+ encodeULEB128(SectionSize, OS, HeaderSecSizeEncodingLen);
if (HasName) {
encodeULEB128(S.Name.size(), OS);
OS << S.Name;
}
// Total section size is the content size plus 1 for the section type and
- // 5 for the LEB-encoded size.
- SectionSize = SectionSize + 1 + 5;
+ // the LEB-encoded size.
+ SectionSize = SectionSize + 1 + HeaderSecSizeEncodingLen;
return Header;
}