Created
June 9, 2022 16:09
-
-
Save Simon-L/8f7386ef1ee05075c8a783b80a1b4312 to your computer and use it in GitHub Desktop.
bare minimum dlsym (dlopen bug on box64)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdio> | |
| #include <dlfcn.h> | |
| typedef void (*LibFunc)(); | |
| LibFunc getSym(const char* sopath) { | |
| void* handle = dlopen(sopath, RTLD_NOW | RTLD_LOCAL); | |
| if (!handle) { | |
| printf("Oops exit1!\n"); | |
| return (LibFunc)(0); | |
| } | |
| dlerror(); | |
| const char* dlsym_error = dlerror(); | |
| LibFunc func = (LibFunc) dlsym(handle, "_Z6myFuncv"); | |
| dlsym_error = dlerror(); | |
| if (dlsym_error) { | |
| printf("error! %s", dlsym_error); | |
| return (LibFunc)(0); | |
| } | |
| if (!func) { | |
| printf("Oops exit2!\n"); | |
| return (LibFunc)(0); | |
| } | |
| return func; | |
| } | |
| int main() { | |
| printf("Loading function from shared1..."); | |
| LibFunc myFunc1 = getSym("shared1/sharedobj.so"); | |
| myFunc1(); | |
| printf("Loading function from shared2..."); | |
| LibFunc myFunc2 = getSym("shared2/sharedobj.so"); | |
| myFunc2(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment