Stephen Cameron
unread,Mar 21, 2012, 1:55:47 PM3/21/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to dynamor...@googlegroups.com
Hi,
I'm new here.
I'm working on an approach to doing some unit testing of linux kernel modules. Linux kernel modules typically only expose a few functions with all module internal functions declared static. My idea was to use objcopy with the --globalize-symbols and possibly the --weaken option to expose those symbols for unti testing. So far so good. But internal calls to internal module functions I cannot override by this method, it seems. i'm wondering if DynamoRio can do it.
Here's a simplified example of what I'm trying to do:
If I start with something like this, a module
with global symbol "foo" is a function that calls
local symbol "bar," that calls local symbol "baz"
[scameron@localhost ~]$ cat foo.c
#include <stdio.h>
static void baz(void)
{
printf("baz\n");
}
static void bar(void)
{
printf("bar\n");
baz();
}
void foo(void)
{
printf("foo\n");
bar();
}
[scameron@localhost ~]$ gcc -g -c foo.c
[scameron@localhost ~]$ objdump -x foo.o | egrep 'foo|bar|baz'
foo.o: file format elf32-i386
foo.o
00000000 l df *ABS* 00000000 foo.c
00000000 l F .text 00000014 baz
00000014 l F .text 00000019 bar
0000002d g F .text 00000019 foo
It has one global, "foo" and two locals "bar" and "baz."
Suppose I want to write some unit tests that exercise bar and baz,
I can do:
[scameron@localhost ~]$ cat barbaz
bar
baz
[scameron@localhost ~]$ objcopy --globalize-symbols=barbaz foo.o foo2.o
[scameron@localhost ~]$ objdump -x foo2.o | egrep 'foo|bar|baz'
foo2.o: file format elf32-i386
foo2.o
00000000 l df *ABS* 00000000 foo.c
00000000 g F .text 00000014 baz
00000014 g F .text 00000019 bar
0000002d g F .text 00000019 foo
[scameron@localhost ~]$
And now bar and baz are global symbols and accessible from
outside the module. So far so good.
But what if I want to interpose my own function on top
of "baz", and have "bar" call my interposed "baz"?
Is there a way to do that?
--wrap option doesn't seem to do it...
[scameron@localhost ~]$ cat ibaz.c
#include <stdio.h>
extern void foo();
extern void bar();
void __wrap_baz()
{
printf("wrapped baz\n");
}
int main(int argc, char *argv[])
{
foo();
baz();
}
[scameron@localhost ~]$ gcc -o ibaz ibaz.c foo2.o -Xlinker --wrap -Xlinker baz
[scameron@localhost ~]$ ./ibaz
foo
bar
baz
wrapped baz
[scameron@localhost ~]$
The baz called from main() got wrapped, but
bar still calls the local baz not the wrapped baz.
I also tried --weaken, still no luck
[scameron@localhost ~]$ objcopy --weaken-symbol=baz foo2.o foo3.o
[scameron@localhost ~]$ objdump -x foo3.o | grep baz
00000000 w F .text 00000014 baz
[scameron@localhost ~]$ gcc -o ibaz ibaz.c foo3.o -Xlinker --wrap -Xlinker baz
[scameron@localhost ~]$ ./ibaz
foo
bar
baz
wrapped baz
[scameron@localhost ~]$
Is there a way to do this with DynamoRIO?
Thanks,
-- steve