taiki-e / cargo-llvm-cov

Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Apache License 2.0
933 stars 57 forks source link

Segmentation fault with test binaries on alpine with musl #225

Closed seanpianka closed 1 year ago

seanpianka commented 1 year ago

Rust Version

$ rustup show
Default host: x86_64-unknown-linux-musl
rustup home:  /usr/local/rustup

installed toolchains
--------------------

nightly-2022-10-21-x86_64-unknown-linux-musl
1.65.0-x86_64-unknown-linux-musl (default)

active toolchain
----------------

1.65.0-x86_64-unknown-linux-musl (default)
rustc 1.65.0 (897e37553 2022-11-02)

Cargo Config

# ~/.cargo/config
[build]
rustflags = "-Clink-arg=-fuse-ld=lld"

alpine 3.16 with musl

$ uname -a 
Linux runner-cmfehkvb-project-15630598-concurrent-0 6.0.6-76060006-generic #202210290932~1667401208~22.04~d2df702 SMP PREEMPT_DYNAMIC Wed N x86_64 Linux

Command

This is the top-level command I run, however it's one of the llvm-cov binaries that later segfaults.

Top level command:

$ cargo llvm-cov nextest --workspace --lcov --output-path target/debug/coverage/lcov.info --features=runtime-blocking-rustls

Binary that segfaults:

$ /builds/api/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360 --list --format terse

I unfortunately cannot provide the source.

Error/Behavior

$ cargo llvm-cov nextest --workspace --lcov --output-path target/debug/coverage/lcov.info --features=runtime-blocking-rustls
...
warning: `infra-green-button` (lib test) generated 194 warnings (171 duplicates)
    Finished test [optimized] target(s) in 11m 01s
error: creating test list failed

Caused by:
  for `infra-green-button`, command `/builds/api/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360 --list --format terse` exited with signal 11 (SIGSEGV)
--- stdout:

--- stderr:

---
error: process didn't exit successfully: `/usr/local/rustup/toolchains/1.65.0-x86_64-unknown-linux-musl/bin/cargo nextest run --manifest-path /builds/api/Cargo.toml --target-dir /builds/api/target/llvm-cov-target --workspace --features=runtime-blocking-rustls` (exit status: 104)

Here's the output from valgrind when I use it on the infra_green_button-2471626eedf10360 that's seg-faulting:

bash-5.1# valgrind /builds/api/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360
==30151== Memcheck, a memory error detector
==30151== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==30151== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==30151== Command: /builds/api/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360
==30151==
==30151== Jump to the invalid address stated on the next line
==30151==    at 0xE1266: ???
==30151==    by 0x5DF623: __covrec_AC41AEED5040894C (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5D98B8: __covrec_D658E9DE4143F5F8u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5BA10D: __covrec_A868EA66A9F96486u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5BA13F: curl_global_init (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5B8290: __covrec_36F2855FBF4B63E8u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x2043CC: __covrec_839BF2CC11464914u (once.rs:434)
==30151==    by 0x2057E7: ??? (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x964E52: libc_start_init (__libc_start_main.c:64)
==30151==    by 0x964E77: libc_start_main_stage2 (__libc_start_main.c:91)
==30151==    by 0x205CAA: __covrec_280000978008D625u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==  Address 0xe1266 is not stack'd, malloc'd or (recently) free'd
==30151==
==30151==
==30151== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==30151==  Bad permissions for mapped region at address 0xE1266
==30151==    at 0xE1266: ???
==30151==    by 0x5DF623: __covrec_AC41AEED5040894C (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5D98B8: __covrec_D658E9DE4143F5F8u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5BA10D: __covrec_A868EA66A9F96486u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5BA13F: curl_global_init (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x5B8290: __covrec_36F2855FBF4B63E8u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x2043CC: __covrec_839BF2CC11464914u (once.rs:434)
==30151==    by 0x2057E7: ??? (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==    by 0x964E52: libc_start_init (__libc_start_main.c:64)
==30151==    by 0x964E77: libc_start_main_stage2 (__libc_start_main.c:91)
==30151==    by 0x205CAA: __covrec_280000978008D625u (in /cache/green-button/target/llvm-cov-target/debug/deps/infra_green_button-2471626eedf10360)
==30151==
==30151== HEAP SUMMARY:
==30151==     in use at exit: 0 bytes in 0 blocks
==30151==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==30151==
==30151== All heap blocks were freed -- no leaks are possible
==30151==
==30151== For lists of detected and suppressed errors, rerun with: -s
==30151== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)

The above command works on our main trunk, but on this branch with this new infra_green_button crate. It only seg-faults when running the above command cargo llvm-cov nextest --workspace --lcov --output-path target/debug/coverage/lcov.info --features=runtime-blocking-rustls in CI with alpine/musl, but compiles and runs fine on macOS.

seanpianka commented 1 year ago

Closed, not your bug 🙂 Dependency is pulling in native-tls when I'm using rustls/musl.