
This enables odr indicators on all platforms and private aliases on non-Windows. Note that GCC also uses private aliases: this fixes bogus `The following global variable is not properly aligned.` errors for interposed global variables Fix https://github.com/google/sanitizers/issues/398 Fix https://github.com/google/sanitizers/issues/1017 Fix https://github.com/llvm/llvm-project/issues/36893 (we can restore D46665) Global variables of non-hasExactDefinition() linkages (i.e. linkonce/linkonce_odr/weak/weak_odr/common/external_weak) are not instrumented. If an instrumented variable gets interposed to an uninstrumented variable due to symbol interposition (e.g. in issue 36893, _ZTS1A in foo.so is resolved to _ZTS1A in the executable), there may be a bogus error. With private aliases, the register code will not resolve to a definition in another module, and thus prevent the issue. Cons: minor size increase. This is mainly due to extra `__odr_asan_gen_*` symbols. (ELF) In addition, in relocatable files private aliases replace some relocations referencing global symbols with .L symbols and may introduce some STT_SECTION symbols. For lld, with -g0, the size increase is 0.07~0.09% for many configurations I have tested: -O0, -O1, -O2, -O3, -O2 -ffunction-sections -fdata-sections -Wl,--gc-sections. With -g1 or above, the size increase ratio will be even smaller. This patch obsoletes D92078. Don't migrate Windows for now: the static data member of a specialization `std::num_put<char>::id` is a weak symbol, as well as its ODR indicator. Unfortunately, link.exe (and lld without -lldmingw) generally doesn't support duplicate weak definitions (weak symbols in different TUs likely pick different defined external symbols and conflict). Differential Revision: https://reviews.llvm.org/D137227
30 lines
1.9 KiB
C++
30 lines
1.9 KiB
C++
// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefixes=CHECK,INDICATOR1,GLOB_ALIAS_INDICATOR,ALIAS1
|
|
// RUN: %clang_cc1 -fsanitize=address -fno-sanitize-address-use-odr-indicator -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefixes=CHECK,INDICATOR0,GLOB_VAR,ALIAS0
|
|
// RUN: %clang_cc1 -fsanitize=address -fno-sanitize-address-use-odr-indicator -fsanitize-address-use-odr-indicator -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefixes=CHECK,INDICATOR1,GLOB_ALIAS_INDICATOR,ALIAS1
|
|
// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-use-odr-indicator -fno-sanitize-address-use-odr-indicator -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefixes=CHECK,INDICATOR0,GLOB_VAR,ALIAS0
|
|
|
|
// No alias on Windows but indicators should work.
|
|
// RUN: %clang_cc1 -fsanitize=address -fno-sanitize-address-use-odr-indicator -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefixes=CHECK,GLOB_VAR,ALIAS0
|
|
// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefixes=CHECK,INDICATOR1,GLOB_VAR_INDICATOR,ALIAS0
|
|
|
|
int global;
|
|
|
|
int main() {
|
|
return global;
|
|
}
|
|
|
|
// CHECK: [[VAR:@.*global.*]] ={{.*}} global { i32, [28 x i8] } zeroinitializer, align 32
|
|
|
|
// INDICATOR0-NOT: __odr_asan_gen
|
|
// INDICATOR1: [[ODR:@.*__odr_asan_gen_.*global.*]] = global i8 0, align 1
|
|
|
|
// GLOB_VAR: @0 = internal global {{.*}} [[VAR]] to i64), {{.*}}, i64 0 }]
|
|
// GLOB_VAR_INDICATOR: @0 = internal global {{.*}} [[VAR]] to i64), {{.*}}, i64 ptrtoint (ptr [[ODR]] to i64) }]
|
|
// GLOB_ALIAS_INDICATOR: @0 = internal global {{.*}} @1 to i64), {{.*}}, i64 ptrtoint (ptr [[ODR]] to i64) }]
|
|
|
|
// ALIAS0-NOT: private alias
|
|
// ALIAS1: @1 = private alias {{.*}} [[VAR]]
|
|
|
|
// CHECK: call void @__asan_register_globals(i64 ptrtoint (ptr @0 to i64), i64 1)
|
|
// CHECK: call void @__asan_unregister_globals(i64 ptrtoint (ptr @0 to i64), i64 1)
|