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

stdenv/linux: remove perl enableThreading=false override from stage1 #169746

Closed
wants to merge 1 commit into from
Closed

stdenv/linux: remove perl enableThreading=false override from stage1 #169746

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 22, 2022

Edit: reworked to break the dependency cycle between this and #161925.

Description of changes

This commit removes the enableThreading=false override from the stage1 perl build. The comment describing that override states that "A threaded perl build needs glibc/libpthread_nonshared.a, which is not included in bootstrapTools". This is not the reason why this workaround was needed. The reason why this workaround was needed is because nuke-refs erases the rpath from libpthread.so, and unpack-bootstrap-tools.sh neglects to undo this using patchelf.

Let's use patchelf on libpthread.so, so we aren't leaving dangling /nix/store/eeee.... refs in libpthread.so, and remove the enableThreading=false override since it is no longer necessary.

Additional Background

The enableThreading=false override not only removes the -Dusethreads from the invocation of perl's Configure script, it also patches the script like this:

# We need to do this because the bootstrap doesn't have a static libpthread
sed -i 's,\(libswanted.*\)pthread,\1,g' Configure

Although this prevents the perl interpreter from linking against libpthread.so, it does not prevent the libraries bundled with the interpreter from doing so. Time/HiRes/HiRes.so will still try to link against libpthread.so, and is only prevented from doing so by the fact that unpack-bootstrap-tools.sh neglects to patchelf out all of the nuke-refs'd rpaths. When all of the nuke-refs'd paths are patchelf'ed out, but the enableThreading=false override is left in place, HiRes.so links against libpthread.so in the bootstrap tools, and the stdenv bootstrap fails:

Can't load '/nix/store/7ny8kmppjzx6kx4xr5kphjz8fqqrlsll-perl-5.34.1/lib/perl5/5.34.1/x86_64-linux/auto/Time/HiRes/HiRes.so' for module Time::HiRes: libpthread.so.0: cannot open shared object file: No such file or directory at /nix/store/7ny8kmppjzx6kx4xr5kphjz8fqqrlsll-perl-5.34.1/lib/perl5/5.34.1/XSLoader.pm line 93.
at /nix/store/7ny8kmppjzx6kx4xr5kphjz8fqqrlsll-perl-5.34.1/lib/perl5/5.34.1/x86_64-linux/Time/HiRes.pm line 94.
Compilation failed in require at lib/Autom4te/FileUtils.pm line 42.
BEGIN failed--compilation aborted at lib/Autom4te/FileUtils.pm line 42.
Compilation failed in require at bin/autom4te line 46.
BEGIN failed--compilation aborted at bin/autom4te line 46.
make[1]: *** [Makefile:2259: tests/wrapper.in] Error 2
make[1]: *** Waiting for unfinished jobs....

To reproduce the error message above, apply the last commit (only) of #161925 (64d30ac321aa7c20a3802328635f1e133a3d85f3) and build stdenv-linux. Perl implements its own custom library loading routines for its modules, which likely do not fully implement rpath searching. This problem was revealed during the course of writing PR #161925, which depends on this PR in order to pass CI.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • mips64el-linux
    • powerpc64le-linux
  • 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/)
  • Fits CONTRIBUTING.md.

@Mindavi
Copy link
Contributor

Mindavi commented Apr 22, 2022

In general we want less files in bootstrap rather than more, but since it's there already anyway, why not use it. Is it in all bootstrap packages?

@ghost
Copy link
Author

ghost commented Apr 22, 2022

Ofborg failed CI on this PR, but passed (completely) on #161925 which includes this PR's commit. It might be that this PR and #161925 both need each other, rather than the dependency being unidirectional. (Edit: this is in fact the case) I will merge the two PRs into a single PR if that turns out to be the case.

Edit: Since the issue is pretty complex, I'd like to continue to use two PRs to break up the review burden. Only one of the PRs needs to merge. Unfortunately github doesn't have any way to tell it "this PR needs that PR in order to pass CI".

See latest comment further downthread.

this discussion is moot, since it turns out that the comment explaining `enableThreading=false` was wrong > In general we want less files in bootstrap rather than more,

Er, maybe if you say "packages" instead of "files".

Deleting some parts of a package from the bootstrap but including other parts really does not seem like a maintainability win. Especially when it forces weird hacks like what we're currently doing to perl5's Configure script.

but since it's there already anyway, why not use it. Is it in all bootstrap packages?

It's present on all but: powerpc64le, arm, and riscv. I have personally verified that the bootstrap (including both this PR and #161925) build and work on powerpc64le and arm. So apparently libpthread(_nonshared).a is not even needed on most platforms. I'm starting to wonder if the comment about why that hack is needed is not actually correct. I'm beginning to suspect that the perl Configure hack is actually needed as a side effect of the weird selective use of patchelf in the bootstrap (which #161925 addresses), rather than because of some file being left out of the bootstrap-files for some reason (why was it left out? nothing in make-bootstrap-files deletes it...).

In any event, if we can't reproduce the failure that led to the hack being added, and removing the hack doesn't break anything, we really ought to remove the hack.

nix@moore:/tmp/bootstrap$ for A in $(grep bootstrap-tools.tar.xz /nix/nixpkgs/pkgs/stdenv/linux/bootstrap-files/*.nix | sed 's_";.*__' | sed 's_.*"__'); do echo; echo $A; curl -s $A | tar -xvJf - | grep libpthread; done

https://wdtz.org/files/wjzsj9cmdkc70f78yh072483x8656nci-stdenv-bootstrap-tools-aarch64-unknown-linux-musl/on-server/bootstrap-tools.tar.xz
./lib/libpthread.a

http://tarballs.nixos.org/stdenv-linux/aarch64/c7c997a0662bf88264db52cbc41e67884eb7a1ff/bootstrap-tools.tar.xz
./lib/libpthread-2.33.so
./lib/libpthread.so
./lib/libpthread.so.0

http://tarballs.nixos.org/stdenv-linux/armv5tel/0eb0ddc4dbe3cd5415c6b6e657538eb809fc3778/bootstrap-tools.tar.xz
./lib/libpthread-2.30.so
./lib/libpthread.so
./lib/libpthread.so.0

https://wdtz.org/files/xmz441m69qrlfdw47l2k10zf87fsya6r-stdenv-bootstrap-tools-armv6l-unknown-linux-musleabihf/on-server/bootstrap-tools.tar.xz
./lib/libpthread.a

http://tarballs.nixos.org/stdenv-linux/armv6l/0eb0ddc4dbe3cd5415c6b6e657538eb809fc3778/bootstrap-tools.tar.xz
./lib/libpthread-2.30.so
./lib/libpthread.so
./lib/libpthread.so.0

http://tarballs.nixos.org/stdenv-linux/armv7l/0eb0ddc4dbe3cd5415c6b6e657538eb809fc3778/bootstrap-tools.tar.xz
./lib/libpthread-2.30.so
./lib/libpthread.so
./lib/libpthread.so.0

http://tarballs.nixos.org/stdenv-linux/i686/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz
./lib/libpthread-2.27.so
./lib/libpthread.so
./lib/libpthread.so.0
./lib/libpthread_nonshared.a

http://tarballs.nixos.org/stdenv-linux/powerpc64le/49a83445c28c4ffb8a1a90a1f68e6150ea48893b/bootstrap-tools.tar.xz
./lib/libpthread-2.33.so
./lib/libpthread.so
./lib/libpthread.so.0

http://tarballs.nixos.org/stdenv-linux/riscv64/9bd3cf0063b80428bd85a286205adab4b6ffcbd6/bootstrap-tools.tar.xz
./lib/libpthread-2.33.so
./lib/libpthread.so
./lib/libpthread.so.0

https://wdtz.org/files/gywxhjgl70sxippa0pxs0vj5qcgz1wi8-stdenv-bootstrap-tools/on-server/bootstrap-tools.tar.xz
./lib/libpthread.a

http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz
./lib/libpthread-2.27.so
./lib/libpthread.so
./lib/libpthread.so.0
./lib/libpthread_nonshared.a

@ghost
Copy link
Author

ghost commented Apr 22, 2022

@ofborg eval

@ghost

This comment was marked as resolved.

The comment for the line removed by this patch states that "A threaded
perl build needs glibc/libpthread_nonshared.a, which is not included
in bootstrapTools".  This is not the reason why it is necessary --
libpthread_nonshared.a part of the bootstrap-files on many platforms.
The reason why this workaround was needed is because nuke-refs erases
the rpath from libpthread.so, and unpack-bootstrap-tools.sh neglects
to undo this using patchelf.  Let's apply patchelf to libpthread.so,
so we aren't leaving dangling /nix/store/eeee.... refs in
libpthread.so, and remove the enableThreading=false override since it
is no longer necessary.

Additional background:

The enableThreading=false attribute not only removes the
"-Dusethreads" from the invocation of perl's Configure script, it also
patches the script like this:

  # We need to do this because the bootstrap doesn't have a static libpthread
  sed -i 's,\(libswanted.*\)pthread,\1,g' Configure

Although this prevents the perl interpreter from linking against
libpthread.so, it does not prevent the libraries bundled with the
interpreter from doing so.  Time/HiRes/HiRes.so will still try to link
against libpthread.so, and is only prevented from doing so by the fact
that unpack-bootstrap-tools.sh neglects to patchelf out all of the
nuke-refs'd rpaths.  When all of the nuke-refs'd paths are patchelf'ed
out, HiRes.so links against libpthread.so in the bootstrap tools, and
the stdenv bootstrap fails:

  Can't load '/nix/store/7ny8kmppjzx6kx4xr5kphjz8fqqrlsll-perl-5.34.1/lib/perl5/5.34.1/x86_64-linux/auto/Time/HiRes/HiRes.so' for module Time::HiRes: libpthread.so.0: cannot open shared object file: No such file or directory at /nix/store/7ny8kmppjzx6kx4xr5kphjz8fqqrlsll-perl-5.34.1/lib/perl5/5.34.1/XSLoader.pm line 93.
  at /nix/store/7ny8kmppjzx6kx4xr5kphjz8fqqrlsll-perl-5.34.1/lib/perl5/5.34.1/x86_64-linux/Time/HiRes.pm line 94.
  Compilation failed in require at lib/Autom4te/FileUtils.pm line 42.
  BEGIN failed--compilation aborted at lib/Autom4te/FileUtils.pm line 42.
  Compilation failed in require at bin/autom4te line 46.
  BEGIN failed--compilation aborted at bin/autom4te line 46.
  make[1]: *** [Makefile:2259: tests/wrapper.in] Error 2
  make[1]: *** Waiting for unfinished jobs....

Perl implements its own custom library loading routines for its
modules, which likely do not fully implement rpath searching.

This problem was revealed during the course of writing PR #161925,
which depends on this PR in order to pass CI.
@ghost
Copy link
Author

ghost commented Apr 23, 2022

The latest push breaks the dependency cycle between this PR and #161925, so they can be evaluated independently.

@Artturin Artturin requested a review from stigtsp May 4, 2022 09:52
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 2, 2022
@ghost ghost closed this Jan 23, 2024
@ghost ghost deleted the dont-override-perl-enableThreading-in-bootstrap branch January 23, 2024 06:44
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant