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] autoPatchelfHook: search a valid interpreter, or fail #66620

Closed
wants to merge 7 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
4 changes: 4 additions & 0 deletions pkgs/applications/audio/bitwig-studio/bitwig-studio1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ stdenv.mkDerivation rec {
substitute usr/share/applications/bitwig-studio.desktop \
$out/share/applications/bitwig-studio.desktop \
--replace /usr/bin/bitwig-studio $out/bin/bitwig-studio

# We only support x86_64-linux anyway,
# and these files cannot be correctly autoPatchelfHooked
Copy link
Member

Choose a reason for hiding this comment

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

Why can't they be correctly autoPatchelfHooked?

rm -r $out/libexec/bin32
'';

postFixup = ''
Expand Down
37 changes: 35 additions & 2 deletions pkgs/build-support/setup-hooks/auto-patchelf.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
declare -a autoPatchelfLibs
declare -a autoPatchelfLinkers

gatherLibraries() {
autoPatchelfLibs+=("$1/lib")
if [ -f "$1/nix-support/dynamic-linker" ]; then
autoPatchelfLinkers+=("$1/nix-support/dynamic-linker")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
autoPatchelfLinkers+=("$1/nix-support/dynamic-linker")
autoPatchelfLinkers+="$(< "$1/nix-support/dynamic-linker")"

fi
if [ -f "$1/nix-support/dynamic-linker-m32" ]; then
autoPatchelfLinkers+=("$1/nix-support/dynamic-linker-m32")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
autoPatchelfLinkers+=("$1/nix-support/dynamic-linker-m32")
autoPatchelfLinkers+="$(< "$1/nix-support/dynamic-linker-m32")"

fi
}

addEnvHooks "$targetOffset" gatherLibraries
Expand Down Expand Up @@ -98,12 +105,38 @@ findDependency() {
return 1
}

patchElfInterpreter() {
local toPatch=$1
local linkers=( \
"$NIX_CC/nix-support/dynamic-linker" \
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to use backslashes for continuations here, besides, why have autoPatchelfLinkers and linkers here again?

"$NIX_CC/nix-support/dynamic-linker-m32" \
"${autoPatchelfLinkers[@]}" \
)

echo "searching an '$(getSoArch "$toPatch")' interpreter for $toPatch" >&2
for f in "${linkers[@]}"; do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for f in "${linkers[@]}"; do
for interpreter in "${interpreters[@]}"; do

[ -f "$f" -a -r "$f" ] || continue
local interpreter=$(< "$f")

[ -n "$interpreter" -a -f "$interpreter" ] || continue
[ "$(getSoArch "$toPatch")" = $(getSoArch "$interpreter") ] || continue

echo "found an '$(getSoArch "$toPatch")' interpreter at '$interpreter'" >&2
patchelf --set-interpreter "$interpreter" "$toPatch"
return
done

echo "error: no '$(getSoArch "$toPatch")' interpreter found but one is required for '$toPatch'" >&2
false
}

autoPatchelfFile() {
local dep rpath="" toPatch="$1"

local interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")"
if isExecutable "$toPatch"; then
patchelf --set-interpreter "$interpreter" "$toPatch"
# Find a suitable interpreter
patchElfInterpreter "$toPatch"

if [ -n "$runtimeDependencies" ]; then
for dep in $runtimeDependencies; do
rpath="$rpath${rpath:+:}$dep/lib"
Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/mobile/androidenv/build-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ deployAndroidPackage {
lib.optional (os == "linux") [ pkgs.glibc pkgs.zlib pkgs.ncurses5 pkgs_i686.glibc pkgs_i686.zlib pkgs_i686.ncurses5 ];
patchInstructions = ''
${lib.optionalString (os == "linux") ''
rm -r $packageBaseDir/{i686,aarch64,mipsel,arm}-linux*
Copy link
Member

Choose a reason for hiding this comment

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


addAutoPatchelfSearchPath $packageBaseDir/lib
addAutoPatchelfSearchPath $packageBaseDir/lib64
autoPatchelf --no-recurse $packageBaseDir/lib64
Expand Down