]>
Commit | Line | Data |
---|---|---|
90fe4186 RM |
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. | |
6 | ||
77db67c5 FW |
7 | BEGIN { |
8 | result = 0; | |
9 | pltrelsize = -1; | |
10 | } | |
90fe4186 RM |
11 | |
12 | FILENAME != lastfile { | |
4f047d9e AZ |
13 | if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0 \ |
14 | && relr_offset == 0) { | |
90fe4186 RM |
15 | print FILENAME ": *** failed to find expected output (readelf -WSdr)"; |
16 | result = 2; | |
17 | } | |
77db67c5 FW |
18 | if (pltrelsz > 0 && jmprel_offset == -1) { |
19 | print FILENAME ": Could not find section for DT_JMPREL"; | |
20 | result = 2; | |
21 | } | |
90fe4186 RM |
22 | lastfile = FILENAME; |
23 | jmprel_offset = 0; | |
9637d8a2 L |
24 | rela_offset = 0; |
25 | rel_offset = 0; | |
4f047d9e | 26 | relr_offset = 0; |
77db67c5 | 27 | pltrelsz = -1; |
90fe4186 RM |
28 | delete section_offset_by_address; |
29 | } | |
30 | ||
31 | /^Section Headers:/ { in_shdrs = 1; next } | |
32 | in_shdrs && !/^ +\[/ { in_shdrs = 0 } | |
33 | ||
34 | in_shdrs && /^ +\[/ { sub(/\[ +/, "[") } | |
35 | in_shdrs { | |
36 | address = strtonum("0x" $4); | |
37 | offset = strtonum("0x" $5); | |
38 | section_offset_by_address[address] = offset; | |
39 | } | |
40 | ||
41 | in_shdrs { next } | |
42 | ||
43 | $1 == "Offset" && $2 == "Info" { in_relocs = 1; next } | |
44 | NF == 0 { in_relocs = 0 } | |
45 | ||
46 | in_relocs && relocs_offset == jmprel_offset && NF >= 5 { | |
7bc5a741 AZ |
47 | # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal |
48 | # value, but rather as the resolver symbol followed by (). | |
49 | if ($4 ~ /\(\)/) { | |
a0af371c | 50 | print whatfile, gensub(/@.*/, "", "g", $5) |
7bc5a741 AZ |
51 | } else { |
52 | symval = strtonum("0x" $4); | |
53 | if (symval != 0) | |
a0af371c | 54 | print whatfile, gensub(/@.*/, "", "g", $5) |
7bc5a741 | 55 | } |
90fe4186 RM |
56 | } |
57 | ||
9637d8a2 L |
58 | in_relocs && relocs_offset == rela_offset && NF >= 5 { |
59 | # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal | |
60 | # value, but rather as the resolver symbol followed by (). | |
61 | if ($4 ~ /\(\)/) { | |
62 | print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3 | |
63 | } else { | |
64 | symval = strtonum("0x" $4); | |
65 | if (symval != 0) | |
66 | print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3 | |
67 | } | |
68 | } | |
69 | ||
70 | in_relocs && relocs_offset == rel_offset && NF >= 5 { | |
71 | # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal | |
72 | # value, but rather as the resolver symbol followed by (). | |
73 | if ($4 ~ /\(\)/) { | |
74 | print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3 | |
75 | } else { | |
76 | symval = strtonum("0x" $4); | |
77 | if (symval != 0) | |
78 | print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3 | |
79 | } | |
80 | } | |
81 | ||
4f047d9e AZ |
82 | # No need to handle DT_RELR (all packed relocations are relative). |
83 | ||
90fe4186 RM |
84 | in_relocs { next } |
85 | ||
86 | $1 == "Relocation" && $2 == "section" && $5 == "offset" { | |
87 | relocs_offset = strtonum($6); | |
88 | whatfile = gensub(/^.*\/([^/]+)\.jmprel$/, "\\1:", 1, FILENAME); | |
89 | next | |
90 | } | |
91 | ||
92 | $2 == "(JMPREL)" { | |
93 | jmprel_addr = strtonum($3); | |
94 | if (jmprel_addr in section_offset_by_address) { | |
95 | jmprel_offset = section_offset_by_address[jmprel_addr]; | |
96 | } else { | |
77db67c5 | 97 | jmprel_offset = -1 |
90fe4186 RM |
98 | } |
99 | next | |
100 | } | |
101 | ||
77db67c5 FW |
102 | $2 == "(PLTRELSZ)" { |
103 | pltrelsz = strtonum($3); | |
104 | next | |
105 | } | |
106 | ||
9637d8a2 L |
107 | $2 == "(RELA)" { |
108 | rela_addr = strtonum($3); | |
109 | if (rela_addr in section_offset_by_address) { | |
110 | rela_offset = section_offset_by_address[rela_addr]; | |
111 | } else { | |
112 | print FILENAME ": *** DT_RELA does not match any section's address"; | |
113 | result = 2; | |
114 | } | |
115 | next | |
116 | } | |
117 | ||
118 | $2 == "(REL)" { | |
119 | rel_addr = strtonum($3); | |
120 | if (rel_addr in section_offset_by_address) { | |
121 | rel_offset = section_offset_by_address[rel_addr]; | |
122 | } else { | |
123 | print FILENAME ": *** DT_REL does not match any section's address"; | |
124 | result = 2; | |
125 | } | |
126 | next | |
127 | } | |
4f047d9e AZ |
128 | |
129 | $2 == "(RELR)" { | |
130 | relr_addr = strtonum($3); | |
131 | if (relr_addr in section_offset_by_address) { | |
132 | relr_offset = section_offset_by_address[relr_addr]; | |
133 | } else { | |
134 | print FILENAME ": *** DT_RELR does not match any section's address"; | |
135 | result = 2; | |
136 | } | |
137 | } | |
90fe4186 | 138 | END { exit(result) } |