Globally disable stripping of debug symbols

How would I go about preventing the stripping of debug symbols for all packages? It looks like strip.sh gets bundled into stdenv. I guess checking out nixpkgs and just commenting that out would work in principle? I wonder if there’s a clever way to set it as override.

I tried a few ways of changing the defaultNativeBuildInputs of stdenv but tended to get infinite recursion or other weird errors.

You can do this with an overlay, like this:

self: super:
{
  stdenv = super.keepDebugInfo super.stdenv;
}

Build it like:

$ nix build --arg overlays '[ (self: super: { stdenv = super.keepDebugInfo super.stdenv; } )]' nixpkgs.hello

Unfortunately this is a mass rebuild, because everything in the stdenv needs to be rebuilt with debug symbols as well. You can also use “crossOverlays” to just get debug symbols for the last stage:

$ nix build --arg crossOverlays '[ (self: super: { stdenv = super.keepDebugInfo super.stdenv; } )]' nixpkgs.hello
$ file result/bin/hello
result/bin/hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/avr2x43njlq4kyb1a9zgrh6fih5fq4si-glibc-2.27/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, with debug_info, not stripped
1 Like

Many thanks! I will leave that churning for a few days :slight_smile:

Impressively, not stripping causes a build to fail with a (spurious, I think) uninitialised variable error:

In file included from regex.c:67:0:
regexec.c: In function 'check_node_accept_bytes':
regexec.c:3802:29: error: 'extra' may be used uninitialized in this function [-Werror=maybe-uninitialized]
        const unsigned char *coll_sym = extra + cset->coll_syms[i];

Looking at the code it seems fine (extra must be set or the loop would not have been entered).

It’s strange that disabling the stripping made the compiler change its mind…

Try forcing a rebuild of this with debug symbol stripping? If you’re getting it as a substitute, maybe the build in general just fails on your machine for some reason. I think you can do this with nix-build '<nixpkgs>' -A hello --check

Slightly confused, or might not have explained myself. The above is in glibc, being built (as intended) without stripping. I got the above with

nix-build -E 'import <nixpkgs> {overlays = [(self: super: { stdenv = super.keepDebugInfo super.stdenv; } )];}' -A glibc

but I also get the same problem running @matthewbauer’s original command (should be the same derivation for glibc).

Cool, I didn’t know about that trick with keepDebugInfo, last time I ended up trying to hack enableDebugging into working with some language infrastructure. It was not a fun time and I gave up in the end (it used a custom builder for an interpreter who’s library build process was kind of weird though…).

I think it would be nice if we had some composeable, homogeneous conventions for enabling debug info on things.

I meant try to force a local build without using keepDebugInfo to see if the error you’re seeing really is coming from that, or is just a consequence of actually building it yourself (as opposed to getting it from a substitute).

@lilyball - sorry now I understand!

  • nix-build -E '(import <nixpkgs> {}).glibc' --check: works (but with non-deterministic)
    $ nix-build -E ‘with import {}; glibc’
    /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27
  • nix-build -E 'with import <nixpkgs> {}; keepDebugInfo glibc' gives the same derivation as regular glibc!
/nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27

vs

$ nix-build -E 'with import <nixpkgs> {}; glibc'
/nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27

That aside, I tried to move past the problem by disabling the compiler warning. I ended up with another strange problem. Here’s my default.nix:

with import <nixpkgs>
{
  overlays = [
    (self: super: {
      stdenv = super.keepDebugInfo super.stdenv;
      glibc = super.glibc.overrideAttrs (o: {
        preConfigure = o.preConfigure + ''
          export CFLAGS="-Wno-error=maybe-uninitialized $CFLAGS"
        '';
      });
    })
  ];
};
stdenv

This fails with:

building '/nix/store/phdndsx0drab3jm06jyp8vgjpqs88zw1-stdenv-linux.drv'...
output '/nix/store/2dlzy6qmjhqgfpisxw85826lq5lw8lj2-stdenv-linux' is not allowed to refer to the following paths:
  /nix/store/6hsapbxi93cpl7j89fv1alg44ny90yml-zlib-1.2.11-dev
  /nix/store/bc6291w9bmkrk74jx4m1axsjf4r1kyjb-pcre-8.42-dev
  /nix/store/k1k15mydvd1mk8vhjhrczlf9jrxl5i4f-acl-2.2.53-bin
  /nix/store/lan2w3ab1mvpxj3ppiw2sizh8i7rpz7s-busybox
  /nix/store/lhf18az81s6ahsvc9wagxg2l6xqzlky1-gmp-6.1.2
  /nix/store/n9acaakxahkv1q3av11l93p7rgd4xqsf-bootstrap-tools
  /nix/store/nsik7zy48r50q1sfvvx77lq764f8z6fa-pcre-8.42-bin
  /nix/store/rprgmprkwn094z5m7aggqikm9ajdigd6-attr-2.4.48-bin
  /nix/store/siddhzdzfl9z5dzch8zm4mfqfs7f7sll-gmp-6.1.2-dev
  /nix/store/wsvlbwxk1plak9x2sbhzi433s62nkb14-acl-2.2.53-dev
  /nix/store/wvycsl2d6fx0n0aha3gpzlywxgz30mqz-attr-2.4.48-dev
error: build of '/nix/store/phdndsx0drab3jm06jyp8vgjpqs88zw1-stdenv-linux.drv' failed

Added an issue https://github.com/NixOS/nixpkgs/issues/64980

Little bit of an update: the uninitialized error is because keepDebugInfo actually modifies some CFLAGS as well as setting dontStrip=true. If I instead use

      stdenv = super.stdenv // {
        mkDerivation = args: super.stdenv.mkDerivation (args // { dontStrip = true; });
      };

then glibc compiles cleanly, but I still get the “is not allowed to” error above.