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

autoPatchelfHook: fix symlink handling #210908

Merged
merged 2 commits into from
Jan 15, 2023
Merged

Conversation

Yarny0
Copy link
Contributor

@Yarny0 Yarny0 commented Jan 15, 2023

Description of changes

The new autoPatchelfHook builds a list of library files/paths to speed up library discovery when patching elf files. However, under certain circumstances, this list gets faulty entries, leading to broken RPATHs.

In #172372 a workaround for tsm-client was implemented as its build process triggered the bug. In #172372 (comment) autoPatchelfHook author @layus uncovered and analysed the underlying bug, and drafted a patch to fix auto-patchelf. Please see there or in the commit message for more details on the bug and the fix.

The pull-request at hand implements that patch, and removes the workaround from tsm-client.

autoPatchelfHook does not have a maintainer. Notifying its author and CODEOWNER:

Dear @layus , I took the liberty to wrap your patch in the pull request at hand. Please have a look to verify if this is according to your intentions and could be merged.

Things done

I tested the fixed autoPatchelfHook with tsm-client and zoom-us:

  • 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.05 Release Notes (or backporting 22.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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

The auto-patchelf python script assembles a list of
library (so=shared object) file names and their paths.
This helps speed up the discovery of
library files later when patching elf files.
As further optimization, if a symlink points to a library file,
the script uses the resolved path and file name.
However, this produces a broken list entry if the
symlink's target name doesn't match the symlink's name.

A symptom of the bug, affecting the `tsm-client` package,
is fixed in NixOS#172372 .

The commit at hand stops resolving symlinks if
the target name differs from the symlink's name.
The commit has been authored by
layus (Guillaume Maudoux <layus.on@gmail.com>)
in pull request comment

NixOS#172372 (comment)
This reverts commit 1ed9ba0.

After the underlying bug in `auto-patchelf.py` got fixed,
this workaround is no longer necessary.
@Yarny0 Yarny0 requested a review from layus as a code owner January 15, 2023 12:56
Copy link
Member

@layus layus left a comment

Choose a reason for hiding this comment

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

@Yarny0 Thanks a lot for pursuing this. This fix was long overdue.

@layus layus merged commit aa7cfc3 into NixOS:staging Jan 15, 2023
@layus
Copy link
Member

layus commented Jan 15, 2023

Now, improvements would be to either

  1. take the latest (most resolved folder) that still contains the lib name.
  2. optimize for RPATH size by taking the smallest covering set of all the intermediate resolved RPATH components.
  3. even smarter thing ?

Because as-is, this change risks to defeat the the optimization, as most links will be of the form /foo/lib.so.3 and resolved to lib.so.3.0.1.so, and as the names do not match, the optimization will be disabled. So implementing 1) is less overkill than it seems. But 🤷 . At least now the code is correct. Thanks again.

@Yarny0 Yarny0 deleted the auto-patchelf branch January 20, 2023 20:51
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.

2 participants