rust-lang / rust-lang/rust

rustc SIGSEGVs when running proc-macro on musl host with link-self-contained=yes

Open
#149,371 21 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkage C-bug O-musl T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

The following Dockerfile fails to build, with rustc experiencing a SIGSEGV.

FROM rust:1.91.1-alpine
 
WORKDIR /mre
 
ENV RUSTFLAGS="-Clink-self-contained=yes"
RUN cargo init
RUN cargo add --build rustversion
RUN echo 'fn main() { if rustversion::cfg!(nightly) {} }' > ./build.rs
RUN cargo build
> docker build -f Dockerfile .
[+] Building 10.5s (9/9) FINISHED                                                                                                                                              docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => => transferring dockerfile: 256B                                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/library/rust:1.91.1-alpine                                                                                                                    1.8s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                          0.0s
 => [1/6] FROM docker.io/library/rust:1.91.1-alpine@sha256:fbcca3e30e26f79986809d5dbfcdbeaaf8d3f8a4475b7a19a973363b45c74d97                                                              0.0s
 => => resolve docker.io/library/rust:1.91.1-alpine@sha256:fbcca3e30e26f79986809d5dbfcdbeaaf8d3f8a4475b7a19a973363b45c74d97                                                              0.0s
 => CACHED [2/6] WORKDIR /mre                                                                                                                                                            0.0s
 => CACHED [3/6] RUN cargo init                                                                                                                                                          0.0s
 => CACHED [4/6] RUN cargo add --build rustversion                                                                                                                                       0.0s
 => CACHED [5/6] RUN echo 'fn main() { if rustversion::cfg!(nightly) {} }' > ./build.rs                                                                                                  0.0s
 => ERROR [6/6] RUN cargo build                                                                                                                                                          8.5s
------                                                                                                                                                                                        
 > [6/6] RUN cargo build:                                                                                                                                                                     
2.084  Downloading crates ...                                                                                                                                                                 
3.075   Downloaded rustversion v1.0.22                                                                                                                                                        
3.256    Compiling rustversion v1.0.22                                                                                                                                                        
7.907    Compiling mre v0.1.0 (/mre)                                                                                                                                                          
8.336 error: could not compile `mre` (build script)
8.336 
8.336 Caused by:
8.336   process didn't exit successfully: `/usr/local/rustup/toolchains/1.91.1-x86_64-unknown-linux-musl/bin/rustc --crate-name build_script_build --edition=2024 build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=91288cbb7c6a86c7 -C extra-filename=-5e8e6de0e4e22d63 --out-dir /mre/target/debug/build/mre-5e8e6de0e4e22d63 -C incremental=/mre/target/debug/incremental -L dependency=/mre/target/debug/deps --extern rustversion=/mre/target/debug/deps/librustversion-07ea97a0736ef05d.so -Clink-self-contained=yes` (signal: 11, SIGSEGV: invalid memory reference)
------
Dockerfile:9
--------------------
   7 |     RUN cargo add --build rustversion
   8 |     RUN echo 'fn main() { if rustversion::cfg!(nightly) {} }' > ./build.rs
   9 | >>> RUN cargo build
  10 |     
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c cargo build" did not complete successfully: exit code: 101

Presumably, the exact issue is loading a dynamic library (the proc-macro) which has musl linked in to a process (rustc) which already has a libc.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the Dockerfile and rust:1.91.1-alpine image with RUSTFLAGS="-Clink-self-contained=yes". Start by investigating rustc's proc-macro loading path on a musl host, especially how the dynamic library is loaded into rustc. Done means the build-script proc-macro no longer causes rustc to SIGSEGV in this configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.