1#! /bin/sh
2# Copyright (C) 2011-2013 Red Hat, Inc.
3# This file is part of elfutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# elfutils is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18. $srcdir/test-subr.sh
19
20
21# testfile52.c:
22#   #include <stdlib.h>
23#   int foo() { exit(0); }
24#
25# gcc -m32 -g -shared testfile52-32.c -o testfile52-32.so
26# eu-strip -f testfile52-32.so.debug testfile52-32.so
27# cp testfile52-32.so testfile52-32.prelink.so
28# prelink -N testfile52-32.prelink.so
29# cp testfile52-32.so testfile52-32.noshdrs.so
30# prelink -r 0x42000000 testfile52-32.noshdrs.so
31# eu-strip --remove-comment --strip-sections testfile52-32.noshdrs.so
32
33testfiles testfile52-32.so testfile52-32.so.debug
34testfiles testfile52-32.prelink.so testfile52-32.noshdrs.so
35tempfiles testmaps52-32 testfile52-32.noshdrs.so.debug
36ln -snf testfile52-32.so.debug testfile52-32.noshdrs.so.debug
37
38cat > testmaps52-32 <<EOF
3900111000-00112000 r-xp 00000000 fd:01 1 `pwd`/testfile52-32.so
4000112000-00113000 rw-p 00000000 fd:01 1 `pwd`/testfile52-32.so
4141000000-41001000 r-xp 00000000 fd:01 2 `pwd`/testfile52-32.prelink.so
4241001000-41002000 rw-p 00000000 fd:01 2 `pwd`/testfile52-32.prelink.so
4342000000-42001000 r-xp 00000000 fd:01 3 `pwd`/testfile52-32.noshdrs.so
4442001000-42002000 rw-p 00000000 fd:01 3 `pwd`/testfile52-32.noshdrs.so
45EOF
46
47# Prior to commit 1743d7f, libdwfl would fail on the second address,
48# because it didn't notice that prelink added a 0x20-byte offset from
49# what the .debug file reports.
50testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps52-32 \
51    0x11140c 0x4100042d 0x4200040e <<\EOF
52foo
53/home/jistone/src/elfutils/tests/testfile52-32.c:2
54foo+0x1
55/home/jistone/src/elfutils/tests/testfile52-32.c:2
56foo+0x2
57/home/jistone/src/elfutils/tests/testfile52-32.c:2
58EOF
59
60# Repeat testfile52 for -m64.  The particular REL>RELA issue doesn't exist, but
61# we'll make sure the rest works anyway.
62testfiles testfile52-64.so testfile52-64.so.debug
63testfiles testfile52-64.prelink.so testfile52-64.noshdrs.so
64tempfiles testmaps52-64 testfile52-64.noshdrs.so.debug
65ln -snf testfile52-64.so.debug testfile52-64.noshdrs.so.debug
66
67cat > testmaps52-64 <<EOF
681000000000-1000001000 r-xp 00000000 fd:11 1 `pwd`/testfile52-64.so
691000001000-1000200000 ---p 00001000 fd:11 1 `pwd`/testfile52-64.so
701000200000-1000201000 rw-p 00000000 fd:11 1 `pwd`/testfile52-64.so
713000000000-3000001000 r-xp 00000000 fd:11 2 `pwd`/testfile52-64.prelink.so
723000001000-3000200000 ---p 00001000 fd:11 2 `pwd`/testfile52-64.prelink.so
733000200000-3000201000 rw-p 00000000 fd:11 2 `pwd`/testfile52-64.prelink.so
743800000000-3800001000 r-xp 00000000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
753800001000-3800200000 ---p 00001000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
763800200000-3800201000 rw-p 00000000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
77EOF
78
79testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps52-64 \
80    0x100000056c 0x300000056d 0x380000056e <<\EOF
81foo
82/home/jistone/src/elfutils/tests/testfile52-64.c:2
83foo+0x1
84/home/jistone/src/elfutils/tests/testfile52-64.c:2
85foo+0x2
86/home/jistone/src/elfutils/tests/testfile52-64.c:2
87EOF
88
89
90# testfile53.c:
91#   char foo[0x1000];
92#   int main() { return 0; }
93#
94# gcc -m32 -g testfile53-32.c -o testfile53-32
95# eu-strip -f testfile53-32.debug testfile53-32
96# cp testfile53-32 testfile53-32.prelink
97# prelink -N testfile53-32.prelink
98testfiles testfile53-32 testfile53-32.debug testfile53-32.prelink
99
100testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-32 0x8048394 0x8048395 <<\EOF
101main
102/home/jistone/src/elfutils/tests/testfile53-32.c:2
103main+0x1
104/home/jistone/src/elfutils/tests/testfile53-32.c:2
105EOF
106
107# prelink shuffled some of the sections, but .text is in the same place.
108testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-32.prelink 0x8048396 0x8048397 <<\EOF
109main+0x2
110/home/jistone/src/elfutils/tests/testfile53-32.c:2
111main+0x3
112/home/jistone/src/elfutils/tests/testfile53-32.c:2
113EOF
114
115# Repeat testfile53 in 64-bit, except use foo[0x800] to achieve the same
116# prelink section shuffling.
117testfiles testfile53-64 testfile53-64.debug testfile53-64.prelink
118
119testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-64 0x400474 0x400475 <<\EOF
120main
121/home/jistone/src/elfutils/tests/testfile53-64.c:2
122main+0x1
123/home/jistone/src/elfutils/tests/testfile53-64.c:2
124EOF
125
126testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-64.prelink 0x400476 0x400477 <<\EOF
127main+0x2
128/home/jistone/src/elfutils/tests/testfile53-64.c:2
129main+0x3
130/home/jistone/src/elfutils/tests/testfile53-64.c:2
131EOF
132
133
134# testfile54.c:
135#   extern void * stdin;
136#   static void * pstdin = &stdin;
137#   void * const foo = &pstdin;
138#
139# gcc -m32 -g -shared -nostartfiles testfile54-32.c -o testfile54-32.so
140# eu-strip -f testfile54-32.so.debug testfile54-32.so
141# cp testfile54-32.so testfile54-32.prelink.so
142# prelink -N testfile54-32.prelink.so
143# cp testfile54-32.so testfile54-32.noshdrs.so
144# prelink -r 0x42000000 testfile54-32.noshdrs.so
145# eu-strip --remove-comment --strip-sections testfile54-32.noshdrs.so
146testfiles testfile54-32.so testfile54-32.so.debug
147testfiles testfile54-32.prelink.so testfile54-32.noshdrs.so
148tempfiles testmaps54-32
149
150# Note we have no testfile54-32.noshdrs.so.debug link here, so
151# this is testing finding the symbols in .dynsym via PT_DYNAMIC.
152
153cat > testmaps54-32 <<EOF
15400111000-00112000 r--p 00000000 fd:01 1 `pwd`/testfile54-32.so
15500112000-00113000 rw-p 00000000 fd:01 1 `pwd`/testfile54-32.so
15641000000-41001000 r--p 00000000 fd:01 2 `pwd`/testfile54-32.prelink.so
15741001000-41002000 rw-p 00000000 fd:01 2 `pwd`/testfile54-32.prelink.so
15842000000-42001000 r--p 00000000 fd:01 3 `pwd`/testfile54-32.noshdrs.so
15942001000-42002000 rw-p 00000000 fd:01 3 `pwd`/testfile54-32.noshdrs.so
160EOF
161
162testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps54-32 \
163    0x1111fc 0x1122a4 0x410001fd 0x410012a5 0x420001fe <<\EOF
164foo
165??:0
166pstdin
167??:0
168foo+0x1
169??:0
170pstdin+0x1
171??:0
172foo+0x2
173??:0
174EOF
175
176# Repeat testfile64 in 64-bit
177testfiles testfile54-64.so testfile54-64.so.debug
178testfiles testfile54-64.prelink.so testfile54-64.noshdrs.so
179tempfiles testmaps54-64
180
181# Note we have no testfile54-64.noshdrs.so.debug link here, so
182# this is testing finding the symbols in .dynsym via PT_DYNAMIC.
183
184cat > testmaps54-64 <<EOF
1851000000000-1000001000 r--p 00000000 fd:11 1 `pwd`/testfile54-64.so
1861000001000-1000200000 ---p 00001000 fd:11 1 `pwd`/testfile54-64.so
1871000200000-1000201000 rw-p 00000000 fd:11 1 `pwd`/testfile54-64.so
1883000000000-3000001000 r--p 00000000 fd:11 2 `pwd`/testfile54-64.prelink.so
1893000001000-3000200000 ---p 00001000 fd:11 2 `pwd`/testfile54-64.prelink.so
1903000200000-3000201000 rw-p 00000000 fd:11 2 `pwd`/testfile54-64.prelink.so
1913800000000-3800001000 r--p 00000000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
1923800001000-3800200000 ---p 00001000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
1933800200000-3800201000 rw-p 00000000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
194EOF
195
196testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps54-64 \
197    0x10000002f8 0x1000200448 0x30000002f9 0x3000200449 0x38000002fa <<\EOF
198foo
199??:0
200pstdin
201??:0
202foo+0x1
203??:0
204pstdin+0x1
205??:0
206foo+0x2
207??:0
208EOF
209
210
211# testfile55.c:
212#   extern void *stdin;
213#   int main() { return !stdin; }
214#
215# gcc -m32 -g testfile55-32.c -o testfile55-32
216# eu-strip -f testfile55-32.debug testfile55-32
217# cp testfile55-32 testfile55-32.prelink
218# prelink -N testfile55-32.prelink
219testfiles testfile55-32 testfile55-32.debug testfile55-32.prelink
220
221testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-32 0x80483b4 0x80483b5 <<\EOF
222main
223/home/jistone/src/elfutils/tests/testfile55-32.c:2
224main+0x1
225/home/jistone/src/elfutils/tests/testfile55-32.c:2
226EOF
227
228# prelink splits .bss into .dynbss+.bss, so the start of .bss changes, but the
229# total size remains the same, and .text doesn't move at all.
230testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-32.prelink 0x80483b6 0x80483b7 <<\EOF
231main+0x2
232/home/jistone/src/elfutils/tests/testfile55-32.c:2
233main+0x3
234/home/jistone/src/elfutils/tests/testfile55-32.c:2
235EOF
236
237# Repeat testfile55 in 64-bit
238testfiles testfile55-64 testfile55-64.debug testfile55-64.prelink
239
240testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-64 0x4004b4 0x4004b5 <<\EOF
241main
242/home/jistone/src/elfutils/tests/testfile55-64.c:2
243main+0x1
244/home/jistone/src/elfutils/tests/testfile55-64.c:2
245EOF
246
247testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-64.prelink 0x4004b6 0x4004b7 <<\EOF
248main+0x2
249/home/jistone/src/elfutils/tests/testfile55-64.c:2
250main+0x3
251/home/jistone/src/elfutils/tests/testfile55-64.c:2
252EOF
253