Hello,
I've tried to build a "hello world" demo live patch for a simple
application. I focused on minimal code and applied a "cargo-cult"
approach.
First, I built an applicaiton with a shared library.
------------8<------------
main.c:
#include <unistd.h>
extern void workload();
int main(void)
{
int counter;
for(counter = 0; counter < 30; counter++)
{
workload();
sleep(2);
}
}
workload.c:
#include <stdio.h>
void workload(void)
{
printf("Hello World!\n");
}
Compiled as:
$ gcc -shared -fPIC -fpatchable-function-entry=40,38 -I/data/src/libpulp/include -o libworkload.so /data/src/libpulp/lib/trm.S workload.c
$ /data/src/libpulp/tools/ulp_post libworkload.so
$ gcc -Wl,-rpath,. -L. -o main main.c -lworkload
And it works:
$ ./main
Hello World!
Hello World!
^C
------------>8------------
Then I prepared a patch for workload().
------------8<------------
workload_patch.c:
#include <stdio.h>
void workload_modernized(void)
{
printf("hello, world\n");
}
libworkload_patch.dsc:
/data/src/libpulp/demo/libworkload_patch.so
@/data/src/libpulp/demo/libworkload.so
workload:workload_modernized
Compiled as:
$ gcc -shared -fPIC -o libworkload_patch.so workload_patch.c
$ /data/src/libpulp/tools/ulp_packer libworkload_patch.dsc libworkload_patch.ulp
------------>8------------
At this point, I believe I have all the bits in place and I want to
try live patching of 'main'.
------------8<------------
$ LD_PRELOAD=/data/src/libpulp/lib/.libs/libpulp.so ./main &
[1] 27910
libpulp loaded...
Hello World!
$ /data/src/libpulp/tools/ulp_trigger "$(pidof main)" /data/src/libpulp/demo/libworkload_patch.ulp
ulp: to be patched object (/data/src/libpulp/demo/libworkload.so) not loaded.
------------>8------------
What am I doing wrong, apart from the uneducated approach, that
ulp_trigger complaints about the missing libworkload.so?
Libor
Side notes:
- It is unclear how to build live patches. README.md contains the
high-level overview but not concrete steps or a pointer to a "how
to".
- ulp_packer help is wrong. It says "packer <descr> <.so> [.ulp]"
while it's now "packer <descr> <.ulp>"
- The role of ulp_post is unclear in the process. There is a clue in
the commit log that introduces it but it was beyong my current
knowledge level.
- I've inferred compiler parameters and command usage from what I saw
in "make check" output.
- ulp_trigger says nothing in case libpulp.so is not preloaded. I
suggest that it prints some diagnostic message.
--
Libor Pechacek
SUSE Labs Remember to have fun...