morehouse created this revision.
morehouse added reviewers: pcc, eugenis, vitalybuka.
morehouse requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.
Allows us to use the small code model when we disable relocation
relaxation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111344
Files:
clang/lib/Driver/SanitizerArgs.cpp
compiler-rt/test/hwasan/TestCases/global.c
compiler-rt/test/hwasan/lit.cfg.py
Index: compiler-rt/test/hwasan/lit.cfg.py
===================================================================
--- compiler-rt/test/hwasan/lit.cfg.py
+++ compiler-rt/test/hwasan/lit.cfg.py
@@ -18,10 +18,12 @@
else:
config.available_features.add('pointer-tagging')
if config.target_arch == 'x86_64':
- # This does basically the same thing as tagged-globals on aarch64. Because
- # the x86_64 implementation is for testing purposes only there is no
- # equivalent target feature implemented on x86_64.
- clang_hwasan_common_cflags += ["-mcmodel=large"]
+ # By default the assembler uses R_X86_64_REX_GOTPCRELX relocations, which can
+ # be relaxed to direct references. When tagged globals are enabled, these
+ # references fail to link since they have more than a 32-bit offset from RIP.
+ # As a workaround, we disable the relaxation.
+ # TODO: Implement a way to disable for the affected relocations only.
+ clang_hwasan_common_cflags += ["-Wa,-mrelax-relocations=no"]
# The callback instrumentation used on x86_64 has a 1/64 chance of choosing a
# stack tag of 0. This causes stack tests to become flaky, so we force tags
Index: compiler-rt/test/hwasan/TestCases/global.c
===================================================================
--- compiler-rt/test/hwasan/TestCases/global.c
+++ compiler-rt/test/hwasan/TestCases/global.c
@@ -5,6 +5,15 @@
// RUN: not %run %t -1 2>&1 | FileCheck --check-prefixes=CHECK,LSYM %s
// RUN: not %env_hwasan_opts=symbolize=0 %run %t -1 2>&1 | FileCheck
--check-prefixes=CHECK,LNOSYM %s
+// Test with and without optimizations, with and without PIC, since different
+// backend passes run depending on these flags.
+// RUN: %clang_hwasan -fno-pic %s -o %t
+// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
+// RUN: %clang_hwasan -fno-pic -O2 %s -o %t
+// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
+// RUN: %clang_hwasan -O2 %s -o %t
+// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
+
// REQUIRES: pointer-tagging
int x = 1;
Index: clang/lib/Driver/SanitizerArgs.cpp
===================================================================
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -1146,7 +1146,7 @@
CmdArgs.push_back(Args.MakeArgString("hwasan-abi=" + HwasanAbi));
}
- if (Sanitizers.has(SanitizerKind::HWAddress) && TC.getTriple().isAArch64()) {
+ if (Sanitizers.has(SanitizerKind::HWAddress) && !HwasanUseAliases) {
CmdArgs.push_back("-target-feature");
CmdArgs.push_back("+tagged-globals");
}
Index: compiler-rt/test/hwasan/lit.cfg.py
===================================================================
--- compiler-rt/test/hwasan/lit.cfg.py
+++ compiler-rt/test/hwasan/lit.cfg.py
@@ -18,10 +18,12 @@
else:
config.available_features.add('pointer-tagging')
if config.target_arch == 'x86_64':
- # This does basically the same thing as tagged-globals on aarch64. Because
- # the x86_64 implementation is for testing purposes only there is no
- # equivalent target feature implemented on x86_64.
- clang_hwasan_common_cflags += ["-mcmodel=large"]
+ # By default the assembler uses R_X86_64_REX_GOTPCRELX relocations, which can
+ # be relaxed to direct references. When tagged globals are enabled, these
+ # references fail to link since they have more than a 32-bit offset from RIP.
+ # As a workaround, we disable the relaxation.
+ # TODO: Implement a way to disable for the affected relocations only.
+ clang_hwasan_common_cflags += ["-Wa,-mrelax-relocations=no"]
# The callback instrumentation used on x86_64 has a 1/64 chance of choosing a
# stack tag of 0. This causes stack tests to become flaky, so we force tags
Index: compiler-rt/test/hwasan/TestCases/global.c
===================================================================
--- compiler-rt/test/hwasan/TestCases/global.c
+++ compiler-rt/test/hwasan/TestCases/global.c
@@ -5,6 +5,15 @@
// RUN: not %run %t -1 2>&1 | FileCheck --check-prefixes=CHECK,LSYM %s
// RUN: not %env_hwasan_opts=symbolize=0 %run %t -1 2>&1 | FileCheck --check-prefixes=CHECK,LNOSYM %s
+// Test with and without optimizations, with and without PIC, since different
+// backend passes run depending on these flags.
+// RUN: %clang_hwasan -fno-pic %s -o %t
+// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
+// RUN: %clang_hwasan -fno-pic -O2 %s -o %t
+// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
+// RUN: %clang_hwasan -O2 %s -o %t
+// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
+
// REQUIRES: pointer-tagging
int x = 1;
Index: clang/lib/Driver/SanitizerArgs.cpp
===================================================================
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -1146,7 +1146,7 @@
CmdArgs.push_back(Args.MakeArgString("hwasan-abi=" + HwasanAbi));
}
- if (Sanitizers.has(SanitizerKind::HWAddress) && TC.getTriple().isAArch64()) {
+ if (Sanitizers.has(SanitizerKind::HWAddress) && !HwasanUseAliases) {
CmdArgs.push_back("-target-feature");
CmdArgs.push_back("+tagged-globals");
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits