[PATCH] D68991: [lld][WebAssembly] Fix static linking of -fPIC code with external undefined data
James Clarke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 07:59:21 PDT 2019
jrtc27 created this revision.
jrtc27 added reviewers: ruiu, sbc100.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68991
Files:
lld/test/wasm/pic-static.ll
lld/wasm/SyntheticSections.cpp
Index: lld/wasm/SyntheticSections.cpp
===================================================================
--- lld/wasm/SyntheticSections.cpp
+++ lld/wasm/SyntheticSections.cpp
@@ -273,8 +273,12 @@
global.InitExpr.Opcode = WASM_OPCODE_I32_CONST;
if (auto *d = dyn_cast<DefinedData>(sym))
global.InitExpr.Value.Int32 = d->getVirtualAddress();
- else if (auto *f = cast<FunctionSymbol>(sym))
+ else if (auto *f = dyn_cast<FunctionSymbol>(sym))
global.InitExpr.Value.Int32 = f->getTableIndex();
+ else {
+ assert(isa<UndefinedData>(sym));
+ global.InitExpr.Value.Int32 = 0;
+ }
writeGlobal(os, global);
}
for (const DefinedData *sym : dataAddressGlobals) {
Index: lld/test/wasm/pic-static.ll
===================================================================
--- lld/test/wasm/pic-static.ll
+++ lld/test/wasm/pic-static.ll
@@ -12,6 +12,7 @@
declare i32 @missing_function(float)
@global_float = global float 1.0
@hidden_float = hidden global float 2.0
+ at missing_float = extern_weak global float
@ret32_ptr = global i32 (float)* @ret32, align 4
@@ -27,6 +28,10 @@
ret i32 ()* @hidden_func;
}
+define float* @getaddr_missing_float() {
+ ret float* @missing_float
+}
+
define hidden i32 @hidden_func() {
ret i32 1
}
@@ -83,16 +88,24 @@
; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 1
-; GOT.mem.global_float
+; GOT.mem.missing_float
; CHECK-NEXT: - Index: 4
; CHECK-NEXT: Type: I32
; CHECK-NEXT: Mutable: false
; CHECK-NEXT: InitExpr:
; CHECK-NEXT: Opcode: I32_CONST
+; CHECK-NEXT: Value: 0
+
+; GOT.mem.global_float
+; CHECK-NEXT: - Index: 5
+; CHECK-NEXT: Type: I32
+; CHECK-NEXT: Mutable: false
+; CHECK-NEXT: InitExpr:
+; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 1024
; GOT.mem.ret32_ptr
-; CHECK-NEXT: - Index: 5
+; CHECK-NEXT: - Index: 6
; CHECK-NEXT: Type: I32
; CHECK-NEXT: Mutable: false
; CHECK-NEXT: InitExpr:
@@ -100,7 +113,7 @@
; CHECK-NEXT: Value: 1032
; __memory_base
-; CHECK-NEXT: - Index: 6
+; CHECK-NEXT: - Index: 7
; CHECK-NEXT: Type: I32
; CHECK-NEXT: Mutable: false
; CHECK-NEXT: InitExpr:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68991.225042.patch
Type: text/x-patch
Size: 2527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191015/72feac00/attachment.bin>
More information about the llvm-commits
mailing list