linux - How can dlsym successfully import function from stripped binary library? -
it's weird dlsym can import functions stripped binaries.
can tell me why/how?
=== file: a.c === int a1() { return 1; } int a2() { return 2; } === end of a.c === === file: b.c === #include <stdio.h> #include <dlfcn.h> #include <stdlib.h> typedef int (*fint)(); fint dlsym_fint(void *handle, char *name) { fint x = (fint)dlsym(handle, name); char *err = null; if ((err = dlerror()) != null) { printf("dlsym: %s\n", err); exit(1); } return x; } int main() { void *dl = dlopen("a.so", rtld_now); fint = null; = dlsym_fint(dl, "a1"); printf("%p: %d\n", a, a()); = dlsym_fint(dl, "a2"); printf("%p: %d\n", a, a()); return 0; } === end of b.c === $ gcc -shared -fpic -o a.so a.c $ nm a.so ... 00000000000004ec t a1 00000000000004f7 t a2 ... $ strip a.so $ nm a.so nm: a.so: no symbols $ gcc -o b b.c -ldl $ ./b 0x2aaaaaac74ec: 1 0x2aaaaaac74f7: 2
try readelf -s a.so
. dynamic symbols still there after strip
.
(or switch nm -d a.so
.)
Comments
Post a Comment