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