Home | History | Annotate | Download | only in tests
      1 #! /bin/sh
      2 # Copyright (C) 2018 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 # Testfile generated by annobin, creates group.
     21 # strip and unstrip it. Check group symbol/name is correct.
     22 
     23 # echo "int __attribute__((cold)) foo (void) { return 42; }" \
     24 #      > testfile-annobingroup.c
     25 # gcc -g -O2 -fplugin=annobin -c testfile-annobingroup.c
     26 testfiles testfile-annobingroup.o
     27 
     28 tempfiles merged.elf stripped.elf debugfile1.elf debugfile2.elf debugfile3.elf remerged.elf
     29 
     30 testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup.o << EOF
     31 
     32 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
     33   [ 7] .gnu.build.attributes..text.unlikely
     34   [ 8] .rela.gnu.build.attributes..text.unlikely
     35   [ 9] .text.unlikely
     36 EOF
     37 
     38 testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile1.elf testfile-annobingroup.o
     39 
     40 testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
     41 
     42 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
     43   [ 7] .gnu.build.attributes..text.unlikely
     44   [ 8] .rela.gnu.build.attributes..text.unlikely
     45   [ 9] .text.unlikely
     46 EOF
     47 
     48 testrun_compare ${abs_top_builddir}/src/readelf -g debugfile1.elf << EOF
     49 
     50 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
     51   [ 7] .gnu.build.attributes..text.unlikely
     52   [ 8] .rela.gnu.build.attributes..text.unlikely
     53   [ 9] .text.unlikely
     54 EOF
     55 
     56 testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile1.elf
     57 
     58 testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
     59 
     60 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
     61   [ 7] .gnu.build.attributes..text.unlikely
     62   [ 8] .rela.gnu.build.attributes..text.unlikely
     63   [ 9] .text.unlikely
     64 EOF
     65 
     66 testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup.o remerged.elf
     67 
     68 # echo "void * __attribute__((cold)) foo (void) { return foo; }"
     69 #      > testfile-annobingroup-i386.c
     70 # gcc -fpic -g -O2 -fplugin=annobin -c testfile-annobingroup-i386.c
     71 testfiles testfile-annobingroup-i386.o
     72 
     73 testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-i386.o << EOF
     74 
     75 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
     76   [ 8] .gnu.build.attributes..text.unlikely
     77   [ 9] .rel.gnu.build.attributes..text.unlikely
     78   [10] .text.unlikely
     79 
     80 COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
     81   [13] .text.__x86.get_pc_thunk.ax
     82 EOF
     83 
     84 testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile2.elf testfile-annobingroup-i386.o
     85 
     86 testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
     87 
     88 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
     89   [ 8] .gnu.build.attributes..text.unlikely
     90   [ 9] .rel.gnu.build.attributes..text.unlikely
     91   [10] .text.unlikely
     92 
     93 COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
     94   [13] .text.__x86.get_pc_thunk.ax
     95 EOF
     96 
     97 testrun_compare ${abs_top_builddir}/src/readelf -g debugfile2.elf << EOF
     98 
     99 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
    100   [ 8] .gnu.build.attributes..text.unlikely
    101   [ 9] .rel.gnu.build.attributes..text.unlikely
    102   [10] .text.unlikely
    103 
    104 COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
    105   [13] .text.__x86.get_pc_thunk.ax
    106 EOF
    107 
    108 testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile2.elf
    109 
    110 testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
    111 
    112 Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
    113   [ 8] .gnu.build.attributes..text.unlikely
    114   [ 9] .rel.gnu.build.attributes..text.unlikely
    115   [10] .text.unlikely
    116 
    117 COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
    118   [13] .text.__x86.get_pc_thunk.ax
    119 EOF
    120 
    121 testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-i386.o remerged.elf
    122 
    123 # echo "void * foo (void) { return foo; }" > testfile-annobingroup-x86_64.c
    124 # gcc -g -O2 -fplugin=annobin -c testfile-annobingroup-x86_64.c
    125 testfiles testfile-annobingroup-x86_64.o
    126 
    127 testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-x86_64.o << EOF
    128 
    129 Section group [ 1] '.group' with signature '.text.hot.group' contains 3 entries:
    130   [11] .text.hot
    131   [12] .gnu.build.attributes.hot
    132   [13] .rela.gnu.build.attributes.hot
    133 
    134 Section group [ 2] '.group' with signature '.text.unlikely.group' contains 3 entries:
    135   [14] .text.unlikely
    136   [15] .gnu.build.attributes.unlikely
    137   [16] .rela.gnu.build.attributes.unlikely
    138 
    139 Section group [ 3] '.group' with signature '.text.hot..group' contains 1 entry:
    140   [26] .text.hot
    141 
    142 Section group [ 4] '.group' with signature '.text.unlikely..group' contains 1 entry:
    143   [27] .text.unlikely
    144 EOF
    145 
    146 testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile3.elf testfile-annobingroup-x86_64.o
    147 
    148 # This would/should work, except for the unknown NOTEs.
    149 # testrun ${abs_top_builddir}/src/elflint --gnu stripped.elf
    150 # testrun ${abs_top_builddir}/src/elflint --gnu --debug debugfile3.elf
    151 
    152 testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile3.elf
    153 
    154 testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-x86_64.o remerged.elf
    155 
    156 exit 0
    157