tags:

views:

149

answers:

2

this

en.wikipedia.org/wiki/Hot_swapping#cite_note-1

says that VS can do it with the help of its debugger. Does gdb provide a similar functionality ?

this is the closest i could find, but doesn't seem to be ready to be used:

http://www.aitdspace.gr/xmlui/handle/123456789/219

dlopen/dlsym/dlclose are also close, but will not work for -lmylib referenced libraries (reference count never gets to 0).

alternatives i've considered:

1) using -Wl,-wrap,foo and on __wrap_foo() { func = dlopen(); func(); }

2) making libfoo.so a shared library and when we need to hotswap we dlopen(RTLD_GLOBAL) to load the new code and provide updated symbols to the next call to foo();

1) doesn't work very well because it requires me to enumerate all the functions i want to hotswap, which are all of them.

2) doesn't work very well because when foo() is called, the new code is loaded, but foo has forever the reference to that symbol. calling dlopen multiple times make foo to be re evaluated.

A: 

You could certainly hack yourself a system where you store a list of function pointers and can change these pointers to point to whatever library you have dlopen()'d at the time.

You're right, there isn't any easy way to intercept calls to routines with fixed linkage. You can always clobber the start of the routine with an assembly jump to another routine, but that can be dangerous (and isn't C).

Maybe a symbol which is weak in your code and strong in a dlopen()'d library would work?

In any of these cases, you have to deal with the situation where the old code is currently running. That isn't easy either, unless you have points in your program where you know no thread is in the library you want to swap.

Keith Randall
is there a way to 'undefine' a symbol ? dlopen(RTL_GLOBAL) defines symbols globally but only for libraries that are loaded after it. if i were to dlopen(RTL_GLOBAL) multiple times to hotswap, i would need the symbols to be 'forgotten' to be reloaded. ideas ?
You can hack the PLT yourself from gdb.
R..
A: 

You may be interested in Ksplice. It's a technology that came out of MIT that allows software patches to be applied to the Linux kernel without rebooting. This is most relevant for applying security updates:

http://www.ksplice.com/paper

Noah Watkins