Skip to content

Commit b936066

Browse files
committed
Further fix for NvOsLibraryLoad function calls
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.
1 parent e7c8fc7 commit b936066

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

UPGRADE_CHECKLIST.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [ ] Update the kernel version in `kernel/default.nix` if it chaged.
99
- [ ] Grep for the previous version strings e.g. "35.4.1"
1010
- [ ] Compare files from `unpackedDebs` before and after
11+
- [ ] Grep for NvOsLibraryLoad in libraries from debs to see if any new packages not already handled in l4t use the function
1112
- [ ] Ensure the soc variants in `modules/flash-script.nix` match those in `jetson_board_spec.cfg` from BSP
1213
- [ ] Ensure logic in `ota-utils/ota_helpers.func` matches `nvidia-l4t-init/opt/nvidia/nv-l4t-bootloader-config.sh`
1314
- [ ] Run `nix build .#genL4tJson` and copy output to `pkgs/containers/l4t.json`

pkgs/l4t/default.nix

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ stdenv
22
, stdenvNoCC
3+
, buildPackages
34
, addOpenGLRunpath
45
, lib
56
, fetchurl
@@ -22,6 +23,16 @@
2223
, l4tVersion
2324
}:
2425
let
26+
# The version currently in nixpkgs 23.11 and master 0.15 is pretty old and
27+
# doesn't have the --rename-dynamic-symbols feature we need
28+
patchelf_new = buildPackages.patchelf.overrideAttrs (_: rec {
29+
version = "0.18.0";
30+
src = fetchurl {
31+
url = "https://github.com/NixOS/patchelf/releases/download/${version}/patchelf-${version}.tar.bz2";
32+
sha256 = "sha256-GVKyp4K6V2J5whHulC40F0j9tEmX9wTdU970bNBVRws=";
33+
};
34+
});
35+
2536
# Wrapper around mkDerivation that has some sensible defaults to extract a .deb file from the L4T BSP pacckage
2637
buildFromDeb =
2738
# Nicely, the t194 and t234 packages are currently identical, so we just
@@ -114,16 +125,26 @@ let
114125
ln -sf libnvidia-ptxjitcompiler.so.${l4tVersion} lib/libnvidia-ptxjitcompiler.so.1
115126
ln -sf libnvidia-ptxjitcompiler.so.${l4tVersion} lib/libnvidia-ptxjitcompiler.so
116127
117-
# Some libraries, like libEGL_nvidia.so.0 from l3t-3d-core use a dlopen
118-
# wrapper called NvOsLibraryLoad, which originates in libnvos.so in this
128+
# Some libraries, like libEGL_nvidia.so.0 from l4t-3d-core use a dlopen
129+
# wrapper called NvOsLibraryLoad, which originates in libnvos.so in
119130
# l4t-core. Unfortunately, calling dlopen from libnvos.so instead of the
120131
# original library/executable means that dlopen will use the DT_RUNPATH
121132
# from libnvos.so instead of the binary/library which called it. In ordo
122-
# to handle this, we Make a copy of libnvos specifically for this package
123-
# so we can set the RUNPATH differently here.
124-
patchelf --replace-needed libnvos.so libnvos_3d.so lib/*.so
133+
# to handle this, we make a copy of libnvos specifically for this package
134+
# so we can set the RUNPATH differently here. Additionally to avoid
135+
# linking conflicts we rename the library and NvOsLibraryLoad symbol.
125136
cp --no-preserve=ownership,mode ${l4t-core}/lib/libnvos.so lib/libnvos_3d.so
126137
patchelf --set-soname libnvos_3d.so lib/libnvos_3d.so
138+
139+
remapFile=$(mktemp)
140+
echo NvOsLibraryLoad NvOsLibraryLoad_3d > $remapFile
141+
for lib in $(find ./lib -name "*.so*"); do
142+
if isELF $lib; then
143+
${patchelf_new}/bin/patchelf "$lib" \
144+
--rename-dynamic-symbols "$remapFile" \
145+
--replace-needed libnvos.so libnvos_3d.so
146+
fi
147+
done
127148
'';
128149

129150
# We append a postFixupHook since we need to have this happen after
@@ -262,9 +283,18 @@ let
262283
263284
# Make a copy of libnvos specifically for this package so we can set the RUNPATH differently here.
264285
# See note above for NvOsLibraryLoad
265-
patchelf --replace-needed libnvos.so libnvos_multimedia.so lib/*.so
266286
cp --no-preserve=ownership,mode ${l4t-core}/lib/libnvos.so lib/libnvos_multimedia.so
267287
patchelf --set-soname libnvos_multimedia.so lib/libnvos_multimedia.so
288+
289+
remapFile=$(mktemp)
290+
echo NvOsLibraryLoad NvOsLibraryLoad_multimedia > $remapFile
291+
for lib in $(find ./lib -name "*.so*"); do
292+
if isELF $lib; then
293+
${patchelf_new}/bin/patchelf "$lib" \
294+
--rename-dynamic-symbols "$remapFile" \
295+
--replace-needed libnvos.so libnvos_multimedia.so
296+
fi
297+
done
268298
'';
269299

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

0 commit comments

Comments
 (0)