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