Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang docs: remove "-s" and "-w" from the ldflags example #274503

Merged
merged 1 commit into from
Dec 22, 2023

Conversation

lopter
Copy link
Contributor

@lopter lopter commented Dec 15, 2023

The go linker -s and -w flags respectively are for:

  • Omit the symbol table and debug information.
  • Omit the DWARF symbol table.

Those actions should be delegated to the fixup build phase instead.

See: https://discourse.nixos.org/t/why-do-so-many-go-packages-use-s-w-in-their-ldflags-it-breaks-dontfixup-dontstrip/36843

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

The go linker `-s` and `-w` flags respectively are for:

- Omit the symbol table and debug information.
- Omit the DWARF symbol table.

Those actions should be delegated to the fixup build phase instead.

See: https://discourse.nixos.org/t/why-do-so-many-go-packages-use-s-w-in-their-ldflags-it-breaks-dontfixup-dontstrip/36843
@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 6.topic: golang labels Dec 15, 2023
@lopter lopter changed the title Remove "-s" and "-w" from the ldflags example Golang docs: remove "-s" and "-w" from the ldflags example Dec 15, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/why-do-so-many-go-packages-use-s-w-in-their-ldflags-it-breaks-dontfixup-dontstrip/36843/6

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Dec 15, 2023
@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Dec 15, 2023
@kalbasit kalbasit merged commit 1bf9271 into NixOS:master Dec 22, 2023
22 checks passed
Copy link
Contributor

Successfully created backport PR for release-23.11:

@zowoq
Copy link
Contributor

zowoq commented Dec 22, 2023

Did anyone bother checking the size difference on darwin?

IIRC the fixup strip wasn't consistent across darwin/linux so binaries on darwin had extra bloat unless we used the golang strip.

@kalbasit
Copy link
Member

kalbasit commented Dec 22, 2023

Did anyone bother checking the size difference on darwin?

IIRC the fixup strip wasn't consistent across darwin/linux so binaries on darwin had extra bloat unless we used the golang strip.

If it's needed then I feel that it should belong within buildGoModule as opposed to being specified per-package and in the documentation.

@zowoq
Copy link
Contributor

zowoq commented Dec 22, 2023

If it's needed then I feel that it should belong within buildGoModule as opposed to being specified per-package and in the documentation.

I don't disagree but the last time that I looked at this I found it wasn't quite as simple as I'd had hoped it would be: #177698.

I don't really care if these flags are included in the docs or not but at the moment I'm against removing these flags from packages and trying to enforce not adding them. I think it is likely that people will care more about binary size then they will about dontfixup/dontstrip not working.

@lopter lopter deleted the patch-1 branch December 29, 2023 19:53
@lopter
Copy link
Contributor Author

lopter commented Dec 29, 2023

If it's needed then I feel that it should belong within buildGoModule as opposed to being specified per-package and in the documentation.

I don't disagree but the last time that I looked at this I found it wasn't quite as simple as I'd had hoped it would be: #177698.

I don't really care if these flags are included in the docs or not but at the moment I'm against removing these flags from packages and trying to enforce not adding them. I think it is likely that people will care more about binary size then they will about dontfixup/dontstrip not working.

Thank you for the follow-up and the merge. It ended up being pretty difficult for me to understand why delve wouldn't work even with dontFixup/dontStrip being true.

Just to make sure I understand:

  1. The strip tools from cctools used in Darwin's stdenv is what is holding us back from a generic approach, where stripping is done in stdenv?
  2. Moreover, the alternative of handling "-s" and "-w" in buildGoModule (to add them to ldflags based on dontFixup/dontStrip) breaks some packages?

@LeSuisse LeSuisse mentioned this pull request Jun 8, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: golang 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants