From cd0b05bc21378533536391677b99c6556558c937 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 11 Jan 2017 16:08:07 +0200 Subject: [PATCH 1/3] Fix -ldl for FreeBSD. On FreeBSD, dlopen(3) is exported from libc. --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f864452..0967117 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,18 @@ install: vtable-dumper mkdir -p $(DESTDIR)$(prefix)/bin/ install vtable-dumper $(DESTDIR)$(prefix)/bin/ +OS=$(shell uname -s) +ifeq ($(OS), Linux) +LIBDL=-ldl +else ifeq ($(OS), FreeBSD) +LIBDL= +else +LIBDL=UNKNOWN +endif + vtable-dumper: dump-vtable.c dump-vtable.h - $(CC) $(CFLAGS) $(LDFLAGS) -o vtable-dumper dump-vtable.c -ldl -lelf -lstdc++ + $(CC) $(CFLAGS) $(LDFLAGS) -o vtable-dumper dump-vtable.c \ + $(LIBDL) -lelf -lstdc++ uninstall: rm -f $(DESTDIR)$(prefix)/bin/vtable-dumper From d0365c78e690b32e30780ff704d5950777416be8 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 11 Jan 2017 16:08:53 +0200 Subject: [PATCH 2/3] For size_t type, limit is provided by stdint.h. --- dump-vtable.h | 1 + 1 file changed, 1 insertion(+) diff --git a/dump-vtable.h b/dump-vtable.h index 001d198..1bf91eb 100644 --- a/dump-vtable.h +++ b/dump-vtable.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include From 5c61d71dbac40e50d9cc232bc26fd8667454e69d Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 11 Jan 2017 16:09:14 +0200 Subject: [PATCH 3/3] Leading zero for %016p "p" format is not portable. --- dump-vtable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dump-vtable.c b/dump-vtable.c index ba72421..2cfab00 100644 --- a/dump-vtable.c +++ b/dump-vtable.c @@ -355,11 +355,11 @@ void print_VTable(void *dlhndl, vtable_info *vtable) { if ((ptrdiff_t)vfuncp < 0) { - printf("(int (*)(...)) -%016p\n", (void*) -(ptrdiff_t)vfuncp); + printf("(int (*)(...)) -%16p\n", (void*) -(ptrdiff_t)vfuncp); } else { - printf("(int (*)(...)) %016p\n", vfuncp); + printf("(int (*)(...)) %16p\n", vfuncp); } } }