facebook / watchman

Watches files and records, or triggers actions, when they change.
https://facebook.github.io/watchman/
MIT License
12.44k stars 990 forks source link

Incorrect fixed paths in generic Linux release #1112

Open skull-squadron opened 1 year ago

skull-squadron commented 1 year ago

The preferred method:

  1. DT_RUNPATH ELF entry set to '$ORIGIN/../lib'
  2. Avoid absolute paths to libraries

If Rust won't allow it easily, here's a script that does it using patchelf (dnf install -y patchelf).

$ for F in bin/* lib/*; do make-rel-bin "$F"; done

readelf watchman as packaged ``` $ readelf -d watchman-v2023.03.13.00-linux/bin/watchman | head 0x0000000000000001 (NEEDED) Shared library: [/usr/local/lib/libglog.so.0] 0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.1.1] 0x0000000000000001 (NEEDED) Shared library: [/usr/local/lib/libgflags.so.2.2] 0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0] 0x0000000000000001 (NEEDED) Shared library: [/usr/local/lib/libevent-2.1.so.7] 0x0000000000000001 (NEEDED) Shared library: [/usr/local/lib/libsnappy.so.1] 0x0000000000000001 (NEEDED) Shared library: [libdl.so.2] ```
After ``` $ make-rel-bin watchman-v2023.03.13.00-linux/bin/watchman + patchelf --remove-rpath watchman-v2023.03.13.00-linux/bin/watchman + patchelf --set-rpath '$ORIGIN/../lib' watchman-v2023.03.13.00-linux/bin/watchman + patchelf --replace-needed /usr/local/lib/libglog.so.0 libglog.so.0 watchman-v2023.03.13.00-linux/bin/watchman + patchelf --replace-needed /usr/local/lib/libgflags.so.2.2 libgflags.so.2.2 watchman-v2023.03.13.00-linux/bin/watchman + patchelf --replace-needed /usr/local/lib/libevent-2.1.so.7 libevent-2.1.so.7 watchman-v2023.03.13.00-linux/bin/watchman + patchelf --replace-needed /usr/local/lib/libsnappy.so.1 libsnappy.so.1 watchman-v2023.03.13.00-linux/bin/watchman $ $ $ readelf -d watchman-v2023.03.13.00-linux/bin/watchman | head Dynamic section at offset 0xaa6000 contains 38 entries: Tag Type Name/Value 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/../lib] 0x0000000000000001 (NEEDED) Shared library: [libglog.so.0] 0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.1.1] 0x0000000000000001 (NEEDED) Shared library: [libgflags.so.2.2] 0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0] 0x0000000000000001 (NEEDED) Shared library: [libevent-2.1.so.7] 0x0000000000000001 (NEEDED) Shared library: [libsnappy.so.1] ```
fanzeyi commented 1 year ago

I think this could be some bug in the fixup-dyn-deps step: https://github.com/facebook/watchman/blob/main/build/fbcode_builder/getdeps/dyndeps.py

Will look closer on Monday.