cht電腦資訊Linux
adm Find login register

.so dlopen(), dlsym() and functions in main() executable

eliu

joined: 2007-08-09
posted: 11473
promoted: 617
bookmarked: 187
新竹, 台灣
1subject: .so dlopen(), dlsym() and functions in main() executablePromote 0 Bookmark 02011-06-12quote  

For a dynamic library .so file , we can use dlopen(), dlsym() to call  functions inside a .so file.

Can the functions in .so call functions in main() executable? Most of the time it works, but not always. It's not very reliable.

A reliable way to let functions in .so call functions in main() executable is to save the fucntion address as a struct, and pass it to a .so initial function and .so save it.

function struct to pass
typedef struct {
  void (*mf_hide_win_sym)();

}

save function address to pass to .so
func->mf_hide_win_sym = hide_win_sym;

.so call main() exec function
gmf.mf_hide_win_sym()

edited: 3
eliu

joined: 2007-08-09
posted: 11473
promoted: 617
bookmarked: 187
新竹, 台灣
2subject: Promote 0 Bookmark 02011-06-12quote  

to check external reference functions in .so, use 'nm file.so' . The functions with 'U'  are undefined external functions.

$nm xxxx.so

00004daa t disp_select
0000a9e4 b dtor_idx.6973
0000aa10 b event_box_anthy

0000aa10 b event_box_anthy
         U exit@@GLIBC_2.0
00004290 t frame_dummy
         U g_signal_connect_data

cht電腦資訊Linux
adm Find login register
views:6189