blob: 3398c0d1321042052c94fa433049cfa2caac1380 [file] [log] [blame]
Josh Stoneffa02002011-01-10 21:28:46 -08001#! /bin/sh
Roland McGrath3f9256d2013-01-07 15:13:46 -08002# Copyright (C) 2011-2013 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003# This file is part of elfutils.
Josh Stoneffa02002011-01-10 21:28:46 -08004#
Mark Wielaardde2ed972012-06-05 17:15:16 +02005# 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.
Josh Stoneffa02002011-01-10 21:28:46 -08009#
Mark Wielaardde2ed972012-06-05 17:15:16 +020010# elfutils is distributed in the hope that it will be useful, but
Josh Stoneffa02002011-01-10 21:28:46 -080011# WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020012# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
Josh Stoneffa02002011-01-10 21:28:46 -080014#
Mark Wielaardde2ed972012-06-05 17:15:16 +020015# 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/>.
Josh Stoneffa02002011-01-10 21:28:46 -080017
18. $srcdir/test-subr.sh
19
20
21# testfile52.c:
22# #include <stdlib.h>
23# int foo() { exit(0); }
24#
Josh Stoned41d9a62011-01-11 19:16:57 -080025# 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
Josh Stoneffa02002011-01-10 21:28:46 -080032
Josh Stoned41d9a62011-01-11 19:16:57 -080033testfiles testfile52-32.so testfile52-32.so.debug
34testfiles testfile52-32.prelink.so testfile52-32.noshdrs.so
Roland McGrath32520bd2011-01-12 10:43:32 -080035tempfiles testmaps52-32 testfile52-32.noshdrs.so.debug
Roland McGrath3f9256d2013-01-07 15:13:46 -080036ln -snf testfile52-32.so.debug testfile52-32.noshdrs.so.debug
Josh Stoneffa02002011-01-10 21:28:46 -080037
Josh Stoned41d9a62011-01-11 19:16:57 -080038cat > 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
Josh Stoneffa02002011-01-10 21:28:46 -080045EOF
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.
Mark Wielaard86be7922013-04-26 23:44:25 +020050testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps52-32 \
Josh Stoned41d9a62011-01-11 19:16:57 -080051 0x11140c 0x4100042d 0x4200040e <<\EOF
Josh Stoneffa02002011-01-10 21:28:46 -080052foo
Josh Stoned41d9a62011-01-11 19:16:57 -080053/home/jistone/src/elfutils/tests/testfile52-32.c:2
Josh Stoneffa02002011-01-10 21:28:46 -080054foo+0x1
Josh Stoned41d9a62011-01-11 19:16:57 -080055/home/jistone/src/elfutils/tests/testfile52-32.c:2
56foo+0x2
Roland McGrath32520bd2011-01-12 10:43:32 -080057/home/jistone/src/elfutils/tests/testfile52-32.c:2
Josh Stoned41d9a62011-01-11 19:16:57 -080058EOF
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
Roland McGrath32520bd2011-01-12 10:43:32 -080064tempfiles testmaps52-64 testfile52-64.noshdrs.so.debug
Roland McGrath3f9256d2013-01-07 15:13:46 -080065ln -snf testfile52-64.so.debug testfile52-64.noshdrs.so.debug
Josh Stoned41d9a62011-01-11 19:16:57 -080066
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
Mark Wielaard86be7922013-04-26 23:44:25 +020079testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps52-64 \
Josh Stoned41d9a62011-01-11 19:16:57 -080080 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
Roland McGrath32520bd2011-01-12 10:43:32 -080086/home/jistone/src/elfutils/tests/testfile52-64.c:2
Josh Stoneffa02002011-01-10 21:28:46 -080087EOF
88
89
90# testfile53.c:
Josh Stonecf514712011-01-11 19:16:58 -080091# char foo[0x1000];
Josh Stoneffa02002011-01-10 21:28:46 -080092# int main() { return 0; }
93#
Josh Stonecf514712011-01-11 19:16:58 -080094# 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
Josh Stoneffa02002011-01-10 21:28:46 -080099
Mark Wielaard86be7922013-04-26 23:44:25 +0200100testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-32 0x8048394 0x8048395 <<\EOF
Josh Stoneffa02002011-01-10 21:28:46 -0800101main
Josh Stonecf514712011-01-11 19:16:58 -0800102/home/jistone/src/elfutils/tests/testfile53-32.c:2
Josh Stoneffa02002011-01-10 21:28:46 -0800103main+0x1
Josh Stonecf514712011-01-11 19:16:58 -0800104/home/jistone/src/elfutils/tests/testfile53-32.c:2
Josh Stoneffa02002011-01-10 21:28:46 -0800105EOF
106
107# prelink shuffled some of the sections, but .text is in the same place.
Mark Wielaard86be7922013-04-26 23:44:25 +0200108testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-32.prelink 0x8048396 0x8048397 <<\EOF
Josh Stoneffa02002011-01-10 21:28:46 -0800109main+0x2
Josh Stonecf514712011-01-11 19:16:58 -0800110/home/jistone/src/elfutils/tests/testfile53-32.c:2
Josh Stoneffa02002011-01-10 21:28:46 -0800111main+0x3
Josh Stonecf514712011-01-11 19:16:58 -0800112/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
Mark Wielaard86be7922013-04-26 23:44:25 +0200119testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-64 0x400474 0x400475 <<\EOF
Josh Stonecf514712011-01-11 19:16:58 -0800120main
121/home/jistone/src/elfutils/tests/testfile53-64.c:2
122main+0x1
123/home/jistone/src/elfutils/tests/testfile53-64.c:2
124EOF
125
Mark Wielaard86be7922013-04-26 23:44:25 +0200126testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-64.prelink 0x400476 0x400477 <<\EOF
Josh Stonecf514712011-01-11 19:16:58 -0800127main+0x2
128/home/jistone/src/elfutils/tests/testfile53-64.c:2
129main+0x3
130/home/jistone/src/elfutils/tests/testfile53-64.c:2
Josh Stoneffa02002011-01-10 21:28:46 -0800131EOF
Josh Stoneccbccef2011-01-11 19:16:59 -0800132
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
Roland McGrath4f6d4e12011-01-12 10:49:40 -0800148tempfiles 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.
Josh Stoneccbccef2011-01-11 19:16:59 -0800152
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
Mark Wielaard86be7922013-04-26 23:44:25 +0200162testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps54-32 \
Josh Stoneccbccef2011-01-11 19:16:59 -0800163 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
Roland McGrath4f6d4e12011-01-12 10:49:40 -0800179tempfiles 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.
Josh Stoneccbccef2011-01-11 19:16:59 -0800183
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
Mark Wielaard86be7922013-04-26 23:44:25 +0200196testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps54-64 \
Josh Stoneccbccef2011-01-11 19:16:59 -0800197 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
Josh Stonedc34eda2011-02-02 16:30:01 -0800209
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
Mark Wielaard86be7922013-04-26 23:44:25 +0200221testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-32 0x80483b4 0x80483b5 <<\EOF
Josh Stonedc34eda2011-02-02 16:30:01 -0800222main
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.
Mark Wielaard86be7922013-04-26 23:44:25 +0200230testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-32.prelink 0x80483b6 0x80483b7 <<\EOF
Josh Stonedc34eda2011-02-02 16:30:01 -0800231main+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
Mark Wielaard86be7922013-04-26 23:44:25 +0200240testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-64 0x4004b4 0x4004b5 <<\EOF
Josh Stonedc34eda2011-02-02 16:30:01 -0800241main
242/home/jistone/src/elfutils/tests/testfile55-64.c:2
243main+0x1
244/home/jistone/src/elfutils/tests/testfile55-64.c:2
245EOF
246
Mark Wielaard86be7922013-04-26 23:44:25 +0200247testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-64.prelink 0x4004b6 0x4004b7 <<\EOF
Josh Stonedc34eda2011-02-02 16:30:01 -0800248main+0x2
249/home/jistone/src/elfutils/tests/testfile55-64.c:2
250main+0x3
251/home/jistone/src/elfutils/tests/testfile55-64.c:2
252EOF