Skip to content

Instantly share code, notes, and snippets.

@novafacing
Last active August 29, 2023 23:04
Show Gist options
  • Save novafacing/5750f48061da14c6cc6b6a296b3a6792 to your computer and use it in GitHub Desktop.
Save novafacing/5750f48061da14c6cc6b6a296b3a6792 to your computer and use it in GitHub Desktop.
RPATH vs RUNPATH in readelf

RPATH vs RUNPATH

I'm doing some ELF parsing and I need to simulate ld.so's lookup routine (man ld.so). To do that, I need to grab RPATH as well as RUNPATH from binaries, so to test my tool I naturally need to make some binaries with each of those. Here's how you do it.

cat <<EOF > /tmp/a.c
int main(){}
EOF
clang -c /tmp/a.c -o /tmp/a.o
mold --disable-new-dtags --rpath '$ORIGIN' -L/lib64 -lm -o /tmp/a-rpath.out /tmp/a.o
mold --enable-new-dtags --rpath '$ORIGIN' -L/lib64 -lm -o /tmp/a-runpath.out /tmp/a.o
readelf -d /tmp/a*.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment