summaryrefslogtreecommitdiffstats
path: root/tests/run-annobingroup.sh
blob: 700df321052321fe73f58d6591be28db51de2362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#! /bin/sh
# Copyright (C) 2018 Red Hat, Inc.
# This file is part of elfutils.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# elfutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

. $srcdir/test-subr.sh

# Testfile generated by annobin, creates group.
# strip and unstrip it. Check group symbol/name is correct.

# echo "int __attribute__((cold)) foo (void) { return 42; }" \
#      > testfile-annobingroup.c
# gcc -g -O2 -fplugin=annobin -c testfile-annobingroup.c
testfiles testfile-annobingroup.o

tempfiles merged.elf stripped.elf debugfile.elf remerged.elf

testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup.o << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 7] .gnu.build.attributes..text.unlikely
  [ 8] .rela.gnu.build.attributes..text.unlikely
  [ 9] .text.unlikely
EOF

testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup.o

testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 7] .gnu.build.attributes..text.unlikely
  [ 8] .rela.gnu.build.attributes..text.unlikely
  [ 9] .text.unlikely
EOF

testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 7] .gnu.build.attributes..text.unlikely
  [ 8] .rela.gnu.build.attributes..text.unlikely
  [ 9] .text.unlikely
EOF

testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile.elf

testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 7] .gnu.build.attributes..text.unlikely
  [ 8] .rela.gnu.build.attributes..text.unlikely
  [ 9] .text.unlikely
EOF

testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup.o remerged.elf

# echo "void * __attribute__((cold)) foo (void) { return foo; }"
#      > testfile-annobingroup-i386.c
# gcc -fpic -g -O2 -fplugin=annobin -c testfile-annobingroup-i386.c
testfiles testfile-annobingroup-i386.o

testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-i386.o << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 8] .gnu.build.attributes..text.unlikely
  [ 9] .rel.gnu.build.attributes..text.unlikely
  [10] .text.unlikely

COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
  [13] .text.__x86.get_pc_thunk.ax
EOF

testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup-i386.o

testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 8] .gnu.build.attributes..text.unlikely
  [ 9] .rel.gnu.build.attributes..text.unlikely
  [10] .text.unlikely

COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
  [13] .text.__x86.get_pc_thunk.ax
EOF

testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 8] .gnu.build.attributes..text.unlikely
  [ 9] .rel.gnu.build.attributes..text.unlikely
  [10] .text.unlikely

COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
  [13] .text.__x86.get_pc_thunk.ax
EOF

testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile.elf

testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF

Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
  [ 8] .gnu.build.attributes..text.unlikely
  [ 9] .rel.gnu.build.attributes..text.unlikely
  [10] .text.unlikely

COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
  [13] .text.__x86.get_pc_thunk.ax
EOF

testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-i386.o remerged.elf

exit 0