[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 15:42:58 PST 2022


gmorer updated this revision to Diff 479766.
gmorer added a comment.

Tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139210/new/

https://reviews.llvm.org/D139210

Files:
  llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp
  llvm/test/tools/llvm-objcopy/wasm/add-section.test


Index: llvm/test/tools/llvm-objcopy/wasm/add-section.test
===================================================================
--- llvm/test/tools/llvm-objcopy/wasm/add-section.test
+++ llvm/test/tools/llvm-objcopy/wasm/add-section.test
@@ -20,6 +20,17 @@
 # REPLACE:   Name:    foo
 # REPLACE:   Payload: 3132330A
 
+# Check that raw data can be imported and exported unchanged.
+# RUN: echo -en '\x02\x01\x00\x01\x02' > %t6
+# RUN: llvm-objcopy --add-section=bar=%t6 %t %t7
+# RUN: llvm-objcopy --dump-section=bar=%t8 %t7
+# RUN: diff %t8 %t6
+# RUN: obj2yaml %t7 | FileCheck %s --check-prefix=RAW-DATA
+
+# Check that raw data is well formated in the file as well.
+# RAW-DATA:      Name: bar
+# RAW-DATA-NEXT: Payload: '0201000102'
+
 --- !WASM
 FileHeader:
   Version: 0x00000001
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.479766.patch
Type: text/x-patch
Size: 1675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221202/81c2d89c/attachment.bin>


More information about the llvm-commits mailing list