Skip to content

gcc-arm-embedded: gcc and binutils report segment fault on start up #577189

Closed

Description

@f-zl

Nixpkgs version

  • Unstable (26.11)

Describe the bug

arm-none-eabi-gcc --version reports segment fault, other binutils too
Test environment is wsl2 Ubuntu 26.04 x86-64

Steps to reproduce

Use the following flake.nix, run nix develop .#broken -c arm-none-eabi-gcc --version
LLM has made a fix in the same flake.nix. It fixes the problem on my machine

Minimal reproducer

{
  description = "gcc-arm-embedded segfaults because of the patchelf call order in nixpkgs";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  outputs = { self, nixpkgs }:
    let
      lib = nixpkgs.lib;
      eachSystem = f: lib.genAttrs [ "x86_64-linux" "aarch64-linux" ]
        (system: f nixpkgs.legacyPackages.${system});

      # nixpkgs' preFixup runs `--set-interpreter` and then `--set-rpath`.
      # The interpreter pass adds a PT_LOAD for the 83-byte nix loader (the
      # binaries only reserve 28 bytes for .interp), and the rpath pass then
      # has to grow .dynstr and relocates .dynamic to 0x400c18 -- a page that
      # the following read-only PT_LOAD also covers.  ld.so patches .dynamic
      # in place at startup and write-faults there -> SIGSEGV.
      # Doing the rpath first makes patchelf re-lay out the whole file, which
      # keeps .dynamic inside a writable PT_LOAD.
      fixed = pkgs: pkgs.gcc-arm-embedded.overrideAttrs (_: {
        preFixup = lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
          find $out -type f | while read f; do
            patchelf "$f" > /dev/null 2>&1 || continue
            patchelf --set-rpath ${
              lib.makeLibraryPath [
                "$out"
                pkgs.stdenv.cc.cc
                pkgs.ncurses6
                pkgs.libxcrypt-legacy
                pkgs.xz
                pkgs.zstd
              ]
            } "$f" || true
            patchelf --set-interpreter $(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker) "$f" || true
          done
        '';
      });
    in
    {
      devShells = eachSystem (pkgs: {
        # nix develop .#broken -c arm-none-eabi-gcc --version  -> SegFault
        broken = pkgs.mkShell { packages = [ pkgs.gcc-arm-embedded ]; };

        # nix develop .#fixed -c arm-none-eabi-gcc --version   -> OK
        fixed = pkgs.mkShell { packages = [ (fixed pkgs) ]; };

        default = pkgs.mkShell { packages = [ (fixed pkgs) ]; };
      });
    };
}

Expected behaviour

arm-none-eabi-gcc and binutils work

Screenshots

No response

Relevant log output

Additional context

flake.lock is

{
  "nodes": {
    "nixpkgs": {
      "locked": {
        "lastModified": 1792502884,
        "narHash": "sha256-IoNisKcGbUjdd45qCqywGMCYmZ5EnkxezvLII0FWwNA=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "02c087f3fe673c9e317f206a627cb6b910336dbe",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}

System metadata

error, NIX_PATH is empty

Notify maintainers

@prusnak @prtzl @ryand56


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

Activity

  1. added
    0.kind: bug
    on Oct 22, 2026
  2. QiroNT commented on Oct 22, 2026

    @QiroNT

    also a NixOS/patchelf#674 issue

  3. prusnak commented on Oct 22, 2026

    @prusnak
    Member

    @f-zl fix in #577329 - can you please test if that fixes your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions