[PATCH] D139210: [llvm-objcopy] Fix --section-add when section contain empty bytes
Guilhem Morer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 10:37:53 PST 2022
gmorer created this revision.
Herald added subscribers: pmatos, asb, abrachet, sunfish, hiraditya, sbc100.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: jhenderson.
Herald added a project: All.
gmorer edited the summary of this revision.
gmorer published this revision for review.
Herald added subscribers: llvm-commits, MaskRay, aheejin.
Herald added a project: LLVM.
Implicit cast between char* and StringRef when writing sections.
Reproduce:
$> llvm-objcopy --dump-section=name=name.data out.wasm
$> llvm-objcopy --remove-section=name out.wasm out_no_name.wasm
$> llvm-objcopy --add-section=name=name.data out_no_name.wasm out_new_name.wasm
# With wasm-objdump -h we can see that the name section is not totally copied in the new wasm file (if it actually contain empty bytes)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D139210
Files:
llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp
Index: llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp
===================================================================
--- llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp
+++ llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp
@@ -126,9 +126,11 @@
Sec.SectionType = llvm::wasm::WASM_SEC_CUSTOM;
Sec.Name = NewSection.SectionName;
+ llvm::StringRef InputData =
+ llvm::StringRef(NewSection.SectionData->getBufferStart(),
+ NewSection.SectionData->getBufferSize());
std::unique_ptr<MemoryBuffer> BufferCopy = MemoryBuffer::getMemBufferCopy(
- NewSection.SectionData->getBufferStart(),
- NewSection.SectionData->getBufferIdentifier());
+ InputData, NewSection.SectionData->getBufferIdentifier());
Sec.Contents = makeArrayRef<uint8_t>(
reinterpret_cast<const uint8_t *>(BufferCopy->getBufferStart()),
BufferCopy->getBufferSize());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139210.479670.patch
Type: text/x-patch
Size: 891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221202/9ed8e5f9/attachment.bin>
More information about the llvm-commits
mailing list