Skip to content

[Wasm] wasm-ld crashed when using --emit-relocs #67111

@MarcoPoloPie

Description

@MarcoPoloPie

When compiling a C file that calls malloc, if -Wl,-emit-relocs is added, wasm-ld will report an error:

#0 0x000055f608fd22e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (.../bin/wasm-ld+0xf052e8)
#1 0x000055f608fcfbfe llvm::sys::RunSignalHandlers() (.../bin/wasm-ld+0xf02bfe)
#2 0x000055f608fd2ef5 SignalHandler(int) Signals.cpp:0:0
#3 0x00007fa79ec89420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x000055f6093e6d67 lld::wasm::LinkingSection::writeBody() (.../bin/wasm-ld+0x1319d67)
#5 0x000055f6093d50ea lld::wasm::SyntheticSection::finalizeContents() Writer.cpp:0:0
#6 0x000055f6093d0141 lld::wasm::(anonymous namespace)::Writer::run() Writer.cpp:0:0
#7 0x000055f6093c11c1 lld::wasm::writeResult() (.../bin/wasm-ld+0x12f41c1)
#8 0x000055f609399d1f lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) Driver.cpp:0:0
#9 0x000055f609395acf lld::wasm::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (.../bin/wasm-ld+0x12c8acf)
#10 0x000055f608fd4d7f lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayReflld::DriverDef, bool) (.../bin/wasm-ld+0xf07d7f)

It appears that createOptionalSymbols() created WasmSym::heapBase and WasmSym::heapEnd with the DefinedData type, and leaves their segment fields as nullptr. However, LinkingSection::writeBody() does not check their segment fields before dereferencing them in getOutputSegmentIndex(), causing wasm-ld to crash.

Is this a bug or an expected behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions