[lld] r358995 - [WebAssembly] Fix typo in relocation checking
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 07:49:38 PDT 2019
Author: sbc
Date: Tue Apr 23 07:49:38 2019
New Revision: 358995
URL: http://llvm.org/viewvc/llvm-project?rev=358995&view=rev
Log:
[WebAssembly] Fix typo in relocation checking
Runtime relocation are generated for relocations of type
R_WASM_MEMORY_ADDR_I32 when in PIC mode (either -shared or -pie).
Followup on https://reviews.llvm.org/D60882.
Differential Revision: https://reviews.llvm.org/D60992
Added:
lld/trunk/test/wasm/pie.ll
Modified:
lld/trunk/wasm/InputFiles.cpp
Added: lld/trunk/test/wasm/pie.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/pie.ll?rev=358995&view=auto
==============================================================================
--- lld/trunk/test/wasm/pie.ll (added)
+++ lld/trunk/test/wasm/pie.ll Tue Apr 23 07:49:38 2019
@@ -0,0 +1,53 @@
+; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o
+; RUN: wasm-ld --no-gc-sections --allow-undefined -pie -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+ at data = global i32 2, align 4
+ at data_external = external global i32
+ at indirect_func = local_unnamed_addr global i32 ()* @foo, align 4
+
+ at data_addr = local_unnamed_addr global i32* @data, align 4
+ at data_addr_external = local_unnamed_addr global i32* @data_external, align 4
+
+define i32 @foo() {
+entry:
+ ; To ensure we use __stack_pointer
+ %ptr = alloca i32
+ %0 = load i32, i32* @data, align 4
+ %1 = load i32 ()*, i32 ()** @indirect_func, align 4
+ call i32 %1()
+ ret i32 %0
+}
+
+define default i32** @get_data_address() {
+entry:
+ ret i32** @data_addr_external
+}
+
+define void @_start() {
+ ret void
+}
+
+; CHECK: - Type: IMPORT
+; CHECK-NEXT: Imports:
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __indirect_function_table
+; CHECK-NEXT: Kind: TABLE
+; CHECK-NEXT: Table:
+; CHECK-NEXT: ElemType: FUNCREF
+; CHECK-NEXT: Limits:
+; CHECK-NEXT: Initial: 0x00000001
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __memory_base
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: GlobalType: I32
+; CHECK-NEXT: GlobalMutable: false
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __table_base
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: GlobalType: I32
+; CHECK-NEXT: GlobalMutable: false
+
+
Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=358995&r1=358994&r2=358995&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Tue Apr 23 07:49:38 2019
@@ -155,7 +155,9 @@ uint32_t ObjFile::calcNewValue(const Was
if (isa<DataSymbol>(Sym) && Sym->isUndefined()) {
if (Sym->isWeak() || Config->Relocatable)
return 0;
- if (Config->Shared && Reloc.Type == R_WASM_MEMORY_ADDR_I32)
+ // R_WASM_MEMORY_ADDR_I32 relocations in PIC code are turned into runtime
+ // fixups in __wasm_apply_relocs
+ if (Config->Pic && Reloc.Type == R_WASM_MEMORY_ADDR_I32)
return 0;
if (Reloc.Type != R_WASM_GLOBAL_INDEX_LEB) {
llvm_unreachable(
More information about the llvm-commits
mailing list