OSDN Git Service

test/plt: add a script to find PLT usage
authorMike Frysinger <vapier@gentoo.org>
Thu, 22 Oct 2009 05:12:47 +0000 (01:12 -0400)
committerAustin Foxley <austinf@cetoncorp.com>
Mon, 9 Nov 2009 23:34:35 +0000 (15:34 -0800)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Rules.mak
test/plt/check-plt.sh [new file with mode: 0755]

index 93e005f..7591dfb 100644 (file)
--- a/Rules.mak
+++ b/Rules.mak
@@ -46,6 +46,7 @@ CC         = $(CROSS)gcc
 AR         = $(CROSS)ar
 LD         = $(CROSS)ld
 NM         = $(CROSS)nm
+OBJDUMP    = $(CROSS)objdump
 STRIPTOOL  = $(CROSS)strip
 
 INSTALL    = install
diff --git a/test/plt/check-plt.sh b/test/plt/check-plt.sh
new file mode 100755 (executable)
index 0000000..bedc8fd
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+allowed="
+calloc
+free
+malloc
+memalign
+realloc
+"
+
+${OBJDUMP:-objdump} -d ${top_builddir:-../..}/lib/libc.so.? | \
+gawk -v allowed="${allowed}" '
+BEGIN {
+       COUNT = split(" " allowed, ALLOWED);
+}
+
+# Strip away the noise.  The name will be like:
+# <brk>:
+# <foo@plt>
+function symstrip(name) {
+       return gensub(/.*<([^>@]*).*/, "\\1", "", name);
+}
+
+{
+# Match the start of the symbol disassembly
+# 00009720 <brk>:
+if ($2 ~ />:$/) {
+       f = symstrip($2);
+
+} else if ($NF ~ /@plt>/) {
+       rf = symstrip($NF);
+       for (a in ALLOWED) {
+               a = ALLOWED[a];
+               if (a == rf)
+                       next;
+       }
+       print "Func " f " references " rf;
+}
+}' | sort -u