Imported Upstream version 0.153
[platform/upstream/elfutils.git] / tests / run-prelink-addr-test.sh
1 #! /bin/sh
2 # Copyright (C) 2011 Red Hat, Inc.
3 # This file is part of Red Hat elfutils.
4 #
5 # Red Hat elfutils is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; version 2 of the License.
8 #
9 # Red Hat elfutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Red Hat elfutils; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
17 #
18 # Red Hat elfutils is an included package of the Open Invention Network.
19 # An included package of the Open Invention Network is a package for which
20 # Open Invention Network licensees cross-license their patents.  No patent
21 # license is granted, either expressly or impliedly, by designation as an
22 # included package.  Should you wish to participate in the Open Invention
23 # Network licensing program, please visit www.openinventionnetwork.com
24 # <http://www.openinventionnetwork.com>.
25
26 . $srcdir/test-subr.sh
27
28
29 # testfile52.c:
30 #   #include <stdlib.h>
31 #   int foo() { exit(0); }
32 #
33 # gcc -m32 -g -shared testfile52-32.c -o testfile52-32.so
34 # eu-strip -f testfile52-32.so.debug testfile52-32.so
35 # cp testfile52-32.so testfile52-32.prelink.so
36 # prelink -N testfile52-32.prelink.so
37 # cp testfile52-32.so testfile52-32.noshdrs.so
38 # prelink -r 0x42000000 testfile52-32.noshdrs.so
39 # eu-strip --remove-comment --strip-sections testfile52-32.noshdrs.so
40
41 testfiles testfile52-32.so testfile52-32.so.debug
42 testfiles testfile52-32.prelink.so testfile52-32.noshdrs.so
43 tempfiles testmaps52-32 testfile52-32.noshdrs.so.debug
44 ln -s testfile52-32.so.debug testfile52-32.noshdrs.so.debug
45
46 cat > testmaps52-32 <<EOF
47 00111000-00112000 r-xp 00000000 fd:01 1 `pwd`/testfile52-32.so
48 00112000-00113000 rw-p 00000000 fd:01 1 `pwd`/testfile52-32.so
49 41000000-41001000 r-xp 00000000 fd:01 2 `pwd`/testfile52-32.prelink.so
50 41001000-41002000 rw-p 00000000 fd:01 2 `pwd`/testfile52-32.prelink.so
51 42000000-42001000 r-xp 00000000 fd:01 3 `pwd`/testfile52-32.noshdrs.so
52 42001000-42002000 rw-p 00000000 fd:01 3 `pwd`/testfile52-32.noshdrs.so
53 EOF
54
55 # Prior to commit 1743d7f, libdwfl would fail on the second address,
56 # because it didn't notice that prelink added a 0x20-byte offset from
57 # what the .debug file reports.
58 testrun_compare ../src/addr2line -S -M testmaps52-32 \
59     0x11140c 0x4100042d 0x4200040e <<\EOF
60 foo
61 /home/jistone/src/elfutils/tests/testfile52-32.c:2
62 foo+0x1
63 /home/jistone/src/elfutils/tests/testfile52-32.c:2
64 foo+0x2
65 /home/jistone/src/elfutils/tests/testfile52-32.c:2
66 EOF
67
68 # Repeat testfile52 for -m64.  The particular REL>RELA issue doesn't exist, but
69 # we'll make sure the rest works anyway.
70 testfiles testfile52-64.so testfile52-64.so.debug
71 testfiles testfile52-64.prelink.so testfile52-64.noshdrs.so
72 tempfiles testmaps52-64 testfile52-64.noshdrs.so.debug
73 ln -s testfile52-64.so.debug testfile52-64.noshdrs.so.debug
74
75 cat > testmaps52-64 <<EOF
76 1000000000-1000001000 r-xp 00000000 fd:11 1 `pwd`/testfile52-64.so
77 1000001000-1000200000 ---p 00001000 fd:11 1 `pwd`/testfile52-64.so
78 1000200000-1000201000 rw-p 00000000 fd:11 1 `pwd`/testfile52-64.so
79 3000000000-3000001000 r-xp 00000000 fd:11 2 `pwd`/testfile52-64.prelink.so
80 3000001000-3000200000 ---p 00001000 fd:11 2 `pwd`/testfile52-64.prelink.so
81 3000200000-3000201000 rw-p 00000000 fd:11 2 `pwd`/testfile52-64.prelink.so
82 3800000000-3800001000 r-xp 00000000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
83 3800001000-3800200000 ---p 00001000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
84 3800200000-3800201000 rw-p 00000000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
85 EOF
86
87 testrun_compare ../src/addr2line -S -M testmaps52-64 \
88     0x100000056c 0x300000056d 0x380000056e <<\EOF
89 foo
90 /home/jistone/src/elfutils/tests/testfile52-64.c:2
91 foo+0x1
92 /home/jistone/src/elfutils/tests/testfile52-64.c:2
93 foo+0x2
94 /home/jistone/src/elfutils/tests/testfile52-64.c:2
95 EOF
96
97
98 # testfile53.c:
99 #   char foo[0x1000];
100 #   int main() { return 0; }
101 #
102 # gcc -m32 -g testfile53-32.c -o testfile53-32
103 # eu-strip -f testfile53-32.debug testfile53-32
104 # cp testfile53-32 testfile53-32.prelink
105 # prelink -N testfile53-32.prelink
106 testfiles testfile53-32 testfile53-32.debug testfile53-32.prelink
107
108 testrun_compare ../src/addr2line -S -e testfile53-32 0x8048394 0x8048395 <<\EOF
109 main
110 /home/jistone/src/elfutils/tests/testfile53-32.c:2
111 main+0x1
112 /home/jistone/src/elfutils/tests/testfile53-32.c:2
113 EOF
114
115 # prelink shuffled some of the sections, but .text is in the same place.
116 testrun_compare ../src/addr2line -S -e testfile53-32.prelink 0x8048396 0x8048397 <<\EOF
117 main+0x2
118 /home/jistone/src/elfutils/tests/testfile53-32.c:2
119 main+0x3
120 /home/jistone/src/elfutils/tests/testfile53-32.c:2
121 EOF
122
123 # Repeat testfile53 in 64-bit, except use foo[0x800] to achieve the same
124 # prelink section shuffling.
125 testfiles testfile53-64 testfile53-64.debug testfile53-64.prelink
126
127 testrun_compare ../src/addr2line -S -e testfile53-64 0x400474 0x400475 <<\EOF
128 main
129 /home/jistone/src/elfutils/tests/testfile53-64.c:2
130 main+0x1
131 /home/jistone/src/elfutils/tests/testfile53-64.c:2
132 EOF
133
134 testrun_compare ../src/addr2line -S -e testfile53-64.prelink 0x400476 0x400477 <<\EOF
135 main+0x2
136 /home/jistone/src/elfutils/tests/testfile53-64.c:2
137 main+0x3
138 /home/jistone/src/elfutils/tests/testfile53-64.c:2
139 EOF
140
141
142 # testfile54.c:
143 #   extern void * stdin;
144 #   static void * pstdin = &stdin;
145 #   void * const foo = &pstdin;
146 #
147 # gcc -m32 -g -shared -nostartfiles testfile54-32.c -o testfile54-32.so
148 # eu-strip -f testfile54-32.so.debug testfile54-32.so
149 # cp testfile54-32.so testfile54-32.prelink.so
150 # prelink -N testfile54-32.prelink.so
151 # cp testfile54-32.so testfile54-32.noshdrs.so
152 # prelink -r 0x42000000 testfile54-32.noshdrs.so
153 # eu-strip --remove-comment --strip-sections testfile54-32.noshdrs.so
154 testfiles testfile54-32.so testfile54-32.so.debug
155 testfiles testfile54-32.prelink.so testfile54-32.noshdrs.so
156 tempfiles testmaps54-32
157
158 # Note we have no testfile54-32.noshdrs.so.debug link here, so
159 # this is testing finding the symbols in .dynsym via PT_DYNAMIC.
160
161 cat > testmaps54-32 <<EOF
162 00111000-00112000 r--p 00000000 fd:01 1 `pwd`/testfile54-32.so
163 00112000-00113000 rw-p 00000000 fd:01 1 `pwd`/testfile54-32.so
164 41000000-41001000 r--p 00000000 fd:01 2 `pwd`/testfile54-32.prelink.so
165 41001000-41002000 rw-p 00000000 fd:01 2 `pwd`/testfile54-32.prelink.so
166 42000000-42001000 r--p 00000000 fd:01 3 `pwd`/testfile54-32.noshdrs.so
167 42001000-42002000 rw-p 00000000 fd:01 3 `pwd`/testfile54-32.noshdrs.so
168 EOF
169
170 testrun_compare ../src/addr2line -S -M testmaps54-32 \
171     0x1111fc 0x1122a4 0x410001fd 0x410012a5 0x420001fe <<\EOF
172 foo
173 ??:0
174 pstdin
175 ??:0
176 foo+0x1
177 ??:0
178 pstdin+0x1
179 ??:0
180 foo+0x2
181 ??:0
182 EOF
183
184 # Repeat testfile64 in 64-bit
185 testfiles testfile54-64.so testfile54-64.so.debug
186 testfiles testfile54-64.prelink.so testfile54-64.noshdrs.so
187 tempfiles testmaps54-64
188
189 # Note we have no testfile54-64.noshdrs.so.debug link here, so
190 # this is testing finding the symbols in .dynsym via PT_DYNAMIC.
191
192 cat > testmaps54-64 <<EOF
193 1000000000-1000001000 r--p 00000000 fd:11 1 `pwd`/testfile54-64.so
194 1000001000-1000200000 ---p 00001000 fd:11 1 `pwd`/testfile54-64.so
195 1000200000-1000201000 rw-p 00000000 fd:11 1 `pwd`/testfile54-64.so
196 3000000000-3000001000 r--p 00000000 fd:11 2 `pwd`/testfile54-64.prelink.so
197 3000001000-3000200000 ---p 00001000 fd:11 2 `pwd`/testfile54-64.prelink.so
198 3000200000-3000201000 rw-p 00000000 fd:11 2 `pwd`/testfile54-64.prelink.so
199 3800000000-3800001000 r--p 00000000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
200 3800001000-3800200000 ---p 00001000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
201 3800200000-3800201000 rw-p 00000000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
202 EOF
203
204 testrun_compare ../src/addr2line -S -M testmaps54-64 \
205     0x10000002f8 0x1000200448 0x30000002f9 0x3000200449 0x38000002fa <<\EOF
206 foo
207 ??:0
208 pstdin
209 ??:0
210 foo+0x1
211 ??:0
212 pstdin+0x1
213 ??:0
214 foo+0x2
215 ??:0
216 EOF
217
218
219 # testfile55.c:
220 #   extern void *stdin;
221 #   int main() { return !stdin; }
222 #
223 # gcc -m32 -g testfile55-32.c -o testfile55-32
224 # eu-strip -f testfile55-32.debug testfile55-32
225 # cp testfile55-32 testfile55-32.prelink
226 # prelink -N testfile55-32.prelink
227 testfiles testfile55-32 testfile55-32.debug testfile55-32.prelink
228
229 testrun_compare ../src/addr2line -S -e testfile55-32 0x80483b4 0x80483b5 <<\EOF
230 main
231 /home/jistone/src/elfutils/tests/testfile55-32.c:2
232 main+0x1
233 /home/jistone/src/elfutils/tests/testfile55-32.c:2
234 EOF
235
236 # prelink splits .bss into .dynbss+.bss, so the start of .bss changes, but the
237 # total size remains the same, and .text doesn't move at all.
238 testrun_compare ../src/addr2line -S -e testfile55-32.prelink 0x80483b6 0x80483b7 <<\EOF
239 main+0x2
240 /home/jistone/src/elfutils/tests/testfile55-32.c:2
241 main+0x3
242 /home/jistone/src/elfutils/tests/testfile55-32.c:2
243 EOF
244
245 # Repeat testfile55 in 64-bit
246 testfiles testfile55-64 testfile55-64.debug testfile55-64.prelink
247
248 testrun_compare ../src/addr2line -S -e testfile55-64 0x4004b4 0x4004b5 <<\EOF
249 main
250 /home/jistone/src/elfutils/tests/testfile55-64.c:2
251 main+0x1
252 /home/jistone/src/elfutils/tests/testfile55-64.c:2
253 EOF
254
255 testrun_compare ../src/addr2line -S -e testfile55-64.prelink 0x4004b6 0x4004b7 <<\EOF
256 main+0x2
257 /home/jistone/src/elfutils/tests/testfile55-64.c:2
258 main+0x3
259 /home/jistone/src/elfutils/tests/testfile55-64.c:2
260 EOF