File: clang_gcc_abi.cpp

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (44 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download | duplicates (31)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// RUN: %clangxx_asan -O0 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O1 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O2 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O3 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s

// REQUIRES: (arm-target-arch || armhf-target-arch), fast-unwinder-works

#include <stdlib.h>

__attribute__((noinline))
int boom() {
  volatile int three = 3;
  char * volatile s = (char *)malloc(three);
// CHECK: #1 0x{{.*}} in boom {{.*}}clang_gcc_abi.cpp:[[@LINE-1]]
  return s[three]; //BOOM
}

__attribute__((naked, noinline)) void gcc_abi() {
// CHECK: #2 0x{{.*}} in gcc_abi {{.*}}clang_gcc_abi.cpp:[[@LINE+1]]
  asm volatile("str fp, [sp, #-8]!\n\t"
               "str lr, [sp, #4]\n\t"
               "add fp, sp, #4\n\t"
               "bl  boom\n\t"
               "sub sp, fp, #4\n\t"
               "ldr fp, [sp]\n\t"
               "add sp, sp, #4\n\t"
               "ldr pc, [sp], #4\n\t"
              );
}

__attribute__((naked, noinline)) void clang_abi() {
// CHECK: #3 0x{{.*}} in clang_abi {{.*}}clang_gcc_abi.cpp:[[@LINE+1]]
  asm volatile("push {r11, lr}\n\t"
               "mov r11, sp\n\t"
               "bl  gcc_abi\n\t"
               "add r0, r0, #1\n\t"
               "pop {r11, pc}\n\t"
              );
}

int main() {
  clang_abi();
// CHECK: #4 0x{{.*}} in main {{.*}}clang_gcc_abi.cpp:[[@LINE-1]]
}