patchelf
patchelf copied to clipboard
patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
Describe the bug
Attempting to patchelf a rust executable to run on NixOS and hitting the error from the subject:
$ patchelf --set-interpreter /nix/store/8mc30d49ghc8m5z96yz39srlhg5s9sjj-glibc-2.38-44/lib/ld-linux-x86-64.so.2 ./GlamorousToolkit-cli
patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
$ patchelf --version
patchelf 0.18.0
A few notes:
- The same error occurs with patchelf 0.15.0.
- The command is being run on NixOS 23.11 (NixOS 23.11.20240304.617579a as I write this, but has been consistent since the problematic executables were built).
- The executable is compiled on Ubuntu 20.04.
I've seen previous issues opened about this (#217, #255, #400) however they don't appear to be the same.
Steps To Reproduce
Download and unzip GlamorousToolkit-cli:
wget https://github.com/feenkcom/gtoolkit-vm/releases/download/v1.0.14/GlamorousToolkit-x86_64-unknown-linux-gnu.zip
unzip GlamorousToolkit-x86_64-unknown-linux-gnu.zip
cd bin
Find an interpreter (this is just for demo purposes, not production code):
GT_INTERPRETER=$(find /nix/store -name ld-linux-x86-64.so.2 | grep 2.38 | head -n 1)
echo $GT_INTERPRETER
attempt to patch the exe:
patchelf --set-interpreter $GT_INTERPRETER GlamorousToolkit-cli
The same issue occurs when attempting to to set the rpath.
Expected behavior
The executable is updated with the specified interpeter.
patchelf --version output
$ patchelf --version
patchelf 0.15.0
and
$ patchelf --version
patchelf 0.18.0
Additional context
None.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/patchelf-cannot-normalize-pt-note-segment-non-contiguous-sht-note-sections/40561/2
patchelf 0.11.20200609.d6b2a72 doesn't have this problem (tag 0.11 in the repository), 0.12 does.
I encountered this error when attempting to use patchelf 0.18 on a library which had already been patched by patchelf 0.10. I fixed it by using version 0.18 for both patches.
@mhsmith Thank you very much! Replacing patchelf 0.10 with 0.18 in the original patch avoids the problem.