[llvm-bugs] [Bug 27194] New: lld segfaults linking mach on linux

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 4 00:01:38 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27194

            Bug ID: 27194
           Summary: lld segfaults linking mach on linux
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: m4b.github.io at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

I'm trying to cross compile a binary (in this case an object file generated by
Rust) on GNU/Linux to the x86_64-apple-darwin target, so I could be doing
something stupid here (nevertheless the bug which is an unchecked null pointer
dereference should probably be fixed/checked).

But assuming I have the macho object file, call it main.0.o, and darwin system
libraries, imagine we have something like the following script:

```
#!/bin/bash

DIR=/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib
DARWIN_PATH=/home/m4b/binaries/darwin/usr/lib
SYS=$DARWIN_PATH/system
LLD=/home/m4b/Downloads/llvm-3.8.0.src/build/bin/lld
$LLD -flavor darwin -Z -arch x86_64 -t -L
"/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib"
"$SYS/libsystem_platform.dylib" "$SYS/libsystem_c.dylib"
"$SYS/libsystem_pthread.dylib" "$SYS/libunwind.dylib" "$SYS/libdyld.dylib"
"$DIR/liblibc-18402db3.rlib" -lcompiler-rt "$DIR/libstd-18402db3.dylib"
"$DIR/libcollections-18402db3.rlib" "$DIR/librustc_unicode-18402db3.rlib"
"$DIR/librand-18402db3.rlib" "$DIR/liballoc-18402db3.rlib"
"$DIR/liballoc_jemalloc-18402db3.rlib" "$DIR/libcore-18402db3.rlib"
"$DIR/libcompiler-rt.a" main.0.o -o main_apple
```

I provide paths to the darwin shared objects and rust libs which provide the
necessary symbols for main.0.o (and no reexporting libs, otherwise we die on an
assertion because obviously it won't find the exporting binary in the right
place on my linux system).

Unfortunately however, lld segfaults in `CompactUnwindPass.cpp` due to the
`dyn_cast` returning null and not being checked in the next line, e.g. at line
509:

```
const DefinedAtom *cfiTarget = dyn_cast<DefinedAtom>(ref->target());
if (cfiTarget->contentType() == DefinedAtom::typeCFI)
```

Why it's null I don't know :/

The full output is:

/home/m4b/binaries/darwin/usr/lib/system/libsystem_platform.dylib
/home/m4b/binaries/darwin/usr/lib/system/libsystem_c.dylib
/home/m4b/binaries/darwin/usr/lib/system/libsystem_pthread.dylib
/home/m4b/binaries/darwin/usr/lib/system/libunwind.dylib
/home/m4b/binaries/darwin/usr/lib/system/libdyld.dylib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liblibc-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcompiler-rt.a
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libstd-18402db3.dylib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcollections-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/librand-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcore-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcompiler-rt.a
t.0.o
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcore-18402db3.rlib(core-18402db3.0.o)
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-18402db3.rlib(alloc_jemalloc-18402db3.0.o)
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc-18402db3.rlib(alloc-18402db3.0.o)
0  lld             0x00000000004ffc8d
1  lld             0x000000000050000a
2  lld             0x00000000004fe768
3  lld             0x00000000004ff78c
4  libpthread.so.0 0x00007fda7187ee80
5  lld             0x0000000001ec80ae
6  lld             0x0000000001ecc2ca
7  lld             0x000000000041fdb4
8  lld             0x000000000041e6d3
9  lld             0x000000000041434a
10 lld             0x000000000040d915
11 lld             0x000000000040c958
12 libc.so.6       0x00007fda70a3a710 __libc_start_main + 240
13 lld             0x000000000040c819
Stack dump:
0.    Program arguments: /usr/bin/lld -Z -arch x86_64 -t -L
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib
/home/m4b/binaries/darwin/usr/lib/system/libsystem_platform.dylib
/home/m4b/binaries/darwin/usr/lib/system/libsystem_c.dylib
/home/m4b/binaries/darwin/usr/lib/system/libsystem_pthread.dylib
/home/m4b/binaries/darwin/usr/lib/system/libunwind.dylib
/home/m4b/binaries/darwin/usr/lib/system/libdyld.dylib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liblibc-18402db3.rlib
-lcompiler-rt
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libstd-18402db3.dylib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcollections-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/librand-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcore-18402db3.rlib
/home/m4b/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcompiler-rt.a
main.0.o -o main_apple -flavor darwin

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160404/64405100/attachment.html>


More information about the llvm-bugs mailing list