Skip to content

[lld][WebAssembly] wasm-ld crash with -pie/-pic and R_WASM_FUNCTION_INDEX_I32 in the data section #146923

Open
@SingleAccretion

Description

@SingleAccretion

Reproduction:

> wasm-ld -o result.wasm ilc_output.o --export-dynamic --experimental-pic --unresolved-symbols=import-dynamic -pie --no-entry

Expected result: no crash.
Actual result:

Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!", file llvm-project\llvm\include\llvm/Support/Casting.h, line 578
wasm-ld.exe(0x00007FF6FCE30000) + 0x5181EC byte(s), HandleAbort() + 0xC byte(s), llvm-project\llvm\lib\Support\Windows\Signals.inc, line 429 + 0x0 byte(s)
C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF84DD50000) + 0xA90ED byte(s), raise() + 0x46D byte(s)
C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF84DD50000) + 0xAAE49 byte(s), abort() + 0x39 byte(s)
C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF84DD50000) + 0xB1345 byte(s), _get_wide_winmain_command_line() + 0x2895 byte(s)
C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF84DD50000) + 0xB0BD7 byte(s), _get_wide_winmain_command_line() + 0x2127 byte(s)
C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF84DD50000) + 0xAEBA1 byte(s), _get_wide_winmain_command_line() + 0xF1 byte(s)
C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF84DD50000) + 0xB18AF byte(s), _wassert() + 0x2F byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10C6681 byte(s), llvm::cast<lld::wasm::DefinedFunction,lld::wasm::FunctionSymbol const >() + 0x41 byte(s), llvm-project\llvm\include\llvm\Support\Casting.h, line 578 + 0x37 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10C455C byte(s), lld::wasm::FunctionSymbol::getFunctionIndex() + 0x5C byte(s), llvm-project\lld\wasm\Symbols.cpp, line 236 + 0xA byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10CCB4E byte(s), lld::wasm::ObjFile::calcNewValue() + 0x2DE byte(s), llvm-project\lld\wasm\InputFiles.cpp, line 201 + 0x20 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10F030C byte(s), lld::wasm::InputChunk::generateRelocationCode() + 0x8BC byte(s), llvm-project\lld\wasm\InputChunks.cpp, line 448 + 0x47 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10FC037 byte(s), lld::wasm::`anonymous namespace'::Writer::createApplyDataRelocationsFunction() + 0x207 byte(s), llvm-project\lld\wasm\Writer.cpp, line 1466 + 0x21 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10FA4B8 byte(s), lld::wasm::`anonymous namespace'::Writer::createSyntheticInitFunctions() + 0xE8 byte(s), llvm-project\lld\wasm\Writer.cpp, line 1140 + 0xD byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10F9891 byte(s), lld::wasm::`anonymous namespace'::Writer::run() + 0x571 byte(s), llvm-project\lld\wasm\Writer.cpp, line 1771 + 0xD byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10F92EE byte(s), lld::wasm::writeResult() + 0x3E byte(s), llvm-project\lld\wasm\Writer.cpp, line 1888 + 0x3E byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10A2895 byte(s), lld::wasm::`anonymous namespace'::LinkerDriver::linkerMain() + 0x1E95 byte(s), llvm-project\lld\wasm\Driver.cpp, line 1502 + 0x0 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x10A3C4A byte(s), lld::wasm::link() + 0x1DA byte(s), llvm-project\lld\wasm\Driver.cpp, line 143 + 0x68 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x67E4BE byte(s), lld::unsafeLldMain() + 0x14E byte(s), llvm-project\lld\Common\DriverDispatcher.cpp, line 163 + 0xA6 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x49DFA2 byte(s), lld_main() + 0x2A2 byte(s), llvm-project\lld\tools\lld\lld.cpp, line 89 + 0x1EE byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x4A3256 byte(s), main() + 0xA6 byte(s), llvm-project\build-debug\tools\lld\tools\lld\lld-driver.cpp, line 17 + 0x4D byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x75FDA89 byte(s), invoke_main() + 0x39 byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 79 + 0x0 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x75FD972 byte(s), __scrt_common_main_seh() + 0x132 byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 288 + 0x5 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x75FD82E byte(s), __scrt_common_main() + 0xE byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 331 + 0x0 byte(s)
wasm-ld.exe(0x00007FF6FCE30000) + 0x75FDB1E byte(s), mainCRTStartup() + 0xE byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp, line 17 + 0x0 byte(s)
C:\WINDOWS\System32\KERNEL32.DLL(0x00007FF884660000) + 0x17374 byte(s), BaseThreadInitThunk() + 0x14 byte(s)
C:\WINDOWS\SYSTEM32\ntdll.dll(0x00007FF884890000) + 0x4CC91 byte(s), RtlUserThreadStart() + 0x21 byte(s)

The input object file contains this entry:

 - segment[79] <.data.RhpStackTraceIpCanary> memory=0 size=4 - init i32=0
  - 0000000: 0000 0000                                ....
           000000: R_WASM_FUNCTION_INDEX_I32 93 <env.RhpGetStackTraceIpCanary>

The crash goes away if we add a definition for RhpGetStackTraceIpCanary to the link (e. g. an empty function). However, I suspect this doesn't actually result in correct code, since there is no "base" symbol for WASM function indices.

ilc_output.zip (an object file with this relocation in the data section can also be constructed manually with the changes in #146952).

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]lld:wasm

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions