[lld] aff75e1 - [lld][Wasm] Wasm-ld emits invalid .debug_ranges entries for non-live symbols

Paolo Severini via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 14:28:18 PDT 2020


Author: Paolo Severini
Date: 2020-03-26T14:26:31-07:00
New Revision: aff75e1a1facbc6cc274070690ff3d725325c0f1

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

LOG: [lld][Wasm] Wasm-ld emits invalid .debug_ranges entries for non-live symbols

When the debug info contains a relocation against a dead symbol, wasm-ld
may emit spurious range-list terminator entries (entries with Start==0
and End==0). This change fixes this by emitting the WasmRelocation
Addend as End value for a non-live symbol.

Reviewed by: sbc100, dblaikie

Differential Revision: https://reviews.llvm.org/D74781

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/debug-removed-fn.ll b/lld/test/wasm/debug-removed-fn.ll
index 6bb23df06a57..89a55a3d4187 100644
--- a/lld/test/wasm/debug-removed-fn.ll
+++ b/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"

diff  --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 2aab5bf10e61..15a85872eefe 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -168,9 +168,11 @@ uint32_t ObjFile::calcNewValue(const WasmRelocation &reloc) const {
     sym = symbols[reloc.Index];
 
     // We can end up with relocations against non-live symbols.  For example
-    // in debug sections.
+    // 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) {


        


More information about the llvm-commits mailing list