Open katexochen opened 1 month ago
I looked at this a while ago: https://github.com/NixOS/nixpkgs/issues/177698
- Add
-s
to theldflags
inside of buildGoModule- Don't add
-s
to theldflags
in casedontStrip
is set- Throw a warning in case
-s
is set in ldflags
Agree.
We can discuss whether we want to always set
dontStrip
on the underlying derivation (maybe to fasten up build time) or if we keep it active to prevent confusion and for mixed language derivations (I'd opt for keeping it for now).
Agree with keeping it for now.
I looked at this a while ago: https://github.com/NixOS/nixpkgs/issues/177698
Ah, I remember that I read that thread a while ago but had forgotten it when opening this issue. Let me catch up with this again, and maybe we should also continue discussion in that thread.
I've updated the issue description with the additional pointers to the previous work. For me, there are two points from the previous discussion we should note:
-s=0
to the ldflags. We must ensure to add the default ldflags first.
Current situation
ldflags = [ "-s" "-w" ];
ldflags = [ "-s" "-w" ];
for Go packagesdontStrip = true;
dontStrip = true;
and get the expected debug symbols, which isn't currently working for many packages that set-s -w
on a package level (see https://github.com/NixOS/nixpkgs/pull/277609)History
About
-w
From the Go v1.22 release notes:
Setting
-w
in combination with-s
has no effect.Suggested action items:
-w
flag-w
in nixpkgsAbout
-s
Go's native stripping works far better than the stripping done by stdenv (see table below for comparison), binaries are smaller and recognized by
file
as stripped.In my opinion, we should use Go's native stripping mechanism by default in
buildGoModule
. This would mean that we:-s
to theldflags
inside of buildGoModule-s
to theldflags
in casedontStrip
is set-s
is set in ldflagsWe can discuss whether we want to always set
dontStrip
on the underlying derivation (maybe to fasten up build time) or if we keep it active to prevent confusion and for mixed language derivations (I'd opt for keeping it for now).Suggested action items:
-s
flagbuildGoModule
to strip with-s
flag by default, to drop-s
whendontStrip = true
, throw warning if flag is parsed from outside-s
in nixpkgsExample: stripping statistics for uplosi on x86_64-linux
Created with https://github.com/katexochen/nixpkgs/commit/169e31b0baad86c8f9bbd820a7919ffe80c68145, which can be used to check results for other packages.