Skip to content

setup-hooks/strip: uniqify files by inode number before stripping#314175

Merged
lheckemann merged 1 commit intoNixOS:stagingfrom
tpwrules:strip-unique-inodes
May 25, 2024
Merged

setup-hooks/strip: uniqify files by inode number before stripping#314175
lheckemann merged 1 commit intoNixOS:stagingfrom
tpwrules:strip-unique-inodes

Conversation

@tpwrules
Copy link
Contributor

@tpwrules tpwrules commented May 24, 2024

Description of changes

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.

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.11 Release Notes (or backporting 23.11 and 24.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.

Add a 👍 reaction to pull requests you find important.

@alyssais
Copy link
Member

Why not just move the symlinkification to before the stripping, like @puckipedia suggested?

@tpwrules
Copy link
Contributor Author

Mesa changes are going to need to go through staging anyway, and this does fix the root cause as also suggested.

However, fixing Mesa might be easier to review. I'll investigate, we should quite possibly do both anyway.

@flokli
Copy link
Member

flokli commented May 24, 2024

The way I understand this, is that possibly other store paths might also be affected by this, not just mesa, if they use hardlinks and stripping strips in parallell from two places.

@flokli flokli requested a review from lheckemann May 24, 2024 19:41
@flokli
Copy link
Member

flokli commented May 24, 2024

cc @trofi

@tpwrules
Copy link
Contributor Author

I built all the way up to Mesa. I did some instrumenting and there are several other packages with multiple hardlinks to strippable binaries that could break like Mesa:

  • libdeflate
  • automake
  • perl
  • ncompress
  • unzip

I had store optimization disabled so these derivations are doing this themselves.

Also did figure out that this patch as it is is wrong, force push coming once I do some more revision and testing. Didn't want to ping until after it was ready but guess that's already done.

@tpwrules tpwrules force-pushed the strip-unique-inodes branch from 60e3040 to 282bc36 Compare May 24, 2024 21:38
@tpwrules tpwrules marked this pull request as ready for review May 24, 2024 21:39
@tpwrules tpwrules requested a review from Ericson2314 as a code owner May 24, 2024 21:39
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`.
@tpwrules tpwrules force-pushed the strip-unique-inodes branch from 282bc36 to 4d6d293 Compare May 24, 2024 21:53
Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this works.

@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels May 25, 2024
Copy link
Member

@lheckemann lheckemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't built anything, but the diff looks good.

@lheckemann lheckemann merged commit eb80f32 into NixOS:staging May 25, 2024
@github-actions
Copy link
Contributor

Successfully created backport PR for staging-24.05:

@winterqt
Copy link
Member

I wonder if it's worth sending this to 23.11 too, since we have at least a few more staging cycles to go in it.

@tpwrules
Copy link
Contributor Author

That would fix the issue in all stable releases which seems like a good thing. I would be happy to at least build such a patch on my machine.

@github-actions
Copy link
Contributor

Successfully created backport PR for staging-23.11:

@github-actions
Copy link
Contributor

Backport failed for staging-24.05, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin staging-24.05
git worktree add -d .worktree/backport-314175-to-staging-24.05 origin/staging-24.05
cd .worktree/backport-314175-to-staging-24.05
git switch --create backport-314175-to-staging-24.05
git cherry-pick -x 4d6d293fad1a84b953e6decb32959425fb9d2043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants