about summary refs log tree commit diff
path: root/scripts/localplt.awk
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2012-05-01 09:26:23 -0700
committerRoland McGrath <roland@hack.frob.com>2012-05-01 13:30:35 -0700
commit90fe4186b377c7bda6788ddd8607c9f30a027355 (patch)
tree6a0b9e09b1d8fcbf52482b540915862f66228b03 /scripts/localplt.awk
parent82397ed6eab79f3f17f66efae5ccfa19fa0e03d0 (diff)
downloadglibc-90fe4186b377c7bda6788ddd8607c9f30a027355.tar.gz
glibc-90fe4186b377c7bda6788ddd8607c9f30a027355.tar.xz
glibc-90fe4186b377c7bda6788ddd8607c9f30a027355.zip
Do check-localplt test using readelf rather than a build-time C program.
Diffstat (limited to 'scripts/localplt.awk')
-rw-r--r--scripts/localplt.awk59
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/localplt.awk b/scripts/localplt.awk
new file mode 100644
index 0000000000..2265b026f0
--- /dev/null
+++ b/scripts/localplt.awk
@@ -0,0 +1,59 @@
+# This awk script expects to get command-line files that are each
+# the output of 'readelf -WSdr' on a single shared object, and named
+# .../NAME.jmprel where NAME is the unadorned file name of the shared object.
+# It writes "NAME: SYMBOL" for each PLT entry in NAME that refers to a
+# symbol defined in the same object.
+
+BEGIN { result = 0 }
+
+FILENAME != lastfile {
+  if (lastfile && jmprel_offset == 0) {
+    print FILENAME ": *** failed to find expected output (readelf -WSdr)";
+    result = 2;
+  }
+  lastfile = FILENAME;
+  jmprel_offset = 0;
+  delete section_offset_by_address;
+}
+
+/^Section Headers:/ { in_shdrs = 1; next }
+in_shdrs && !/^ +\[/ { in_shdrs = 0 }
+
+in_shdrs && /^ +\[/ { sub(/\[ +/, "[") }
+in_shdrs {
+  address = strtonum("0x" $4);
+  offset = strtonum("0x" $5);
+  section_offset_by_address[address] = offset;
+}
+
+in_shdrs { next }
+
+$1 == "Offset" && $2 == "Info" { in_relocs = 1; next }
+NF == 0 { in_relocs = 0 }
+
+in_relocs && relocs_offset == jmprel_offset && NF >= 5 {
+  symval = strtonum("0x" $4);
+  if (symval != 0)
+    print whatfile, $5
+}
+
+in_relocs { next }
+
+$1 == "Relocation" && $2 == "section" && $5 == "offset" {
+  relocs_offset = strtonum($6);
+  whatfile = gensub(/^.*\/([^/]+)\.jmprel$/, "\\1:", 1, FILENAME);
+  next
+}
+
+$2 == "(JMPREL)" {
+  jmprel_addr = strtonum($3);
+  if (jmprel_addr in section_offset_by_address) {
+    jmprel_offset = section_offset_by_address[jmprel_addr];
+  } else {
+    print FILENAME ": *** DT_JMPREL does not match any section's address";
+    result = 2;
+  }
+  next
+}
+
+END { exit(result) }