[lld] r369423 - [WebAssembly][lld] Fix crash when applying relocations to debug sections

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 11:39:24 PDT 2019


Author: sbc
Date: Tue Aug 20 11:39:24 2019
New Revision: 369423

URL: http://llvm.org/viewvc/llvm-project?rev=369423&view=rev
Log:
[WebAssembly][lld] Fix crash when applying relocations to debug sections

Debug sections are special in that they can contain relocations against
symbols that are not present in the final output (i.e. not live).
However it is also possible to have R_WASM_TABLE_INDEX relocations
against symbols that don't have a table index assigned (since they are
not address taken by actual code.

Fixes: https://github.com/emscripten-core/emscripten/issues/9023

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

Added:
    lld/trunk/test/wasm/debuginfo-relocs.s
Modified:
    lld/trunk/wasm/InputChunks.cpp
    lld/trunk/wasm/InputFiles.cpp

Added: lld/trunk/test/wasm/debuginfo-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/debuginfo-relocs.s?rev=369423&view=auto
==============================================================================
--- lld/trunk/test/wasm/debuginfo-relocs.s (added)
+++ lld/trunk/test/wasm/debuginfo-relocs.s Tue Aug 20 11:39:24 2019
@@ -0,0 +1,23 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+# RUN: wasm-ld %t.o -o %t.wasm
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+bar:
+    .functype bar () -> ()
+    end_function
+
+    .globl _start
+_start:
+    .functype _start () -> ()
+    call bar
+    end_function
+
+    .section .debug_info,"",@
+    .int32 bar
+
+# Even though `bar` is live in the final binary it doesn't have a table entry
+# since its not address taken in the code.  In this case any relocations in the
+# debug sections see a address of zero.
+
+# CHECK:         Name:            .debug_info
+# CHECK-NEXT:    Payload:         '00000000'

Modified: lld/trunk/wasm/InputChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.cpp?rev=369423&r1=369422&r2=369423&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.cpp (original)
+++ lld/trunk/wasm/InputChunks.cpp Tue Aug 20 11:39:24 2019
@@ -100,7 +100,7 @@ void InputChunk::writeTo(uint8_t *buf) c
   verifyRelocTargets();
 #endif
 
-  LLVM_DEBUG(dbgs() << "applying relocations: " << getName()
+  LLVM_DEBUG(dbgs() << "applying relocations: " << toString(this)
                     << " count=" << relocations.size() << "\n");
   int32_t off = outputOffset - getInputSectionOffset();
 

Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=369423&r1=369422&r2=369423&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Tue Aug 20 11:39:24 2019
@@ -166,7 +166,7 @@ uint32_t ObjFile::calcNewValue(const Was
   case R_WASM_TABLE_INDEX_I32:
   case R_WASM_TABLE_INDEX_SLEB:
   case R_WASM_TABLE_INDEX_REL_SLEB:
-    if (config->isPic && !getFunctionSymbol(reloc.Index)->hasTableIndex())
+    if (!getFunctionSymbol(reloc.Index)->hasTableIndex())
       return 0;
     return getFunctionSymbol(reloc.Index)->getTableIndex();
   case R_WASM_MEMORY_ADDR_SLEB:




More information about the llvm-commits mailing list