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.
10 if (lastfile
&& jmprel_offset ==
0 && rela_offset ==
0 && rel_offset ==
0) {
11 print FILENAME ": *** failed to find expected output (readelf -WSdr)";
18 delete section_offset_by_address
;
21 /^Section Headers
:/ { in_shdrs =
1; next }
22 in_shdrs
&& !
/^
+\
[/ { in_shdrs =
0 }
24 in_shdrs
&& /^
+\
[/ { sub(/\
[ +/, "[") }
26 address = strtonum
("0x" $
4);
27 offset = strtonum
("0x" $
5);
28 section_offset_by_address
[address
] = offset
;
33 $
1 ==
"Offset" && $
2 ==
"Info" { in_relocs =
1; next }
34 NF ==
0 { in_relocs =
0 }
36 in_relocs
&& relocs_offset == jmprel_offset
&& NF >=
5 {
37 # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
38 # value, but rather as the resolver symbol followed by ().
40 print whatfile
, gensub
(/@.
*/, "", "g", $
5)
42 symval = strtonum
("0x" $
4);
44 print whatfile
, gensub
(/@.
*/, "", "g", $
5)
48 in_relocs
&& relocs_offset == rela_offset
&& NF >=
5 {
49 # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
50 # value, but rather as the resolver symbol followed by ().
52 print whatfile
, gensub
(/@.
*/, "", "g", $
5), "RELA", $
3
54 symval = strtonum
("0x" $
4);
56 print whatfile
, gensub
(/@.
*/, "", "g", $
5), "RELA", $
3
60 in_relocs
&& relocs_offset == rel_offset
&& NF >=
5 {
61 # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
62 # value, but rather as the resolver symbol followed by ().
64 print whatfile
, gensub
(/@.
*/, "", "g", $
5), "REL", $
3
66 symval = strtonum
("0x" $
4);
68 print whatfile
, gensub
(/@.
*/, "", "g", $
5), "REL", $
3
74 $
1 ==
"Relocation" && $
2 ==
"section" && $
5 ==
"offset" {
75 relocs_offset = strtonum
($
6);
76 whatfile = gensub
(/^.
*\
/([^
/]+)\.jmprel$
/, "\\1:", 1, FILENAME);
81 jmprel_addr = strtonum
($
3);
82 if (jmprel_addr in section_offset_by_address
) {
83 jmprel_offset = section_offset_by_address
[jmprel_addr
];
85 print FILENAME ": *** DT_JMPREL does not match any section's address";
92 rela_addr = strtonum
($
3);
93 if (rela_addr in section_offset_by_address
) {
94 rela_offset = section_offset_by_address
[rela_addr
];
96 print FILENAME ": *** DT_RELA does not match any section's address";
103 rel_addr = strtonum
($
3);
104 if (rel_addr in section_offset_by_address
) {
105 rel_offset = section_offset_by_address
[rel_addr
];
107 print FILENAME ": *** DT_REL does not match any section's address";