Skip to content

Commit 6851dcc

Browse files
sbc100tstellar
authored andcommitted
Merging r375077:
------------------------------------------------------------------------ r375077 | sbc | 2019-10-16 20:21:02 -0700 (Wed, 16 Oct 2019) | 10 lines [lld][WebAssembly] Fix for weak references to data symbols in archives Fix a bug where were not handling relocations against weakly undefined data symbol. Add a test for this case. Also ensure that the weak references to data symbols are not pulled in from archive files by default (but are if `-u <name>` is added to the command line). Fixes: PR43696 Differential Revision: https://reviews.llvm.org/D69073 ------------------------------------------------------------------------
1 parent 9497074 commit 6851dcc

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1+
; Test that weak undefined symbols do not fetch members from archive files.
12
; RUN: llc -filetype=obj %s -o %t.o
2-
; RUN: llc -filetype=obj %S/Inputs/ret32.ll -o %t.a1.o
3+
; RUN: llc -filetype=obj %S/Inputs/ret32.ll -o %t.ret32.o
4+
; RUN: llc -filetype=obj %S/Inputs/hello.ll -o %t.hello.o
35
; RUN: rm -f %t.a
4-
; RUN: llvm-ar rcs %t.a %t.a1.o
6+
; RUN: llvm-ar rcs %t.a %t.ret32.o %t.hello.o
7+
58
; RUN: wasm-ld %t.o %t.a -o %t.wasm
69
; RUN: obj2yaml %t.wasm | FileCheck %s
710

11+
; RUN: wasm-ld -u hello_str %t.o %t.a -o %t2.wasm
12+
; RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=CHECK-DATA
13+
814
target triple = "wasm32-unknown-unknown"
915

16+
; Weak external function symbol
1017
declare extern_weak i32 @ret32()
1118

19+
; Weak external data symbol
20+
@hello_str = extern_weak global i8*, align 4
21+
1222
define void @_start() {
13-
entry:
23+
br i1 icmp ne (i8** @hello_str, i8** null), label %if.then, label %if.end
24+
25+
if.then:
1426
%call1 = call i32 @ret32()
27+
br label %if.end
28+
29+
if.end:
1530
ret void
1631
}
1732

33+
; Ensure we have no data section. If we do, would mean that hello_str was
34+
; pulled out of the library.
35+
; CHECK-NOT: Type: DATA
36+
; CHECK-DATA: Type: DATA
37+
1838
; CHECK: Name: 'undefined:ret32'
1939
; CHECK-NOT: Name: ret32

lld/wasm/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ uint32_t ObjFile::calcNewValue(const WasmRelocation &reloc) const {
173173
case R_WASM_MEMORY_ADDR_I32:
174174
case R_WASM_MEMORY_ADDR_LEB:
175175
case R_WASM_MEMORY_ADDR_REL_SLEB:
176-
if (isa<UndefinedData>(sym))
176+
if (isa<UndefinedData>(sym) || sym->isUndefWeak())
177177
return 0;
178178
return cast<DefinedData>(sym)->getVirtualAddress() + reloc.Addend;
179179
case R_WASM_TYPE_INDEX_LEB:

0 commit comments

Comments
 (0)