summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Clarke <jrtc27@jrtc27.com>2019-10-15 17:05:42 +0000
committerJames Clarke <jrtc27@jrtc27.com>2019-10-15 17:05:42 +0000
commit1ab27c74d4b183454e2b7ab74c42a39f7c02cab4 (patch)
tree8bc1bd49a311f8ee77e58456bf2a091690c2dad6
parent311dbb1bd7c2933e8c1f5317aa9ef8715b4fae3c (diff)
downloadbcm5719-llvm-1ab27c74d4b183454e2b7ab74c42a39f7c02cab4.tar.gz
bcm5719-llvm-1ab27c74d4b183454e2b7ab74c42a39f7c02cab4.zip
[lld][WebAssembly] Fix static linking of -fPIC code with external undefined data
Reviewers: ruiu, sbc100 Reviewed By: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68991 llvm-svn: 374913
-rw-r--r--lld/test/wasm/pic-static.ll19
-rw-r--r--lld/wasm/SyntheticSections.cpp6
2 files changed, 21 insertions, 4 deletions
diff --git a/lld/test/wasm/pic-static.ll b/lld/test/wasm/pic-static.ll
index d13d74d8a21..83752f3bdb3 100644
--- a/lld/test/wasm/pic-static.ll
+++ b/lld/test/wasm/pic-static.ll
@@ -12,6 +12,7 @@ declare i32 @ret32(float)
declare i32 @missing_function(float)
@global_float = global float 1.0
@hidden_float = hidden global float 2.0
+@missing_float = extern_weak global float
@ret32_ptr = global i32 (float)* @ret32, align 4
@@ -27,6 +28,10 @@ define i32 ()* @getaddr_hidden() {
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 @@ entry:
; 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 @@ entry:
; 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:
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index b00bd0ce9d0..30c1096e16c 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -273,8 +273,12 @@ void GlobalSection::writeBody() {
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) {
OpenPOWER on IntegriCloud