Skip to content

SIGSEGV: invalid memory reference in librustc_trans-llvm #47953

Closed
@PaulGrandperrin

Description

@PaulGrandperrin

Rust version:

rustc 1.25.0-nightly (def3269a7 2018-01-30)
binary: rustc
commit-hash: def3269a71be2e737cad27418a3dad9f5bd6cd32
commit-date: 2018-01-30
host: x86_64-unknown-linux-gnu
release: 1.25.0-nightly
LLVM version: 4.0

Steps to reproduce:

cd /tmp
git clone https://github.com/rust-fuzz/cargo-fuzz.git
cd cargo-fuzz
cargo install
cd testcrate
cargo-fuzz init
sed -i'' -e 's/\/\/.*/testcrate\:\:test_func\(data\)\;/g' fuzz/fuzz_targets/fuzz_target_1.rs
cargo-fuzz run fuzz_target_1 -- -runs=1000 # no bugs
# now, we just add "-O" which will be transformed into "-C opt-level=3" and it makes the compiler segfault
cargo-fuzz run fuzz_target_1 -O -- -runs=1000

The log of the last command leading to the crash:

   Compiling arbitrary v0.1.0
   Compiling testcrate v0.1.0 (file:///tmp/cargo-fuzz/testcrate)
   Compiling cc v1.0.4
     Running `rustc --crate-name arbitrary /home/paulg/.cargo/registry/src/github.com-1ecc6299db9ec823/arbitrary-0.1.0/src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=ec259e09376489d8 -C extra-filename=-ec259e09376489d8 --out-dir /tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/release/deps --cap-lints allow --cfg fuzzing -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=3 -Zsanitizer=address -Cpanic=abort`
     Running `rustc --crate-name testcrate /tmp/cargo-fuzz/testcrate/src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=2716f80b1364d7ff -C extra-filename=-2716f80b1364d7ff --out-dir /tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/release/deps --cfg fuzzing -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=3 -Zsanitizer=address -Cpanic=abort`
     Running `rustc --crate-name cc /home/paulg/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.4/src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=c8e56a194d56e32d -C extra-filename=-c8e56a194d56e32d --out-dir /tmp/cargo-fuzz/testcrate/fuzz/target/release/deps -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/release/deps --cap-lints allow`
error: Could not compile `testcrate`.

Caused by:
  process didn't exit successfully: `rustc --crate-name testcrate /tmp/cargo-fuzz/testcrate/src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=2716f80b1364d7ff -C extra-filename=-2716f80b1364d7ff --out-dir /tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/release/deps --cfg fuzzing -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=3 -Zsanitizer=address -Cpanic=abort` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
error: Could not compile `arbitrary`.

Caused by:
  process didn't exit successfully: `rustc --crate-name arbitrary /home/paulg/.cargo/registry/src/github.com-1ecc6299db9ec823/arbitrary-0.1.0/src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=ec259e09376489d8 -C extra-filename=-ec259e09376489d8 --out-dir /tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/release/deps --cap-lints allow --cfg fuzzing -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=3 -Zsanitizer=address -Cpanic=abort` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
error: build failed
error: could not build fuzz script: "cargo" "build" "--manifest-path" "/tmp/cargo-fuzz/testcrate/fuzz/Cargo.toml" "--verbose" "--bin" "fuzz_target_1" "--target" "x86_64-unknown-linux-gnu" "--release"⏎

The backtrace of one the subcommands leading to a segfault:

(gdb) r --crate-name testcrate /tmp/cargo-fuzz/testcrate/src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=2716f80b1364d7ff -C extra-filename=-2716f80b1364d7ff --out-dir /tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/release/deps --cfg fuzzing -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=3 -Zsanitizer=address -Cpanic=abort
Starting program: /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/bin/rustc --crate-name testcrate /tmp/cargo-fuzz/testcrate/src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=2716f80b1364d7ff -C extra-filename=-2716f80b1364d7ff --out-dir /tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/tmp/cargo-fuzz/testcrate/fuzz/target/release/deps --cfg fuzzing -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=3 -Zsanitizer=address -Cpanic=abort
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff03ff700 (LWP 15244)]
[New Thread 0x7fffe71ff700 (LWP 15245)]
[New Thread 0x7fffe6ffe700 (LWP 15246)]
[New Thread 0x7fffe67ff700 (LWP 15247)]
[Thread 0x7fffe67ff700 (LWP 15247) exited]
[New Thread 0x7fffe67ff700 (LWP 15248)]
[New Thread 0x7fffe61ff700 (LWP 15249)]
[New Thread 0x7fffe5bff700 (LWP 15250)]
[Thread 0x7fffe5bff700 (LWP 15250) exited]
[Thread 0x7fffe61ff700 (LWP 15249) exited]
[Thread 0x7fffe67ff700 (LWP 15248) exited]
[New Thread 0x7fffe67ff700 (LWP 15251)]
[New Thread 0x7fffe61ff700 (LWP 15252)]
[New Thread 0x7fffe5bff700 (LWP 15253)]
[Thread 0x7fffe5bff700 (LWP 15253) exited]

Thread 10 "rustc" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe61ff700 (LWP 15252)]
0x00007fffed7d0ca8 in llvm::FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(llvm::GlobalValue const*) ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
(gdb) bt
#0  0x00007fffed7d0ca8 in llvm::FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(llvm::GlobalValue const*) ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#1  0x00007fffed7d0d95 in llvm::FunctionImportGlobalProcessing::processGlobalForThinLTO(llvm::GlobalValue&) ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#2  0x00007fffed7d0ee3 in llvm::FunctionImportGlobalProcessing::processGlobalsForThinLTO() ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#3  0x00007fffed7d0f69 in llvm::FunctionImportGlobalProcessing::run() ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#4  0x00007fffed7d0fc5 in llvm::renameModuleForThinLTO(llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::DenseSet<llvm::GlobalValue const*, llvm::DenseMapInfo<llvm::GlobalValue const*> >*) ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#5  0x00007fffec6b06e4 in LLVMRustPrepareThinLTORename ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#6  0x00007fffec59d81a in rustc_trans::back::lto::LtoModuleTranslation::optimize::h46113886aa1450f7 ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#7  0x00007fffec5c39ad in rustc_trans::back::write::execute_work_item::h09a8ebc4759a9634 ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#8  0x00007fffec64cecb in std::sys_common::backtrace::__rust_begin_short_backtrace::h62d6fad4039b8b81 ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#9  0x00007fffec5d9d36 in std::panicking::try::do_call::hd60f009b46a55adc ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#10 0x00007ffff76a40af in __rust_maybe_catch_panic () at libpanic_unwind/lib.rs:102
#11 0x00007fffec68e56b in _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::h3e81a62f6b1fa3a2 ()
   from /home/paulg/.rustup/toolchains/nightly-2018-02-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_trans-llvm.so
#12 0x00007ffff7693478 in _$LT$alloc..boxed..Box$LT$alloc..boxed..FnBox$LT$A$C$$u20$Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h6a4c702f42d64d79 ()
    at /checkout/src/liballoc/boxed.rs:798
#13 std::sys_common::thread::start_thread::hb176f2ed2201bf7e () at libstd/sys_common/thread.rs:24
#14 0x00007ffff7661ee9 in std::sys::unix::thread::Thread::new::thread_start::hc30d7b5fed49aff0 () at libstd/sys/unix/thread.rs:90
#15 0x00007ffff1b4751a in start_thread (arg=0x7fffe61ff700) at pthread_create.c:465
#16 0x00007ffff734d3ef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

If needed I can build rustc and llvm with the debug symbols to get a better backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions