1*7c3d14c8STreehugger Robot //===-- ubsan_init_standalone.cc ------------------------------------------===// 2*7c3d14c8STreehugger Robot // 3*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure 4*7c3d14c8STreehugger Robot // 5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source 6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details. 7*7c3d14c8STreehugger Robot // 8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===// 9*7c3d14c8STreehugger Robot // 10*7c3d14c8STreehugger Robot // Initialization of standalone UBSan runtime. 11*7c3d14c8STreehugger Robot // 12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===// 13*7c3d14c8STreehugger Robot 14*7c3d14c8STreehugger Robot #include "ubsan_platform.h" 15*7c3d14c8STreehugger Robot #if !CAN_SANITIZE_UB 16*7c3d14c8STreehugger Robot # error "UBSan is not supported on this platform!" 17*7c3d14c8STreehugger Robot #endif 18*7c3d14c8STreehugger Robot 19*7c3d14c8STreehugger Robot #include "sanitizer_common/sanitizer_internal_defs.h" 20*7c3d14c8STreehugger Robot #include "ubsan_init.h" 21*7c3d14c8STreehugger Robot 22*7c3d14c8STreehugger Robot #if SANITIZER_CAN_USE_PREINIT_ARRAY 23*7c3d14c8STreehugger Robot __attribute__((section(".preinit_array"), used)) 24*7c3d14c8STreehugger Robot void (*__local_ubsan_preinit)(void) = __ubsan::InitAsStandalone; 25*7c3d14c8STreehugger Robot #else 26*7c3d14c8STreehugger Robot // Use a dynamic initializer. 27*7c3d14c8STreehugger Robot class UbsanStandaloneInitializer { 28*7c3d14c8STreehugger Robot public: UbsanStandaloneInitializer()29*7c3d14c8STreehugger Robot UbsanStandaloneInitializer() { 30*7c3d14c8STreehugger Robot __ubsan::InitAsStandalone(); 31*7c3d14c8STreehugger Robot } 32*7c3d14c8STreehugger Robot }; 33*7c3d14c8STreehugger Robot static UbsanStandaloneInitializer ubsan_standalone_initializer; 34*7c3d14c8STreehugger Robot #endif // SANITIZER_CAN_USE_PREINIT_ARRAY 35*7c3d14c8STreehugger Robot 36