[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
Tue Mar 24 20:24:45 PDT 2020


paolosev updated this revision to Diff 252477.
paolosev marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74781

Files:
  lld/test/wasm/debug-removed-fn.ll
  lld/wasm/InputFiles.cpp


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) {
Index: lld/test/wasm/debug-removed-fn.ll
===================================================================
--- lld/test/wasm/debug-removed-fn.ll
+++ lld/test/wasm/debug-removed-fn.ll
@@ -1,11 +1,16 @@
 ; RUN: llc -filetype=obj < %s -o %t.o
 ; RUN: wasm-ld %t.o --no-entry --export=foo -o %t.wasm
-; RUN: llvm-dwarfdump -debug-line %t.wasm | FileCheck %s
+; RUN: llvm-dwarfdump -debug-line -debug-ranges %t.wasm | FileCheck %s
 
 ; CHECK: Address
 ; CHECK: 0x0000000000000005
 ; CHECK: 0x0000000000000000
 
+; CHECK: .debug_ranges contents:
+; CHECK: 00000000 {{[0-9]+}} {{[0-9]+}}
+; CHECK: 00000000 {{[0-9]+}} {{[0-9]+}}
+; CHECK: 00000000 <End of list>
+
 ; ModuleID = 't.bc'
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown-wasm"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74781.252477.patch
Type: text/x-patch
Size: 1562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200325/7436c3df/attachment.bin>


More information about the llvm-commits mailing list