Skip to content

Commit

Permalink
Resolve NvOsLibraryLoad issue by making unique copies of libnvos.so
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfullmer committed Mar 26, 2024
1 parent 485f104 commit 205ae5c
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions pkgs/l4t/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,6 @@ let
l4t-core = buildFromDeb {
name = "nvidia-l4t-core";
buildInputs = [ stdenv.cc.cc.lib expat libglvnd ];

# Some libraries, like libEGL_nvidia.so.0 from l3t-3d-core use a dlopen
# wrapper called NvOsLibraryLoad, which originates in libnvos.so in this
# l4t-core. Unfortunately, calling dlopen from libnvos.so instead of the
# original library/executable means that dlopen will use the DT_RUNPATH
# from libnvos.so instead of the binary/library which called it. We
# typically just need /run/opengl-driver/lib anyway, so lets add it to
# libnvos.so here instead.
#
# We append a postFixupHook since we need to have this happen after
# autoPatchelfHook, which itself also runs as a postFixupHook.
# TODO: Use runtimeDependencies instead
preFixup = ''
postFixupHooks+=('
patchelf --add-rpath /run/opengl-driver/lib $out/lib/libnvos.so
')
'';
};

l4t-3d-core = buildFromDeb {
Expand All @@ -129,6 +112,17 @@ let
# Make some symlinks also done by OE4T
ln -sf libnvidia-ptxjitcompiler.so.${l4tVersion} lib/libnvidia-ptxjitcompiler.so.1
ln -sf libnvidia-ptxjitcompiler.so.${l4tVersion} lib/libnvidia-ptxjitcompiler.so
# Some libraries, like libEGL_nvidia.so.0 from l3t-3d-core use a dlopen
# wrapper called NvOsLibraryLoad, which originates in libnvos.so in this
# l4t-core. Unfortunately, calling dlopen from libnvos.so instead of the
# original library/executable means that dlopen will use the DT_RUNPATH
# from libnvos.so instead of the binary/library which called it. In ordo
# to handle this, we Make a copy of libnvos specifically for this package
# so we can set the RUNPATH differently here.
patchelf --replace-needed libnvos.so libnvos_3d.so lib/*.so
cp --no-preserve=ownership,mode ${l4t-core}/lib/libnvos.so lib/libnvos_3d.so
patchelf --set-soname libnvos_3d.so lib/libnvos_3d.so
'';

# We append a postFixupHook since we need to have this happen after
Expand All @@ -143,7 +137,7 @@ let
patchelf --add-rpath ${lib.makeLibraryPath (with xorg; [ libX11 libXext libxcb ])} \
$out/lib/libGLX_nvidia.so.0 \
$out/lib/libnvidia-glsi.so.* \
$out/lib/libnvidia-glsi.so.*
for lib in $(find "$out/lib" -name "*.so*"); do
patchelf $lib --add-rpath $out/lib
Expand Down Expand Up @@ -264,6 +258,12 @@ let
ln -sf ../../../libv4l2_nvcuvidvideocodec.so lib/libv4l/plugins/nv/libv4l2_nvcuvidvideocodec.so
ln -sf ../../../libv4l2_nvvideocodec.so lib/libv4l/plugins/nv/libv4l2_nvvideocodec.so
# Make a copy of libnvos specifically for this package so we can set the RUNPATH differently here.
# See note above for NvOsLibraryLoad
patchelf --replace-needed libnvos.so libnvos_multimedia.so lib/*.so
cp --no-preserve=ownership,mode ${l4t-core}/lib/libnvos.so lib/libnvos_multimedia.so
patchelf --set-soname libnvos_multimedia.so lib/libnvos_multimedia.so
'';

# We append a postFixupHook since we need to have this happen after
Expand All @@ -272,6 +272,9 @@ let
preFixup = ''
postFixupHooks+=('
patchelf --add-rpath ${lib.getLib l4t-nvsci}/lib $out/lib/libnvmedia*.so
# dlopen in NvOsLibraryLoad from libnvos.so needs to be able to access these libraries
patchelf --add-rpath $out/lib $out/lib/libnvos_multimedia.so
')
'';
};
Expand Down

0 comments on commit 205ae5c

Please sign in to comment.