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