ELF load command address/offset not page-aligned

Hi! I’m trying to get PyTorch’s libtorch to work. I downloaded its prebuilt binaries from Start Locally | PyTorch and got this weird message:

<command line>: libtorch_cuda.so: ELF load command address/offset not page-aligned

I checked the file with readelf and the 4th load command’s offset is indeed not aligned.

$ readelf -l /home/kenhkan/libtorch/lib/libtorch_cuda.so

Elf file type is DYN (Shared object file)
Entry point 0x1191370
There are 14 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x000000000114e878 0x000000000114e878  R      0x1000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10
  LOAD           0x000000000114f000 0x000000000114f000 0x000000000114f000
                 0x00000000036d5b41 0x00000000036d5b41  R E    0x1000
  LOAD           0x0000000004825000 0x0000000004825000 0x0000000004825000
                 0x000000004a567323 0x000000004a567323  R      0x1000
  GNU_EH_FRAME   0x000000004e64a808 0x000000004e64a808 0x000000004e64a808
                 0x00000000000cb63c 0x00000000000cb63c  R      0x4
  LOAD           0x000000004ed8ccd0 0x000000004ed8dcd0 0x000000004ed8dcd0
                 0x000000000dc74800 0x000000000ec468a8  RW     0x1000
... <redacted> ...

So NixOS is correctly reporting the issue, but I’ve used the same binary successfully for a long time on Ubuntu, and I assume that the same binary has been working for many people since it’s a popular library.

I assume that NixOS is just stricter in checking boundary misalignment even if it wouldn’t cause a problem when run. Is there a way to “relax” this check on NixOS?

Or if anyone has had experience with this or has some insights/alternatives, please chime in as well. Thank you!

I forgot to attach some contextual information:

$ nixos-version
24.05.1358.47b604b07d1e (Uakari)

$ uname -r
5.15.160

$ gcc --version
gcc (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


$ ldd --version
ldd (GNU libc) 2.39
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

$

Options:

Try torch from nixpkgs NixOS Search (maybe with devenv, devshell hand)

May be a case for patchelf GitHub - NixOS/patchelf: A small utility to modify the dynamic linker and RPATH of ELF executables (I not sure about this but the name is promising). Usually is required for executables not for libraries.

Thanks for the ideas Hugo! I’ve tried patchelf before for rpaths but I haven’t been able to adjust boundaries of .so files. As for python312Packages.torch. It seems to work for Python, but not is C++ distributable. There is some magic hidden in that package. Maybe I should reach out to them instead. Thanks for taking a look!