1da0c48c4Sopenharmony_ci#! /bin/sh
2da0c48c4Sopenharmony_ci# Copyright (C) 2020 Red Hat, Inc.
3da0c48c4Sopenharmony_ci# This file is part of elfutils.
4da0c48c4Sopenharmony_ci#
5da0c48c4Sopenharmony_ci# This file is free software; you can redistribute it and/or modify
6da0c48c4Sopenharmony_ci# it under the terms of the GNU General Public License as published by
7da0c48c4Sopenharmony_ci# the Free Software Foundation; either version 3 of the License, or
8da0c48c4Sopenharmony_ci# (at your option) any later version.
9da0c48c4Sopenharmony_ci#
10da0c48c4Sopenharmony_ci# elfutils is distributed in the hope that it will be useful, but
11da0c48c4Sopenharmony_ci# WITHOUT ANY WARRANTY; without even the implied warranty of
12da0c48c4Sopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13da0c48c4Sopenharmony_ci# GNU General Public License for more details.
14da0c48c4Sopenharmony_ci#
15da0c48c4Sopenharmony_ci# You should have received a copy of the GNU General Public License
16da0c48c4Sopenharmony_ci# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17da0c48c4Sopenharmony_ci
18da0c48c4Sopenharmony_ci. $srcdir/test-subr.sh
19da0c48c4Sopenharmony_ci
20da0c48c4Sopenharmony_ci# On Fedora 31 with GCC 9.2.1 and binutils 2.32-31
21da0c48c4Sopenharmony_ci# echo "int main () { }" | \
22da0c48c4Sopenharmony_ci# gcc -o testfile_pt_gnu_prop \
23da0c48c4Sopenharmony_ci#     -Os -fstack-clash-protection -fcf-protection=full -xc - && \
24da0c48c4Sopenharmony_ci# eu-strip --remove-comment -R .gnu.build.attributes testfile_pt_gnu_prop
25da0c48c4Sopenharmony_ci#
26da0c48c4Sopenharmony_ci# echo "int main () { }" | \
27da0c48c4Sopenharmony_ci# gcc -m32 -o testfile_pt_gnu_prop \
28da0c48c4Sopenharmony_ci#     -Os -fstack-clash-protection -fcf-protection=full -xc - && \
29da0c48c4Sopenharmony_ci# eu-strip --remove-comment -R .gnu.build.attributes testfile_pt_gnu_prop32
30da0c48c4Sopenharmony_ci
31da0c48c4Sopenharmony_citestfiles testfile_pt_gnu_prop testfile_pt_gnu_prop32
32da0c48c4Sopenharmony_ci
33da0c48c4Sopenharmony_citestrun_compare ${abs_top_builddir}/src/readelf -ln testfile_pt_gnu_prop32 <<\EOF
34da0c48c4Sopenharmony_ciProgram Headers:
35da0c48c4Sopenharmony_ci  Type           Offset   VirtAddr   PhysAddr   FileSiz  MemSiz   Flg Align
36da0c48c4Sopenharmony_ci  PHDR           0x000034 0x08048034 0x08048034 0x000180 0x000180 R   0x4
37da0c48c4Sopenharmony_ci  INTERP         0x0001b4 0x080481b4 0x080481b4 0x000013 0x000013 R   0x1
38da0c48c4Sopenharmony_ci	[Requesting program interpreter: /lib/ld-linux.so.2]
39da0c48c4Sopenharmony_ci  LOAD           0x000000 0x08048000 0x08048000 0x000308 0x000308 R   0x1000
40da0c48c4Sopenharmony_ci  LOAD           0x001000 0x08049000 0x08049000 0x000224 0x000224 R E 0x1000
41da0c48c4Sopenharmony_ci  LOAD           0x002000 0x0804a000 0x0804a000 0x00015c 0x00015c R   0x1000
42da0c48c4Sopenharmony_ci  LOAD           0x002f0c 0x0804bf0c 0x0804bf0c 0x000108 0x00010c RW  0x1000
43da0c48c4Sopenharmony_ci  DYNAMIC        0x002f14 0x0804bf14 0x0804bf14 0x0000e8 0x0000e8 RW  0x4
44da0c48c4Sopenharmony_ci  NOTE           0x0001c8 0x080481c8 0x080481c8 0x000060 0x000060 R   0x4
45da0c48c4Sopenharmony_ci  GNU_PROPERTY   0x0001ec 0x080481ec 0x080481ec 0x00001c 0x00001c R   0x4
46da0c48c4Sopenharmony_ci  GNU_EH_FRAME   0x00200c 0x0804a00c 0x0804a00c 0x00004c 0x00004c R   0x4
47da0c48c4Sopenharmony_ci  GNU_STACK      0x000000 0x00000000 0x00000000 0x000000 0x000000 RW  0x10
48da0c48c4Sopenharmony_ci  GNU_RELRO      0x002f0c 0x0804bf0c 0x0804bf0c 0x0000f4 0x0000f4 R   0x1
49da0c48c4Sopenharmony_ci
50da0c48c4Sopenharmony_ci Section to Segment mapping:
51da0c48c4Sopenharmony_ci  Segment Sections...
52da0c48c4Sopenharmony_ci   00     
53da0c48c4Sopenharmony_ci   01      [RO: .interp]
54da0c48c4Sopenharmony_ci   02      [RO: .interp .note.gnu.build-id .note.gnu.property .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt]
55da0c48c4Sopenharmony_ci   03      [RO: .init .plt .plt.sec .text .fini]
56da0c48c4Sopenharmony_ci   04      [RO: .rodata .eh_frame_hdr .eh_frame]
57da0c48c4Sopenharmony_ci   05      [RELRO: .init_array .fini_array .dynamic .got] .got.plt .data .bss
58da0c48c4Sopenharmony_ci   06      [RELRO: .dynamic]
59da0c48c4Sopenharmony_ci   07      [RO: .note.gnu.build-id .note.gnu.property .note.ABI-tag]
60da0c48c4Sopenharmony_ci   08      [RO: .note.gnu.property]
61da0c48c4Sopenharmony_ci   09      [RO: .eh_frame_hdr]
62da0c48c4Sopenharmony_ci   10     
63da0c48c4Sopenharmony_ci   11      [RELRO: .init_array .fini_array .dynamic .got]
64da0c48c4Sopenharmony_ci
65da0c48c4Sopenharmony_ciNote section [ 2] '.note.gnu.build-id' of 36 bytes at offset 0x1c8:
66da0c48c4Sopenharmony_ci  Owner          Data size  Type
67da0c48c4Sopenharmony_ci  GNU                   20  GNU_BUILD_ID
68da0c48c4Sopenharmony_ci    Build ID: 2fcce91f5c2532f78b00a9f5f565354d2f44bc19
69da0c48c4Sopenharmony_ci
70da0c48c4Sopenharmony_ciNote section [ 3] '.note.gnu.property' of 28 bytes at offset 0x1ec:
71da0c48c4Sopenharmony_ci  Owner          Data size  Type
72da0c48c4Sopenharmony_ci  GNU                   12  GNU_PROPERTY_TYPE_0
73da0c48c4Sopenharmony_ci    X86 FEATURE_1_AND: 00000003 IBT SHSTK
74da0c48c4Sopenharmony_ci
75da0c48c4Sopenharmony_ciNote section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x208:
76da0c48c4Sopenharmony_ci  Owner          Data size  Type
77da0c48c4Sopenharmony_ci  GNU                   16  GNU_ABI_TAG
78da0c48c4Sopenharmony_ci    OS: Linux, ABI: 3.2.0
79da0c48c4Sopenharmony_ciEOF
80da0c48c4Sopenharmony_ci
81da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/src/elflint --gnu testfile_pt_gnu_prop32
82da0c48c4Sopenharmony_ci
83da0c48c4Sopenharmony_citestrun_compare ${abs_top_builddir}/src/readelf -ln testfile_pt_gnu_prop <<\EOF
84da0c48c4Sopenharmony_ciProgram Headers:
85da0c48c4Sopenharmony_ci  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
86da0c48c4Sopenharmony_ci  PHDR           0x000040 0x0000000000400040 0x0000000000400040 0x0002d8 0x0002d8 R   0x8
87da0c48c4Sopenharmony_ci  INTERP         0x000318 0x0000000000400318 0x0000000000400318 0x00001c 0x00001c R   0x1
88da0c48c4Sopenharmony_ci	[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
89da0c48c4Sopenharmony_ci  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x000498 0x000498 R   0x1000
90da0c48c4Sopenharmony_ci  LOAD           0x001000 0x0000000000401000 0x0000000000401000 0x0001a5 0x0001a5 R E 0x1000
91da0c48c4Sopenharmony_ci  LOAD           0x002000 0x0000000000402000 0x0000000000402000 0x000100 0x000100 R   0x1000
92da0c48c4Sopenharmony_ci  LOAD           0x002e50 0x0000000000403e50 0x0000000000403e50 0x0001cc 0x0001d0 RW  0x1000
93da0c48c4Sopenharmony_ci  DYNAMIC        0x002e60 0x0000000000403e60 0x0000000000403e60 0x000190 0x000190 RW  0x8
94da0c48c4Sopenharmony_ci  NOTE           0x000338 0x0000000000400338 0x0000000000400338 0x000020 0x000020 R   0x8
95da0c48c4Sopenharmony_ci  NOTE           0x000358 0x0000000000400358 0x0000000000400358 0x000044 0x000044 R   0x4
96da0c48c4Sopenharmony_ci  GNU_PROPERTY   0x000338 0x0000000000400338 0x0000000000400338 0x000020 0x000020 R   0x8
97da0c48c4Sopenharmony_ci  GNU_EH_FRAME   0x002010 0x0000000000402010 0x0000000000402010 0x000034 0x000034 R   0x4
98da0c48c4Sopenharmony_ci  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x10
99da0c48c4Sopenharmony_ci  GNU_RELRO      0x002e50 0x0000000000403e50 0x0000000000403e50 0x0001b0 0x0001b0 R   0x1
100da0c48c4Sopenharmony_ci
101da0c48c4Sopenharmony_ci Section to Segment mapping:
102da0c48c4Sopenharmony_ci  Segment Sections...
103da0c48c4Sopenharmony_ci   00     
104da0c48c4Sopenharmony_ci   01      [RO: .interp]
105da0c48c4Sopenharmony_ci   02      [RO: .interp .note.gnu.property .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn]
106da0c48c4Sopenharmony_ci   03      [RO: .init .text .fini]
107da0c48c4Sopenharmony_ci   04      [RO: .rodata .eh_frame_hdr .eh_frame]
108da0c48c4Sopenharmony_ci   05      [RELRO: .init_array .fini_array .dynamic .got] .got.plt .data .bss
109da0c48c4Sopenharmony_ci   06      [RELRO: .dynamic]
110da0c48c4Sopenharmony_ci   07      [RO: .note.gnu.property]
111da0c48c4Sopenharmony_ci   08      [RO: .note.gnu.build-id .note.ABI-tag]
112da0c48c4Sopenharmony_ci   09      [RO: .note.gnu.property]
113da0c48c4Sopenharmony_ci   10      [RO: .eh_frame_hdr]
114da0c48c4Sopenharmony_ci   11     
115da0c48c4Sopenharmony_ci   12      [RELRO: .init_array .fini_array .dynamic .got]
116da0c48c4Sopenharmony_ci
117da0c48c4Sopenharmony_ciNote section [ 2] '.note.gnu.property' of 32 bytes at offset 0x338:
118da0c48c4Sopenharmony_ci  Owner          Data size  Type
119da0c48c4Sopenharmony_ci  GNU                   16  GNU_PROPERTY_TYPE_0
120da0c48c4Sopenharmony_ci    X86 FEATURE_1_AND: 00000003 IBT SHSTK
121da0c48c4Sopenharmony_ci
122da0c48c4Sopenharmony_ciNote section [ 3] '.note.gnu.build-id' of 36 bytes at offset 0x358:
123da0c48c4Sopenharmony_ci  Owner          Data size  Type
124da0c48c4Sopenharmony_ci  GNU                   20  GNU_BUILD_ID
125da0c48c4Sopenharmony_ci    Build ID: 84fa4d40bad074bc82431575821902da624a5b22
126da0c48c4Sopenharmony_ci
127da0c48c4Sopenharmony_ciNote section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x37c:
128da0c48c4Sopenharmony_ci  Owner          Data size  Type
129da0c48c4Sopenharmony_ci  GNU                   16  GNU_ABI_TAG
130da0c48c4Sopenharmony_ci    OS: Linux, ABI: 3.2.0
131da0c48c4Sopenharmony_ciEOF
132da0c48c4Sopenharmony_ci
133da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/src/elflint --gnu testfile_pt_gnu_prop
134da0c48c4Sopenharmony_ci
135da0c48c4Sopenharmony_ciexit 0
136