1#!/usr/local/bin/bash
2# Copyright (C) 2020 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# On Fedora 31 with GCC 9.2.1 and binutils 2.32-31
21# echo "int main () { }" | \
22# gcc -o testfile_pt_gnu_prop \
23#     -Os -fstack-clash-protection -fcf-protection=full -xc - && \
24# eu-strip --remove-comment -R .gnu.build.attributes testfile_pt_gnu_prop
25#
26# echo "int main () { }" | \
27# gcc -m32 -o testfile_pt_gnu_prop \
28#     -Os -fstack-clash-protection -fcf-protection=full -xc - && \
29# eu-strip --remove-comment -R .gnu.build.attributes testfile_pt_gnu_prop32
30
31testfiles testfile_pt_gnu_prop testfile_pt_gnu_prop32
32
33testrun_compare ${abs_top_builddir}/src/readelf -ln testfile_pt_gnu_prop32 <<\EOF
34Program Headers:
35  Type           Offset   VirtAddr   PhysAddr   FileSiz  MemSiz   Flg Align
36  PHDR           0x000034 0x08048034 0x08048034 0x000180 0x000180 R   0x4
37  INTERP         0x0001b4 0x080481b4 0x080481b4 0x000013 0x000013 R   0x1
38	[Requesting program interpreter: /lib/ld-linux.so.2]
39  LOAD           0x000000 0x08048000 0x08048000 0x000308 0x000308 R   0x1000
40  LOAD           0x001000 0x08049000 0x08049000 0x000224 0x000224 R E 0x1000
41  LOAD           0x002000 0x0804a000 0x0804a000 0x00015c 0x00015c R   0x1000
42  LOAD           0x002f0c 0x0804bf0c 0x0804bf0c 0x000108 0x00010c RW  0x1000
43  DYNAMIC        0x002f14 0x0804bf14 0x0804bf14 0x0000e8 0x0000e8 RW  0x4
44  NOTE           0x0001c8 0x080481c8 0x080481c8 0x000060 0x000060 R   0x4
45  GNU_PROPERTY   0x0001ec 0x080481ec 0x080481ec 0x00001c 0x00001c R   0x4
46  GNU_EH_FRAME   0x00200c 0x0804a00c 0x0804a00c 0x00004c 0x00004c R   0x4
47  GNU_STACK      0x000000 0x00000000 0x00000000 0x000000 0x000000 RW  0x10
48  GNU_RELRO      0x002f0c 0x0804bf0c 0x0804bf0c 0x0000f4 0x0000f4 R   0x1
49
50 Section to Segment mapping:
51  Segment Sections...
52   00
53   01      [RO: .interp]
54   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]
55   03      [RO: .init .plt .plt.sec .text .fini]
56   04      [RO: .rodata .eh_frame_hdr .eh_frame]
57   05      [RELRO: .init_array .fini_array .dynamic .got] .got.plt .data .bss
58   06      [RELRO: .dynamic]
59   07      [RO: .note.gnu.build-id .note.gnu.property .note.ABI-tag]
60   08      [RO: .note.gnu.property]
61   09      [RO: .eh_frame_hdr]
62   10
63   11      [RELRO: .init_array .fini_array .dynamic .got]
64
65Note section [ 2] '.note.gnu.build-id' of 36 bytes at offset 0x1c8:
66  Owner          Data size  Type
67  GNU                   20  GNU_BUILD_ID
68    Build ID: 2fcce91f5c2532f78b00a9f5f565354d2f44bc19
69
70Note section [ 3] '.note.gnu.property' of 28 bytes at offset 0x1ec:
71  Owner          Data size  Type
72  GNU                   12  GNU_PROPERTY_TYPE_0
73    X86 FEATURE_1_AND: 00000003 IBT SHSTK
74
75Note section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x208:
76  Owner          Data size  Type
77  GNU                   16  GNU_ABI_TAG
78    OS: Linux, ABI: 3.2.0
79EOF
80
81testrun ${abs_top_builddir}/src/elflint --gnu testfile_pt_gnu_prop32
82
83testrun_compare ${abs_top_builddir}/src/readelf -ln testfile_pt_gnu_prop <<\EOF
84Program Headers:
85  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
86  PHDR           0x000040 0x0000000000400040 0x0000000000400040 0x0002d8 0x0002d8 R   0x8
87  INTERP         0x000318 0x0000000000400318 0x0000000000400318 0x00001c 0x00001c R   0x1
88	[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
89  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x000498 0x000498 R   0x1000
90  LOAD           0x001000 0x0000000000401000 0x0000000000401000 0x0001a5 0x0001a5 R E 0x1000
91  LOAD           0x002000 0x0000000000402000 0x0000000000402000 0x000100 0x000100 R   0x1000
92  LOAD           0x002e50 0x0000000000403e50 0x0000000000403e50 0x0001cc 0x0001d0 RW  0x1000
93  DYNAMIC        0x002e60 0x0000000000403e60 0x0000000000403e60 0x000190 0x000190 RW  0x8
94  NOTE           0x000338 0x0000000000400338 0x0000000000400338 0x000020 0x000020 R   0x8
95  NOTE           0x000358 0x0000000000400358 0x0000000000400358 0x000044 0x000044 R   0x4
96  GNU_PROPERTY   0x000338 0x0000000000400338 0x0000000000400338 0x000020 0x000020 R   0x8
97  GNU_EH_FRAME   0x002010 0x0000000000402010 0x0000000000402010 0x000034 0x000034 R   0x4
98  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x10
99  GNU_RELRO      0x002e50 0x0000000000403e50 0x0000000000403e50 0x0001b0 0x0001b0 R   0x1
100
101 Section to Segment mapping:
102  Segment Sections...
103   00
104   01      [RO: .interp]
105   02      [RO: .interp .note.gnu.property .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn]
106   03      [RO: .init .text .fini]
107   04      [RO: .rodata .eh_frame_hdr .eh_frame]
108   05      [RELRO: .init_array .fini_array .dynamic .got] .got.plt .data .bss
109   06      [RELRO: .dynamic]
110   07      [RO: .note.gnu.property]
111   08      [RO: .note.gnu.build-id .note.ABI-tag]
112   09      [RO: .note.gnu.property]
113   10      [RO: .eh_frame_hdr]
114   11
115   12      [RELRO: .init_array .fini_array .dynamic .got]
116
117Note section [ 2] '.note.gnu.property' of 32 bytes at offset 0x338:
118  Owner          Data size  Type
119  GNU                   16  GNU_PROPERTY_TYPE_0
120    X86 FEATURE_1_AND: 00000003 IBT SHSTK
121
122Note section [ 3] '.note.gnu.build-id' of 36 bytes at offset 0x358:
123  Owner          Data size  Type
124  GNU                   20  GNU_BUILD_ID
125    Build ID: 84fa4d40bad074bc82431575821902da624a5b22
126
127Note section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x37c:
128  Owner          Data size  Type
129  GNU                   16  GNU_ABI_TAG
130    OS: Linux, ABI: 3.2.0
131EOF
132
133testrun ${abs_top_builddir}/src/elflint --gnu testfile_pt_gnu_prop
134
135exit 0
136