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

setup-hooks/strip: resolve/uniq symlinks before stripping #246164

Merged
merged 1 commit into from
Jul 31, 2023

Conversation

trofi
Copy link
Contributor

@trofi trofi commented Jul 30, 2023

Before the change the hook had a chance to run strip against the same file using multiple link paths. In case of gcc libgcc.a was stripped multiple times in parallel and produces corrupted archive.

The change runs inputs via realpath | uniq to make sure we don't attempt to strip the same files multiple times.

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • 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/)
  • 23.11 Release Notes (or backporting 23.05 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.

Before the change the hook had a chance to run `strip` against the same
file using multiple link paths. In case of `gcc` `libgcc.a` was stripped
multiple times in parallel and produces corrupted archive.

The change runs inputs via `realpath | uniq` to make sure we don't
attempt to strip the same files multiple times.
@trofi trofi force-pushed the strip-no-symlinks branch from e035aed to 7adf0a4 Compare July 30, 2023 15:28
vcunat added a commit that referenced this pull request Jul 30, 2023
Adapted from PR #246164
TODO: clean up / use it everywhere on the next rebuild.
@lheckemann
Copy link
Member

Good shout!

This makes me wonder though if we should also filter to avoid even trying to strip files outside the outputs of the current derivation -- currently, if we have a symlink pointing to another store path, stripping it will be attempted but of course fail because it's read-only.

@trofi
Copy link
Contributor Author

trofi commented Jul 31, 2023

I sounds reasonable to fix those cases as well. I'm a bit worried to add bigger changes to this specific PR.

@lheckemann lheckemann merged commit a3d2e71 into NixOS:staging Jul 31, 2023
@trofi trofi deleted the strip-no-symlinks branch July 31, 2023 20:37
@ghost
Copy link

ghost commented Jul 31, 2023

In case of gcc libgcc.a was stripped multiple times in parallel and produces corrupted archive.

Wow, nice find.

tpwrules added a commit to tpwrules/nixpkgs that referenced this pull request May 24, 2024
NixOS#246164 but for hardlinks.

Mesa, among other packages, has binaries that are linked together and
can end up corrupted when the same binary is stripped through two
different names.

To resolve this, print out the device and inode number before each file
name, sort/uniq based on that, then cut it back out before stripping.

The symlink resolution logic is removed as the same file accessed
through two different links in `$paths` will necessarily have the same
numbers. File/directory within the paths listed in `$paths` are
correctly not (and were never) processed due to the `-type f` predicate
and (implied) `-P` option to `find`.
github-actions bot pushed a commit that referenced this pull request May 25, 2024
#246164 but for hardlinks.

Mesa, among other packages, has binaries that are linked together and
can end up corrupted when the same binary is stripped through two
different names.

To resolve this, print out the device and inode number before each file
name, sort/uniq based on that, then cut it back out before stripping.

The symlink resolution logic is removed as the same file accessed
through two different links in `$paths` will necessarily have the same
numbers. File/directory within the paths listed in `$paths` are
correctly not (and were never) processed due to the `-type f` predicate
and (implied) `-P` option to `find`.

(cherry picked from commit 4d6d293)
winterqt pushed a commit that referenced this pull request May 26, 2024
#246164 but for hardlinks.

Mesa, among other packages, has binaries that are linked together and
can end up corrupted when the same binary is stripped through two
different names.

To resolve this, print out the device and inode number before each file
name, sort/uniq based on that, then cut it back out before stripping.

The symlink resolution logic is removed as the same file accessed
through two different links in `$paths` will necessarily have the same
numbers. File/directory within the paths listed in `$paths` are
correctly not (and were never) processed due to the `-type f` predicate
and (implied) `-P` option to `find`.

(cherry picked from commit 4d6d293)
github-actions bot pushed a commit that referenced this pull request May 26, 2024
#246164 but for hardlinks.

Mesa, among other packages, has binaries that are linked together and
can end up corrupted when the same binary is stripped through two
different names.

To resolve this, print out the device and inode number before each file
name, sort/uniq based on that, then cut it back out before stripping.

The symlink resolution logic is removed as the same file accessed
through two different links in `$paths` will necessarily have the same
numbers. File/directory within the paths listed in `$paths` are
correctly not (and were never) processed due to the `-type f` predicate
and (implied) `-P` option to `find`.

(cherry picked from commit 4d6d293)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants