Created
June 28, 2012 19:40
-
-
Save GunnarFarneback/3013408 to your computer and use it in GitHub Desktop.
Symbol collision in Julia
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
| gcc -Wall -fPIC -O3 -c test_move.c | |
| gcc -shared -Wl,-soname,libtest_move.so -o libtest_move.so test_move.o | |
| gcc -o test_move test_move.c |
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 <stdio.h> | |
| int foo; | |
| int move[10000]; | |
| void test_move() | |
| { | |
| printf("foo: %p\nmove: %p\n", &foo, move); | |
| move[9999] = 13; | |
| } | |
| int main(int argc, char **argv) | |
| { | |
| test_move(); | |
| return 0; | |
| } |
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
| lib_test_move = dlopen("./libtest_move.so") | |
| test_move = dlsym(lib_test_move, :test_move) | |
| println("foo: ", dlsym(lib_test_move, :foo)) | |
| println("move: ", dlsym(lib_test_move, :move)) | |
| ccall(test_move, Void, ()) |
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
| main_program = ccall(:jl_load_dynamic_library, Ptr{Void}, (Ptr{Uint8},), 0) | |
| lib_test_move = dlopen("./libtest_move.so") | |
| test_move = dlsym(lib_test_move, :test_move) | |
| println("foo: ", dlsym(lib_test_move, :foo)) | |
| println("move: ", dlsym(lib_test_move, :move)) | |
| println("main_program move: ", dlsym(main_program, :move)) | |
| ccall(test_move, Void, ()) |
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
| libdl = dlopen("/usr/lib/x86_64-linux-gnu/libdl.so") | |
| function dlopen2(lib) | |
| # From bits/dlfcn.h | |
| const RTLD_LAZY = 0x00001 | |
| const RTLD_DEEPBIND = 0x00008 | |
| flags = RTLD_LAZY | RTLD_DEEPBIND | |
| ccall(dlsym(libdl, :dlopen), Ptr{Void}, (Ptr{Uint8}, Int32), lib, flags) | |
| end | |
| function dlsym2(lib, sym) | |
| ccall(dlsym(libdl, :dlsym), Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), lib, sym) | |
| end | |
| lib_test_move = dlopen2("./libtest_move.so") | |
| test_move = dlsym2(lib_test_move, :test_move) | |
| println("foo: ", dlsym2(lib_test_move, :foo)) | |
| println("move: ", dlsym2(lib_test_move, :move)) | |
| ccall(test_move, Void, ()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment