2013-12-05 12:06:10 +01:00
|
|
|
//===-- sanitizer_asm.h -----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-08-14 10:47:11 +02:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-12-05 12:06:10 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2021-09-27 19:43:33 +02:00
|
|
|
// Various support for assembler.
|
2013-12-05 12:06:10 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Some toolchains do not support .cfi asm directives, so we have to hide
|
|
|
|
// them inside macros.
|
|
|
|
#if defined(__clang__) || \
|
|
|
|
(defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM))
|
|
|
|
// GCC defined __GCC_HAVE_DWARF2_CFI_ASM if it supports CFI.
|
|
|
|
// Clang seems to support CFI by default (or not?).
|
|
|
|
// We need two versions of macros: for inline asm and standalone asm files.
|
|
|
|
# define CFI_INL_ADJUST_CFA_OFFSET(n) ".cfi_adjust_cfa_offset " #n ";"
|
|
|
|
|
|
|
|
# define CFI_STARTPROC .cfi_startproc
|
|
|
|
# define CFI_ENDPROC .cfi_endproc
|
|
|
|
# define CFI_ADJUST_CFA_OFFSET(n) .cfi_adjust_cfa_offset n
|
2015-11-23 10:07:18 +01:00
|
|
|
# define CFI_DEF_CFA_OFFSET(n) .cfi_def_cfa_offset n
|
2013-12-05 12:06:10 +01:00
|
|
|
# define CFI_REL_OFFSET(reg, n) .cfi_rel_offset reg, n
|
2015-11-23 10:07:18 +01:00
|
|
|
# define CFI_OFFSET(reg, n) .cfi_offset reg, n
|
2013-12-05 12:06:10 +01:00
|
|
|
# define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg
|
2015-11-23 10:07:18 +01:00
|
|
|
# define CFI_DEF_CFA(reg, n) .cfi_def_cfa reg, n
|
2013-12-05 12:06:10 +01:00
|
|
|
# define CFI_RESTORE(reg) .cfi_restore reg
|
|
|
|
|
|
|
|
#else // No CFI
|
|
|
|
# define CFI_INL_ADJUST_CFA_OFFSET(n)
|
|
|
|
# define CFI_STARTPROC
|
|
|
|
# define CFI_ENDPROC
|
|
|
|
# define CFI_ADJUST_CFA_OFFSET(n)
|
2015-11-23 10:07:18 +01:00
|
|
|
# define CFI_DEF_CFA_OFFSET(n)
|
2013-12-05 12:06:10 +01:00
|
|
|
# define CFI_REL_OFFSET(reg, n)
|
2015-11-23 10:07:18 +01:00
|
|
|
# define CFI_OFFSET(reg, n)
|
2013-12-05 12:06:10 +01:00
|
|
|
# define CFI_DEF_CFA_REGISTER(reg)
|
2015-11-23 10:07:18 +01:00
|
|
|
# define CFI_DEF_CFA(reg, n)
|
2013-12-05 12:06:10 +01:00
|
|
|
# define CFI_RESTORE(reg)
|
|
|
|
#endif
|
2016-11-08 23:04:09 +01:00
|
|
|
|
|
|
|
#if !defined(__APPLE__)
|
|
|
|
# define ASM_HIDDEN(symbol) .hidden symbol
|
2019-08-14 10:47:11 +02:00
|
|
|
# define ASM_TYPE_FUNCTION(symbol) .type symbol, %function
|
2016-11-08 23:04:09 +01:00
|
|
|
# define ASM_SIZE(symbol) .size symbol, .-symbol
|
2018-10-31 12:14:23 +01:00
|
|
|
# define ASM_SYMBOL(symbol) symbol
|
|
|
|
# define ASM_SYMBOL_INTERCEPTOR(symbol) symbol
|
2019-08-14 10:47:11 +02:00
|
|
|
# define ASM_WRAPPER_NAME(symbol) __interceptor_##symbol
|
2016-11-08 23:04:09 +01:00
|
|
|
#else
|
|
|
|
# define ASM_HIDDEN(symbol)
|
|
|
|
# define ASM_TYPE_FUNCTION(symbol)
|
|
|
|
# define ASM_SIZE(symbol)
|
2018-10-31 12:14:23 +01:00
|
|
|
# define ASM_SYMBOL(symbol) _##symbol
|
|
|
|
# define ASM_SYMBOL_INTERCEPTOR(symbol) _wrap_##symbol
|
2019-08-14 10:47:11 +02:00
|
|
|
# define ASM_WRAPPER_NAME(symbol) __interceptor_##symbol
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__ELF__) && (defined(__GNU__) || defined(__FreeBSD__) || \
|
|
|
|
defined(__Fuchsia__) || defined(__linux__))
|
2019-11-05 14:54:57 +01:00
|
|
|
// clang-format off
|
2021-09-27 19:43:33 +02:00
|
|
|
#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
|
2019-11-05 14:54:57 +01:00
|
|
|
// clang-format on
|
2019-08-14 10:47:11 +02:00
|
|
|
#else
|
|
|
|
#define NO_EXEC_STACK_DIRECTIVE
|
2016-11-08 23:04:09 +01:00
|
|
|
#endif
|
2021-10-06 19:24:24 +02:00
|
|
|
|
2021-11-04 09:20:14 +01:00
|
|
|
#if (defined(__x86_64__) || defined(__i386__)) && defined(__has_include) && __has_include(<cet.h>)
|
2021-10-06 19:24:24 +02:00
|
|
|
#include <cet.h>
|
|
|
|
#endif
|
2021-11-04 09:20:14 +01:00
|
|
|
#ifndef _CET_ENDBR
|
|
|
|
#define _CET_ENDBR
|
|
|
|
#endif
|