[llvm-bugs] [Bug 30434] New: [Rust] Executable linked with -pie segfaults
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Sep 17 14:43:41 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=30434
Bug ID: 30434
Summary: [Rust] Executable linked with -pie segfaults
Product: lld
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: ELF
Assignee: unassignedbugs at nondot.org
Reporter: japaricious at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Trying to link a hello world program written in Rust succeeds but running the
executable produces a
segfault. If I remove the `-pie` flag from the arguments `rustc` passes to
`lld` then the link
also succeeds but I get an executable that works correctly this time.
### Steps To Reproduce
As a bash script but I've also attached the .cpio file generated by these
commands:
``` bash
main() {
install_rust
# test program
echo 'fn main() { println!("Hello, world!"); }' > hello.rs
# compile only, we'll link manually
rm -f hello.o
rustc --emit=obj hello.rs
# store the path to the sysroot in a variable to make the following
commands shorter
local sysroot=$(rustc --print sysroot)
# link
# NOTE The arguments used here are what `rustc` (and `cc`) would ultimately
pass to `ld` when
# directly building an executable via the `rustc hello.rs` command. You can
see what flags
# `rustc` passes to `cc` with the `rustc -Z print-link-args hello.rs`
command.
# NOTE(2) You will have to update the library search paths and paths to
startup objects
ld.lld \
--build-id \
--eh-frame-hdr \
--hash-style=gnu \
-m \
elf_x86_64 \
-dynamic-linker \
/lib64/ld-linux-x86-64.so.2 \
-pie \
-o \
hello \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/Scrt1.o \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crti.o \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/crtbeginS.o \
-L$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib \
-L$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib \
-L/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1 \
-L/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib \
-L/lib/../lib \
-L/usr/lib/../lib \
-L/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../.. \
--as-needed \
-z \
noexecstack \
hello.o \
--gc-sections \
-Bstatic \
-Bdynamic \
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-411f48d3.rlib \
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-411f48d3.rlib \
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-411f48d3.rlib
\
-ldl \
-lpthread \
-lgcc_s \
-lpthread \
-lc \
-lm \
-lrt \
-lutil \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/crtendS.o \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crtn.o \
--reproduce pie
# segfaults
./hello
# NOTE some link command as above but without the -pie flag
ld.lld \
--build-id \
--eh-frame-hdr \
--hash-style=gnu \
-m \
elf_x86_64 \
-dynamic-linker \
/lib64/ld-linux-x86-64.so.2 \
-o \
hello \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/Scrt1.o \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crti.o \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/crtbeginS.o \
-L$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib \
-L$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib \
-L/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1 \
-L/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib \
-L/lib/../lib \
-L/usr/lib/../lib \
-L/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../.. \
--as-needed \
-z \
noexecstack \
hello.o \
--gc-sections \
-Bstatic \
-Bdynamic \
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-411f48d3.rlib \
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-411f48d3.rlib \
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-411f48d3.rlib
\
$sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-411f48d3.rlib
\
-ldl \
-lpthread \
-lgcc_s \
-lpthread \
-lc \
-lm \
-lrt \
-lutil \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/crtendS.o \
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crtn.o
# OK
./hello
uninstall_rust
}
install_rust() {
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain
nightly-2016-09-15 --no-modify-path -y
source ~/.cargo/env
}
uninstall_rust() {
rustup self uninstall
}
main
```
### Meta
```
$ ld.lld --version
LLD 4.0 (git://github.com/llvm-mirror/lld.git
a499b2da2436789a9136f046f193caad0801ed93)
```
```
$ rustc -Vv
rustc 1.13.0-nightly (6ffdda1ba 2016-09-14)
binary: rustc
commit-hash: 6ffdda1ba183c981d57e63b59c88184be449eee4
commit-date: 2016-09-14
host: x86_64-unknown-linux-gnu
release: 1.13.0-nightly
```
--
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/20160917/986a59ff/attachment.html>
More information about the llvm-bugs
mailing list