mold
mold copied to clipboard
elf: `-u foo %t/a.so %t/a.a` crashes
# RUN: rm -rf %t && mkdir %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t/a.o
# RUN: llvm-ar rc %t/a.a %t/a.o
# RUN: mold -shared -soname=a %t/a.o -o %t/a.so
# RUN: mold -u foo %t/a.so %t/a.a -o %t/out
.globl foo
foo:
In GNU ld and ld.lld, the symbol resolves to %t/a.so and the output has no foo.
mold currently crashes mold: elf/passes.cc:243: std::vector<std::span<T>> mold::elf::split(std::vector<T> &, mold::elf::i64) [T = mold::elf::ObjectFile<mold::elf::X86_64> *]: Assertion input.size() > 0' failed.`
(If I swap %t/a.so %t/a.a, foo will be provided by %t/a.a.)
It is indeed a crash bug. I'll fix. Thanks!
@rui314 I'm seeing a crash in the test created for this bug test/elf/bug178.sh on FreeBSD
./elf/bug178.sh: line 29: 57452 Segmentation fault "$mold" -o $t/exe $t/a.a gmake[2]: *** [Makefile.linux:6: elf/bug178.sh] Error 139
... under gdb
(gdb) bt
#0 thr_kill () at thr_kill.S:4
#1 0x00000008020391f4 in __raise (s=11) at /usr/src/lib/libc/gen/raise.c:52
#2 0x0000000001891d88 in mold::elf::fork_child () at elf/subprocess.cc:49
#3 0x00000000013f03c3 in mold::elf::elf_main<mold::elf::X86_64> (argc=4, argv=0x7fffffffdec0) at elf/main.cc:437
#4 0x00000000013efccf in mold::elf::main (argc=4, argv=0x7fffffffdec0) at elf/main.cc:760
#5 0x00000000010ce4dd in main (argc=4, argv=0x7fffffffdec0) at main.cc:46
Let me know if you'd like it in a separate/new issue or this one where I can attach the bt full
@koobs mold forks itself at the beginning, so the stacktrace does not cointain the real location of the crash. Can you re-run mold with --no-fork to suppress that behavior?
Testing bug178 ... GNU gdb (GDB) 11.2 [GDB v11.2 for FreeBSD]
... <snip> ...
Reading symbols from /var/tmp/tmpfs0/usr/home/koobs/repos/freebsd/ports/devel/mold/work/mold-1.2/mold...
(gdb) run
Starting program: /var/tmp/tmpfs0/usr/home/koobs/repos/freebsd/ports/devel/mold/work/mold-1.2/mold --no-fork -o out/test/elf/bug178/exe out/test/elf/bug178/a.a
warning: Could not load shared library symbols for [vdso].
Do you need "set solib-search-path" or "set sysroot"?
[New LWP 623283 of process 80114]
Thread 1 received signal SIGSEGV, Segmentation fault.
Address not mapped to object.
0x00000000014fa969 in std::__1::partition_point<std::__1::__wrap_iter<mold::elf::Symbol<mold::elf::X86_64>**>, mold::elf::DynsymSection<mold::elf::X86_64>::finalize(mold::elf::Context<mold::elf::X86_64>&)::{lambda(mold::elf::Symbol<mold::elf::X86_64>*)#1}>(std::__1::__wrap_iter<mold::elf::Symbol<mold::elf::X86_64>**>, std::__1::__wrap_iter<mold::elf::Symbol<mold::elf::X86_64>**>, mold::elf::DynsymSection<mold::elf::X86_64>::finalize(mold::elf::Context<mold::elf::X86_64>&)::{lambda(mold::elf::Symbol<mold::elf::X86_64>*)#1}) (__first=..., __last=..., __pred=...) at /usr/include/c++/v1/__algorithm/partition_point.h:36
36 if (__pred(*__m))
(gdb) bt
#0 0x00000000014fa969 in std::__1::partition_point<std::__1::__wrap_iter<mold::elf::Symbol<mold::elf::X86_64>**>, mold::elf::DynsymSection<mold::elf::X86_64>::finalize(mold::elf::Context<mold::elf::X86_64>&)::{lambda(mold::elf::Symbol<mold::elf::X86_64>*)#1}>(std::__1::__wrap_iter<mold::elf::Symbol<mold::elf::X86_64>**>, std::__1::__wrap_iter<mold::elf::Symbol<mold::elf::X86_64>**>, mold::elf::DynsymSection<mold::elf::X86_64>::finalize(mold::elf::Context<mold::elf::X86_64>&)::{lambda(mold::elf::Symbol<mold::elf::X86_64>*)#1}) (__first=..., __last=..., __pred=...) at /usr/include/c++/v1/__algorithm/partition_point.h:36
#1 0x00000000014fa558 in mold::elf::DynsymSection<mold::elf::X86_64>::finalize (this=0x804080da0, ctx=...) at elf/output-chunks.cc:1306
#2 0x00000000013f0d24 in mold::elf::elf_main<mold::elf::X86_64> (argc=5, argv=0x7fffffffdeb0) at elf/main.cc:595
#3 0x00000000013efccf in mold::elf::main (argc=5, argv=0x7fffffffdeb0) at elf/main.cc:760
#4 0x00000000010ce4dd in main (argc=5, argv=0x7fffffffdeb0) at main.cc:46