-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: An implementation of ubsan runtime library suitable for use in production. Minimal attack surface. * No stack traces. * Definitely no C++ demangling. * No UBSAN_OPTIONS=log_file=/path (very suid-unfriendly). And no UBSAN_OPTIONS in general. * as simple as possible Minimal CPU and RAM overhead. * Source locations unnecessary in the presence of (split) debug info. * Values and types (as in A+B overflows T) can be reconstructed from register/stack dumps, once you know what type of error you are looking at. * above two items save 3% binary size. When UBSan is used with -ftrap-function=abort, sometimes it is hard to reason about failures. This library replaces abort with a slightly more informative message without much extra overhead. Since ubsan interface in not stable, this code must reside in compiler-rt. Reviewers: pcc, kcc Subscribers: srhines, mgorny, aprantl, krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D36810 llvm-svn: 312029
- Loading branch information
Showing
20 changed files
with
436 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=unsigned-integer-overflow -fsanitize-minimal-runtime %s -emit-llvm -o - | FileCheck %s | ||
|
||
unsigned long li, lj, lk; | ||
|
||
// CHECK-LABEL: define void @testlongadd() | ||
void testlongadd() { | ||
// CHECK: call void @__ubsan_handle_add_overflow_minimal_abort() | ||
li = lj + lk; | ||
} | ||
|
||
// CHECK-LABEL: define void @testlongsub() | ||
void testlongsub() { | ||
// CHECK: call void @__ubsan_handle_sub_overflow_minimal_abort() | ||
li = lj - lk; | ||
} | ||
|
||
// CHECK-LABEL: define void @testlongmul() | ||
void testlongmul() { | ||
// CHECK: call void @__ubsan_handle_mul_overflow_minimal_abort() | ||
li = lj * lk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Build for the undefined behavior sanitizer runtime support library. | ||
|
||
set(UBSAN_MINIMAL_SOURCES | ||
ubsan_minimal_handlers.cc | ||
) | ||
|
||
include_directories(..) | ||
|
||
set(UBSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) | ||
append_rtti_flag(OFF UBSAN_CFLAGS) | ||
|
||
set(UBSAN_STANDALONE_CFLAGS ${SANITIZER_COMMON_CFLAGS}) | ||
append_rtti_flag(OFF UBSAN_STANDALONE_CFLAGS) | ||
|
||
add_compiler_rt_component(ubsan-minimal) | ||
|
||
# Common parts of UBSan runtime. | ||
add_compiler_rt_object_libraries(RTUbsan_minimal | ||
ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH} | ||
SOURCES ${UBSAN_MINIMAL_SOURCES} CFLAGS ${UBSAN_CFLAGS}) | ||
|
||
|
||
if(COMPILER_RT_HAS_UBSAN) | ||
# Initializer of standalone UBSan runtime. | ||
|
||
# Standalone UBSan runtimes. | ||
add_compiler_rt_runtime(clang_rt.ubsan_minimal | ||
STATIC | ||
ARCHS ${UBSAN_SUPPORTED_ARCH} | ||
OBJECT_LIBS RTUbsan_minimal | ||
CFLAGS ${UBSAN_CFLAGS} | ||
PARENT_TARGET ubsan-minimal) | ||
|
||
add_compiler_rt_runtime(clang_rt.ubsan_minimal | ||
SHARED | ||
ARCHS ${UBSAN_SUPPORTED_ARCH} | ||
OBJECT_LIBS RTUbsan_minimal | ||
CFLAGS ${UBSAN_CFLAGS} | ||
LINK_LIBS ${UBSAN_DYNAMIC_LIBS} | ||
PARENT_TARGET ubsan-minimal) | ||
|
||
if (UNIX) | ||
set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH}) | ||
list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386 i686) | ||
add_sanitizer_rt_symbols(clang_rt.ubsan_minimal | ||
ARCHS ${ARCHS_FOR_SYMBOLS} | ||
PARENT_TARGET ubsan-minimal | ||
EXTRA ubsan.syms.extra) | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__ubsan_* |
Oops, something went wrong.