File: asan-globals-alias.cpp

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (45 lines) | stat: -rw-r--r-- 2,163 bytes parent folder | download | duplicates (21)
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
45
// RUN: %clang_cc1 -triple x86_64-linux -fsanitize=address -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,ASAN
// RUN: %clang_cc1 -triple x86_64-linux -O2 -fsanitize=address -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,ASAN
// RUN: %clang_cc1 -triple x86_64-linux -fsanitize=kernel-address -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,KASAN
// RUN: %clang_cc1 -triple x86_64-linux -O2 -fsanitize=kernel-address -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,KASAN
//
// Not all platforms support aliases - test for Linux only.

int global; // generate ctor for at least 1 global
int aliased_global; // KASAN ignored
extern int __attribute__((alias("aliased_global"))) __global_alias;

// Recursive alias:
int aliased_global_2; // KASAN ignored
extern int __attribute__((alias("aliased_global_2"))) global_alias_2;
extern int __attribute__((alias("global_alias_2"))) __global_alias_2_alias;

// Potential indirect alias:
struct input_device_id {
  unsigned long keybit[24];
  unsigned long driver_info;
};
struct input_device_id joydev_ids[] = { { {1}, 1234 } }; // KASAN ignored
extern struct input_device_id __attribute__((alias("joydev_ids"))) __mod_joydev_ids_device_table;

// ASAN: @aliased_global{{.*}} global { i32, [28 x i8] }{{.*}}, align 32
// ASAN: @aliased_global_2{{.*}} global { i32, [28 x i8] }{{.*}}, align 32
// ASAN: @joydev_ids{{.*}} global { {{.*}}[56 x i8] zeroinitializer }, align 32
// KASAN: @aliased_global{{.*}} global i32
// KASAN: @aliased_global_2{{.*}} global i32
// KASAN: @joydev_ids{{.*}} global [1 x {{.*}}i64 1234 }], align 16

// Check the aliases exist:
// CHECK: @__global_alias ={{.*}} alias
// CHECK: @global_alias_2 ={{.*}} alias
// CHECK: @__global_alias_2_alias ={{.*}} alias
// CHECK: @__mod_joydev_ids_device_table ={{.*}} alias

// CHECK-LABEL: define internal void @asan.module_ctor
// ASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 4)
// KASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 1)
// CHECK-NEXT: ret void

// CHECK-LABEL: define internal void @asan.module_dtor
// CHECK-NEXT: call void @__asan_unregister_globals
// CHECK-NEXT: ret void