Home | History | Annotate | Download | only in tests
      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 
     33 testfiles testfile52-32.so testfile52-32.so.debug
     34 testfiles testfile52-32.prelink.so testfile52-32.noshdrs.so
     35 tempfiles testmaps52-32 testfile52-32.noshdrs.so.debug
     36 ln -snf testfile52-32.so.debug testfile52-32.noshdrs.so.debug
     37 
     38 cat > testmaps52-32 <<EOF
     39 00111000-00112000 r-xp 00000000 fd:01 1 `pwd`/testfile52-32.so
     40 00112000-00113000 rw-p 00000000 fd:01 1 `pwd`/testfile52-32.so
     41 41000000-41001000 r-xp 00000000 fd:01 2 `pwd`/testfile52-32.prelink.so
     42 41001000-41002000 rw-p 00000000 fd:01 2 `pwd`/testfile52-32.prelink.so
     43 42000000-42001000 r-xp 00000000 fd:01 3 `pwd`/testfile52-32.noshdrs.so
     44 42001000-42002000 rw-p 00000000 fd:01 3 `pwd`/testfile52-32.noshdrs.so
     45 EOF
     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.
     50 testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps52-32 \
     51     0x11140c 0x4100042d 0x4200040e <<\EOF
     52 foo
     53 /home/jistone/src/elfutils/tests/testfile52-32.c:2
     54 foo+0x1
     55 /home/jistone/src/elfutils/tests/testfile52-32.c:2
     56 foo+0x2
     57 /home/jistone/src/elfutils/tests/testfile52-32.c:2
     58 EOF
     59 
     60 # Repeat testfile52 for -m64.  The particular REL>RELA issue doesn't exist, but
     61 # we'll make sure the rest works anyway.
     62 testfiles testfile52-64.so testfile52-64.so.debug
     63 testfiles testfile52-64.prelink.so testfile52-64.noshdrs.so
     64 tempfiles testmaps52-64 testfile52-64.noshdrs.so.debug
     65 ln -snf testfile52-64.so.debug testfile52-64.noshdrs.so.debug
     66 
     67 cat > testmaps52-64 <<EOF
     68 1000000000-1000001000 r-xp 00000000 fd:11 1 `pwd`/testfile52-64.so
     69 1000001000-1000200000 ---p 00001000 fd:11 1 `pwd`/testfile52-64.so
     70 1000200000-1000201000 rw-p 00000000 fd:11 1 `pwd`/testfile52-64.so
     71 3000000000-3000001000 r-xp 00000000 fd:11 2 `pwd`/testfile52-64.prelink.so
     72 3000001000-3000200000 ---p 00001000 fd:11 2 `pwd`/testfile52-64.prelink.so
     73 3000200000-3000201000 rw-p 00000000 fd:11 2 `pwd`/testfile52-64.prelink.so
     74 3800000000-3800001000 r-xp 00000000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
     75 3800001000-3800200000 ---p 00001000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
     76 3800200000-3800201000 rw-p 00000000 fd:11 3 `pwd`/testfile52-64.noshdrs.so
     77 EOF
     78 
     79 testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps52-64 \
     80     0x100000056c 0x300000056d 0x380000056e <<\EOF
     81 foo
     82 /home/jistone/src/elfutils/tests/testfile52-64.c:2
     83 foo+0x1
     84 /home/jistone/src/elfutils/tests/testfile52-64.c:2
     85 foo+0x2
     86 /home/jistone/src/elfutils/tests/testfile52-64.c:2
     87 EOF
     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
     98 testfiles testfile53-32 testfile53-32.debug testfile53-32.prelink
     99 
    100 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-32 0x8048394 0x8048395 <<\EOF
    101 main
    102 /home/jistone/src/elfutils/tests/testfile53-32.c:2
    103 main+0x1
    104 /home/jistone/src/elfutils/tests/testfile53-32.c:2
    105 EOF
    106 
    107 # prelink shuffled some of the sections, but .text is in the same place.
    108 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-32.prelink 0x8048396 0x8048397 <<\EOF
    109 main+0x2
    110 /home/jistone/src/elfutils/tests/testfile53-32.c:2
    111 main+0x3
    112 /home/jistone/src/elfutils/tests/testfile53-32.c:2
    113 EOF
    114 
    115 # Repeat testfile53 in 64-bit, except use foo[0x800] to achieve the same
    116 # prelink section shuffling.
    117 testfiles testfile53-64 testfile53-64.debug testfile53-64.prelink
    118 
    119 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-64 0x400474 0x400475 <<\EOF
    120 main
    121 /home/jistone/src/elfutils/tests/testfile53-64.c:2
    122 main+0x1
    123 /home/jistone/src/elfutils/tests/testfile53-64.c:2
    124 EOF
    125 
    126 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile53-64.prelink 0x400476 0x400477 <<\EOF
    127 main+0x2
    128 /home/jistone/src/elfutils/tests/testfile53-64.c:2
    129 main+0x3
    130 /home/jistone/src/elfutils/tests/testfile53-64.c:2
    131 EOF
    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
    146 testfiles testfile54-32.so testfile54-32.so.debug
    147 testfiles testfile54-32.prelink.so testfile54-32.noshdrs.so
    148 tempfiles 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 
    153 cat > testmaps54-32 <<EOF
    154 00111000-00112000 r--p 00000000 fd:01 1 `pwd`/testfile54-32.so
    155 00112000-00113000 rw-p 00000000 fd:01 1 `pwd`/testfile54-32.so
    156 41000000-41001000 r--p 00000000 fd:01 2 `pwd`/testfile54-32.prelink.so
    157 41001000-41002000 rw-p 00000000 fd:01 2 `pwd`/testfile54-32.prelink.so
    158 42000000-42001000 r--p 00000000 fd:01 3 `pwd`/testfile54-32.noshdrs.so
    159 42001000-42002000 rw-p 00000000 fd:01 3 `pwd`/testfile54-32.noshdrs.so
    160 EOF
    161 
    162 testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps54-32 \
    163     0x1111fc 0x1122a4 0x410001fd 0x410012a5 0x420001fe <<\EOF
    164 foo
    165 ??:0
    166 pstdin
    167 ??:0
    168 foo+0x1
    169 ??:0
    170 pstdin+0x1
    171 ??:0
    172 foo+0x2
    173 ??:0
    174 EOF
    175 
    176 # Repeat testfile64 in 64-bit
    177 testfiles testfile54-64.so testfile54-64.so.debug
    178 testfiles testfile54-64.prelink.so testfile54-64.noshdrs.so
    179 tempfiles 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 
    184 cat > testmaps54-64 <<EOF
    185 1000000000-1000001000 r--p 00000000 fd:11 1 `pwd`/testfile54-64.so
    186 1000001000-1000200000 ---p 00001000 fd:11 1 `pwd`/testfile54-64.so
    187 1000200000-1000201000 rw-p 00000000 fd:11 1 `pwd`/testfile54-64.so
    188 3000000000-3000001000 r--p 00000000 fd:11 2 `pwd`/testfile54-64.prelink.so
    189 3000001000-3000200000 ---p 00001000 fd:11 2 `pwd`/testfile54-64.prelink.so
    190 3000200000-3000201000 rw-p 00000000 fd:11 2 `pwd`/testfile54-64.prelink.so
    191 3800000000-3800001000 r--p 00000000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
    192 3800001000-3800200000 ---p 00001000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
    193 3800200000-3800201000 rw-p 00000000 fd:11 3 `pwd`/testfile54-64.noshdrs.so
    194 EOF
    195 
    196 testrun_compare ${abs_top_builddir}/src/addr2line -S -M testmaps54-64 \
    197     0x10000002f8 0x1000200448 0x30000002f9 0x3000200449 0x38000002fa <<\EOF
    198 foo
    199 ??:0
    200 pstdin
    201 ??:0
    202 foo+0x1
    203 ??:0
    204 pstdin+0x1
    205 ??:0
    206 foo+0x2
    207 ??:0
    208 EOF
    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
    219 testfiles testfile55-32 testfile55-32.debug testfile55-32.prelink
    220 
    221 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-32 0x80483b4 0x80483b5 <<\EOF
    222 main
    223 /home/jistone/src/elfutils/tests/testfile55-32.c:2
    224 main+0x1
    225 /home/jistone/src/elfutils/tests/testfile55-32.c:2
    226 EOF
    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.
    230 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-32.prelink 0x80483b6 0x80483b7 <<\EOF
    231 main+0x2
    232 /home/jistone/src/elfutils/tests/testfile55-32.c:2
    233 main+0x3
    234 /home/jistone/src/elfutils/tests/testfile55-32.c:2
    235 EOF
    236 
    237 # Repeat testfile55 in 64-bit
    238 testfiles testfile55-64 testfile55-64.debug testfile55-64.prelink
    239 
    240 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-64 0x4004b4 0x4004b5 <<\EOF
    241 main
    242 /home/jistone/src/elfutils/tests/testfile55-64.c:2
    243 main+0x1
    244 /home/jistone/src/elfutils/tests/testfile55-64.c:2
    245 EOF
    246 
    247 testrun_compare ${abs_top_builddir}/src/addr2line -S -e testfile55-64.prelink 0x4004b6 0x4004b7 <<\EOF
    248 main+0x2
    249 /home/jistone/src/elfutils/tests/testfile55-64.c:2
    250 main+0x3
    251 /home/jistone/src/elfutils/tests/testfile55-64.c:2
    252 EOF
    253