brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.5 KiB · b109c1d Raw
208 lines · plain
1# REQUIRES: aarch642 3# RUN: rm -rf %t4 5## Ensure MTE globals doesn't work with REL (only RELA).6# RUN: yaml2obj %s -o %t.rel.o7# RUN: not ld.lld -shared --android-memtag-mode=sync %t.rel.o -o %t1.so 2>&1 | FileCheck %s --check-prefix=CHECK-RELA8# CHECK-RELA: non-RELA relocations are not allowed with memtag globals9--- !ELF10FileHeader:11  Class:           ELFCLASS6412  Data:            ELFDATA2LSB13  Type:            ET_REL14  Machine:         EM_AARCH6415  SectionHeaderStringTable: .strtab16Sections:17  - Name:            .text18    Type:            SHT_PROGBITS19    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]20    AddressAlign:    0x421    Content:         '00'22  - Name:            .data23    Type:            SHT_PROGBITS24    Flags:           [ SHF_WRITE, SHF_ALLOC ]25    AddressAlign:    0x1026    Content:         '00'27  - Name:            .memtag.globals.static28    Type:            SHT_AARCH64_MEMTAG_GLOBALS_STATIC29    AddressAlign:    0x130  - Name:            .rel.memtag.globals.static31    Type:            SHT_REL32    Flags:           [ SHF_INFO_LINK ]33    Link:            .symtab34    AddressAlign:    0x835    Info:            .memtag.globals.static36    Relocations:37      - Symbol:          four38        Type:            R_AARCH64_NONE39  - Type:            SectionHeaderTable40    Sections:41      - Name:            .strtab42      - Name:            .text43      - Name:            .data44      - Name:            .memtag.globals.static45      - Name:            .rel.memtag.globals.static46      - Name:            .symtab47Symbols:48  - Name:            four49    Type:            STT_OBJECT50    Section:         .data51    Binding:         STB_GLOBAL52    Value:           0x053    Size:            0x1054 55## Functional testing for MTE globals.56# RUN: split-file %S/Inputs/aarch64-memtag-globals.s %t57# RUN: llvm-mc --filetype=obj -triple=aarch64-linux-android \58# RUN:   %t/input_1.s -o %t1.o59# RUN: llvm-mc --filetype=obj -triple=aarch64-linux-android \60# RUN:   %t/input_2.s -o %t2.o61# RUN: ld.lld -shared --android-memtag-mode=sync %t1.o %t2.o -o %t.so62 63## Normally relocations are printed before the symbol tables, so reorder it a64## bit to make it easier on matching addresses of relocations up with the65## symbols.66# RUN: llvm-readelf %t.so -s > %t.out67# RUN: llvm-readelf %t.so --section-headers --relocs --memtag >> %t.out68# RUN: FileCheck %s < %t.out69# RUN: llvm-objdump -Dz %t.so | FileCheck %s --check-prefix=CHECK-SPECIAL-RELOCS70 71## And ensure that --apply-dynamic-relocs is banned.72# RUN: not ld.lld --apply-dynamic-relocs -shared --android-memtag-mode=sync \73# RUN:   %t1.o %t2.o -o %t1.so 2>&1 | FileCheck %s --check-prefix=CHECK-DYNRELOC74# CHECK-DYNRELOC: --apply-dynamic-relocs cannot be used with MTE globals75 76## Ensure that fully statically linked executables just simply drop the MTE77## globals stuff: special relocations, data in the place to be relocated,78## dynamic entries, etc.79# RUN: llvm-mc --filetype=obj -triple=aarch64-linux-android \80# RUN:   %t/input_3.s -o %t3.o81# RUN: ld.lld -static --android-memtag-mode=sync %t1.o %t2.o %t3.o -o %t.static.so82# RUN: llvm-readelf -s --section-headers --relocs --memtag %t.static.so | \83# RUN:   FileCheck %s --check-prefix=CHECK-STATIC84# CHECK-STATIC-NOT: .memtag.globals.static85# CHECK-STATIC-NOT: DT_AARCH64_MEMTAG_86 87# CHECK-STATIC:      There are no relocations in this file88# CHECK-STATIC:      Memtag Dynamic Entries:89# CHECK-STATIC-NEXT: < none found >90 91# RUN: llvm-objdump -tDz %t.static.so | FileCheck %s --check-prefix=CHECK-STATIC-SPECIAL-RELOCS92# CHECK-STATIC-SPECIAL-RELOCS:      [[#%x,HIDDEN_GLOBAL_ADDR:]] {{.*}} .bss {{0*}}10 hidden_global93# CHECK-STATIC-SPECIAL-RELOCS:      <pointer_to_hidden_global_end>:94# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x{{0*}}[[#HIDDEN_GLOBAL_ADDR + 12]]95# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x0000000096# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x0000000097# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x0000000098# CHECK-STATIC-SPECIAL-RELOCS:      <pointer_past_hidden_global_end>:99# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x{{0*}}[[#HIDDEN_GLOBAL_ADDR + 16]]100# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x00000000101# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x00000000102# CHECK-STATIC-SPECIAL-RELOCS-NEXT:   .word 0x00000000103 104# CHECK:     Symbol table '.dynsym' contains105# CHECK-DAG: [[#%x,GLOBAL:]] 32 OBJECT GLOBAL DEFAULT [[#]] global{{$}}106# CHECK-DAG: [[#%x,GLOBAL_UNTAGGED:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_untagged{{$}}107# CHECK-DAG: [[#%x,CONST_GLOBAL:]] 4 OBJECT GLOBAL DEFAULT [[#]] const_global{{$}}108# CHECK-DAG: [[#%x,GLOBAL_EXTERN:]] 16 OBJECT GLOBAL DEFAULT [[#]] global_extern{{$}}109# CHECK-DAG: [[#%x,GLOBAL_EXTERN_UNTAGGED:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_extern_untagged{{$}}110# CHECK-DAG: 0 NOTYPE GLOBAL DEFAULT UND global_extern_outside_this_dso{{$}}111# CHECK-DAG: [[#%x,GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_extern_untagged_definition_but_tagged_import{{$}}112# CHECK-DAG: [[#%x,GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_extern_const_definition_but_nonconst_import{{$}}113# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global{{$}}114# CHECK-DAG: [[#%x,POINTER_INSIDE_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_inside_global{{$}}115# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_end{{$}}116# CHECK-DAG: [[#%x,POINTER_PAST_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_past_global_end{{$}}117# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_UNTAGGED:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_untagged{{$}}118# CHECK-DAG: [[#%x,POINTER_TO_CONST_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_const_global{{$}}119# CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_CONST_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_const_global{{$}}120# CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_global{{$}}121# CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_global_end{{$}}122# CHECK-DAG: [[#%x,POINTER_PAST_HIDDEN_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_past_hidden_global_end{{$}}123# CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_ATTR_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_attr_global{{$}}124# CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_ATTR_CONST_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_attr_const_global{{$}}125# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern{{$}}126# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_UNTAGGED:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_untagged{{$}}127# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_OUTSIDE_THIS_DSO:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_outside_this_dso{{$}}128# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_const_definition_but_nonconst_import{{$}}129# CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_untagged_definition_but_tagged_import{{$}}130 131# CHECK:     Symbol table '.symtab' contains132# CHECK-DAG: [[#%x,HIDDEN_CONST_GLOBAL:]] 4 OBJECT LOCAL DEFAULT [[#]] hidden_const_global{{$}}133# CHECK-DAG: [[#%x,HIDDEN_GLOBAL:]] 16 OBJECT LOCAL DEFAULT [[#]] hidden_global{{$}}134# CHECK-DAG: [[#%x,HIDDEN_ATTR_GLOBAL:]] 16 OBJECT LOCAL HIDDEN [[#]] hidden_attr_global{{$}}135# CHECK-DAG: [[#%x,HIDDEN_ATTR_CONST_GLOBAL:]] 4 OBJECT LOCAL HIDDEN [[#]] hidden_attr_const_global{{$}}136 137# CHECK:     Section Headers:138# CHECK:     .memtag.globals.dynamic AARCH64_MEMTAG_GLOBALS_DYNAMIC139# CHECK-NOT: .memtag.globals.static140# CHECK-NOT: AARCH64_MEMTAG_GLOBALS_STATIC141 142# CHECK: Relocation section '.rela.dyn'143# CHECK-DAG: [[#POINTER_TO_GLOBAL]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 0144# CHECK-DAG: [[#POINTER_INSIDE_GLOBAL]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 11145# CHECK-DAG: [[#POINTER_TO_GLOBAL_END]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 1e146# CHECK-DAG: [[#POINTER_PAST_GLOBAL_END]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 30147# CHECK-DAG: [[#POINTER_TO_GLOBAL_UNTAGGED]] {{.*}} R_AARCH64_ABS64 {{.*}} global_untagged + 0148# CHECK-DAG: [[#POINTER_TO_CONST_GLOBAL]] {{.*}} R_AARCH64_ABS64 {{.*}} const_global + 0149 150## RELATIVE relocations.151# CHECK-DAG: [[#POINTER_TO_HIDDEN_CONST_GLOBAL]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_CONST_GLOBAL]]152# CHECK-DAG: [[#POINTER_TO_HIDDEN_GLOBAL]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_GLOBAL]]153 154## AArch64 MemtagABI special RELATIVE relocation semantics, where the offset is encoded in the place.155# CHECK-DAG:                 [[#POINTER_TO_HIDDEN_GLOBAL_END]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_GLOBAL + 12]]156# CHECK-SPECIAL-RELOCS:      <pointer_to_hidden_global_end>:157# CHECK-SPECIAL-RELOCS-NEXT:   .word 0x00000000158# CHECK-SPECIAL-RELOCS-NEXT:   .word 0x00000000159# CHECK-DAG:                 [[#POINTER_PAST_HIDDEN_GLOBAL_END]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_GLOBAL + 16]]160# CHECK-SPECIAL-RELOCS:      <pointer_past_hidden_global_end>:161# CHECK-SPECIAL-RELOCS-NEXT:   .word 0xfffffff0162# CHECK-SPECIAL-RELOCS-NEXT:   .word 0xffffffff163 164## More ABS64 relocations.165# CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern + 0166# CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_untagged + 0167# CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_OUTSIDE_THIS_DSO]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_outside_this_dso + 0168# CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_const_definition_but_nonconst_import + 0169# CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_untagged_definition_but_tagged_import + 0170 171# CHECK:      Memtag Dynamic Entries172# CHECK-NEXT: AARCH64_MEMTAG_MODE: Synchronous (0)173# CHECK-NEXT: AARCH64_MEMTAG_HEAP: Disabled (0)174# CHECK-NEXT: AARCH64_MEMTAG_STACK: Disabled (0)175# CHECK-NEXT: AARCH64_MEMTAG_GLOBALS: 0x{{[0-9a-f]+}}176# CHECK-NEXT: AARCH64_MEMTAG_GLOBALSSZ: 23177 178# CHECK:      Memtag Android Note179# CHECK-NEXT: Tagging Mode: SYNC180# CHECK-NEXT: Heap: Disabled181# CHECK-NEXT: Stack: Disabled182 183## Global variable order hopefully isn't too brittle of a test here, but this allows us to make sure184## that we have all the global variables we expect, and no more.185# CHECK:      Memtag Global Descriptors:186# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL]]: 0x10187# CHECK-NEXT: 0x[[#POINTER_INSIDE_GLOBAL]]: 0x10188# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_END]]: 0x10189# CHECK-NEXT: 0x[[#POINTER_PAST_GLOBAL_END]]: 0x10190# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_UNTAGGED]]: 0x10191# CHECK-NEXT: 0x[[#POINTER_TO_CONST_GLOBAL]]: 0x10192# CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_CONST_GLOBAL]]: 0x10193# CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_GLOBAL]]: 0x10194# CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_ATTR_GLOBAL]]: 0x10195# CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_ATTR_CONST_GLOBAL]]: 0x10196# CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_GLOBAL_END]]: 0x10197# CHECK-NEXT: 0x[[#POINTER_PAST_HIDDEN_GLOBAL_END]]: 0x10198# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN]]: 0x10199# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED]]: 0x10200# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_OUTSIDE_THIS_DSO]]: 0x10201# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT]]: 0x10202# CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT]]: 0x10203# CHECK-NEXT: 0x[[#GLOBAL]]: 0x20204# CHECK-NEXT: 0x[[#HIDDEN_ATTR_GLOBAL]]: 0x10205# CHECK-NEXT: 0x[[#HIDDEN_GLOBAL]]: 0x10206# CHECK-NEXT: 0x[[#GLOBAL_EXTERN]]: 0x10207# CHECK-NOT:  0x208