1# Copyright (C) 2018 Red Hat, Inc. 2# This file is part of elfutils. 3# 4# This file is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3 of the License, or 7# (at your option) any later version. 8# 9# elfutils is distributed in the hope that it will be useful, but 10# WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17. $srcdir/test-subr.sh 18 19# - testfile-gnu-property-note.c 20# int 21# main () 22# { 23# return 0; 24# } 25# 26# gcc -fcf-protection -c testfile-gnu-property-note.c 27# gcc -o testfile-gnu-property-note testfile-gnu-property-note.o 28# eu-strip --strip-sections testfile-gnu-property-note 29 30testfiles testfile-gnu-property-note.o testfile-gnu-property-note 31 32# Test reading notes through sections 33testrun_compare ${abs_top_builddir}/src/readelf -n testfile-gnu-property-note.o << EOF 34 35Note section [ 6] '.note.gnu.property' of 32 bytes at offset 0x80: 36 Owner Data size Type 37 GNU 16 GNU_PROPERTY_TYPE_0 38 X86 FEATURE_1_AND: 00000003 IBT SHSTK 39EOF 40 41# Test reading notes through segments 42testrun_compare ${abs_top_builddir}/src/readelf -n testfile-gnu-property-note << EOF 43 44Note segment of 32 bytes at offset 0x300: 45 Owner Data size Type 46 GNU 16 GNU_PROPERTY_TYPE_0 47 X86 FEATURE_1_AND: 00000003 IBT SHSTK 48 49Note segment of 68 bytes at offset 0x320: 50 Owner Data size Type 51 GNU 16 GNU_ABI_TAG 52 OS: Linux, ABI: 3.2.0 53 GNU 20 GNU_BUILD_ID 54 Build ID: 83cb2229fabd2065d1361f5b46424cd75270f94b 55EOF 56 57# NT_VERSION note type clashes with "GNU" owner type NT_GNU_ABI_TAG. 58# Uses owner name (with zero desc) for version string. 59testfiles testfile11 60testrun_compare ${abs_top_builddir}/src/readelf -n testfile11 << EOF 61 62Note section [ 2] '.note.ABI-tag' of 32 bytes at offset 0x128: 63 Owner Data size Type 64 GNU 16 GNU_ABI_TAG 65 OS: Linux, ABI: 2.2.5 66 67Note section [35] '.note' of 60 bytes at offset 0x13364: 68 Owner Data size Type 69 01.01 0 VERSION 70 01.01 0 VERSION 71 01.01 0 VERSION 72EOF 73 74# See run-annobingroup.sh 75testfiles testfile-annobingroup.o 76testrun_compare ${abs_top_builddir}/src/readelf -n testfile-annobingroup.o << EOF 77 78Note section [ 5] '.gnu.build.attributes' of 272 bytes at offset 0x50: 79 Owner Data size Type 80 GA 16 GNU Build Attribute OPEN 81 Address Range: 0 - 0 82 VERSION: "3p8" 83 GA 0 GNU Build Attribute OPEN 84 TOOL: "gcc 8.1.1 20180712" 85 GA 0 GNU Build Attribute OPEN 86 "GOW": 5 87 GA 0 GNU Build Attribute OPEN 88 STACK_PROT: 0 89 GA 0 GNU Build Attribute OPEN 90 "stack_clash": FALSE 91 GA 0 GNU Build Attribute OPEN 92 "cf_protection": 0 93 GA 0 GNU Build Attribute OPEN 94 PIC: 0 95 GA 0 GNU Build Attribute OPEN 96 SHORT_ENUM: FALSE 97 GA 0 GNU Build Attribute OPEN 98 ABI: c001100000012 99 GA 0 GNU Build Attribute OPEN 100 "stack_realign": FALSE 101 102Note section [ 7] '.gnu.build.attributes..text.unlikely' of 216 bytes at offset 0x160: 103 Owner Data size Type 104 GA 16 GNU Build Attribute FUNC 105 Address Range: 0 - 0 106 ABI: c001100000012 107 GA 0 GNU Build Attribute FUNC 108 "stack_realign": FALSE 109 GA 0 GNU Build Attribute FUNC 110 STACK_PROT: 0 111 GA 0 GNU Build Attribute FUNC 112 "stack_clash": FALSE 113 GA 0 GNU Build Attribute FUNC 114 "cf_protection": 0 115 GA 0 GNU Build Attribute FUNC 116 PIC: 0 117 GA 0 GNU Build Attribute FUNC 118 "GOW": 5 119 GA 0 GNU Build Attribute FUNC 120 SHORT_ENUM: FALSE 121 122Note section [22] '.note.gnu.property' of 48 bytes at offset 0x40c: 123 Owner Data size Type 124 GNU 32 GNU_PROPERTY_TYPE_0 125 X86 0xc0000000 data: 00 00 00 00 126 X86 0xc0000001 data: 00 00 00 00 127EOF 128 129# 130# = gnu_props.S 131# 132# #define NT_GNU_PROPERTY_TYPE_0 5 133# #define GNU_PROPERTY_STACK_SIZE 1 134# #define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2 135 136# /* Normal notes always have alignment and padding of 4 bytes, 137# but GNU Property notes use 4 byte words, with 8 byte padding 138# for ELFCLASS64. */ 139# #if __SIZEOF_PTRDIFF_T__ == 8 140# # define ALIGN 3 141# #elif __SIZEOF_PTRDIFF_T__ == 4 142# # define ALIGN 2 143# #endif 144# 145# .section ".note.gnu.property", "a" 146# .p2align ALIGN 147# /* First note. */ 148# .long 1f - 0f /* name length. */ 149# .long 4f - 2f /* data length. */ 150# .long NT_GNU_PROPERTY_TYPE_0 /* note type. */ 151# 0: 152# .asciz "GNU" /* vendor name. */ 153# 1: 154# .p2align ALIGN /* Padding. */ 155# 2: 156# .long GNU_PROPERTY_STACK_SIZE /* pr_type. */ 157# .long 4f - 3f /* pr_datasz. */ 158# 3: 159# .dc.a 0x280000 /* Stack size. */ 160# 4: 161# .p2align ALIGN 162# 163# /* Second note. */ 164# .long 6f - 5f /* name length. */ 165# .long 8f - 7f /* data length. */ 166# .long NT_GNU_PROPERTY_TYPE_0 /* note type. */ 167# 5: 168# .asciz "GNU" /* vendor name. */ 169# 6: 170# .p2align ALIGN /* Padding. */ 171# 7: 172# .long GNU_PROPERTY_NO_COPY_ON_PROTECTED /* pr_type. */ 173# .long 0 /* pr_datasz. */ 174# /* No data. */ 175# 8: 176# .p2align ALIGN 177# 178# On x86_64 179# gcc -m64 -c -o testfile_gnu_props_64le.o gnu_props.S 180# gcc -m32 -c -o testfile_gnu_props_32le.o gnu_props.S 181 182testfiles testfile_gnu_props.32le.o testfile_gnu_props.64le.o 183 184testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.32le.o << EOF 185 186Note section [ 4] '.note.gnu.property' of 52 bytes at offset 0x34: 187 Owner Data size Type 188 GNU 12 GNU_PROPERTY_TYPE_0 189 STACK_SIZE 0x280000 190 GNU 8 GNU_PROPERTY_TYPE_0 191 NO_COPY_ON_PROTECTION 192EOF 193 194testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.64le.o << EOF 195 196Note section [ 4] '.note.gnu.property' of 56 bytes at offset 0x40: 197 Owner Data size Type 198 GNU 16 GNU_PROPERTY_TYPE_0 199 STACK_SIZE 0x280000 200 GNU 8 GNU_PROPERTY_TYPE_0 201 NO_COPY_ON_PROTECTION 202EOF 203 204# On ppc64 205# gcc -m32 -c -o testfile_gnu_props.32be.o gnu_props.S 206# gcc -m64 -c -o testfile_gnu_props.64be.o gnu_props.S 207 208testfiles testfile_gnu_props.32be.o testfile_gnu_props.64be.o 209 210testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.32be.o << EOF 211 212Note section [ 4] '.note.gnu.property' of 52 bytes at offset 0x34: 213 Owner Data size Type 214 GNU 12 GNU_PROPERTY_TYPE_0 215 STACK_SIZE 0x280000 216 GNU 8 GNU_PROPERTY_TYPE_0 217 NO_COPY_ON_PROTECTION 218EOF 219 220testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.64be.o << EOF 221 222Note section [ 4] '.note.gnu.property' of 56 bytes at offset 0x40: 223 Owner Data size Type 224 GNU 16 GNU_PROPERTY_TYPE_0 225 STACK_SIZE 0x280000 226 GNU 8 GNU_PROPERTY_TYPE_0 227 NO_COPY_ON_PROTECTION 228EOF 229 230# - testfile-gnu-property-note.c 231# int 232# main () 233# { 234# return 0; 235# } 236# 237# gcc -mbranch-protection=standard -c testfile-gnu-property-note.c 238# gcc -o testfile-gnu-property-note-aarch64 testfile-gnu-property-note.o 239# eu-strip --remove-section=.gnu.build.attributes \ 240# testfile-gnu-property-note-aarch64 241 242testfiles testfile-gnu-property-note-aarch64 243testrun_compare ${abs_top_builddir}/src/readelf -n testfile-gnu-property-note-aarch64 << EOF 244 245Note section [ 2] '.note.gnu.property' of 32 bytes at offset 0x2c8: 246 Owner Data size Type 247 GNU 16 GNU_PROPERTY_TYPE_0 248 AARCH64 FEATURE_1_AND: 00000003 BTI PAC 249 250Note section [ 3] '.note.gnu.build-id' of 36 bytes at offset 0x2e8: 251 Owner Data size Type 252 GNU 20 GNU_BUILD_ID 253 Build ID: af82d6df6f3b396487e3e27a826ca9cbbbecbe5f 254 255Note section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x30c: 256 Owner Data size Type 257 GNU 16 GNU_ABI_TAG 258 OS: Linux, ABI: 3.7.0 259EOF 260