Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 940bd71

Browse files
committed
[sanitizer] support toolchains that don't understand CFI directives
Summary: Support toolchains that don't understand CFI directives. Reviewers: dvyukov Reviewed By: dvyukov CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2336 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@196480 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 31589b2 commit 940bd71

File tree

3 files changed

+168
-126
lines changed

3 files changed

+168
-126
lines changed

lib/sanitizer_common/sanitizer_asm.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- sanitizer_asm.h -----------------------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// Various support for assemebler.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
// Some toolchains do not support .cfi asm directives, so we have to hide
15+
// them inside macros.
16+
#if defined(__clang__) || \
17+
(defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM))
18+
// GCC defined __GCC_HAVE_DWARF2_CFI_ASM if it supports CFI.
19+
// Clang seems to support CFI by default (or not?).
20+
// We need two versions of macros: for inline asm and standalone asm files.
21+
# define CFI_INL_ADJUST_CFA_OFFSET(n) ".cfi_adjust_cfa_offset " #n ";"
22+
23+
# define CFI_STARTPROC .cfi_startproc
24+
# define CFI_ENDPROC .cfi_endproc
25+
# define CFI_ADJUST_CFA_OFFSET(n) .cfi_adjust_cfa_offset n
26+
# define CFI_REL_OFFSET(reg, n) .cfi_rel_offset reg, n
27+
# define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg
28+
# define CFI_RESTORE(reg) .cfi_restore reg
29+
30+
#else // No CFI
31+
# define CFI_INL_ADJUST_CFA_OFFSET(n)
32+
# define CFI_STARTPROC
33+
# define CFI_ENDPROC
34+
# define CFI_ADJUST_CFA_OFFSET(n)
35+
# define CFI_REL_OFFSET(reg, n)
36+
# define CFI_DEF_CFA_REGISTER(reg)
37+
# define CFI_RESTORE(reg)
38+
#endif
39+
40+

lib/tsan/rtl/tsan_rtl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "sanitizer_common/sanitizer_allocator.h"
3030
#include "sanitizer_common/sanitizer_allocator_internal.h"
31+
#include "sanitizer_common/sanitizer_asm.h"
3132
#include "sanitizer_common/sanitizer_common.h"
3233
#include "sanitizer_common/sanitizer_libignore.h"
3334
#include "sanitizer_common/sanitizer_suppressions.h"
@@ -736,11 +737,11 @@ void AcquireReleaseImpl(ThreadState *thr, uptr pc, SyncClock *c);
736737
// so we create a reserve stack frame for it (1024b must be enough).
737738
#define HACKY_CALL(f) \
738739
__asm__ __volatile__("sub $1024, %%rsp;" \
739-
".cfi_adjust_cfa_offset 1024;" \
740+
CFI_INL_ADJUST_CFA_OFFSET(1024) \
740741
".hidden " #f "_thunk;" \
741742
"call " #f "_thunk;" \
742743
"add $1024, %%rsp;" \
743-
".cfi_adjust_cfa_offset -1024;" \
744+
CFI_INL_ADJUST_CFA_OFFSET(-1024) \
744745
::: "memory", "cc");
745746
#else
746747
#define HACKY_CALL(f) f()

0 commit comments

Comments
 (0)