[PATCH] D74781: Wasm-ld emits invalid .debug_ranges entries for non-live symbols

Paolo Severini via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 23 20:41:25 PDT 2020


paolosev updated this revision to Diff 252209.
paolosev added a comment.
Herald added a subscriber: jgravelle-google.

@sbc100  Adding a test.

@dblaikie Strangely, I can't find a way to generate a **.debug_loc** section for Wasm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74781

Files:
  lld/wasm/InputFiles.cpp
  llvm/test/DebugInfo/WebAssembly/Inputs/nonlive-symbols1.c
  llvm/test/DebugInfo/WebAssembly/Inputs/nonlive-symbols2.c
  llvm/test/DebugInfo/WebAssembly/dbg-ranges-nonlive-symbols.test


Index: llvm/test/DebugInfo/WebAssembly/dbg-ranges-nonlive-symbols.test
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/WebAssembly/dbg-ranges-nonlive-symbols.test
@@ -0,0 +1,16 @@
+RUN: rm -rf %t && mkdir -p %t
+RUN: clang -gfull --target=wasm32 -ffunction-sections -fdata-sections -c %S/Inputs/nonlive-symbols1.c -o %t/nonlive-symbols1.o
+RUN: clang -gfull --target=wasm32 -ffunction-sections -fdata-sections -c %S/Inputs/nonlive-symbols2.c -o %t/nonlive-symbols2.o
+RUN: clang -Wl,--gc-sections %t/nonlive-symbols1.o %t/nonlive-symbols2.o -nostdlib --target=wasm32 -o %t/nonlive-symbols2.wasm
+RUN: llvm-dwarfdump -v %t/nonlive-symbols2.wasm | FileCheck %s
+
+The second compilation unit (Inputs/nonlive-symbols2.c) contains a function
+(bar) which can be GC'd by --gc-sections. When this happens, references to that
+function will still exist in the `.debug_ranges` section. In this case the
+linker should not emit a spurious range-list terminator entry (an entry with
+Start==0 and End==0).
+
+CHECK:      .debug_ranges contents:
+CHECK:      00000000 {{[0-9]+}} {{[0-9]+}}
+CHECK:      00000000 {{[0-9]+}} {{[0-9]+}}
+CHECK:      <End of list>
Index: llvm/test/DebugInfo/WebAssembly/Inputs/nonlive-symbols2.c
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/WebAssembly/Inputs/nonlive-symbols2.c
@@ -0,0 +1,9 @@
+int foo() {
+  int b = 10;
+  return b + 2;
+}
+
+int bar() {
+  int a = 10;
+  return a + 5;
+}
Index: llvm/test/DebugInfo/WebAssembly/Inputs/nonlive-symbols1.c
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/WebAssembly/Inputs/nonlive-symbols1.c
@@ -0,0 +1,5 @@
+extern int foo();
+
+int _start() {
+  return foo();
+}
Index: lld/wasm/InputFiles.cpp
===================================================================
--- lld/wasm/InputFiles.cpp
+++ lld/wasm/InputFiles.cpp
@@ -167,10 +167,12 @@
   if (reloc.Type != R_WASM_TYPE_INDEX_LEB) {
     sym = symbols[reloc.Index];
 
-    // We can end up with relocations against non-live symbols.  For example
-    // in debug sections.
+    // We can end up with relocations against non-live symbols. For example
+    // in debug sections. We return reloc.Addend because always returning zero
+    // causes the generation of spurious range-list terminators in the
+    // .debug_ranges section.
     if ((isa<FunctionSymbol>(sym) || isa<DataSymbol>(sym)) && !sym->isLive())
-      return 0;
+      return reloc.Addend;
   }
 
   switch (reloc.Type) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74781.252209.patch
Type: text/x-patch
Size: 2606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200324/7c152e93/attachment-0001.bin>


More information about the llvm-commits mailing list