xref: /aosp_15_r20/external/elfutils/tests/run-annobingroup.sh (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker#! /bin/sh
2*7304104dSAndroid Build Coastguard Worker# Copyright (C) 2018 Red Hat, Inc.
3*7304104dSAndroid Build Coastguard Worker# This file is part of elfutils.
4*7304104dSAndroid Build Coastguard Worker#
5*7304104dSAndroid Build Coastguard Worker# This file is free software; you can redistribute it and/or modify
6*7304104dSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by
7*7304104dSAndroid Build Coastguard Worker# the Free Software Foundation; either version 3 of the License, or
8*7304104dSAndroid Build Coastguard Worker# (at your option) any later version.
9*7304104dSAndroid Build Coastguard Worker#
10*7304104dSAndroid Build Coastguard Worker# elfutils is distributed in the hope that it will be useful, but
11*7304104dSAndroid Build Coastguard Worker# WITHOUT ANY WARRANTY; without even the implied warranty of
12*7304104dSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*7304104dSAndroid Build Coastguard Worker# GNU General Public License for more details.
14*7304104dSAndroid Build Coastguard Worker#
15*7304104dSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License
16*7304104dSAndroid Build Coastguard Worker# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17*7304104dSAndroid Build Coastguard Worker
18*7304104dSAndroid Build Coastguard Worker. $srcdir/test-subr.sh
19*7304104dSAndroid Build Coastguard Worker
20*7304104dSAndroid Build Coastguard Worker# Testfile generated by annobin, creates group.
21*7304104dSAndroid Build Coastguard Worker# strip and unstrip it. Check group symbol/name is correct.
22*7304104dSAndroid Build Coastguard Worker
23*7304104dSAndroid Build Coastguard Worker# echo "int __attribute__((cold)) foo (void) { return 42; }" \
24*7304104dSAndroid Build Coastguard Worker#      > testfile-annobingroup.c
25*7304104dSAndroid Build Coastguard Worker# gcc -g -O2 -fplugin=annobin -c testfile-annobingroup.c
26*7304104dSAndroid Build Coastguard Workertestfiles testfile-annobingroup.o
27*7304104dSAndroid Build Coastguard Worker
28*7304104dSAndroid Build Coastguard Workertempfiles merged.elf stripped.elf debugfile1.elf debugfile2.elf debugfile3.elf remerged.elf
29*7304104dSAndroid Build Coastguard Worker
30*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup.o << EOF
31*7304104dSAndroid Build Coastguard Worker
32*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
33*7304104dSAndroid Build Coastguard Worker  [ 7] .gnu.build.attributes..text.unlikely
34*7304104dSAndroid Build Coastguard Worker  [ 8] .rela.gnu.build.attributes..text.unlikely
35*7304104dSAndroid Build Coastguard Worker  [ 9] .text.unlikely
36*7304104dSAndroid Build Coastguard WorkerEOF
37*7304104dSAndroid Build Coastguard Worker
38*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile1.elf testfile-annobingroup.o
39*7304104dSAndroid Build Coastguard Worker
40*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
41*7304104dSAndroid Build Coastguard Worker
42*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
43*7304104dSAndroid Build Coastguard Worker  [ 7] .gnu.build.attributes..text.unlikely
44*7304104dSAndroid Build Coastguard Worker  [ 8] .rela.gnu.build.attributes..text.unlikely
45*7304104dSAndroid Build Coastguard Worker  [ 9] .text.unlikely
46*7304104dSAndroid Build Coastguard WorkerEOF
47*7304104dSAndroid Build Coastguard Worker
48*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g debugfile1.elf << EOF
49*7304104dSAndroid Build Coastguard Worker
50*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
51*7304104dSAndroid Build Coastguard Worker  [ 7] .gnu.build.attributes..text.unlikely
52*7304104dSAndroid Build Coastguard Worker  [ 8] .rela.gnu.build.attributes..text.unlikely
53*7304104dSAndroid Build Coastguard Worker  [ 9] .text.unlikely
54*7304104dSAndroid Build Coastguard WorkerEOF
55*7304104dSAndroid Build Coastguard Worker
56*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile1.elf
57*7304104dSAndroid Build Coastguard Worker
58*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
59*7304104dSAndroid Build Coastguard Worker
60*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
61*7304104dSAndroid Build Coastguard Worker  [ 7] .gnu.build.attributes..text.unlikely
62*7304104dSAndroid Build Coastguard Worker  [ 8] .rela.gnu.build.attributes..text.unlikely
63*7304104dSAndroid Build Coastguard Worker  [ 9] .text.unlikely
64*7304104dSAndroid Build Coastguard WorkerEOF
65*7304104dSAndroid Build Coastguard Worker
66*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup.o remerged.elf
67*7304104dSAndroid Build Coastguard Worker
68*7304104dSAndroid Build Coastguard Worker# echo "void * __attribute__((cold)) foo (void) { return foo; }"
69*7304104dSAndroid Build Coastguard Worker#      > testfile-annobingroup-i386.c
70*7304104dSAndroid Build Coastguard Worker# gcc -fpic -g -O2 -fplugin=annobin -c testfile-annobingroup-i386.c
71*7304104dSAndroid Build Coastguard Workertestfiles testfile-annobingroup-i386.o
72*7304104dSAndroid Build Coastguard Worker
73*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-i386.o << EOF
74*7304104dSAndroid Build Coastguard Worker
75*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
76*7304104dSAndroid Build Coastguard Worker  [ 8] .gnu.build.attributes..text.unlikely
77*7304104dSAndroid Build Coastguard Worker  [ 9] .rel.gnu.build.attributes..text.unlikely
78*7304104dSAndroid Build Coastguard Worker  [10] .text.unlikely
79*7304104dSAndroid Build Coastguard Worker
80*7304104dSAndroid Build Coastguard WorkerCOMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
81*7304104dSAndroid Build Coastguard Worker  [13] .text.__x86.get_pc_thunk.ax
82*7304104dSAndroid Build Coastguard WorkerEOF
83*7304104dSAndroid Build Coastguard Worker
84*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile2.elf testfile-annobingroup-i386.o
85*7304104dSAndroid Build Coastguard Worker
86*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF
87*7304104dSAndroid Build Coastguard Worker
88*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
89*7304104dSAndroid Build Coastguard Worker  [ 8] .gnu.build.attributes..text.unlikely
90*7304104dSAndroid Build Coastguard Worker  [ 9] .rel.gnu.build.attributes..text.unlikely
91*7304104dSAndroid Build Coastguard Worker  [10] .text.unlikely
92*7304104dSAndroid Build Coastguard Worker
93*7304104dSAndroid Build Coastguard WorkerCOMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
94*7304104dSAndroid Build Coastguard Worker  [13] .text.__x86.get_pc_thunk.ax
95*7304104dSAndroid Build Coastguard WorkerEOF
96*7304104dSAndroid Build Coastguard Worker
97*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g debugfile2.elf << EOF
98*7304104dSAndroid Build Coastguard Worker
99*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
100*7304104dSAndroid Build Coastguard Worker  [ 8] .gnu.build.attributes..text.unlikely
101*7304104dSAndroid Build Coastguard Worker  [ 9] .rel.gnu.build.attributes..text.unlikely
102*7304104dSAndroid Build Coastguard Worker  [10] .text.unlikely
103*7304104dSAndroid Build Coastguard Worker
104*7304104dSAndroid Build Coastguard WorkerCOMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
105*7304104dSAndroid Build Coastguard Worker  [13] .text.__x86.get_pc_thunk.ax
106*7304104dSAndroid Build Coastguard WorkerEOF
107*7304104dSAndroid Build Coastguard Worker
108*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile2.elf
109*7304104dSAndroid Build Coastguard Worker
110*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF
111*7304104dSAndroid Build Coastguard Worker
112*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries:
113*7304104dSAndroid Build Coastguard Worker  [ 8] .gnu.build.attributes..text.unlikely
114*7304104dSAndroid Build Coastguard Worker  [ 9] .rel.gnu.build.attributes..text.unlikely
115*7304104dSAndroid Build Coastguard Worker  [10] .text.unlikely
116*7304104dSAndroid Build Coastguard Worker
117*7304104dSAndroid Build Coastguard WorkerCOMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry:
118*7304104dSAndroid Build Coastguard Worker  [13] .text.__x86.get_pc_thunk.ax
119*7304104dSAndroid Build Coastguard WorkerEOF
120*7304104dSAndroid Build Coastguard Worker
121*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-i386.o remerged.elf
122*7304104dSAndroid Build Coastguard Worker
123*7304104dSAndroid Build Coastguard Worker# echo "void * foo (void) { return foo; }" > testfile-annobingroup-x86_64.c
124*7304104dSAndroid Build Coastguard Worker# gcc -g -O2 -fplugin=annobin -c testfile-annobingroup-x86_64.c
125*7304104dSAndroid Build Coastguard Workertestfiles testfile-annobingroup-x86_64.o
126*7304104dSAndroid Build Coastguard Worker
127*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-x86_64.o << EOF
128*7304104dSAndroid Build Coastguard Worker
129*7304104dSAndroid Build Coastguard WorkerSection group [ 1] '.group' with signature '.text.hot.group' contains 3 entries:
130*7304104dSAndroid Build Coastguard Worker  [11] .text.hot
131*7304104dSAndroid Build Coastguard Worker  [12] .gnu.build.attributes.hot
132*7304104dSAndroid Build Coastguard Worker  [13] .rela.gnu.build.attributes.hot
133*7304104dSAndroid Build Coastguard Worker
134*7304104dSAndroid Build Coastguard WorkerSection group [ 2] '.group' with signature '.text.unlikely.group' contains 3 entries:
135*7304104dSAndroid Build Coastguard Worker  [14] .text.unlikely
136*7304104dSAndroid Build Coastguard Worker  [15] .gnu.build.attributes.unlikely
137*7304104dSAndroid Build Coastguard Worker  [16] .rela.gnu.build.attributes.unlikely
138*7304104dSAndroid Build Coastguard Worker
139*7304104dSAndroid Build Coastguard WorkerSection group [ 3] '.group' with signature '.text.hot..group' contains 1 entry:
140*7304104dSAndroid Build Coastguard Worker  [26] .text.hot
141*7304104dSAndroid Build Coastguard Worker
142*7304104dSAndroid Build Coastguard WorkerSection group [ 4] '.group' with signature '.text.unlikely..group' contains 1 entry:
143*7304104dSAndroid Build Coastguard Worker  [27] .text.unlikely
144*7304104dSAndroid Build Coastguard WorkerEOF
145*7304104dSAndroid Build Coastguard Worker
146*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile3.elf testfile-annobingroup-x86_64.o
147*7304104dSAndroid Build Coastguard Worker
148*7304104dSAndroid Build Coastguard Worker# This would/should work, except for the unknown NOTEs.
149*7304104dSAndroid Build Coastguard Worker# testrun ${abs_top_builddir}/src/elflint --gnu stripped.elf
150*7304104dSAndroid Build Coastguard Worker# testrun ${abs_top_builddir}/src/elflint --gnu --debug debugfile3.elf
151*7304104dSAndroid Build Coastguard Worker
152*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile3.elf
153*7304104dSAndroid Build Coastguard Worker
154*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-x86_64.o remerged.elf
155*7304104dSAndroid Build Coastguard Worker
156*7304104dSAndroid Build Coastguard Workerexit 0
157