[llvm] e4b2f30 - [WebAssembly][libObject] Avoid re-use of Section object during parsing
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 10 06:31:18 PDT 2021
Author: Sam Clegg
Date: 2021-09-10T09:30:50-04:00
New Revision: e4b2f3054a77ec28d501e269affbac6cfdfda35c
URL: https://github.com/llvm/llvm-project/commit/e4b2f3054a77ec28d501e269affbac6cfdfda35c
DIFF: https://github.com/llvm/llvm-project/commit/e4b2f3054a77ec28d501e269affbac6cfdfda35c.diff
LOG: [WebAssembly][libObject] Avoid re-use of Section object during parsing
The re-use of this struct across iterations of the loop was causing
fields (specifically Name) to be incorrectly shared between multiple
sections.
Differential Revision: https://reviews.llvm.org/D108984
Added:
Modified:
llvm/lib/Object/WasmObjectFile.cpp
llvm/test/tools/llvm-objcopy/wasm/basic-only-section.test
Removed:
################################################################################
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index a08c648358c03..9a4e246f765a1 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -286,9 +286,9 @@ WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err)
return;
}
- WasmSection Sec;
WasmSectionOrderChecker Checker;
while (Ctx.Ptr < Ctx.End) {
+ WasmSection Sec;
if ((Err = readSection(Sec, Ctx, Checker)))
return;
if ((Err = parseSection(Sec)))
diff --git a/llvm/test/tools/llvm-objcopy/wasm/basic-only-section.test b/llvm/test/tools/llvm-objcopy/wasm/basic-only-section.test
index f4b7d91a12367..fe47d5c027733 100644
--- a/llvm/test/tools/llvm-objcopy/wasm/basic-only-section.test
+++ b/llvm/test/tools/llvm-objcopy/wasm/basic-only-section.test
@@ -1,32 +1,36 @@
## Test --only-section.
# RUN: yaml2obj %s -o %t
-# RUN: llvm-objcopy --only-section=producers %t %t2
+# RUN: llvm-objcopy --only-section=foo %t %t2
# RUN: obj2yaml %t2 | FileCheck --implicit-check-not TYPE --implicit-check-not linking %s
## Test that it's the same with only-section + keep-section (for the same section).
-# RUN: llvm-objcopy --only-section=producers --keep-section=producers %t %t2
+# RUN: llvm-objcopy --only-section=foo --keep-section=foo %t %t2
# RUN: obj2yaml %t2 | FileCheck --implicit-check-not TYPE --implicit-check-not linking %s
## Also test that only-section overrides remove-section.
-# RUN: llvm-objcopy --only-section=producers --remove-section=producers %t %t2
+# RUN: llvm-objcopy --only-section=foo --remove-section=foo %t %t2
# RUN: obj2yaml %t2 | FileCheck --implicit-check-not linking %s
-## This file has both known and custom sections. Check that only the producers section is left.
+## This file has both known and custom sections. Check that only the foo section is left.
# CHECK: Sections:
# CHECK-NEXT: - Type: CUSTOM
-# CHECK-NEXT: Name: producers
-# CHECK-NEXT: Tools:
+# CHECK-NEXT: Name: foo
+# CHECK-NEXT: Payload: DEADBEEF
+# CHECK-NEXT: ...
## Test that only-section + keep-section keeps both sections.
-# RUN: llvm-objcopy --only-section=producers --keep-section=linking %t %t2
+# RUN: llvm-objcopy --only-section=foo --keep-section=linking %t %t2
# RUN: obj2yaml %t2 | FileCheck --implicit-check-not=TYPE --check-prefix=KEEP %s
+# KEEP: Name: foo
# KEEP: Name: linking
-# KEEP: Name: producers
--- !WASM
FileHeader:
Version: 0x00000001
Sections:
+ - Type: CUSTOM
+ Name: foo
+ Payload: DEADBEEF
- Type: TYPE
Signatures:
- Index: 0
@@ -37,8 +41,3 @@ Sections:
- Type: CUSTOM
Name: linking
Version: 2
- - Type: CUSTOM
- Name: producers
- Tools:
- - Name: clang
- Version: 9.0.0
More information about the llvm-commits
mailing list