Skip to content

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

@kayabaNerve

Description

@kayabaNerve

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-muslTarget: The musl libcT-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