Skip to content

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

Merged
kalbasit merged 1 commit into
NixOS:masterfrom
lopter:patch-1
Dec 22, 2023
Merged

kalbasit merged 1 commit into
NixOS:masterfrom
lopter:patch-1

Conversation

@lopter

@lopter lopter commented Dec 15, 2023

Copy link
Copy Markdown
Contributor

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 Go is a high-level general purpose programming language that is statically typed and compiled. 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
Copy Markdown

@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 person. label Dec 15, 2023
@kalbasit
kalbasit merged commit 1bf9271 into NixOS:master Dec 22, 2023
@github-actions

Copy link
Copy Markdown
Contributor

Successfully created backport PR for release-23.11:

@zowoq

zowoq commented Dec 22, 2023

Copy link
Copy Markdown
Contributor

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

kalbasit commented Dec 22, 2023 •

Copy link
Copy Markdown
Member

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

zowoq commented Dec 22, 2023

Copy link
Copy Markdown
Contributor

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

lopter commented Dec 29, 2023

Copy link
Copy Markdown
Contributor Author

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
2 of 13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 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 person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants