1 # This awk script expects to get command-line files that are each
2 # the output of 'readelf -WSdr' on a single shared object, and named
3 # .../NAME.jmprel where NAME is the unadorned file name of the shared object.
4 # It writes "NAME: SYMBOL" for each PLT entry in NAME that refers to a
5 # symbol defined in the same object.
12 FILENAME != lastfile {
13 if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0) {
14 print FILENAME ": *** failed to find expected output (readelf -WSdr)";
17 if (pltrelsz > 0 && jmprel_offset == -1) {
18 print FILENAME ": Could not find section for DT_JMPREL";
26 delete section_offset_by_address;
29 /^Section Headers:/ { in_shdrs = 1; next }
30 in_shdrs && !/^ +\[/ { in_shdrs = 0 }
32 in_shdrs && /^ +\[/ { sub(/\[ +/, "[") }
34 address = strtonum("0x" $4);
35 offset = strtonum("0x" $5);
36 section_offset_by_address[address] = offset;
41 $1 == "Offset" && $2 == "Info" { in_relocs = 1; next }
42 NF == 0 { in_relocs = 0 }
44 in_relocs && relocs_offset == jmprel_offset && NF >= 5 {
45 # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
46 # value, but rather as the resolver symbol followed by ().
48 print whatfile, gensub(/@.*/, "", "g", $5)
50 symval = strtonum("0x" $4);
52 print whatfile, gensub(/@.*/, "", "g", $5)
56 in_relocs && relocs_offset == rela_offset && NF >= 5 {
57 # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
58 # value, but rather as the resolver symbol followed by ().
60 print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
62 symval = strtonum("0x" $4);
64 print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
68 in_relocs && relocs_offset == rel_offset && NF >= 5 {
69 # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
70 # value, but rather as the resolver symbol followed by ().
72 print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
74 symval = strtonum("0x" $4);
76 print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
82 $1 == "Relocation" && $2 == "section" && $5 == "offset" {
83 relocs_offset = strtonum($6);
84 whatfile = gensub(/^.*\/([^/]+)\.jmprel$/, "\\1:", 1, FILENAME);
89 jmprel_addr = strtonum($3);
90 if (jmprel_addr in section_offset_by_address) {
91 jmprel_offset = section_offset_by_address[jmprel_addr];
99 pltrelsz = strtonum($3);
104 rela_addr = strtonum($3);
105 if (rela_addr in section_offset_by_address) {
106 rela_offset = section_offset_by_address[rela_addr];
108 print FILENAME ": *** DT_RELA does not match any section's address";
115 rel_addr = strtonum($3);
116 if (rel_addr in section_offset_by_address) {
117 rel_offset = section_offset_by_address[rel_addr];
119 print FILENAME ": *** DT_REL does not match any section's address";