2
0
Fork 0

genodeSources: make shared library references absolute

Use patchelf in a postFixupHook to replace any relative library names
with absolute file-sytsem paths. This ensures that the proper runtime
closures are constructed and makes it easier to route the loader to the
correct ROMs.

This requires that packages built from the Genode depot must specify
runtime dependencies as "buildInputs" in the depot-targets.nix file.
This commit is contained in:
Emery Hemingway 2020-11-06 21:00:27 +01:00
parent e859a030a4
commit 0a8d11c368
1 changed files with 44 additions and 2 deletions

View File

@ -125,10 +125,46 @@ let
stdenv' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv toolchain;
patchRelativeLibraries = ''
if [ -z "''${noAbsoluteLibraries:-}" ]; then
find "''${!outputBin}" "''${!outputLib}" -type f | while read -r elf; do
if ! isELF "$elf"; then continue; fi
args=
for name in $(patchelf --print-needed "$elf"); do
if [ "ld.lib.so" == "$name" ]; then
continue
fi
if [ -f "$name" ]; then
continue
fi
argPair=
for input in ''${!outputLib} ''${libraryBuildInputs:-}; do
local libdir="$input/lib"
local libabs=$(realpath "$libdir/$name" 2>/dev/null || true)
if [ -f "$libabs" ]; then
echo "Replace $name reference with $libabs"
argPair="--replace-needed $name $libabs"
break
fi
done
if [ -z "$argPair" ]; then
echo "Could not find absolute path to $name in buildInputs"
exit 1
fi
args="$args $argPair"
done
if [ -n "$args" ]; then
patchelf $args $elf
fi
done
fi
'';
buildUpstream =
# Build from the Genode sources
{ name, targets, portInputs ? [ ], nativeBuildInputs ? [ ], patches ? [ ]
, enableParallelBuilding ? true, meta ? { }, ... }@extraAttrs:
{ name, targets, portInputs ? [ ], nativeBuildInputs ? [ ]
, buildInputs ? [ ], patches ? [ ], enableParallelBuilding ? true
, meta ? { }, ... }@extraAttrs:
let havePatches = patches != [ ];
in stdenv'.mkDerivation (extraAttrs // {
@ -172,6 +208,9 @@ let
runHook postInstall
'';
libraryBuildInputs = map pkgs.stdenv.lib.getLib buildInputs;
postFixup = patchRelativeLibraries;
meta = { platforms = lib.platforms.genode; } // meta;
});
@ -230,6 +269,9 @@ let
runHook postInstall
'';
libraryBuildInputs = map pkgs.stdenv.lib.getLib buildInputs;
postFixup = patchRelativeLibraries;
meta = { platforms = lib.platforms.genode; } // meta;
});