Skip to content

Instantly share code, notes, and snippets.

@fzakaria
Created January 12, 2022 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzakaria/375f2c27f2db000369ec49a684ef8095 to your computer and use it in GitHub Desktop.
Save fzakaria/375f2c27f2db000369ec49a684ef8095 to your computer and use it in GitHub Desktop.
musl soname cache discrepancy
all: exe
# This library depends libx.so soname and calls f() from it
b/liby.so: c/libx.so
@mkdir -p $(dir $@)
echo 'int g() { h(); }' | $(CC) -o $@ -include dlfcn.h -shared -Wl,--no-as-needed -x c - -Lc -lx
# This library has both file and soname libx.so
c/libx.so:
@mkdir -p $(dir $@)
echo 'int h(){return 12;}' | $(CC) -o $@ -shared -Wl,-soname,libx.so,--no-as-needed -x c -
# This links to b/liby.so and c/libx.so, and gets libx.so and liby.so in DT_NEEDED, no paths.
exe: b/liby.so c/libx.so
echo 'extern int g(); extern int h(); int main(){ printf("\%d\\n", g() + h()); }' | $(CC) -o $@ -include stdio.h -x c - -Lb -Lc -ly -l:libx.so '-Wl,--no-as-needed,--enable-new-dtags,-rpath,$$ORIGIN/b'
patchelf --replace-needed libx.so $(shell pwd)/c/libx.so exe
clean:
rm -rf -- a b c exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment