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: do not patch statically linked files #47222

Merged
merged 4 commits into from Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 9 additions & 18 deletions pkgs/build-support/setup-hooks/auto-patchelf.sh
Expand Up @@ -7,21 +7,7 @@ gatherLibraries() {
addEnvHooks "$targetOffset" gatherLibraries

isExecutable() {
[ "$(file -b -N --mime-type "$1")" = application/x-executable ]
}

findElfs() {
find "$1" -type f -exec "$SHELL" -c '
while [ -n "$1" ]; do
mimeType="$(file -b -N --mime-type "$1")"
if [ "$mimeType" = application/x-executable \
-o "$mimeType" = application/x-pie-executable \
-o "$mimeType" = application/x-sharedlib ]; then
echo "$1"
fi
shift
done
' -- {} +
readelf -h "$1" 2> /dev/null | grep -q '^ *Type: *EXEC\>'
}

# We cache dependencies so that we don't need to search through all of them on
Expand Down Expand Up @@ -167,9 +153,14 @@ autoPatchelf() {
# findDependency outside of this, the dependency cache needs to be rebuilt
# from scratch, so keep this in mind if you want to run findDependency
# outside of this function.
findElfs "$prefix" | while read -r elffile; do
autoPatchelfFile "$elffile"
done
while IFS= read -r -d $'\0' file; do
Copy link
Member

Choose a reason for hiding this comment

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

Why the IFS=?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

The page says it is required.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right, otherwise it's trimmed by IFS.

isELF "$file" || continue
if isExecutable "$file"; then
# Skip if the executable is statically linked.
readelf -l "$file" | grep -q "^ *INTERP\\>" || continue
fi
autoPatchelfFile "$file"
done < <(find "$prefix" -type f -print0)
}

# XXX: This should ultimately use fixupOutputHooks but we currently don't have
Expand Down
3 changes: 2 additions & 1 deletion pkgs/servers/search/elasticsearch/default.nix
Expand Up @@ -29,7 +29,8 @@ stdenv.mkDerivation (rec {
sed -i "s|ES_CLASSPATH=\"\$ES_HOME/lib/\*\"|ES_CLASSPATH=\"$out/lib/*\"|" ./bin/elasticsearch-env
'';

buildInputs = [ makeWrapper jre_headless utillinux ];
buildInputs = [ makeWrapper jre_headless utillinux ]
++ optional enableUnfree zlib;

installPhase = ''
mkdir -p $out
Expand Down
3 changes: 1 addition & 2 deletions pkgs/top-level/all-packages.nix
Expand Up @@ -81,8 +81,7 @@ with pkgs;
{ deps = [ autoconf264 automake111x gettext libtool ]; }
../build-support/setup-hooks/autoreconf.sh;

autoPatchelfHook = makeSetupHook
{ name = "auto-patchelf-hook"; deps = [ file ]; }
autoPatchelfHook = makeSetupHook { name = "auto-patchelf-hook"; }
../build-support/setup-hooks/auto-patchelf.sh;

ensureNewerSourcesHook = { year }: makeSetupHook {}
Expand Down