Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-ld crash when linking huge wasm binary without gc-sections #53987

Closed
TerrorJack opened this issue Feb 22, 2022 · 4 comments · Fixed by #78643
Closed

wasm-ld crash when linking huge wasm binary without gc-sections #53987

TerrorJack opened this issue Feb 22, 2022 · 4 comments · Fixed by #78643
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] lld:wasm

Comments

@TerrorJack
Copy link

The complete verbose log is available at https://gist.github.com/TerrorJack/6e241c2671782e441bcd25ccaff89689.

wasm-ld: warning: function signature mismatch: memmove
>>> defined as (i32, i32, i32) -> void in /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(PrimOps.o)
>>> defined as (i32, i32, i32) -> i32 in /nix/store/vfakx52ca5dg871dphaz4m7hcynbhj70-wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi/libc.a(memmove.o)

wasm-ld: warning: function signature mismatch: memcpy
>>> defined as (i32, i32, i32) -> void in /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/ghc-bignum-1.3/libHSghc-bignum-1.3.a(WordArray.o)
>>> defined as (i32, i32, i32) -> i32 in /nix/store/vfakx52ca5dg871dphaz4m7hcynbhj70-wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi/libc.a(memcpy.o)

wasm-ld: warning: function signature mismatch: memset
>>> defined as (i32, i32, i32) -> void in /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(PrimOps.o)
>>> defined as (i32, i32, i32) -> i32 in /nix/store/vfakx52ca5dg871dphaz4m7hcynbhj70-wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi/libc.a(memset.o)

wasm-ld: warning: function signature mismatch: barf
>>> defined as (i32) -> void in /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(Exception.o)
>>> defined as (i32, i32) -> void in /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(RtsMessages.o)

wasm-ld: warning: function signature mismatch: barf
>>> defined as () -> void in /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(StgStartup.o)
>>> defined as (i32, i32) -> void in /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(RtsMessages.o)

wasm-ld: -- createOutputSegments

wasm-ld: -- createSyntheticSections

wasm-ld: -- layoutMemory

wasm-ld: mem: stack size  = 65536

wasm-ld: mem: stack base  = 0

wasm-ld: mem: stack top   = 65536

wasm-ld: mem: .rodata         offset=65536    size=959396   align=6

wasm-ld: mem: .data           offset=1024944  size=830152   align=4

wasm-ld: mem: .bss            offset=1855104  size=342532   align=6

wasm-ld: mem: static data = 2132100

wasm-ld: mem: heap base   = 2197648

wasm-ld: mem: total pages = 34

wasm-ld: -- createSyntheticSectionsPostLayout

wasm-ld: -- populateProducers

wasm-ld: -- calculateImports

wasm-ld: -- scanRelocations

wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Sync.o): undefined symbol: getNumberOfProcessors
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: chmod
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: umask
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: fork
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: waitpid
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: tcsetattr
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: tcgetattr
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: sigprocmask
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: sigaddset
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: sigemptyset
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: mkfifo
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(Inlines.o): undefined symbol: pthread_mutex_trylock
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(ExecPage.o): undefined symbol: mmapAnonForLinker
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(ExecPage.o): undefined symbol: mprotectForLinker
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(ExecPage.o): undefined symbol: munmapForLinker
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(RtsSymbols.o): undefined symbol: forkOS_createThread
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Sync.o): undefined symbol: getNumberOfProcessors
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(RtsSymbols.o): undefined symbol: setTimerManagerControlFd
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(RtsSymbols.o): undefined symbol: setIOManagerWakeupFd
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(RtsSymbols.o): undefined symbol: blockUserSignals
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(RtsSymbols.o): undefined symbol: unblockUserSignals
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0/libHSbase-4.16.0.0.a(Internals.o): undefined symbol: fork
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(MBlock.o): undefined symbol: osReleaseFreeMemory
wasm-ld: warning: /tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2/libHSrts-1.0.2.a(MBlock.o): undefined symbol: osFreeMBlocks
wasm-ld: -- finalizeIndirectFunctionTable
wasm-ld: -- populateTargetFeatures
wasm-ld: -- createSyntheticInitFunctions
wasm-ld: -- assignIndexes
wasm-ld: -- calculateInitFunctions
wasm-ld: -- createCommandExportWrappers
wasm-ld: -- calculateTypes
wasm-ld: -- calculateExports
wasm-ld: -- calculateCustomSections
wasm-ld: calculateCustomSections
wasm-ld: -- populateSymtab
wasm-ld: -- checkImportExportTargetFeatures
wasm-ld: -- addSections
wasm-ld: addSection: TYPE
wasm-ld: addSection: IMPORT
wasm-ld: addSection: FUNCTION
wasm-ld: addSection: TABLE
wasm-ld: addSection: MEMORY
wasm-ld: addSection: GLOBAL
wasm-ld: addSection: EXPORT
wasm-ld: addSection: ELEM
wasm-ld: addSection: CODE
wasm-ld: addSection: DATA
wasm-ld: createCustomSections
wasm-ld: addSection: CUSTOM(.debug_info)
wasm-ld: addSection: CUSTOM(.debug_loc)
wasm-ld: addSection: CUSTOM(.debug_ranges)
wasm-ld: addSection: CUSTOM(.debug_abbrev)
wasm-ld: addSection: CUSTOM(.debug_line)
wasm-ld: addSection: CUSTOM(.debug_str)
wasm-ld: addSection: CUSTOM(name)
wasm-ld: addSection: CUSTOM(producers)
wasm-ld: addSection: CUSTOM(target_features)
wasm-ld: Defined Functions: 72931
wasm-ld: Defined Globals  : 1
wasm-ld: Defined Tags     : 0
wasm-ld: Defined Tables   : 1
wasm-ld: Function Imports : 45
wasm-ld: Global Imports   : 0
wasm-ld: Tag Imports      : 0
wasm-ld: Table Imports    : 0
wasm-ld: -- finalizeSections
wasm-ld: createHeader: TYPE body=13021 total=13024
wasm-ld: createHeader: IMPORT body=1756 total=1759
wasm-ld: createHeader: FUNCTION body=98478 total=98482
wasm-ld: createHeader: TABLE body=6 total=8
wasm-ld: createHeader: MEMORY body=3 total=5
wasm-ld: createHeader: GLOBAL body=8 total=10
wasm-ld: createHeader: EXPORT body=21 total=23
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /nix/store/vfakx52ca5dg871dphaz4m7hcynbhj70-wasi-sdk/bin/wasm-ld -m wasm32 -L/tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/base-4.16.0.0 -L/tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/ghc-bignum-1.3 -L/tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/ghc-prim-0.8.0 -L/tmp/nix-build-ghc-9.3.drv-0/ghc-src/_build/stage1/lib/../lib/wasm32-wasi-ghc-9.3.20220222/rts-1.0.2 -L/nix/store/6x93b5xp8m7by9g95q1qdwp3qpvzmmn3-libffi/lib -L/nix/store/vfakx52ca5dg871dphaz4m7hcynbhj70-wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi /nix/store/vfakx52ca5dg871dphaz4m7hcynbhj70-wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi/crt1-command.o --error-limit=0 --growable-table --stack-first -lm Main.o fib.o /tmp/ghc3762343_0/ghc_9.o -u base_GHCziTopHandler_runIO_closure -u base_GHCziTopHandler_runNonIO_closure -u ghczmprim_GHCziTuple_Z0T_closure -u ghczmprim_GHCziTypes_True_closure -u ghczmprim_GHCziTypes_False_closure -u base_GHCziPack_unpackCString_closure -u base_GHCziWeak_runFinalizzerBatch_closure -u base_GHCziIOziException_stackOverflow_closure -u base_GHCziIOziException_heapOverflow_closure -u base_GHCziIOziException_allocationLimitExceeded_closure -u base_GHCziIOziException_blockedIndefinitelyOnMVar_closure -u base_GHCziIOziException_blockedIndefinitelyOnSTM_closure -u base_GHCziIOziException_cannotCompactFunction_closure -u base_GHCziIOziException_cannotCompactPinned_closure -u base_GHCziIOziException_cannotCompactMutable_closure -u base_GHCziIOPort_doubleReadException_closure -u base_ControlziExceptionziBase_nonTermination_closure -u base_ControlziExceptionziBase_nestedAtomically_closure -u base_GHCziEventziThread_blockedOnBadFD_closure -u base_GHCziConcziSync_runSparks_closure -u base_GHCziConcziIO_ensureIOManagerIsRunning_closure -u base_GHCziConcziIO_interruptIOManager_closure -u base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure -u base_GHCziConcziSignal_runHandlersPtr_closure -u base_GHCziTopHandler_flushStdHandles_closure -u base_GHCziTopHandler_runMainIO_closure -u ghczmprim_GHCziTypes_Czh_con_info -u ghczmprim_GHCziTypes_Izh_con_info -u ghczmprim_GHCziTypes_Fzh_con_info -u ghczmprim_GHCziTypes_Dzh_con_info -u ghczmprim_GHCziTypes_Wzh_con_info -u base_GHCziPtr_Ptr_con_info -u base_GHCziPtr_FunPtr_con_info -u base_GHCziInt_I8zh_con_info -u base_GHCziInt_I16zh_con_info -u base_GHCziInt_I32zh_con_info -u base_GHCziInt_I64zh_con_info -u base_GHCziWord_W8zh_con_info -u base_GHCziWord_W16zh_con_info -u base_GHCziWord_W32zh_con_info -u base_GHCziWord_W64zh_con_info -u base_GHCziStable_StablePtr_con_info -u hs_atomic_add8 -u hs_atomic_add16 -u hs_atomic_add32 -u hs_atomic_sub8 -u hs_atomic_sub16 -u hs_atomic_sub32 -u hs_atomic_and8 -u hs_atomic_and16 -u hs_atomic_and32 -u hs_atomic_nand8 -u hs_atomic_nand16 -u hs_atomic_nand32 -u hs_atomic_or8 -u hs_atomic_or16 -u hs_atomic_or32 -u hs_atomic_xor8 -u hs_atomic_xor16 -u hs_atomic_xor32 -u hs_cmpxchg8 -u hs_cmpxchg16 -u hs_cmpxchg32 -u hs_cmpxchg64 -u hs_xchg8 -u hs_xchg16 -u hs_xchg32 -u hs_xchg64 -u hs_atomicread8 -u hs_atomicread16 -u hs_atomicread32 -u hs_atomicwrite8 -u hs_atomicwrite16 -u hs_atomicwrite32 -u base_GHCziStackziCloneStack_StackSnapshot_closure -lHSbase-4.16.0.0 -lHSghc-bignum-1.3 -lHSghc-prim-0.8.0 -lHSrts-1.0.2 -lm -lrt -lffi --no-gc-sections --warn-unresolved-symbols --verbose -lc /nix/store/vfakx52ca5dg871dphaz4m7hcynbhj70-wasi-sdk/lib/clang/14.0.0/lib/wasi/libclang_rt.builtins-wasm32.a -o Main
 #0 0x000000000079cae4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /build/wasi-sdk-src/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:13

 #1 0x000000000079cae4 PrintStackTraceSignalHandler(void*) (.llvm.4032290631565588858) /build/wasi-sdk-src/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:631:0: error:
    3
     #2 0x000000000079a7a0 llvm::sys::RunSignalHandlers() /build/wasi-sdk-src/src/llvm-project/llvm/lib/Support/Signals.cpp:98:18
     #3 0x000000000079d19a SignalHandler(int) /build/wasi-sdk-src/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
     #4 0x00007f67a3c64ee0 __restore_rt (/nix/store/jcb7fny2k03pfbdqk1hcnh12bxgax6vf-glibc-2.33-108/lib/libpthread.so.0+0x12ee0)
     #5 0x0000000000af9fd4 lld::wasm::InputFunction::getFunctionIndex() const /build/wasi-sdk-src/src/llvm-project/lld/wasm/InputChunks.h:279:60
     #6 0x0000000000af9fd4 lld::wasm::FunctionSymbol::getFunctionIndex() const /build/wasi-sdk-src/src/llvm-project/lld/wasm/Symbols.cpp:255:23
     #7 0x0000000000af9fd4 lld::wasm::ElemSection::writeBody() /build/wasi-sdk-src/src/llvm-project/lld/wasm/SyntheticSections.cpp:562:27
     #8 0x0000000000aeaf3a llvm::raw_ostream::flush() /build/wasi-sdk-src/src/llvm-project/llvm/include/llvm/Support/raw_ostream.h:188:22
     #9 0x0000000000aeaf3a lld::wasm::SyntheticSection::finalizeContents() /build/wasi-sdk-src/src/llvm-project/lld/wasm/SyntheticSections.h:59:22
#10 0x0000000000ae6b81 lld::wasm::(anonymous namespace)::Writer::finalizeSections() /build/wasi-sdk-src/src/llvm-project/lld/wasm/Writer.cpp:428:20
#11 0x0000000000ae6b81 lld::wasm::(anonymous namespace)::Writer::run() /build/wasi-sdk-src/src/llvm-project/lld/wasm/Writer.cpp:1642:3
#12 0x0000000000adadc7 llvm::SmallDenseMap<llvm::StringRef, lld::wasm::OutputSegment*, 4u, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, lld::wasm::OutputSegment*> >::deallocateBuckets() /build/wasi-sdk-src/src/llvm-project/llvm/include/llvm/ADT/DenseMap.h:1173:9
#13 0x0000000000adadc7 llvm::SmallDenseMap<llvm::StringRef, lld::wasm::OutputSegment*, 4u, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, lld::wasm::OutputSegment*> >::~SmallDenseMap() /build/wasi-sdk-src/src/llvm-project/llvm/include/llvm/ADT/DenseMap.h:933:5
#14 0x0000000000adadc7 lld::wasm::(anonymous namespace)::Writer::~Writer() /build/wasi-sdk-src/src/llvm-project/lld/wasm/Writer.cpp:50:7
#15 0x0000000000adadc7 lld::wasm::writeResult() /build/wasi-sdk-src/src/llvm-project/lld/wasm/Writer.cpp:1686:22
#16 0x0000000000abf4ee std::__1::__vector_base<lld::wasm::WrappedSymbol, std::__1::allocator<lld::wasm::WrappedSymbol> >::~__vector_base() /nix/store/2ayc3c2kybakqva1rap5l486is23rnr9-libcxx-13.0.0-dev/include/c++/v1/vector:485:9
#17 0x0000000000abf4ee std::__1::vector<lld::wasm::WrappedSymbol, std::__1::allocator<lld::wasm::WrappedSymbol> >::~vector() /nix/store/2ayc3c2kybakqva1rap5l486is23rnr9-libcxx-13.0.0-dev/include/c++/v1/vector:579:5
#18 0x0000000000abf4ee lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) /build/wasi-sdk-src/src/llvm-project/lld/wasm/Driver.cpp:1013:1
#19 0x0000000000abb506 std::__1::__vector_base<lld::wasm::InputFile*, std::__1::allocator<lld::wasm::InputFile*> >::~__vector_base() /nix/store/2ayc3c2kybakqva1rap5l486is23rnr9-libcxx-13.0.0-dev/include/c++/v1/vector:485:9
#20 0x0000000000abb506 std::__1::vector<lld::wasm::InputFile*, std::__1::allocator<lld::wasm::InputFile*> >::~vector() /nix/store/2ayc3c2kybakqva1rap5l486is23rnr9-libcxx-13.0.0-dev/include/c++/v1/vector:579:5
#21 0x0000000000abb506 lld::wasm::(anonymous namespace)::LinkerDriver::~LinkerDriver() /build/wasi-sdk-src/src/llvm-project/lld/wasm/Driver.cpp:68:7
#22 0x0000000000abb506 lld::wasm::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) /build/wasi-sdk-src/src/llvm-project/lld/wasm/Driver.cpp:98:3
#23 0x000000000071ccdc lldMain(int, char const**, llvm::raw_ostream&, llvm::raw_ostream&, bool) /build/wasi-sdk-src/src/llvm-project/lld/tools/lld/lld.cpp:164:12

#24 0x000000000071c3aa main /build/wasi-sdk-src/src/llvm-project/lld/tools/lld/lld.cpp:220:0: error:
    12
#25 0x00007f67a380e790 __libc_start_main (/nix/store/jcb7fny2k03pfbdqk1hcnh12bxgax6vf-glibc-2.33-108/lib/libc.so.6+0x27790)

#26 0x000000000071bfea _start /build/glibc-2.33/csu/../sysdeps/x86_64/start.S:122:0: error:
    0
clang-14: error: unable to execute command: Segmentation fault (core dumped)
clang-14: error: linker command failed due to signal (use -v to see invocation)

The above verbose log and stack traces comes from the llvmorg-14.0.0-rc1 revision on x86_64-linux.

@llvmbot
Copy link
Member

llvmbot commented Feb 22, 2022

@llvm/issue-subscribers-lld-wasm

@sbc100
Copy link
Collaborator

sbc100 commented Feb 25, 2022

To be clear if you use --gc-sections the crash doesn't happen?

Is there any way you could try narrow this down? Or at least could you attach the set of all inputs uses so its can be reproduced?

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Jan 18, 2024

I think I have what is likely the same failure, here's the stack obtained with a debug linker:

wasm-ld: warning: C:/Users/Accretion/source/dotnet/runtimelab/artifacts/bin/microsoft.netcore.app.runtime.wasi-wasm/Release/runtimes/wasi-wasm/native/libSystem.Native.a(pal_datetime.c.obj): undefined symbol: mono_bundled_resources_get_data_resource_values
Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!", file C:\Users\Accretion\source\dotnet\llvm-project\llvm\include\llvm/Support/Casting.h, line 578PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Exception Code: 0x80000003
 #0 0x00007ff61a23619c HandleAbort C:\Users\Accretion\source\dotnet\llvm-project\llvm\lib\Support\Windows\Signals.inc:419:0
 #1 0x00007ffdada0bc31 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6bc31)
 #2 0x00007ffdada0d889 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6d889)
 #3 0x00007ffdada134b5 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x734b5)
 #4 0x00007ffdada13027 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x73027)
 #5 0x00007ffdada11091 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x71091)
 #6 0x00007ffdada13a1f (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x73a1f)
 #7 0x00007ff61ac44181 C:\Users\Accretion\source\dotnet\llvm-project\llvm\include\llvm\Support\Casting.h:578:0
 #8 0x00007ff61ac41afc lld::wasm::FunctionSymbol::getFunctionIndex(void) const C:\Users\Accretion\source\dotnet\llvm-project\lld\wasm\Symbols.cpp:258:0
 #9 0x00007ff61ac4a975 lld::wasm::ObjFile::calcNewValue(struct llvm::wasm::WasmRelocation const &, unsigned __int64, class lld::wasm::InputChunk const *) const C:\Users\Accretion\source\dotnet\llvm-project\lld\wasm\InputFiles.cpp:197:0
#10 0x00007ff61ac6cce3 lld::wasm::InputChunk::relocate(unsigned char *) const C:\Users\Accretion\source\dotnet\llvm-project\lld\wasm\InputChunks.cpp:122:0
#11 0x00007ff61ac6c7ab lld::wasm::InputChunk::writeTo(unsigned char *) const C:\Users\Accretion\source\dotnet\llvm-project\lld\wasm\InputChunks.cpp:101:0
#12 0x00007ff61acdc591 lld::wasm::CodeSection::writeTo(unsigned char *) C:\Users\Accretion\source\dotnet\llvm-project\lld\wasm\OutputSections.cpp:84:0
#13 0x00007ff61ac81554 `lld::wasm::`anonymous namespace'::Writer::writeSections'::`2'::<lambda_1>::operator() C:\Users\Accretion\source\dotnet\llvm-project\lld\wasm\Writer.cpp:225:0
#14 0x00007ff61ac835b0 `llvm::parallelForEach<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<lld::wasm::OutputSection *> > >,`lld::wasm::`anonymous namespace'::Writer::writeSections'::`2'::<lambda_1> >'::`2'::<lambda_1>::operator() C:\Users\Accretion\source\dotnet\llvm-project\llvm\include\llvm\Support\Parallel.h:234:0
#15 0x00007ff61ac95866 llvm::function_ref<void __cdecl(unsigned __int64)>::callback_fn<`llvm::parallelForEach<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<lld::wasm::OutputSection *> > >,`lld::wasm::`anonymous namespace'::Writer::writeSections'::`2'::<lambda_1> >'::`2'::<lambda_1> > C:\Users\Accretion\source\dotnet\llvm-project\llvm\include\llvm\ADT\STLFunctionalExtras.h:47:0
#16 0x00007ff622c73e9a llvm::function_ref<(unsigned __int64)>::operator()(unsigned __int64) const C:\Users\Accretion\source\dotnet\llvm-project\llvm\include\llvm\ADT\STLFunctionalExtras.h:69:0
#17 0x00007ff622c6f426 `llvm::parallelFor'::`9'::<lambda_1>::operator() C:\Users\Accretion\source\dotnet\llvm-project\llvm\lib\Support\Parallel.cpp:242:0
#18 0x00007ff622c730d4 std::invoke<`llvm::parallelFor'::`9'::<lambda_1> &> C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\type_traits:1549:0
#19 0x00007ff622c70d84 std::_Invoker_ret<void>::_Call<`llvm::parallelFor'::`9'::<lambda_1> &> C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\functional:672:0
#20 0x00007ff622c6f8fb std::_Func_impl_no_alloc<`llvm::parallelFor'::`9'::<lambda_1>,void>::_Do_call C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\functional:832:0
#21 0x00007ff61a39b7ff std::_Func_class<void>::operator()(void) const C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\functional:879:0
#22 0x00007ff622c6f267 `llvm::parallel::TaskGroup::spawn'::`5'::<lambda_1>::operator() C:\Users\Accretion\source\dotnet\llvm-project\llvm\lib\Support\Parallel.cpp:215:0
#23 0x00007ff622c730b4 std::invoke<`llvm::parallel::TaskGroup::spawn'::`5'::<lambda_1> &> C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\type_traits:1549:0
#24 0x00007ff622c70d64 std::_Invoker_ret<void>::_Call<`llvm::parallel::TaskGroup::spawn'::`5'::<lambda_1> &> C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\functional:672:0
#25 0x00007ff622c6f70b std::_Func_impl_no_alloc<`llvm::parallel::TaskGroup::spawn'::`5'::<lambda_1>,void>::_Do_call C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\functional:832:0
#26 0x00007ff61a39b7ff std::_Func_class<void>::operator()(void) const C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\functional:879:0
#27 0x00007ff622c6eda7 llvm::parallel::detail::`anonymous namespace'::ThreadPoolExecutor::work C:\Users\Accretion\source\dotnet\llvm-project\llvm\lib\Support\Parallel.cpp:142:0
#28 0x00007ff622c6f003 ``llvm::parallel::detail::`anonymous namespace'::ThreadPoolExecutor::ThreadPoolExecutor'::`2'::<lambda_1>::operator()'::`5'::<lambda_1>::operator() C:\Users\Accretion\source\dotnet\llvm-project\llvm\lib\Support\Parallel.cpp:64:0
#29 0x00007ff622c73134 std::invoke<``llvm::parallel::detail::`anonymous namespace'::ThreadPoolExecutor::ThreadPoolExecutor'::`2'::<lambda_1>::operator()'::`5'::<lambda_1> > C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\type_traits:1549:0
#30 0x00007ff622c71b78 std::thread::_Invoke<std::tuple<``llvm::parallel::detail::`anonymous namespace'::ThreadPoolExecutor::ThreadPoolExecutor'::`2'::<lambda_1>::operator()'::`5'::<lambda_1> >,0> C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\include\thread:56:0
#31 0x00007ffdada14c7c (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x74c7c)
#32 0x00007ffddfa77614 (C:\WINDOWS\System32\KERNEL32.DLL+0x17614)
#33 0x00007ffde19a26f1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526f1)

It seems that --warn-unresolved-symbols is a contributor, as this links fine with --unresolved-symbols=ignore-all. Will continue to investigate.

Edit: debug log:

apply reloc: type=R_WASM_FUNCTION_INDEX_LEB sym=mono_bundled_resources_get_data_resource_values addend=0 index=5 offset=132
Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!", file C:\Users\Accretion\source\dotnet\llvm-project\llvm\include\llvm/Support/Casting.h, line 578

@EugeneZelenko EugeneZelenko added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Jan 18, 2024
@SingleAccretion
Copy link
Contributor

SingleAccretion commented Jan 18, 2024

Here's the minimal reproduction, you just need an undefined function:

; main.c
extern int func();
int main() { return func(); }

; wasi-sdk clang
> clang main.c -o main.wasm -Wl,--warn-unresolved-symbols

wasm-ld: warning: C:/Users/ACCRET~1/AppData/Local/Temp/main-03c656.o: undefined symbol: func
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.

Edit: I think the bug is in Relocations.cpp/reportUndefined. It only makes the undefined functions into stubs with UnresolvedPolicy::Ignore. It should do that for UnresolvedPolicy::Warn too.

sbc100 added a commit to sbc100/llvm-project that referenced this issue Jan 19, 2024
…-symbols

When undefined functions exist in the final link we need to create
stub functions (otherwise direct calls to those functions could
not be generated).  We were creating those stub when
`--unresolved-symbols=ignore-all` was passed but overlooked the fact
that `--warn-unresolved-symbols` essentially has the same effect (i.e.
undefined function can exist in the final link).

Fixes: llvm#53987
sbc100 added a commit that referenced this issue Jan 19, 2024
…-symbols (#78643)

When undefined functions exist in the final link we need to create
stub functions (otherwise direct calls to those functions could
not be generated).  We were creating those stub when
`--unresolved-symbols=ignore-all` was passed but overlooked the fact
that `--warn-unresolved-symbols` essentially has the same effect (i.e.
undefined function can exist in the final link).

Fixes: #53987
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] lld:wasm
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants