[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 Feb 18 11:21:03 PST 2020


paolosev created this revision.
paolosev added reviewers: sbc100, kripken, dschuff.
paolosev added a project: lld.
Herald added subscribers: llvm-commits, sunfish, aheejin, aprantl.
Herald added a project: LLVM.

When the debug info contains a relocation against a dead symbol, wasm-ld emits a range-list terminator entry (an entry with Start==0 and End==0).
This is not correct, because it incorrectly terminates the range list of that compilation unit, hiding the valid range entries that come after that invalid entry.

The behavior is different when compiling to native, in that case we get entries with Start==0 and End > 0:

//.debug_ranges section//
00004280 0000000000231030 000000000023105a
**00004280 0000000000000000 0000000000000024
00004280 0000000000000000 000000000000007a**
00004280 0000000000231060 00000000002310a7
...

while with Wasm we see range entries (0, 0) that spuriously terminate the sequence:

//.debug_ranges contents://
00000000 000002ef 0000032d
00000000 00000357 00000360
**00000000 <End of list>**
00000028 000004ba 000004ff
00000028 00000576 000005c1
00000028 <End of list>
...

This patch fixes this problem by emitting the WasmRelocation //Addend// as End value for a non-live symbol.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74781

Files:
  lld/wasm/InputChunks.cpp


Index: lld/wasm/InputChunks.cpp
===================================================================
--- lld/wasm/InputChunks.cpp
+++ lld/wasm/InputChunks.cpp
@@ -107,6 +107,13 @@
   for (const WasmRelocation &rel : relocations) {
     uint8_t *loc = buf + rel.Offset + off;
     uint32_t value = file->calcNewValue(rel);
+
+    // 'value' can be zero when relocating against non-live symbols. We should
+    // not generate a range-list terminator in this case.
+    if (value == 0 && getName() == ".debug_ranges") {
+      value = rel.Addend;
+    }
+
     LLVM_DEBUG(dbgs() << "apply reloc: type=" << relocTypeToString(rel.Type));
     if (rel.Type != R_WASM_TYPE_INDEX_LEB)
       LLVM_DEBUG(dbgs() << " sym=" << file->getSymbols()[rel.Index]->getName());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74781.245196.patch
Type: text/x-patch
Size: 759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200218/f025924f/attachment.bin>


More information about the llvm-commits mailing list