NixOS / patchelf

A small utility to modify the dynamic linker and RPATH of ELF executables
GNU General Public License v3.0
3.49k stars 483 forks source link

shrink-rpath renames global variable symbol name #169

Open jtojnar opened 5 years ago

jtojnar commented 5 years ago

patchelf --shrink-rpath renames global variable symbol breaking DeaDBeeF’s wildmidi plug-in.

This is the variable in question:

https://github.com/DeaDBeeF-Player/deadbeef/blob/7ac83fb204fc3c8a35486ef8f9550cd98cec674e/plugins/wildmidi/src/wildmidi_lib.c#L399

Compare the patched and unpatched libraries:

$ nm -A -D -l result/wildmidi-patched.so | grep wildmidi_lib.c:399
result/wildmidi-patched.so:000000000001f2a0 B X /build/source/plugins/wildmidi/src/wildmidi_lib.c:399
$ nm -A -D -l result/wildmidi.so | grep wildmidi_lib.c:399
result/wildmidi.so:000000000001f2a0 B b /build/source/plugins/wildmidi/src/wildmidi_lib.c:399

Here is the reproducible:

with import <nixpkgs> { };
with pkgs;

let
  deadbeef = fetchFromGitHub {
    owner = "DeaDBeeF-Player";
    repo = "deadbeef";
    rev = "1.8.0";
    sha256 = "126i5qlkpv7pvi1mmc9y0jhqs6jjspsj7j615n2ddvsb2jsps81c";
  };

in runCommand "patchelf" {
    buildInputs = [ patchelf gcc ];
  } ''
    cp -r ${deadbeef} source
    chmod -R u+w -- source
    cd source/plugins/wildmidi
    gcc -ggdb -shared -Iinclude -DWILDMIDI_VERSION=\"0.2.2\" -DWILDMIDILIB_VERSION=\"0.2.2\" -DTIMIDITY_CFG=\"/etc/timidity.conf\" -fPIC wildmidiplug.c src/wildmidi_lib.c include/wildmidi_lib.h -o wildmidi.so -lm

    mkdir $out
    cp wildmidi.so $out/wildmidi-patched.so
    cp wildmidi.so $out/wildmidi.so
    patchelf --shrink-rpath $out/wildmidi-patched.so
  ''
jtojnar commented 5 years ago

Likely the same issue as https://github.com/NixOS/patchelf/issues/45

solna86 commented 5 years ago

It does indeed look like #45, which arises for example in several Rpackages like Seurat. It'd be good to see if there are any similarities to narrow down what causes patchelf to output wrong binaries.

domenkozar commented 4 years ago

@jtojnar could you try again with master (or patchelfUnstable in nixpkgs)?

jtojnar commented 4 years ago

Can still reproduce with /nix/store/xlkfqvahjpd2cm7kysy1g43gcw9pjgja-patchelf-2020-06-03 on NixOS/nixpkgs@fd9d37e271e9d98189ffa7e52abf163384eb67b5:

with import ./. { };
with pkgs;

let
  deadbeef = fetchFromGitHub {
    owner = "DeaDBeeF-Player";
    repo = "deadbeef";
    rev = "1.8.0";
    sha256 = "126i5qlkpv7pvi1mmc9y0jhqs6jjspsj7j615n2ddvsb2jsps81c";
  };

in runCommand "patchelf" {
    buildInputs = [ patchelfUnstable gcc ];
  } ''
    cp -r ${deadbeef} source
    chmod -R u+w -- source
    cd source/plugins/wildmidi
    gcc -ggdb -shared -Iinclude -DWILDMIDI_VERSION=\"0.2.2\" -DWILDMIDILIB_VERSION=\"0.2.2\" -DTIMIDITY_CFG=\"/etc/timidity.conf\" -fPIC wildmidiplug.c src/wildmidi_lib.c include/wildmidi_lib.h -o wildmidi.so -lm

    mkdir $out
    cp wildmidi.so $out/wildmidi-patched.so
    cp wildmidi.so $out/wildmidi.so
    patchelf --shrink-rpath $out/wildmidi-patched.so

    echo "These should be the same:"
    nm -A -D -l $out/wildmidi.so | grep wildmidi_lib.c:399
    nm -A -D -l $out/wildmidi-patched.so | grep wildmidi_lib.c:399
    echo "^ The symbol should not have been renamed to X."
  ''
domenkozar commented 4 years ago

It would be helpful if you can also try 0.9 as the linked issue says it used to work.

jtojnar commented 4 years ago

I originally reproduced this with 0.9. Just tried it again to be sure and replacing patchelfUnstable by patchelf in the example above indeed does not fix the issue.