Sam Clegg accad76c14 [lld][WebAssembly] Fix handling of comdat functions in init array.
When hidden symbols are discarded by comdat rules we still want to
create a local defined symbol, otherwise `Symbol::isDiscarded()` relies
on begin able to check `getChunk->discarded`.

This is a followup on rL362769. The comdat.ll test was previously GC'ing
the `__wasm_call_ctors` functions so `do_init` was not actually being
included in the link.  Once that function was included in triggered the
crash bug that this change addresses.

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

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

llvm-svn: 366358
2019-07-17 18:43:36 +00:00

23 lines
540 B
LLVM

target triple = "wasm32-unknown-unknown"
$foo = comdat any
@constantData = constant [3 x i8] c"abc", comdat($foo)
define i32 @comdatFn() comdat($foo) {
ret i32 ptrtoint ([3 x i8]* @constantData to i32)
}
define internal void @do_init() comdat($foo) {
ret void
}
%0 = type { i32, void ()*, i8* }
@llvm.global_ctors = appending global [1 x %0 ] [%0 { i32 65535, void ()* @do_init, i8* null }]
; Everything above this is part of the `foo` comdat group
define i32 @callComdatFn1() {
ret i32 ptrtoint (i32 ()* @comdatFn to i32)
}