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
26testfiles testfile-annobingroup.o
27
28tempfiles merged.elf stripped.elf debugfile1.elf debugfile2.elf debugfile3.elf remerged.elf
29
30testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup.o << EOF
31
32Section 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
36EOF
37
38testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile1.elf testfile-annobingroup.o
39
40testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
41
42Section 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
46EOF
47
48testrun_compare ${abs_top_builddir}/src/readelf -g debugfile1.elf << EOF
49
50Section 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
54EOF
55
56testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile1.elf
57
58testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
59
60Section 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
64EOF
65
66testrun ${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
71testfiles testfile-annobingroup-i386.o
72
73testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-i386.o << EOF
74
75Section 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
80COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
81  [13] .text.__x86.get_pc_thunk.ax
82EOF
83
84testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile2.elf testfile-annobingroup-i386.o
85
86testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
87
88Section 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
93COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
94  [13] .text.__x86.get_pc_thunk.ax
95EOF
96
97testrun_compare ${abs_top_builddir}/src/readelf -g debugfile2.elf << EOF
98
99Section 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
104COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
105  [13] .text.__x86.get_pc_thunk.ax
106EOF
107
108testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile2.elf
109
110testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
111
112Section 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
117COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
118  [13] .text.__x86.get_pc_thunk.ax
119EOF
120
121testrun ${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
125testfiles testfile-annobingroup-x86_64.o
126
127testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-x86_64.o << EOF
128
129Section 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
134Section 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
139Section group [ 3] '.group' with signature '.text.hot..group' contains 1 entry:
140  [26] .text.hot
141
142Section group [ 4] '.group' with signature '.text.unlikely..group' contains 1 entry:
143  [27] .text.unlikely
144EOF
145
146testrun ${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
152testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile3.elf
153
154testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-x86_64.o remerged.elf
155
156exit 0
157