Skip to content

Commit

Permalink
Further fix for NvOsLibraryLoad function calls
Browse files Browse the repository at this point in the history
Programs which linked against both multimedia libs and libEGL_nvidia.so
would end up with two versions of NvOsLibraryLoad and one of them would
be used arbitrarily.

Now, we rename the symbols to have unique names to
avoid the conflict.  This required a version of patchelf that is not yet
in upstream nixpkgs.

As an additional note, this was discovered when runnig the
video_cuda_enc sample, and debugged using LD_DEBUG=all + grepping for
NvOsLibraryLoad and seeing that it was coming from the
libnvos_multimedia lib.
  • Loading branch information
danielfullmer committed Mar 27, 2024
1 parent e7c8fc7 commit b936066
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions UPGRADE_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [ ] Update the kernel version in `kernel/default.nix` if it chaged.
- [ ] Grep for the previous version strings e.g. "35.4.1"
- [ ] Compare files from `unpackedDebs` before and after
- [ ] Grep for NvOsLibraryLoad in libraries from debs to see if any new packages not already handled in l4t use the function
- [ ] Ensure the soc variants in `modules/flash-script.nix` match those in `jetson_board_spec.cfg` from BSP
- [ ] Ensure logic in `ota-utils/ota_helpers.func` matches `nvidia-l4t-init/opt/nvidia/nv-l4t-bootloader-config.sh`
- [ ] Run `nix build .#genL4tJson` and copy output to `pkgs/containers/l4t.json`
Expand Down
42 changes: 36 additions & 6 deletions pkgs/l4t/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ stdenv
, stdenvNoCC
, buildPackages
, addOpenGLRunpath
, lib
, fetchurl
Expand All @@ -22,6 +23,16 @@
, l4tVersion
}:
let
# The version currently in nixpkgs 23.11 and master 0.15 is pretty old and
# doesn't have the --rename-dynamic-symbols feature we need
patchelf_new = buildPackages.patchelf.overrideAttrs (_: rec {
version = "0.18.0";
src = fetchurl {
url = "https://github.com/NixOS/patchelf/releases/download/${version}/patchelf-${version}.tar.bz2";
sha256 = "sha256-GVKyp4K6V2J5whHulC40F0j9tEmX9wTdU970bNBVRws=";
};
});

# Wrapper around mkDerivation that has some sensible defaults to extract a .deb file from the L4T BSP pacckage
buildFromDeb =
# Nicely, the t194 and t234 packages are currently identical, so we just
Expand Down Expand Up @@ -114,16 +125,26 @@ let
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
# Some libraries, like libEGL_nvidia.so.0 from l4t-3d-core use a dlopen
# wrapper called NvOsLibraryLoad, which originates in libnvos.so in
# 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
# to handle this, we make a copy of libnvos specifically for this package
# so we can set the RUNPATH differently here. Additionally to avoid
# linking conflicts we rename the library and NvOsLibraryLoad symbol.
cp --no-preserve=ownership,mode ${l4t-core}/lib/libnvos.so lib/libnvos_3d.so
patchelf --set-soname libnvos_3d.so lib/libnvos_3d.so
remapFile=$(mktemp)
echo NvOsLibraryLoad NvOsLibraryLoad_3d > $remapFile
for lib in $(find ./lib -name "*.so*"); do
if isELF $lib; then
${patchelf_new}/bin/patchelf "$lib" \
--rename-dynamic-symbols "$remapFile" \
--replace-needed libnvos.so libnvos_3d.so
fi
done
'';

# We append a postFixupHook since we need to have this happen after
Expand Down Expand Up @@ -262,9 +283,18 @@ let
# 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
remapFile=$(mktemp)
echo NvOsLibraryLoad NvOsLibraryLoad_multimedia > $remapFile
for lib in $(find ./lib -name "*.so*"); do
if isELF $lib; then
${patchelf_new}/bin/patchelf "$lib" \
--rename-dynamic-symbols "$remapFile" \
--replace-needed libnvos.so libnvos_multimedia.so
fi
done
'';

# We append a postFixupHook since we need to have this happen after
Expand Down

0 comments on commit b936066

Please sign in to comment.