diff options
author | Guilhem <guilhem@trail.gg> | 2022-12-02 16:48:27 -0800 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2022-12-02 16:59:57 -0800 |
commit | 0041382198f20fe51d8574363bc91c317c7f3c71 (patch) | |
tree | 29b237f5b0e11d3d0fb111c54dfb2229d8af5eca /llvm/lib | |
parent | fccab9f90b0327c00116e593351e1e4cd19b5677 (diff) | |
download | llvm-0041382198f20fe51d8574363bc91c317c7f3c71.zip llvm-0041382198f20fe51d8574363bc91c317c7f3c71.tar.gz llvm-0041382198f20fe51d8574363bc91c317c7f3c71.tar.bz2 |
[llvm-objcopy] Fix --section-add when section contain empty bytes
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)
```
Reviewed By: dschuff
Differential Revision: https://reviews.llvm.org/D139210
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp b/llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp index 6877cd6..19f10bf 100644 --- a/llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp +++ b/llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp @@ -126,9 +126,11 @@ static Error handleArgs(const CommonConfig &Config, Object &Obj) { 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()); |