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

[WIP] Set absolute sonames #45105

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/stdenv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,15 @@ installTargets = "install-bin install-doc";</programlisting>
dependencies.
</para>
</listitem>
<listitem>
<para>
On Linux, it uses <command>patchelf</command> on all libraries in
the <filename>lib</filename> tree to make the <varname>DT_SONAME</varname>
an absolute path to the library. This makes other binaries that
link against it access it directly rather than searching through
<varname>DT_RUNPATH</varname>, which increases efficiency.
</para>
</listitem>
<listitem>
<para>
It rewrites the interpreter paths of shell scripts to paths found in
Expand Down Expand Up @@ -1621,6 +1630,18 @@ installTargets = "install-bin install-doc";</programlisting>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<varname>noAbsoluteSoname</varname>
</term>
<listitem>
<para>
If set, the <varname>DT_SONAME</varname> entries of the shared
libraries in the output will be left unmodified. Only applies
to Linux.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<varname>dontPatchShebangs</varname>
Expand Down
26 changes: 21 additions & 5 deletions nixos/modules/system/boot/stage-1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ let
ld*.so.?) continue;;
esac

# $next might be an absolute path
if [ -f "$next" ]; then
echo "$next"
add_needed "$next"
continue
fi

IFS=: read -ra paths <<< $rpath
res=
for path in "''${paths[@]}"; do
Expand Down Expand Up @@ -166,16 +173,25 @@ let
stripDirs "$STRIP" "lib bin" "-s"

# Run patchelf to make the programs refer to the copied libraries.
find $out/bin $out/lib -type f | while read i; do
( find $out/bin -type f ; find $out/lib -type f -not -name "ld*" ) | while read i; do
if ! test -L $i; then
nuke-refs -e $out $i
echo "patching $i..."
libs=$(patchelf --print-needed $i)
replacements=""
for library in $libs; do
[[ library = */ld* ]] && continue
replacements+="--replace-needed $library $(basename $library) "
done
patchelf $replacements $i || true
patchelf --set-rpath $out/lib $i || true
[[ $i = $out/bin/* ]] && patchelf --set-interpreter $out/lib/ld*.so.? $i || true
fi
done

find $out/bin -type f | while read i; do
# Remove any remaining refs to the outside
find $out/bin $out/lib -type f | while read i; do
if ! test -L $i; then
echo "patching $i..."
patchelf --set-interpreter $out/lib/ld*.so.? --set-rpath $out/lib $i || true
nuke-refs -e $out $i
fi
done

Expand Down
8 changes: 8 additions & 0 deletions pkgs/build-support/setup-hooks/set-soname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[ -z "$noAbsoluteSoname" ]] && fixupOutputHooks+=(_doAbsoluteSoname)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add this option also in doc/stdenv.xml?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!


_doAbsoluteSoname() {
echo "Making sonames absolute"
if test -d "$prefix" ; then
find "$prefix" -type f '(' -name "lib*.so.*" -or -name 'lib*.so' ')' -not -name 'ld*' -exec patchelf --set-soname {} {} ';'
fi
}
2 changes: 2 additions & 0 deletions pkgs/development/compilers/gcc/6/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ stdenv.mkDerivation ({

builder = ../builder.sh;

noAbsoluteSoname = true;

src = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
sha256 = "1m0lr7938lw5d773dkvwld90hjlcq2282517d1gwvrfzmwgg42w5";
Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/libraries/glibc/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ stdenv.mkDerivation ({
# prevent a retained dependency on the bootstrap tools in the stdenv-linux
# bootstrap.
BASH_SHELL = "/bin/sh";

noAbsoluteSoname = true;
}

// (removeAttrs args [ "withLinuxHeaders" "withGd" ]) //
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/tools/misc/binutils/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ stdenv.mkDerivation rec {
buildInputs = [ zlib ];

inherit noSysDirs;
noAbsoluteSoname = true;

preConfigure = ''
# Clear the default library search path.
Expand Down
1 change: 1 addition & 0 deletions pkgs/stdenv/generic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let
../../build-support/setup-hooks/compress-man-pages.sh
../../build-support/setup-hooks/strip.sh
../../build-support/setup-hooks/patch-shebangs.sh
../../build-support/setup-hooks/set-soname.sh
]
# FIXME this on Darwin; see
# https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369
Expand Down