Relocate the external headers provided by ASan and the common sanitizer
library.
These headers are intended to be available to user code when built with
AddressSanitizer (or one of the other sanitizer's in the future) to
interface with the runtime library. As such, they form stable external
C interfaces, and the headers shouldn't be located within the
implementation.
I've pulled them out into what seem like fairly obvious locations and
names, but I'm wide open to further bikeshedding of these names and
locations.
I've updated the code and the build system to cope with the new
locations, both CMake and Makefile. Please let me know if this breaks
anyone's build.
The eventual goal is to install these headers along side the Clang
builtin headers when we build the ASan runtime and install it. My
current thinking is to locate them at:
<prefix>/lib/clang/X.Y/include/sanitizer/common_interface_defs.h
<prefix>/lib/clang/X.Y/include/sanitizer/asan_interface.h
<prefix>/lib/clang/X.Y/include/sanitizer/...
But maybe others have different suggestions?
Fixing the style of the #include between these headers at least unblocks
experimentation with installing them as they now should work when
installed in these locations.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162822 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 088a59a..844660f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,6 +100,9 @@
set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
endfunction()
+# Add the public header's directory to the includes for all of compiler-rt.
+include_directories(include)
+
add_subdirectory(lib)
if(LLVM_INCLUDE_TESTS)
diff --git a/lib/asan/asan_interface.h b/include/sanitizer/asan_interface.h
similarity index 97%
rename from lib/asan/asan_interface.h
rename to include/sanitizer/asan_interface.h
index 54a0312..4d344f6 100644
--- a/lib/asan/asan_interface.h
+++ b/include/sanitizer/asan_interface.h
@@ -1,4 +1,4 @@
-//===-- asan_interface.h ----------------------------------------*- C++ -*-===//
+//===-- sanitizer/asan_interface.h ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,10 +12,11 @@
// This header can be included by the instrumented program to fetch
// data (mostly allocator statistics) from ASan runtime library.
//===----------------------------------------------------------------------===//
-#ifndef ASAN_INTERFACE_H
-#define ASAN_INTERFACE_H
+#ifndef SANITIZER_ASAN_INTERFACE_H
+#define SANITIZER_ASAN_INTERFACE_H
-#include "sanitizer_common/sanitizer_interface_defs.h"
+#include <sanitizer/common_interface_defs.h>
+
// ----------- ATTENTION -------------
// This header should NOT include any other headers from ASan runtime.
// All functions in this header are extern "C" and start with __asan_.
@@ -198,4 +199,4 @@
SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
} // extern "C"
-#endif // ASAN_INTERFACE_H
+#endif // SANITIZER_ASAN_INTERFACE_H
diff --git a/lib/sanitizer_common/sanitizer_interface_defs.h b/include/sanitizer/common_interface_defs.h
similarity index 88%
rename from lib/sanitizer_common/sanitizer_interface_defs.h
rename to include/sanitizer/common_interface_defs.h
index 2395ea5..f76462c 100644
--- a/lib/sanitizer_common/sanitizer_interface_defs.h
+++ b/include/sanitizer/common_interface_defs.h
@@ -1,4 +1,4 @@
-//===-- sanitizer_interface_defs.h -----------------------------*- C++ -*-===//
+//===-- sanitizer/common_interface_defs.h -----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,8 +12,8 @@
// NOTE: This file may be included into user code.
//===----------------------------------------------------------------------===//
-#ifndef SANITIZER_INTERFACE_DEFS_H
-#define SANITIZER_INTERFACE_DEFS_H
+#ifndef SANITIZER_COMMON_INTERFACE_DEFS_H
+#define SANITIZER_COMMON_INTERFACE_DEFS_H
// ----------- ATTENTION -------------
// This header should NOT include any other headers to avoid portability issues.
@@ -53,4 +53,4 @@
} // namespace __sanitizer
-#endif // SANITIZER_INTERFACE_DEFS_H
+#endif // SANITIZER_COMMON_INTERFACE_DEFS_H
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc
index e64085d..924f292 100644
--- a/lib/asan/asan_allocator.cc
+++ b/lib/asan/asan_allocator.cc
@@ -27,7 +27,6 @@
#include "asan_allocator.h"
#include "asan_interceptors.h"
-#include "asan_interface.h"
#include "asan_internal.h"
#include "asan_lock.h"
#include "asan_mapping.h"
@@ -35,6 +34,7 @@
#include "asan_report.h"
#include "asan_thread.h"
#include "asan_thread_registry.h"
+#include "sanitizer/asan_interface.h"
#include "sanitizer_common/sanitizer_atomic.h"
#if defined(_WIN32) && !defined(__clang__)
diff --git a/lib/asan/asan_flags.h b/lib/asan/asan_flags.h
index 8b5c11c..ce30fcb 100644
--- a/lib/asan/asan_flags.h
+++ b/lib/asan/asan_flags.h
@@ -15,7 +15,7 @@
#ifndef ASAN_FLAGS_H
#define ASAN_FLAGS_H
-#include "sanitizer_common/sanitizer_interface_defs.h"
+#include "sanitizer/common_interface_defs.h"
// ASan flag values can be defined in three ways:
// 1) initialized with default values at startup.
diff --git a/lib/asan/asan_globals.cc b/lib/asan/asan_globals.cc
index 377a4c6..6e90cb5 100644
--- a/lib/asan/asan_globals.cc
+++ b/lib/asan/asan_globals.cc
@@ -12,7 +12,6 @@
// Handle globals.
//===----------------------------------------------------------------------===//
#include "asan_interceptors.h"
-#include "asan_interface.h"
#include "asan_internal.h"
#include "asan_lock.h"
#include "asan_mapping.h"
@@ -20,6 +19,7 @@
#include "asan_stack.h"
#include "asan_stats.h"
#include "asan_thread.h"
+#include "sanitizer/asan_interface.h"
namespace __asan {
diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc
index 71ea623..db0e00b 100644
--- a/lib/asan/asan_interceptors.cc
+++ b/lib/asan/asan_interceptors.cc
@@ -15,7 +15,6 @@
#include "asan_allocator.h"
#include "asan_intercepted_functions.h"
-#include "asan_interface.h"
#include "asan_internal.h"
#include "asan_mapping.h"
#include "asan_report.h"
@@ -23,6 +22,7 @@
#include "asan_stats.h"
#include "asan_thread_registry.h"
#include "interception/interception.h"
+#include "sanitizer/asan_interface.h"
#include "sanitizer_common/sanitizer_libc.h"
namespace __asan {
diff --git a/lib/asan/asan_poisoning.cc b/lib/asan/asan_poisoning.cc
index 3b9d9f6..ce9de92 100644
--- a/lib/asan/asan_poisoning.cc
+++ b/lib/asan/asan_poisoning.cc
@@ -13,9 +13,9 @@
//===----------------------------------------------------------------------===//
#include "asan_interceptors.h"
-#include "asan_interface.h"
#include "asan_internal.h"
#include "asan_mapping.h"
+#include "sanitizer/asan_interface.h"
namespace __asan {
diff --git a/lib/asan/asan_report.h b/lib/asan/asan_report.h
index e7ef326..0845690 100644
--- a/lib/asan/asan_report.h
+++ b/lib/asan/asan_report.h
@@ -12,8 +12,8 @@
// ASan-private header for error reporting functions.
//===----------------------------------------------------------------------===//
-#include "asan_interface.h"
#include "asan_internal.h"
+#include "sanitizer/asan_interface.h"
namespace __asan {
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index a2e85fd..2970fd5 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//
#include "asan_allocator.h"
#include "asan_interceptors.h"
-#include "asan_interface.h"
#include "asan_internal.h"
#include "asan_lock.h"
#include "asan_mapping.h"
@@ -22,6 +21,7 @@
#include "asan_stats.h"
#include "asan_thread.h"
#include "asan_thread_registry.h"
+#include "sanitizer/asan_interface.h"
#include "sanitizer_common/sanitizer_atomic.h"
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_libc.h"
diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc
index a69accd..f8ebc82 100644
--- a/lib/asan/asan_stack.cc
+++ b/lib/asan/asan_stack.cc
@@ -12,8 +12,8 @@
// Code for ASan stack trace.
//===----------------------------------------------------------------------===//
#include "asan_flags.h"
-#include "asan_interface.h"
#include "asan_stack.h"
+#include "sanitizer/asan_interface.h"
namespace __asan {
diff --git a/lib/asan/asan_stats.cc b/lib/asan/asan_stats.cc
index c286c37..189315b 100644
--- a/lib/asan/asan_stats.cc
+++ b/lib/asan/asan_stats.cc
@@ -12,11 +12,11 @@
// Code related to statistics collected by AddressSanitizer.
//===----------------------------------------------------------------------===//
#include "asan_interceptors.h"
-#include "asan_interface.h"
#include "asan_internal.h"
#include "asan_lock.h"
#include "asan_stats.h"
#include "asan_thread_registry.h"
+#include "sanitizer/asan_interface.h"
namespace __asan {
diff --git a/lib/asan/lit_tests/interface_symbols.c b/lib/asan/lit_tests/interface_symbols.c
index 8b92695..03998d5 100644
--- a/lib/asan/lit_tests/interface_symbols.c
+++ b/lib/asan/lit_tests/interface_symbols.c
@@ -3,7 +3,8 @@
// RUN: %clang -faddress-sanitizer -dead_strip -O2 %s -o %t.exe
// RUN: nm %t.exe | egrep " [TW] " | sed "s/.* T //" | sed "s/.* W //" \
// RUN: | grep "__asan_" | sed "s/___asan_/__asan_/" > %t.symbols
-// RUN: cat %p/../asan_interface.h | sed "s/\/\/.*//" | sed "s/typedef.*//" \
+// RUN: cat %p/../../../include/sanitizer/asan_interface.h \
+// RUN: | sed "s/\/\/.*//" | sed "s/typedef.*//" \
// RUN: | grep "__asan_.*(" | sed "s/.* __asan_/__asan_/;s/(.*//" \
// RUN: > %t.interface
// RUN: echo __asan_report_load1 >> %t.interface
diff --git a/lib/asan/output_tests/test_output.sh b/lib/asan/output_tests/test_output.sh
index fb2d74c..eef8ef6 100755
--- a/lib/asan/output_tests/test_output.sh
+++ b/lib/asan/output_tests/test_output.sh
@@ -8,7 +8,7 @@
FILE_CHECK=$3
CXXFLAGS="-mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -g"
SYMBOLIZER=../scripts/asan_symbolize.py
-ASAN_INTERFACE_H=../asan_interface.h
+ASAN_INTERFACE_H=../../../include/sanitizer/asan_interface.h
TMP_ASAN_REPORT=asan_report.tmp
run_program() {
diff --git a/lib/asan/tests/asan_noinst_test.cc b/lib/asan/tests/asan_noinst_test.cc
index e326497..70b59f0 100644
--- a/lib/asan/tests/asan_noinst_test.cc
+++ b/lib/asan/tests/asan_noinst_test.cc
@@ -11,13 +11,14 @@
//
// This test file should be compiled w/o asan instrumentation.
//===----------------------------------------------------------------------===//
+
#include "asan_allocator.h"
-#include "asan_interface.h"
#include "asan_internal.h"
#include "asan_mapping.h"
#include "asan_stack.h"
#include "asan_test_utils.h"
#include "asan_test_config.h"
+#include "sanitizer/asan_interface.h"
#include <assert.h>
#include <stdio.h>
diff --git a/lib/sanitizer_common/sanitizer_internal_defs.h b/lib/sanitizer_common/sanitizer_internal_defs.h
index 98d911c..5d00cd0 100644
--- a/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -13,7 +13,7 @@
#ifndef SANITIZER_DEFS_H
#define SANITIZER_DEFS_H
-#include "sanitizer_interface_defs.h"
+#include "sanitizer/common_interface_defs.h"
using namespace __sanitizer; // NOLINT
// ----------- ATTENTION -------------
// This header should NOT include any other headers to avoid portability issues.
diff --git a/lib/sanitizer_common/sanitizer_libc.h b/lib/sanitizer_common/sanitizer_libc.h
index 257af2c..8c3a78c 100644
--- a/lib/sanitizer_common/sanitizer_libc.h
+++ b/lib/sanitizer_common/sanitizer_libc.h
@@ -18,7 +18,7 @@
// ----------- ATTENTION -------------
// This header should NOT include any other headers from sanitizer runtime.
-#include "sanitizer_interface_defs.h"
+#include "sanitizer/common_interface_defs.h"
namespace __sanitizer {
diff --git a/make/config.mk b/make/config.mk
index 42fb9a8..12d8bc2 100644
--- a/make/config.mk
+++ b/make/config.mk
@@ -42,5 +42,5 @@
###
# Common compiler options
-COMMON_CXXFLAGS=-fno-exceptions -fPIC -funwind-tables -I${ProjSrcRoot}/lib
+COMMON_CXXFLAGS=-fno-exceptions -fPIC -funwind-tables -I${ProjSrcRoot}/lib -I${ProjSrcRoot}/include
COMMON_CFLAGS=-fPIC