rui314 / mold

Mold: A Modern Linker 🦠
MIT License
14.38k stars 470 forks source link

Broken on OpenBSD 7.3 #1042

Open realchonk opened 1 year ago

realchonk commented 1 year ago

Hi,

your linker doesn't produce working binaries on OpenBSD 7.3. I compiled it following the instructions in #970.

Here's a bit of (maybe) useful data. If you need anything else, don't hesitate to ask.

test.c

#include <stdio.h>

int main (void)
{
    puts ("Hello World");
    return 0;
}

Compilation

$ clang -fuse-ld=mold -o test.mold test.c -g -Og
$ clang --o test.clang test.c -g -Og
$ ./test.clang
Hello World
$ ./test.mold
Segmentation fault

Debugging

$ egdb ./test.mold
GNU gdb (GDB) 9.2
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-unknown-openbsd7.3".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test.mold...
(gdb) r
Starting program: /tmp/test/test.mold

Program received signal SIGSEGV, Segmentation fault.
_dl_boot (argv=<optimized out>, envp=<optimized out>, dyn_loff=10249736192, dl_data=0x7b1a06dff5a0) at /usr/src/libexec/ld.so/loader.c:586
586             exe_obj->load_list = load_list;
(gdb) bt
#0  _dl_boot (argv=<optimized out>, envp=<optimized out>, dyn_loff=10249736192, dl_data=0x7b1a06dff5a0) at /usr/src/libexec/ld.so/loader.c:586
#1  0x0000000262eec296 in _dl_start () at /usr/src/libexec/ld.so/amd64/ldasm.S:61
#2  0x0000000000000000 in ?? ()
(gdb) disassemble _dl_start
Dump of assembler code for function _dl_start:
   0x0000000262eec250 <+0>:     mov    %rsp,%r12
   0x0000000262eec253 <+3>:     sub    $0x8,%rsp
   0x0000000262eec257 <+7>:     and    $0xfffffffffffffff0,%rsp
   0x0000000262eec25b <+11>:    add    $0x8,%rsp
   0x0000000262eec25f <+15>:    push   %rbx
   0x0000000262eec260 <+16>:    sub    $0x80,%rsp
   0x0000000262eec267 <+23>:    lea    0xfd2ca(%rip),%rdx        # 0x262fe9538
   0x0000000262eec26e <+30>:    mov    %rsp,%rsi
   0x0000000262eec271 <+33>:    mov    %r12,%rdi
   0x0000000262eec274 <+36>:    callq  0x262eec2b0 <_dl_boot_bind>
   0x0000000262eec279 <+41>:    mov    %rsp,%rcx
   0x0000000262eec27c <+44>:    mov    0x38(%rsp),%rdx
   0x0000000262eec281 <+49>:    mov    (%r12),%rdi
   0x0000000262eec285 <+53>:    lea    0x10(%r12,%rdi,8),%rsi
   0x0000000262eec28a <+58>:    mov    %r12,%rdi
   0x0000000262eec28d <+61>:    add    $0x8,%rdi
   0x0000000262eec291 <+65>:    callq  0x262eed480 <_dl_boot>
   0x0000000262eec296 <+70>:    add    $0x80,%rsp
   0x0000000262eec29d <+77>:    lea    0xa60c(%rip),%rdx        # 0x262ef68b0 <_dl_dtors>
   0x0000000262eec2a4 <+84>:    mov    %r12,%rsp
   0x0000000262eec2a7 <+87>:    jmpq   *%rax
End of assembler dump.

readelf -a test.clang

https://pastebin.com/ixn6t2XJ

readelf -a test.mold

https://pastebin.com/cV46jdFB

rui314 commented 1 year ago

Let me try to use mold on an OpenBSD machine.

rui314 commented 1 year ago

OK, so I think you guys should fix libtbb first so that mold can be built on OpenBSD out-of-the-box. We can't maintain OpenBSD-specific local patches for libtbb as we are not using the operating system. Can you file a bug to libtbb?

realchonk commented 1 year ago

Seems like OpenBSD has a tbb package, but it doesn't provide CMake or pkg-config files, only headers and libs.

brad0 commented 1 year ago

OK, so I think you guys should fix libtbb first so that mold can be built on OpenBSD out-of-the-box. We can't maintain OpenBSD-specific local patches for libtbb as we are not using the operating system. Can you file a bug to libtbb?

That has now been fixed upstream. https://github.com/oneapi-src/oneTBB/commit/ea4e6156a2cde839fc01b21b76cd9b5743ec0cef

brad0 commented 1 year ago

Seems like OpenBSD has a tbb package, but it doesn't provide CMake or pkg-config files, only headers and libs.

That is TBB 2020. I have an update to 2021.

rui314 commented 1 year ago

@brad0 That's good news! With that I can now build mold on an OpenBSD machine. Currently mold unittests only care about Linux, so the first step to port it to OpenBSD is to enable them on non-Linux non-Apple Unix-like systems. Let me take a look.

brad0 commented 1 year ago

@rui34 Just as a note, we have a fair bit of patching to our lld linker. Here is a complete diff from upstream and commit history.

https://github.com/llvm/llvm-project/compare/release/13.x...mordak:llvm-project:openbsd-release/13.x.diff https://github.com/mordak/llvm-project/commits/openbsd-release/13.x/lld