[lld] 3e7bc0d - [lld][WebAssembly] Allow relocations against non-live global symbols

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 28 10:30:14 PDT 2021


Author: Sam Clegg
Date: 2021-04-28T10:29:41-07:00
New Revision: 3e7bc0da57f17673ac61e5af3b005ffabfb449f3

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

LOG: [lld][WebAssembly] Allow relocations against non-live global symbols

Just like the in case for function and data symbols this is needed to
support relocations in debug info sections which are allowed contains
relocations against non-live symbols.

The motivating use case is an object file that contains debug info that
references `__stack_pointer` (a local symbol) but does not actually
contain any uses of `__stack_pointer`.

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

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

Added: 
    lld/test/wasm/debuginfo-undefined-global.s

Modified: 
    lld/test/wasm/globals.s
    lld/wasm/InputFiles.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/debuginfo-undefined-global.s b/lld/test/wasm/debuginfo-undefined-global.s
new file mode 100644
index 0000000000000..76794779e3c4f
--- /dev/null
+++ b/lld/test/wasm/debuginfo-undefined-global.s
@@ -0,0 +1,23 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+# RUN: wasm-ld -o %t.wasm %t.o
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+# Debug sections are allowed to contains references to non-live symbols that
+# then get GC'd.  In this test the .debug_info seciton contains a reference to
+# foo which is not otherwise used and will not be marked a live in the output.
+# Verify the tombstone value is written to debug_info section.
+
+.globl  _start
+_start:
+  .functype _start () -> ()
+  end_function
+
+.section .debug_info,"",@
+  .int32 foo
+
+.globaltype foo, i32
+foo:
+
+# CHECK:       - Type:            CUSTOM
+# CHECK-NEXT:    Name:            .debug_info
+# CHECK-NEXT:    Payload:         FFFFFFFF

diff  --git a/lld/test/wasm/globals.s b/lld/test/wasm/globals.s
index 6e049e1e73f91..bc3f7824cb208 100644
--- a/lld/test/wasm/globals.s
+++ b/lld/test/wasm/globals.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+mm# 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
 

diff  --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 6b3b0d2c2e523..889280a71c1ad 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -212,7 +212,7 @@ uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
     // so this will not produce a valid range conflicting with ranges of actual
     // code. In other sections we return reloc.Addend.
 
-    if ((isa<FunctionSymbol>(sym) || isa<DataSymbol>(sym)) && !sym->isLive())
+    if (!isa<SectionSymbol>(sym) && !sym->isLive())
       return tombstone ? tombstone : reloc.Addend;
   }
 


        


More information about the llvm-commits mailing list