[PATCH] D42389: [ubsan] Add preinit initializer for ubsan
Francis Ricci via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 22 11:48:59 PST 2018
fjricci updated this revision to Diff 130939.
fjricci added a comment.
Remove extra whitespace
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D42389
Files:
lib/ubsan/CMakeLists.txt
lib/ubsan/ubsan_init.h
lib/ubsan/ubsan_init_standalone.cc
lib/ubsan/ubsan_preinit.cc
Index: lib/ubsan/ubsan_preinit.cc
===================================================================
--- /dev/null
+++ lib/ubsan/ubsan_preinit.cc
@@ -0,0 +1,22 @@
+//===-- ubsan_preinit.cc --------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Call __ubsan_init at the very early stage of process startup.
+//
+//===----------------------------------------------------------------------===//
+#include "ubsan_init.h"
+
+using namespace __ubsan;
+
+#if SANITIZER_CAN_USE_PREINIT_ARRAY
+ // The symbol is called __local_ubsan_preinit, because it's not intended to be
+ // exported.
+ __attribute__((section(".preinit_array"), used))
+ void (*__local_ubsan_preinit)(void) = __ubsan_init;
+#endif
Index: lib/ubsan/ubsan_init_standalone.cc
===================================================================
--- lib/ubsan/ubsan_init_standalone.cc
+++ lib/ubsan/ubsan_init_standalone.cc
@@ -20,13 +20,19 @@
#include "ubsan_init.h"
#include "ubsan_signals_standalone.h"
+using namespace __ubsan;
+
+extern "C" void __ubsan_init() {
+ InitAsStandalone();
+ InitializeDeadlySignals();
+}
+
namespace __ubsan {
class UbsanStandaloneInitializer {
public:
UbsanStandaloneInitializer() {
- InitAsStandalone();
- InitializeDeadlySignals();
+ __ubsan_init();
}
};
static UbsanStandaloneInitializer ubsan_standalone_initializer;
Index: lib/ubsan/ubsan_init.h
===================================================================
--- lib/ubsan/ubsan_init.h
+++ lib/ubsan/ubsan_init.h
@@ -13,6 +13,8 @@
#ifndef UBSAN_INIT_H
#define UBSAN_INIT_H
+#include "sanitizer_common/sanitizer_flags.h"
+
namespace __ubsan {
// Get the full tool name for UBSan.
@@ -29,6 +31,8 @@
// from "parent tool" (e.g. ASan) initialization.
void InitAsPlugin();
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __ubsan_init();
+
} // namespace __ubsan
#endif // UBSAN_INIT_H
Index: lib/ubsan/CMakeLists.txt
===================================================================
--- lib/ubsan/CMakeLists.txt
+++ lib/ubsan/CMakeLists.txt
@@ -11,6 +11,7 @@
set(UBSAN_STANDALONE_SOURCES
ubsan_diag_standalone.cc
ubsan_init_standalone.cc
+ ubsan_preinit.cc
ubsan_signals_standalone.cc
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42389.130939.patch
Type: text/x-patch
Size: 2479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180122/5605b3f9/attachment.bin>
More information about the llvm-commits
mailing list