1 // RUN: %clangxx_asan -arch x86_64 -arch x86_64h -g -O0 %s -c -o %t.o.fat
2 // RUN: %clangxx_asan -arch x86_64 -arch x86_64h -g %t.o.fat -o %t.fat
3
4 // RUN: lipo %t.fat -thin x86_64 -output %t.thin.x86_64 && lipo %t.thin.x86_64 -info | FileCheck %s --check-prefix=CHECK-LIPO-THIN-X86_64
5 // RUN: lipo %t.fat -thin x86_64h -output %t.thin.x86_64h && lipo %t.thin.x86_64h -info | FileCheck %s --check-prefix=CHECK-LIPO-THIN-X86_64H
6 // RUN: lipo %t.fat -extract x86_64 -output %t.fat.x86_64 && lipo %t.fat.x86_64 -info | FileCheck %s --check-prefix=CHECK-LIPO-FAT-X86_64
7 // RUN: lipo %t.fat -extract x86_64h -output %t.fat.x86_64h && lipo %t.fat.x86_64h -info | FileCheck %s --check-prefix=CHECK-LIPO-FAT-X86_64H
8
9 // CHECK-LIPO-THIN-X86_64: Non-fat file: {{.*}} is architecture: x86_64
10 // CHECK-LIPO-THIN-X86_64H: Non-fat file: {{.*}} is architecture: x86_64h
11 // CHECK-LIPO-FAT-X86_64: Architectures in the fat file: {{.*}} are: x86_64
12 // CHECK-LIPO-FAT-X86_64H: Architectures in the fat file: {{.*}} are: x86_64h
13
14 // RUN: dsymutil %t.thin.x86_64
15 // RUN: dsymutil %t.thin.x86_64h
16 // RUN: dsymutil %t.fat.x86_64
17 // RUN: dsymutil %t.fat.x86_64h
18
19 // Check LLVM symbolizer
20 // RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.thin.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
21 // RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.thin.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
22 // RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.fat.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
23 // RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.fat.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
24
25 // Check atos
26 // RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.thin.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
27 // RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.thin.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
28 // RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.fat.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
29 // RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.fat.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
30
31 // Check dladdr
32 // RUN: %env_asan_opts=external_symbolizer_path= not %run %t.thin.x86_64 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
33 // RUN: %env_asan_opts=external_symbolizer_path= not %run %t.thin.x86_64h 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
34 // RUN: %env_asan_opts=external_symbolizer_path= not %run %t.fat.x86_64 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
35 // RUN: %env_asan_opts=external_symbolizer_path= not %run %t.fat.x86_64h 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
36
37 // Check asan_symbolize.py with llvm-symbolizer
38 // RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
39 // RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64h 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
40 // RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
41 // RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64h 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
42
43 // Check asan_symbolize.py with atos
44 // RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
45 // RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64h 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
46 // RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
47 // RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64h 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
48
49 // REQUIRES: x86-target-arch
50 // REQUIRES: x86_64h
51 // UNSUPPORTED: ios
52
53 #include <sanitizer/common_interface_defs.h>
54 #include <stdio.h>
55 #include <stdlib.h>
56
57 #if __x86_64h__
58 // Unused functions and globals, just to mess up the offsets in x86_64h.
dummy(char * a,char * b)59 void dummy(char *a, char *b) {
60 while (*a == *b) {
61 a[0] = b[0];
62 a[1] = b[1];
63 a[2] = b[2];
64 a[3] = b[3];
65 fprintf(stderr, "dummy\n");
66 }
67 fprintf(stderr, "dummy\n");
68 }
69 long dummy_global;
70 long dummy_global2[100];
71 #endif
72
73 extern "C"
74 long faulty_global = 10;
75
check_data_symbolication()76 void check_data_symbolication() {
77 char data[100];
78 __sanitizer_symbolize_global(&faulty_global, "%g", data, sizeof(data));
79 fprintf(stderr, "symbolized global: %s\n", data);
80 // CHECK-DATA: symbolized global: faulty_global
81 }
82
83 extern "C"
faulty_func(char * p)84 void faulty_func(char *p) {
85 *p = 'x'; // BOOM
86 // CHECK: AddressSanitizer: global-buffer-overflow
87 // CHECK-LI: #0 0x{{.*}} in faulty_func{{.*}} {{.*}}haswell-symbolication.cpp:[[@LINE-2]]
88 // CHECK-NOLI: #0 0x{{.*}} in faulty_func{{.*}} {{.*}}haswell-symbolication
89 // CHECK: is located 2 bytes to the right of global variable 'faulty_global'
90 // CHECK-NOT: LLVMSymbolizer: error reading file
91 }
92
main()93 int main() {
94 check_data_symbolication();
95
96 char *p = (char *)(void *)&faulty_global;
97 p += 10;
98 faulty_func(p);
99 return 0;
100 }
101