Description
(allowing specifying code models was added to rustc in #15698)
I want to build a large code model binary. But (correct me if I'm wrong) I believe this requires all code to be generated with a large code model (otherwise we could end up with rip relative addressing in the stdlib, which defeats the point).
So I tried the obvious (controlling it with RUSTFLAGS
) and got the following build log:
/rust# ./configure && RUSTFLAGS="-C code-model=large" VERBOSE=1 make
[...]
CFG_LLVM_LINKAGE_FILE=/rust/x86_64-unknown-linux-gnu/rt/llvmdeps.rs LD_LIBRARY_PATH=/rust/x86_64-unknown-linux-gnu/stage0/lib:/rust/x86_64-unknown-linux-gnu/llvm/lib:$LD$
LIBRARY_PATH x86_64-unknown-linux-gnu/stage0/bin/rustc --cfg stage0 -C code-model=large -O --cfg rtopt -C rpath -C prefer-dynamic -C no-stack-check --target=x86_64-unk$
own-linux-gnu -L "x86_64-unknown-linux-gnu/rt" -L native="/rust/x86_64-unknown-linux-gnu/llvm/lib" --out-dir x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unk$
own-linux-gnu/lib -C extra-filename=-3d98e1dd -C metadata=3d98e1dd src/librustc_save_analysis/lib.rs
info: now are following matches for librustc_save_analysis-*.so libraries:
x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_save_analysis-3d98e1dd.so
info: now are following matches for librustc_save_analysis-*.rlib libraries:
x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_save_analysis-3d98e1dd.rlib
MATCHES=""; if [ -n "$MATCHES" ] ; then echo "warning: removing previous" \'librustc_driver-*.so\' "libraries:" $MATCHES; rm $MATCHES ; fi
MATCHES=""; if [ -n "$MATCHES" ] ; then echo "warning: removing previous" \'librustc_driver-*.rlib\' "libraries:" $MATCHES; rm $MATCHES ; fi
CFG_LLVM_LINKAGE_FILE=/rust/x86_64-unknown-linux-gnu/rt/llvmdeps.rs LD_LIBRARY_PATH=/rust/x86_64-unknown-linux-gnu/stage0/lib:/rust/x86_64-unknown-linux-gnu/llvm/lib:$LD$
LIBRARY_PATH x86_64-unknown-linux-gnu/stage0/bin/rustc --cfg stage0 -C code-model=large -O --cfg rtopt -C rpath -C prefer-dynamic -C no-stack-check --target=x86_64-unk$
own-linux-gnu -L "x86_64-unknown-linux-gnu/rt" -L native="/rust/x86_64-unknown-linux-gnu/llvm/lib" --out-dir x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unk$
own-linux-gnu/lib -C extra-filename=-3d98e1dd -C metadata=3d98e1dd src/librustc_driver/lib.rs
info: now are following matches for librustc_driver-*.so libraries:
x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_driver-3d98e1dd.so
info: now are following matches for librustc_driver-*.rlib libraries:
x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_driver-3d98e1dd.rlib
mkdir -p x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/bin/
LD_LIBRARY_PATH=/rust/x86_64-unknown-linux-gnu/stage0/lib:/rust/x86_64-unknown-linux-gnu/llvm/lib:$LD_LIBRARY_PATH x86_64-unknown-linux-gnu/stage0/bin/rustc --cfg stag$
0 -C code-model=large -O --cfg rtopt -C rpath -C prefer-dynamic -C no-stack-check --target=x86_64-unknown-linux-gnu -L native="/rust/x86_64-unknown-linux-gnu/llvm/lib" $
o x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/bin/rustc /rust/src/driver/driver.rs --cfg rustc
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.core
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.libc
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.rand
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.alloc
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.collections
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.compiler_builtins
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.rustc_unicode
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.alloc_system
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.panic_abort
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.panic_unwind
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.unwind
touch x86_64-unknown-linux-gnu/stage1/lib/stamp.alloc_jemalloc
[...]
cp x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/stamp.rustc_save_analysis x86_64-unknown-linux-gnu/stage1/lib/stamp.rustc_save_analysis
cp -R x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_save_analysis-*.so x86_64-unknown-linux-gnu/stage1/lib
info: now are following matches for librustc_save_analysis-*.so libraries:
x86_64-unknown-linux-gnu/stage1/lib/librustc_save_analysis-3d98e1dd.so
MATCHES=""; if [ -n "$MATCHES" ] ; then echo "warning: removing previous" \'librustc_driver-*.so\' "libraries:" $MATCHES; rm $MATCHES ; fi
cp x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/stamp.rustc_driver x86_64-unknown-linux-gnu/stage1/lib/stamp.rustc_driver
cp -R x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_driver-*.so x86_64-unknown-linux-gnu/stage1/lib
info: now are following matches for librustc_driver-*.so libraries:
x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-3d98e1dd.so
cp x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/bin/rustc x86_64-unknown-linux-gnu/stage1/bin/rustc
touch tmp/install-debugger-scripts1_H_x86_64-unknown-linux-gnu-all.done.start_time
mkdir -p x86_64-unknown-linux-gnu/stage1/bin
mkdir -p x86_64-unknown-linux-gnu/stage1/lib/rustlib/etc
install /rust/src/etc/rust-gdb /rust/src/etc/rust-lldb x86_64-unknown-linux-gnu/stage1/bin
install /rust/src/etc/gdb_load_rust_pretty_printers.py /rust/src/etc/gdb_rust_pretty_printing.py /rust/src/etc/lldb_rust_formatters.py /rust/src/etc/debugger_pretty_p
rinters_common.py x86_64-unknown-linux-gnu/stage1/lib/rustlib/etc
touch -r tmp/install-debugger-scripts1_H_x86_64-unknown-linux-gnu-all.done.start_time tmp/install-debugger-scripts1_H_x86_64-unknown-linux-gnu-all.done && rm tmp/install-
debugger-scripts1_H_x86_64-unknown-linux-gnu-all.done.start_time
mkdir -p x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/
MATCHES=""; if [ -n "$MATCHES" ] ; then echo "warning: removing previous" \'libcore-*.so\' "libraries:" $MATCHES; rm $MATCHES ; fi
MATCHES=""; if [ -n "$MATCHES" ] ; then echo "warning: removing previous" \'libcore-*.rlib\' "libraries:" $MATCHES; rm $MATCHES ; fi
CFG_LLVM_LINKAGE_FILE=/rust/x86_64-unknown-linux-gnu/rt/llvmdeps.rs LD_LIBRARY_PATH=/rust/x86_64-unknown-linux-gnu/stage1/lib:/rust/x86_64-unknown-linux-gnu/llvm/lib:$LD_
LIBRARY_PATH x86_64-unknown-linux-gnu/stage1/bin/rustc --cfg stage1 -C code-model=large -O --cfg rtopt -C rpath -C prefer-dynamic --target=x86_64-unknown-linux-gnu -L
"x86_64-unknown-linux-gnu/rt" -L native="/rust/x86_64-unknown-linux-gnu/llvm/lib" --out-dir x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib
-C extra-filename=-3d98e1dd -C metadata=3d98e1dd src/libcore/lib.rs
Segmentation fault (core dumped)
/rust/mk/target.mk:191: recipe for target 'x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/stamp.core' failed
make: *** [x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/stamp.core] Error 139
Brief explanation of the three parts:
- the command is run
- the tail end of the stage1 stdlib and rustc itself being built by stage0
- the tail end of the stage1 stdlib and rustc itself being copied out of the stage0 build directory and into the stage1 directory, then the new stage1 rustc attempting to build the first part of the stage2 stdlib (libcore)...and segfaulting
In fact, this stage1 rustc segfaults when not doing much:
/rust# x86_64-unknown-linux-gnu/stage1/bin/rustc --version
rustc 1.14.0-dev (f26eedb57 2016-10-31)
Segmentation fault (core dumped)
Reducing the command line used to build rustc:
/rust# echo 'fn main() {}' > mini.rs
/rust# x86_64-unknown-linux-gnu/stage0/bin/rustc -C code-model=large --target=x86_64-unknown-linux-gnu mini.rs
/rust# ./mini
Segmentation fault (core dumped)
/rust# x86_64-unknown-linux-gnu/stage0/bin/rustc --target=x86_64-unknown-linux-gnu mini.rs
/rust# ./mini
Segmentation fault (core dumped)
GDB gives the backtrace as
#0 0x000055555555f1e0 in std::thread::local::elf::destroy_value::h1727d3182d3ee514 ()
#1 0x00007ffff74115ff in __GI___call_tls_dtors () at cxa_thread_atexit_impl.c:155
#2 0x00007ffff7410f27 in __run_exit_handlers (status=0, listp=0x7ffff779a5f8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true) at exit.c:40
#3 0x00007ffff7411045 in __GI_exit (status=<optimized out>) at exit.c:104
#4 0x00007ffff73f7837 in __libc_start_main (main=0x55555555dac0 <main>, argc=1, argv=0x7fffffffe7a8, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffe798) at ../csu/libc-start.c:325
#5 0x000055555555d9a9 in _start ()
I've dumped a bunch of info in the hope that someone might be able to lend a hand, but I can find little discussion of this feature (code models) so they may not be well-tested? I plan to investigate myself, but wanted a) to see if anyone has any pointers and b) make this a searchable issue.
As a datapoint, note that redox uses a .json target specification and builds its own stdlib manually with kernel model, which obviously works fine. Altering the configure+make command I used to use the kernel model rather than large also worked fine. So it looks like the issue is with memory model large.