1// REQUIRES: arm 2/// Test CMSE diagnostics. 3 4// RUN: rm -rf %t && split-file %s %t && cd %t 5 6/// Test diagnostics emitted during checks of the CMSE import library 7// RUN: llvm-mc -arm-add-build-attributes -filetype=obj --triple=thumbv8m.base lib -o lib.o 8// RUN: llvm-mc -arm-add-build-attributes -filetype=obj --triple=thumbv8m.base app -I %S/Inputs -o app.o 9// RUN: llvm-objcopy --redefine-sym=entry7_duplicate=entry6_duplicate lib.o 10// RUN: not ld.lld --cmse-implib --in-implib=lib.o app.o -o /dev/null 2>&1 | FileCheck %s --check-prefixes=ERR_IMPLIB 11// RUN: not ld.lld --cmse-implib --in-implib=lib.o --in-implib=lib.o app.o -o /dev/null 2>&1 | FileCheck %s --check-prefixes=ERR_MULT_INIMPLIB 12// RUN: not ld.lld --in-implib=lib.o app.o -o /dev/null 2>&1 | FileCheck %s --check-prefixes=ERR_IN_IMPLIB 13// RUN: not ld.lld --out-implib=out.lib app.o -o /dev/null 2>&1 | FileCheck %s --check-prefixes=ERR_OUT_IMPLIB 14// RUN: not ld.lld --out-implib=out.lib --in-implib=lib.o app.o -o /dev/null 2>&1 | FileCheck %s --check-prefixes=ERR_IN_IMPLIB,ERR_OUT_IMPLIB 15 16// ERR_IMPLIB: error: CMSE symbol 'entry_not_external' in import library '{{.*}}' is not global 17// ERR_IMPLIB: error: CMSE symbol 'entry_not_absolute' in import library '{{.*}}' is not absolute 18// ERR_IMPLIB: error: CMSE symbol 'entry_not_function' in import library '{{.*}}' is not a Thumb function definition 19// ERR_IMPLIB: error: CMSE symbol 'entry_not_thumb' in import library '{{.*}}' is not a Thumb function definition 20// ERR_IMPLIB: warning: CMSE symbol 'entry5_incorrect_size' in import library '{{.*}}' does not have correct size of 8 bytes 21// ERR_IMPLIB: error: CMSE symbol 'entry6_duplicate' is multiply defined in import library '{{.*}}' 22// ERR_MULT_INIMPLIB: error: multiple CMSE import libraries not supported 23// ERR_IN_IMPLIB: error: --in-implib may not be used without --cmse-implib 24// ERR_OUT_IMPLIB: error: --out-implib may not be used without --cmse-implib 25 26/// CMSE Only supported by ARMv8-M architecture or later. 27// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv8m.base app -I %S/Inputs -o app1.o 28// RUN: ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app1 app1.o 2>&1 | FileCheck /dev/null --implicit-check-not=error: 29 30// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv8m.main app -I %S/Inputs -o app2.o 31// RUN: ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app2 app2.o 2>&1 | FileCheck /dev/null --implicit-check-not=error: 32 33// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv8.1m.main app -I %S/Inputs -o app3.o 34// RUN: ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app3 app3.o 2>&1 | FileCheck /dev/null --implicit-check-not=error: 35 36/// Expect errors for other architectures. 37// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv9a app -I %S/Inputs -o app4.o 38// RUN: not ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app4 app4.o 2>&1 | FileCheck %s --check-prefixes=ERR_ARCH 39 40// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7-m app -I %S/Inputs -o app5.o 41// RUN: not ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app5 app5.o 2>&1 | FileCheck %s --check-prefixes=ERR_ARCH 42 43// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv8-m app -I %S/Inputs -o app6.o 44// RUN: not ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app6 app6.o 2>&1 | FileCheck %s --check-prefixes=ERR_ARCH 45 46/// Invalid triple defaults to v4T. Error. 47// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumb app -I %S/Inputs -o app7.o 48// RUN: not ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app7 app7.o 2>&1 | FileCheck %s --check-prefixes=ERR_ARCH 49 50/// No build attributes. Error. 51// RUN: llvm-mc -filetype=obj -triple=thumb app -I %S/Inputs -o app8.o 52// RUN: not ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 -o app8 app8.o 2>&1 | FileCheck %s --check-prefixes=ERR_ARCH 53 54// ERR_ARCH: CMSE is only supported by ARMv8-M architecture or later 55 56/// Test that the linker diagnoses cases where the linker synthesized veneer addresses 57/// specified by the CMSE input library cannot be placed at the .gnu.sgstubs section address. 58 59// RUN: llvm-mc -arm-add-build-attributes -filetype=obj --triple=thumbv8m.main app -I %S/Inputs -o 1.o 60/// Create a CMSE import library with a secure gateway veneer at 0x10000 61// RUN: ld.lld --cmse-implib --section-start .gnu.sgstubs=0x10000 1.o -o 1 --out-implib=1.lib 2>&1 | FileCheck /dev/null --implicit-check-not=error: 62/// Create a new import library with the secure gateway veneer and .gnu.sgstubs specified at the same address 63// RUN: ld.lld --cmse-implib --section-start .gnu.sgstubs=0x10000 1.o -o 2 --out-implib=2.lib --in-implib=1.lib 2>&1 | FileCheck /dev/null --implicit-check-not=error: 64/// Create a new import library with the secure gateway veneer specified at a same address but .gnu.sgstubs at a higher address. 65// RUN: not ld.lld --cmse-implib --section-start .gnu.sgstubs=0x11000 1.o -o 3 --out-implib=3.lib --in-implib=1.lib 2>&1 | FileCheck %s --check-prefixes=ERR_ADDR 66/// Create a new import library with the secure gateway veneer specified at a same address but .gnu.sgstubs at a lower address. 67// RUN: not ld.lld --cmse-implib --section-start .gnu.sgstubs=0x9000 1.o -o 4 --out-implib=4.lib --in-implib=1.lib 2>&1 | FileCheck %s --check-prefixes=ERR_ADDR 68 69// ERR_ADDR: error: start address of '.gnu.sgstubs' is different from previous link 70 71/// Test that the address of .gnu.sgstubs can be specified via command line or linker script. 72/// Test that the linker errors when the address of .gnu.sgstubs is not specified using either method. 73 74// RUN: ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 --script with_sgstubs.script 1.o -o 1 2>&1 | FileCheck /dev/null --implicit-check-not=error: 75// RUN: ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 --script wout_sgstubs.script 1.o -o 2 2>&1 | FileCheck /dev/null --implicit-check-not=error: 76// RUN: ld.lld --cmse-implib -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 1.o -o 3 2>&1 | FileCheck /dev/null --implicit-check-not=error: 77// RUN: ld.lld --cmse-implib -Ttext=0x8000 --script with_sgstubs.script 1.o -o 4 2>&1 | FileCheck /dev/null --implicit-check-not=error: 78// RUN: not ld.lld --cmse-implib -Ttext=0x8000 --script wout_sgstubs.script 1.o -o 5 2>&1 | FileCheck %s --check-prefixes=ERR_NOADDR 79 80// RUN: llvm-readelf -S 1 | FileCheck %s --check-prefixes=ADDRCMDLINE 81// RUN: llvm-readelf -S 2 | FileCheck %s --check-prefixes=ADDRCMDLINE 82// RUN: llvm-readelf -S 3 | FileCheck %s --check-prefixes=ADDRCMDLINE 83// RUN: llvm-readelf -S 4 | FileCheck %s --check-prefixes=ADDRLNKSCRIPT 84 85// ERR_NOADDR: error: no address assigned to the veneers output section .gnu.sgstubs 86 87/// Name Type Address Off Size ES Flg Lk Inf Al 88// ADDRCMDLINE: .gnu.sgstubs PROGBITS 00020000 020000 000008 08 AX 0 0 32 89// ADDRLNKSCRIPT: .gnu.sgstubs PROGBITS 00040000 040000 000008 08 AX 0 0 32 90 91/// Test diagnostics emitted during symbol attribute checks. 92 93// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -I %S/Inputs --triple=thumbv8m.base symattr -o symattr.o 94// RUN: not ld.lld --cmse-implib symattr.o -o /dev/null 2>&1 | FileCheck %s --check-prefixes=ERR_SYMATTR 95 96// ERR_SYMATTR-NOT: __acle_se_valid_{{.*}} 97// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_1' is not a Thumb function definition 98// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_2' is not a Thumb function definition 99// ERR_SYMATTR: error: {{.*}}: cmse entry symbol 'invalid_3' is not a Thumb function definition 100// ERR_SYMATTR: error: {{.*}}: cmse entry symbol 'invalid_4' is not a Thumb function definition 101// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_5' detected, but no associated entry function definition 'invalid_5' with external linkage found 102// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_6' detected, but no associated entry function definition 'invalid_6' with external linkage found 103// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_7' is not a Thumb function definition 104// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_8' detected, but no associated entry function definition 'invalid_8' with external linkage found 105// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_9' cannot be an absolute symbol 106// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_10' cannot be an absolute symbol 107// ERR_SYMATTR: error: {{.*}}: cmse special symbol '__acle_se_invalid_11' is not a Thumb function definition 108// ERR_SYMATTR: error: {{.*}}: cmse entry symbol 'invalid_12' is not a Thumb function definition 109 110/// Test diagnostics emitted when a symbol is removed from a later version of the import library. 111// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -I %S/Inputs --triple=thumbv8m.base libv1 -o libv1.o 112// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -I %S/Inputs --triple=thumbv8m.base libv2 -o libv2.o 113// RUN: ld.lld -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 --cmse-implib libv1.o --out-implib=libv1.lib -o /dev/null 114// RUN: ld.lld -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 --cmse-implib libv2.o --in-implib=libv1.lib --out-implib=libv2.lib -o /dev/null 2>&1 | FileCheck %s --check-prefixes=WARN_MISSING 115// RUN: ld.lld -Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 --cmse-implib libv1.o --in-implib=libv2.lib -o /dev/null 2>&1 | FileCheck %s --check-prefixes=WARN_NEWENTRY 116 117// WARN_MISSING: warning: entry function 'bar' from CMSE import library is not present in secure application 118// WARN_NEWENTRY: warning: new entry function 'bar' introduced but no output import library specified 119 120//--- with_sgstubs.script 121SECTIONS { 122 .text : { *(.text) } 123 .gnu.sgstubs 0x40000 : { *(.gnu.sgstubs*) } 124} 125 126//--- wout_sgstubs.script 127SECTIONS { 128 .text : { *(.text) } 129} 130 131//--- app 132 .include "arm-cmse-macros.s" 133 .text 134 .thumb 135 136cmse_veneer entry, function, global, function, global 137 138//--- lib 139 .text 140 .thumb 141 142/// Symbol not absolute. 143 .global entry_not_absolute 144 .type entry_not_absolute, STT_FUNC 145 .thumb_func 146entry_not_absolute: 147 .size entry_not_absolute, 8 148 149/// Symbol not global or weak. 150 .local entry_not_external 151 .type entry_not_external, STT_FUNC 152entry_not_external=0x1001 153 .size entry_not_external, 8 154 155/// Symbol not the function type. 156 .global entry_not_function 157 .type entry_not_function, STT_NOTYPE 158entry_not_function=0x1001 159 .size entry_not_function, 8 160 161/// Symbol not a Thumb code symbol. 162 .global entry_not_thumb 163 .type entry_not_thumb, STT_FUNC 164entry_not_thumb=0x1000 165 .size entry_not_thumb, 8 166 167/// Symbol with incorrect size. 168 .global entry5_incorrect_size 169 .type entry5_incorrect_size, STT_FUNC 170entry5_incorrect_size=0x1009 171 .size entry5_incorrect_size, 6 172 173/// Duplicate symbols. 174 .global entry6_duplicate 175 .type entry6_duplicate, STT_FUNC 176entry6_duplicate=0x1001 177 .size entry6_duplicate, 8 178 179/// entry7_duplicate gets renamed to entry6_duplicate by llvm-objcopy. 180 .global entry7_duplicate 181 .type entry7_duplicate, STT_FUNC 182entry7_duplicate=0x1009 183 .size entry7_duplicate, 8 184 185//--- symattr 186.include "arm-cmse-macros.s" 187 188 .text 189 .thumb 190 191/// Valid sequences 192/// both sym and __acle_se_sym should be global or weak Thumb code symbols. 193 cmse_veneer valid_1, function, global, function, global 194 cmse_veneer valid_2, function, weak, function, weak 195 cmse_veneer valid_3, function, weak, function, global 196 cmse_veneer valid_4, function, global, function, weak 197 198/// Invalid sequences 199/// __acle_se_sym is an object 200 cmse_veneer invalid_1, function, global, object, global 201 cmse_veneer invalid_2, function, global, object, weak 202/// sym is an object 203 cmse_veneer invalid_3, object, global, function, global 204 cmse_veneer invalid_4, object, global, function, weak 205/// sym is local 206 cmse_veneer invalid_5, function, local, function, global 207 cmse_veneer invalid_6, function, local, function, weak 208 209/// __acle_se_invalid_7 not defined. 210 .global invalid_7 211 .type invalid_7, %function 212 .global __acle_se_invalid_7 213 .thumb_func 214invalid_7: 215 216/// invalid_8 not defined. 217 .global __acle_se_invalid_8 218 .thumb_func 219__acle_se_invalid_8: 220 221// Absolute symbols with same values 222 .global invalid_9 223 .global __acle_se_invalid_9 224 .type __acle_se_invalid_9, %function 225 .type invalid_9, %function 226__acle_se_invalid_9=0x1001 227invalid_9=0x1001 228 .size invalid_9, 0 229 .size __acle_se_invalid_9, 0 230 231// Absolute symbols with different values 232 .align 2 233 .global __acle_se_invalid_10 234 .global invalid_10 235 .type __acle_se_invalid_10, %function 236 .type invalid_10, %function 237__acle_se_invalid_10 = 0x10001 238invalid_10 = 0x10005 239 .size invalid_10, 0 240 .size __acle_se_invalid_10, 0 241 242 .section nonthumb 243 .thumb 244 .align 2 245 .global invalid_11 246 .global __acle_se_invalid_11 247 .type invalid_11, %function 248 .type __acle_se_invalid_11, %function 249invalid_11: 250 .size invalid_11, .-invalid_11 251/// Invalid non-thumb function symbol __acle_se_invalid_11 252__acle_se_invalid_11=0x1000 253 254 .global invalid_12 255 .global __acle_se_invalid_12 256 .type invalid_12, %function 257 .type __acle_se_invalid_12, %function 258/// Invalid non-thumb function symbol invalid_12 259invalid_12=0x1000 260 .thumb 261__acle_se_invalid_12: 262 .size __acle_se_invalid_12, .-__acle_se_invalid_12 263 264//--- libv1 265.include "arm-cmse-macros.s" 266 267 .text 268 .thumb 269 270/// Import library version 1 with foo and bar 271 cmse_veneer foo, function, global, function, global 272 cmse_veneer bar, function, weak, function, weak 273 274//--- libv2 275.include "arm-cmse-macros.s" 276 277 .text 278 .thumb 279 280/// Import library version 2 with bar missing. 281 cmse_veneer foo, function, global, function, global 282