Browse Source

test/plt: add a script to find PLT usage

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Mike Frysinger 14 years ago
parent
commit
e219bc7c1b
2 changed files with 39 additions and 0 deletions
  1. 1 0
      Rules.mak
  2. 38 0
      test/plt/check-plt.sh

+ 1 - 0
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

+ 38 - 0
test/plt/check-plt.sh

@@ -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