[Lldb-commits] [lldb] 585df63 - [lldb] Index Wasm data segment names by their entry's index (#226302)

via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 24 22:07:35 PDT 2026


Author: Jonas Devlieghere
Date: 2026-09-24T22:07:27-07:00
New Revision: 585df631037b5cf8d822b9d6de5abb74cf79d1f4

URL: https://github.com/llvm/llvm-project/commit/585df631037b5cf8d822b9d6de5abb74cf79d1f4
DIFF: https://github.com/llvm/llvm-project/commit/585df631037b5cf8d822b9d6de5abb74cf79d1f4.diff

LOG: [lldb] Index Wasm data segment names by their entry's index (#226302)

ParseNames bounds-checked each data segment name entry's index but wrote
the name to the slot of the loop counter. A name subsection with more
entries than segments wrote past the end of the segment vector, and
entries listed out of order named the wrong segment.

rdar://186890690

Added: 
    lldb/test/Shell/ObjectFile/wasm/data-segment-names.yaml

Modified: 
    lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp b/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
index cb7e04c1925b62..a266464e49aabb 100644
--- a/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
+++ b/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
@@ -701,7 +701,7 @@ ParseNames(SectionSP code_section_sp, SectionSP global_section_sp,
         if (*idx >= segments.size())
           continue;
         // Update the segment name.
-        segments[i].name = *name;
+        segments[*idx].name = *name;
       }
 
     } break;

diff  --git a/lldb/test/Shell/ObjectFile/wasm/data-segment-names.yaml b/lldb/test/Shell/ObjectFile/wasm/data-segment-names.yaml
new file mode 100644
index 00000000000000..b14a4152fc1183
--- /dev/null
+++ b/lldb/test/Shell/ObjectFile/wasm/data-segment-names.yaml
@@ -0,0 +1,48 @@
+# REQUIRES: webassembly
+
+# A data segment name applies to the segment its entry indexes, independent of
+# the entry's position in the name subsection. Entries naming the same segment
+# repeatedly must not write past the segments.
+
+# RUN: yaml2obj %s -o %t.wasm
+# RUN: %lldb %t.wasm -o "target modules dump sections" -o exit 2>&1 \
+# RUN:   | FileCheck %s
+
+# CHECK: [0x0000000000010000-0x0000000000010004) {{.*}}.wasm.first
+# CHECK: [0x0000000000020000-0x0000000000020004) {{.*}}.wasm.second
+
+--- !WASM
+FileHeader:
+  Version: 0x1
+Sections:
+  - Type: MEMORY
+    Memories:
+      - Minimum: 0x4
+  - Type: DATA
+    Segments:
+      - SectionOffset:   6
+        InitFlags:       0
+        Offset:
+          Opcode:          I32_CONST
+          Value:           65536
+        Content:          'DEADBEEF'
+      - SectionOffset:   16
+        InitFlags:       0
+        Offset:
+          Opcode:          I32_CONST
+          Value:           131072
+        Content:          'CAFEF00D'
+  - Type: CUSTOM
+    Name: name
+    DataSegmentNames:
+      - Index: 1
+        Name: second
+      - Index: 0
+        Name: first
+      - Index: 0
+        Name: first
+      - Index: 0
+        Name: first
+      - Index: 0
+        Name: first
+...


        


More information about the lldb-commits mailing list