facebook / facebook/watchman

Incorrect fixed paths in generic Linux release

Open
#1,112 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

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`)](https://gist.github.com/steakknife/1a0df1b7ff83809a7ecb5ade361750c3).

`$ 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]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.