Merge compiler-rt trunk r291476.
This commit is contained in:
commit
552de5b5d0
@ -179,6 +179,8 @@ class ScopedInErrorReport {
|
||||
if (common_flags()->print_cmdline)
|
||||
PrintCmdline();
|
||||
|
||||
if (common_flags()->print_module_map == 2) PrintModuleMap();
|
||||
|
||||
// Copy the message buffer so that we could start logging without holding a
|
||||
// lock that gets aquired during printing.
|
||||
InternalScopedBuffer<char> buffer_copy(kErrorMessageBufferSize);
|
||||
|
@ -46,6 +46,7 @@ static void AsanDie() {
|
||||
// Don't die twice - run a busy loop.
|
||||
while (1) { }
|
||||
}
|
||||
if (common_flags()->print_module_map >= 1) PrintModuleMap();
|
||||
if (flags()->sleep_before_dying) {
|
||||
Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying);
|
||||
SleepForSeconds(flags()->sleep_before_dying);
|
||||
|
3
contrib/compiler-rt/lib/asan/weak_symbols.txt
Normal file
3
contrib/compiler-rt/lib/asan/weak_symbols.txt
Normal file
@ -0,0 +1,3 @@
|
||||
___asan_default_options
|
||||
___asan_default_suppressions
|
||||
___asan_on_error
|
@ -26,10 +26,10 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond) \
|
||||
bl SYMBOL_NAME(__ ## cond ## sf2) SEPARATOR \
|
||||
cmp r0, #0 SEPARATOR \
|
||||
b ## cond 1f SEPARATOR \
|
||||
mov r0, #0 SEPARATOR \
|
||||
movs r0, #0 SEPARATOR \
|
||||
pop { r4, pc } SEPARATOR \
|
||||
1: SEPARATOR \
|
||||
mov r0, #1 SEPARATOR \
|
||||
movs r0, #1 SEPARATOR \
|
||||
pop { r4, pc } SEPARATOR \
|
||||
END_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond)
|
||||
|
||||
|
@ -47,27 +47,50 @@
|
||||
DEFINE_COMPILERRT_FUNCTION(__eqsf2)
|
||||
// Make copies of a and b with the sign bit shifted off the top. These will
|
||||
// be used to detect zeros and NaNs.
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
push {r6, lr}
|
||||
lsls r2, r0, #1
|
||||
lsls r3, r1, #1
|
||||
#else
|
||||
mov r2, r0, lsl #1
|
||||
mov r3, r1, lsl #1
|
||||
#endif
|
||||
|
||||
// We do the comparison in three stages (ignoring NaN values for the time
|
||||
// being). First, we orr the absolute values of a and b; this sets the Z
|
||||
// flag if both a and b are zero (of either sign). The shift of r3 doesn't
|
||||
// effect this at all, but it *does* make sure that the C flag is clear for
|
||||
// the subsequent operations.
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
lsrs r6, r3, #1
|
||||
orrs r6, r2, r6
|
||||
#else
|
||||
orrs r12, r2, r3, lsr #1
|
||||
|
||||
#endif
|
||||
// Next, we check if a and b have the same or different signs. If they have
|
||||
// opposite signs, this eor will set the N flag.
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
beq 1f
|
||||
movs r6, r0
|
||||
eors r6, r1
|
||||
1:
|
||||
#else
|
||||
it ne
|
||||
eorsne r12, r0, r1
|
||||
#endif
|
||||
|
||||
// If a and b are equal (either both zeros or bit identical; again, we're
|
||||
// ignoring NaNs for now), this subtract will zero out r0. If they have the
|
||||
// same sign, the flags are updated as they would be for a comparison of the
|
||||
// absolute values of a and b.
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
bmi 1f
|
||||
subs r0, r2, r3
|
||||
1:
|
||||
#else
|
||||
it pl
|
||||
subspl r0, r2, r3
|
||||
#endif
|
||||
|
||||
// If a is smaller in magnitude than b and both have the same sign, place
|
||||
// the negation of the sign of b in r0. Thus, if both are negative and
|
||||
@ -79,30 +102,69 @@ DEFINE_COMPILERRT_FUNCTION(__eqsf2)
|
||||
// still clear from the shift argument in orrs; if a is positive and b
|
||||
// negative, this places 0 in r0; if a is negative and b positive, -1 is
|
||||
// placed in r0.
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
bhs 1f
|
||||
// Here if a and b have the same sign and absA < absB, the result is thus
|
||||
// b < 0 ? 1 : -1. Same if a and b have the opposite sign (ignoring Nan).
|
||||
movs r0, #1
|
||||
lsrs r1, #31
|
||||
bne LOCAL_LABEL(CHECK_NAN)
|
||||
negs r0, r0
|
||||
b LOCAL_LABEL(CHECK_NAN)
|
||||
1:
|
||||
#else
|
||||
it lo
|
||||
mvnlo r0, r1, asr #31
|
||||
#endif
|
||||
|
||||
// If a is greater in magnitude than b and both have the same sign, place
|
||||
// the sign of b in r0. Thus, if both are negative and a < b, -1 is placed
|
||||
// in r0, which is the desired result. Conversely, if both are positive
|
||||
// and a > b, zero is placed in r0.
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
bls 1f
|
||||
// Here both have the same sign and absA > absB.
|
||||
movs r0, #1
|
||||
lsrs r1, #31
|
||||
beq LOCAL_LABEL(CHECK_NAN)
|
||||
negs r0, r0
|
||||
1:
|
||||
#else
|
||||
it hi
|
||||
movhi r0, r1, asr #31
|
||||
#endif
|
||||
|
||||
// If you've been keeping track, at this point r0 contains -1 if a < b and
|
||||
// 0 if a >= b. All that remains to be done is to set it to 1 if a > b.
|
||||
// If a == b, then the Z flag is set, so we can get the correct final value
|
||||
// into r0 by simply or'ing with 1 if Z is clear.
|
||||
// For Thumb-1, r0 contains -1 if a < b, 0 if a > b and 0 if a == b.
|
||||
#if __ARM_ARCH_ISA_THUMB != 1
|
||||
it ne
|
||||
orrne r0, r0, #1
|
||||
#endif
|
||||
|
||||
// Finally, we need to deal with NaNs. If either argument is NaN, replace
|
||||
// the value in r0 with 1.
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
LOCAL_LABEL(CHECK_NAN):
|
||||
movs r6, #0xff
|
||||
lsls r6, #24
|
||||
cmp r2, r6
|
||||
bhi 1f
|
||||
cmp r3, r6
|
||||
1:
|
||||
bls 2f
|
||||
movs r0, #1
|
||||
2:
|
||||
pop {r6, pc}
|
||||
#else
|
||||
cmp r2, #0xff000000
|
||||
ite ls
|
||||
cmpls r3, #0xff000000
|
||||
movhi r0, #1
|
||||
JMP(lr)
|
||||
#endif
|
||||
END_COMPILERRT_FUNCTION(__eqsf2)
|
||||
DEFINE_COMPILERRT_FUNCTION_ALIAS(__lesf2, __eqsf2)
|
||||
DEFINE_COMPILERRT_FUNCTION_ALIAS(__ltsf2, __eqsf2)
|
||||
@ -114,8 +176,45 @@ DEFINE_COMPILERRT_FUNCTION(__gtsf2)
|
||||
// Given that the two paths share so much code, one might be tempted to
|
||||
// unify them; however, the extra code needed to do so makes the code size
|
||||
// to performance tradeoff very hard to justify for such small functions.
|
||||
mov r2, r0, lsl #1
|
||||
mov r3, r1, lsl #1
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
push {r6, lr}
|
||||
lsls r2, r0, #1
|
||||
lsls r3, r1, #1
|
||||
lsrs r6, r3, #1
|
||||
orrs r6, r2, r6
|
||||
beq 1f
|
||||
movs r6, r0
|
||||
eors r6, r1
|
||||
1:
|
||||
bmi 2f
|
||||
subs r0, r2, r3
|
||||
2:
|
||||
bhs 3f
|
||||
movs r0, #1
|
||||
lsrs r1, #31
|
||||
bne LOCAL_LABEL(CHECK_NAN_2)
|
||||
negs r0, r0
|
||||
b LOCAL_LABEL(CHECK_NAN_2)
|
||||
3:
|
||||
bls 4f
|
||||
movs r0, #1
|
||||
lsrs r1, #31
|
||||
beq LOCAL_LABEL(CHECK_NAN_2)
|
||||
negs r0, r0
|
||||
4:
|
||||
LOCAL_LABEL(CHECK_NAN_2):
|
||||
movs r6, #0xff
|
||||
lsls r6, #24
|
||||
cmp r2, r6
|
||||
bhi 5f
|
||||
cmp r3, r6
|
||||
5:
|
||||
bls 6f
|
||||
movs r0, #1
|
||||
negs r0, r0
|
||||
6:
|
||||
pop {r6, pc}
|
||||
#else
|
||||
orrs r12, r2, r3, lsr #1
|
||||
it ne
|
||||
eorsne r12, r0, r1
|
||||
@ -132,19 +231,32 @@ DEFINE_COMPILERRT_FUNCTION(__gtsf2)
|
||||
cmpls r3, #0xff000000
|
||||
movhi r0, #-1
|
||||
JMP(lr)
|
||||
#endif
|
||||
END_COMPILERRT_FUNCTION(__gtsf2)
|
||||
DEFINE_COMPILERRT_FUNCTION_ALIAS(__gesf2, __gtsf2)
|
||||
|
||||
.p2align 2
|
||||
DEFINE_COMPILERRT_FUNCTION(__unordsf2)
|
||||
// Return 1 for NaN values, 0 otherwise.
|
||||
mov r2, r0, lsl #1
|
||||
mov r3, r1, lsl #1
|
||||
mov r0, #0
|
||||
lsls r2, r0, #1
|
||||
lsls r3, r1, #1
|
||||
movs r0, #0
|
||||
#if __ARM_ARCH_ISA_THUMB == 1
|
||||
movs r1, #0xff
|
||||
lsls r1, #24
|
||||
cmp r2, r1
|
||||
bhi 1f
|
||||
cmp r3, r1
|
||||
1:
|
||||
bls 2f
|
||||
movs r0, #1
|
||||
2:
|
||||
#else
|
||||
cmp r2, #0xff000000
|
||||
ite ls
|
||||
cmpls r3, #0xff000000
|
||||
movhi r0, #1
|
||||
#endif
|
||||
JMP(lr)
|
||||
END_COMPILERRT_FUNCTION(__unordsf2)
|
||||
|
||||
|
@ -258,4 +258,17 @@ SANITIZER_INTERFACE_ATTRIBUTE
|
||||
uptr __sanitizer_get_allocated_size(const void *p) {
|
||||
return GetMallocUsableSize(p);
|
||||
}
|
||||
|
||||
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
|
||||
// Provide default (no-op) implementation of malloc hooks.
|
||||
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
||||
void __sanitizer_malloc_hook(void *ptr, uptr size) {
|
||||
(void)ptr;
|
||||
(void)size;
|
||||
}
|
||||
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
||||
void __sanitizer_free_hook(void *ptr) {
|
||||
(void)ptr;
|
||||
}
|
||||
#endif
|
||||
} // extern "C"
|
||||
|
@ -758,5 +758,10 @@ SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
||||
int __lsan_is_turned_off() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
||||
const char *__lsan_default_suppressions() {
|
||||
return "";
|
||||
}
|
||||
#endif
|
||||
} // extern "C"
|
||||
|
@ -270,6 +270,8 @@ void LoadedModule::set(const char *module_name, uptr base_address,
|
||||
|
||||
void LoadedModule::clear() {
|
||||
InternalFree(full_name_);
|
||||
base_address_ = 0;
|
||||
max_executable_address_ = 0;
|
||||
full_name_ = nullptr;
|
||||
arch_ = kModuleArchUnknown;
|
||||
internal_memset(uuid_, 0, kModuleUUIDSize);
|
||||
@ -285,6 +287,8 @@ void LoadedModule::addAddressRange(uptr beg, uptr end, bool executable) {
|
||||
void *mem = InternalAlloc(sizeof(AddressRange));
|
||||
AddressRange *r = new(mem) AddressRange(beg, end, executable);
|
||||
ranges_.push_back(r);
|
||||
if (executable && end > max_executable_address_)
|
||||
max_executable_address_ = end;
|
||||
}
|
||||
|
||||
bool LoadedModule::containsAddress(uptr address) const {
|
||||
|
@ -283,6 +283,7 @@ void UpdateProcessName();
|
||||
void CacheBinaryName();
|
||||
void DisableCoreDumperIfNecessary();
|
||||
void DumpProcessMap();
|
||||
void PrintModuleMap();
|
||||
bool FileExists(const char *filename);
|
||||
const char *GetEnv(const char *name);
|
||||
bool SetEnv(const char *name, const char *value);
|
||||
@ -665,6 +666,32 @@ enum ModuleArch {
|
||||
kModuleArchARM64
|
||||
};
|
||||
|
||||
// When adding a new architecture, don't forget to also update
|
||||
// script/asan_symbolize.py and sanitizer_symbolizer_libcdep.cc.
|
||||
inline const char *ModuleArchToString(ModuleArch arch) {
|
||||
switch (arch) {
|
||||
case kModuleArchUnknown:
|
||||
return "";
|
||||
case kModuleArchI386:
|
||||
return "i386";
|
||||
case kModuleArchX86_64:
|
||||
return "x86_64";
|
||||
case kModuleArchX86_64H:
|
||||
return "x86_64h";
|
||||
case kModuleArchARMV6:
|
||||
return "armv6";
|
||||
case kModuleArchARMV7:
|
||||
return "armv7";
|
||||
case kModuleArchARMV7S:
|
||||
return "armv7s";
|
||||
case kModuleArchARMV7K:
|
||||
return "armv7k";
|
||||
case kModuleArchARM64:
|
||||
return "arm64";
|
||||
}
|
||||
CHECK(0 && "Invalid module arch");
|
||||
}
|
||||
|
||||
const uptr kModuleUUIDSize = 16;
|
||||
|
||||
// Represents a binary loaded into virtual memory (e.g. this can be an
|
||||
@ -674,6 +701,7 @@ class LoadedModule {
|
||||
LoadedModule()
|
||||
: full_name_(nullptr),
|
||||
base_address_(0),
|
||||
max_executable_address_(0),
|
||||
arch_(kModuleArchUnknown),
|
||||
instrumented_(false) {
|
||||
internal_memset(uuid_, 0, kModuleUUIDSize);
|
||||
@ -688,6 +716,7 @@ class LoadedModule {
|
||||
|
||||
const char *full_name() const { return full_name_; }
|
||||
uptr base_address() const { return base_address_; }
|
||||
uptr max_executable_address() const { return max_executable_address_; }
|
||||
ModuleArch arch() const { return arch_; }
|
||||
const u8 *uuid() const { return uuid_; }
|
||||
bool instrumented() const { return instrumented_; }
|
||||
@ -707,6 +736,7 @@ class LoadedModule {
|
||||
private:
|
||||
char *full_name_; // Owned.
|
||||
uptr base_address_;
|
||||
uptr max_executable_address_;
|
||||
ModuleArch arch_;
|
||||
u8 uuid_[kModuleUUIDSize];
|
||||
bool instrumented_;
|
||||
|
@ -74,6 +74,9 @@ COMMON_FLAG(bool, allocator_may_return_null, false,
|
||||
COMMON_FLAG(bool, print_summary, true,
|
||||
"If false, disable printing error summaries in addition to error "
|
||||
"reports.")
|
||||
COMMON_FLAG(int, print_module_map, 0,
|
||||
"OS X only. 0 = don't print, 1 = print only once before process "
|
||||
"exits, 2 = print after each report.")
|
||||
COMMON_FLAG(bool, check_printf, true, "Check printf arguments.")
|
||||
COMMON_FLAG(bool, handle_segv, true,
|
||||
"If set, registers the tool's custom SIGSEGV/SIGBUS handler.")
|
||||
|
@ -32,7 +32,7 @@
|
||||
# define SANITIZER_WEAK_ATTRIBUTE __attribute__((weak))
|
||||
#endif
|
||||
|
||||
#if (SANITIZER_LINUX || SANITIZER_WINDOWS) && !SANITIZER_GO
|
||||
#if (SANITIZER_LINUX || SANITIZER_MAC || SANITIZER_WINDOWS) && !SANITIZER_GO
|
||||
# define SANITIZER_SUPPORTS_WEAK_HOOKS 1
|
||||
#else
|
||||
# define SANITIZER_SUPPORTS_WEAK_HOOKS 0
|
||||
|
@ -1393,6 +1393,8 @@ void MaybeReexec() {
|
||||
// No need to re-exec on Linux.
|
||||
}
|
||||
|
||||
void PrintModuleMap() { }
|
||||
|
||||
uptr FindAvailableMemoryRange(uptr size, uptr alignment, uptr left_padding) {
|
||||
UNREACHABLE("FindAvailableMemoryRange is not available");
|
||||
return 0;
|
||||
|
@ -26,10 +26,7 @@
|
||||
#include "sanitizer_procmaps.h"
|
||||
#include "sanitizer_stacktrace.h"
|
||||
|
||||
#if SANITIZER_ANDROID || SANITIZER_FREEBSD
|
||||
#include <dlfcn.h> // for dlsym()
|
||||
#endif
|
||||
|
||||
#include <link.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
@ -854,6 +854,36 @@ void SignalContext::DumpAllRegisters(void *context) {
|
||||
# undef DUMPREG
|
||||
}
|
||||
|
||||
static inline bool CompareBaseAddress(const LoadedModule &a,
|
||||
const LoadedModule &b) {
|
||||
return a.base_address() < b.base_address();
|
||||
}
|
||||
|
||||
void FormatUUID(char *out, uptr size, const u8 *uuid) {
|
||||
internal_snprintf(out, size,
|
||||
"<%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-"
|
||||
"%02X%02X%02X%02X%02X%02X>",
|
||||
uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5],
|
||||
uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11],
|
||||
uuid[12], uuid[13], uuid[14], uuid[15]);
|
||||
}
|
||||
|
||||
void PrintModuleMap() {
|
||||
Printf("Process module map:\n");
|
||||
MemoryMappingLayout memory_mapping(false);
|
||||
InternalMmapVector<LoadedModule> modules(/*initial_capacity*/ 128);
|
||||
memory_mapping.DumpListOfModules(&modules);
|
||||
InternalSort(&modules, modules.size(), CompareBaseAddress);
|
||||
for (uptr i = 0; i < modules.size(); ++i) {
|
||||
char uuid_str[128];
|
||||
FormatUUID(uuid_str, sizeof(uuid_str), modules[i].uuid());
|
||||
Printf("0x%zx-0x%zx %s (%s) %s\n", modules[i].base_address(),
|
||||
modules[i].max_executable_address(), modules[i].full_name(),
|
||||
ModuleArchToString(modules[i].arch()), uuid_str);
|
||||
}
|
||||
Printf("End of module map.\n");
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // SANITIZER_MAC
|
||||
|
@ -43,7 +43,7 @@ static int AppendChar(char **buff, const char *buff_end, char c) {
|
||||
// on the value of |pad_with_zero|.
|
||||
static int AppendNumber(char **buff, const char *buff_end, u64 absolute_value,
|
||||
u8 base, u8 minimal_num_length, bool pad_with_zero,
|
||||
bool negative) {
|
||||
bool negative, bool uppercase) {
|
||||
uptr const kMaxLen = 30;
|
||||
RAW_CHECK(base == 10 || base == 16);
|
||||
RAW_CHECK(base == 10 || !negative);
|
||||
@ -76,23 +76,25 @@ static int AppendNumber(char **buff, const char *buff_end, u64 absolute_value,
|
||||
if (negative && !pad_with_zero) result += AppendChar(buff, buff_end, '-');
|
||||
for (; pos >= 0; pos--) {
|
||||
char digit = static_cast<char>(num_buffer[pos]);
|
||||
result += AppendChar(buff, buff_end, (digit < 10) ? '0' + digit
|
||||
: 'a' + digit - 10);
|
||||
digit = (digit < 10) ? '0' + digit : (uppercase ? 'A' : 'a') + digit - 10;
|
||||
result += AppendChar(buff, buff_end, digit);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int AppendUnsigned(char **buff, const char *buff_end, u64 num, u8 base,
|
||||
u8 minimal_num_length, bool pad_with_zero) {
|
||||
u8 minimal_num_length, bool pad_with_zero,
|
||||
bool uppercase) {
|
||||
return AppendNumber(buff, buff_end, num, base, minimal_num_length,
|
||||
pad_with_zero, false /* negative */);
|
||||
pad_with_zero, false /* negative */, uppercase);
|
||||
}
|
||||
|
||||
static int AppendSignedDecimal(char **buff, const char *buff_end, s64 num,
|
||||
u8 minimal_num_length, bool pad_with_zero) {
|
||||
bool negative = (num < 0);
|
||||
return AppendNumber(buff, buff_end, (u64)(negative ? -num : num), 10,
|
||||
minimal_num_length, pad_with_zero, negative);
|
||||
minimal_num_length, pad_with_zero, negative,
|
||||
false /* uppercase */);
|
||||
}
|
||||
|
||||
static int AppendString(char **buff, const char *buff_end, int precision,
|
||||
@ -112,14 +114,16 @@ static int AppendPointer(char **buff, const char *buff_end, u64 ptr_value) {
|
||||
int result = 0;
|
||||
result += AppendString(buff, buff_end, -1, "0x");
|
||||
result += AppendUnsigned(buff, buff_end, ptr_value, 16,
|
||||
SANITIZER_POINTER_FORMAT_LENGTH, true);
|
||||
SANITIZER_POINTER_FORMAT_LENGTH,
|
||||
true /* pad_with_zero */, false /* uppercase */);
|
||||
return result;
|
||||
}
|
||||
|
||||
int VSNPrintf(char *buff, int buff_length,
|
||||
const char *format, va_list args) {
|
||||
static const char *kPrintfFormatsHelp =
|
||||
"Supported Printf formats: %([0-9]*)?(z|ll)?{d,u,x}; %p; %(\\.\\*)?s; %c\n";
|
||||
"Supported Printf formats: %([0-9]*)?(z|ll)?{d,u,x,X}; %p; %(\\.\\*)?s; "
|
||||
"%c\n";
|
||||
RAW_CHECK(format);
|
||||
RAW_CHECK(buff_length > 0);
|
||||
const char *buff_end = &buff[buff_length - 1];
|
||||
@ -164,12 +168,14 @@ int VSNPrintf(char *buff, int buff_length,
|
||||
break;
|
||||
}
|
||||
case 'u':
|
||||
case 'x': {
|
||||
case 'x':
|
||||
case 'X': {
|
||||
uval = have_ll ? va_arg(args, u64)
|
||||
: have_z ? va_arg(args, uptr)
|
||||
: va_arg(args, unsigned);
|
||||
result += AppendUnsigned(&buff, buff_end, uval,
|
||||
(*cur == 'u') ? 10 : 16, width, pad_with_zero);
|
||||
bool uppercase = (*cur == 'X');
|
||||
result += AppendUnsigned(&buff, buff_end, uval, (*cur == 'u') ? 10 : 16,
|
||||
width, pad_with_zero, uppercase);
|
||||
break;
|
||||
}
|
||||
case 'p': {
|
||||
|
@ -93,7 +93,7 @@ void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
|
||||
vs_style, strip_path_prefix);
|
||||
} else if (info.module) {
|
||||
RenderModuleLocation(buffer, info.module, info.module_offset,
|
||||
strip_path_prefix);
|
||||
info.module_arch, strip_path_prefix);
|
||||
} else {
|
||||
buffer->append("(<unknown module>)");
|
||||
}
|
||||
@ -103,8 +103,9 @@ void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
|
||||
if (info.address & kExternalPCBit)
|
||||
{} // There PCs are not meaningful.
|
||||
else if (info.module)
|
||||
buffer->append("(%s+%p)", StripModuleName(info.module),
|
||||
(void *)info.module_offset);
|
||||
// Always strip the module name for %M.
|
||||
RenderModuleLocation(buffer, StripModuleName(info.module),
|
||||
info.module_offset, info.module_arch, "");
|
||||
else
|
||||
buffer->append("(%p)", (void *)info.address);
|
||||
break;
|
||||
@ -165,9 +166,13 @@ void RenderSourceLocation(InternalScopedString *buffer, const char *file,
|
||||
}
|
||||
|
||||
void RenderModuleLocation(InternalScopedString *buffer, const char *module,
|
||||
uptr offset, const char *strip_path_prefix) {
|
||||
buffer->append("(%s+0x%zx)", StripPathPrefix(module, strip_path_prefix),
|
||||
offset);
|
||||
uptr offset, ModuleArch arch,
|
||||
const char *strip_path_prefix) {
|
||||
buffer->append("(%s", StripPathPrefix(module, strip_path_prefix));
|
||||
if (arch != kModuleArchUnknown) {
|
||||
buffer->append(":%s", ModuleArchToString(arch));
|
||||
}
|
||||
buffer->append("+0x%zx)", offset);
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
@ -57,7 +57,8 @@ void RenderSourceLocation(InternalScopedString *buffer, const char *file,
|
||||
const char *strip_path_prefix);
|
||||
|
||||
void RenderModuleLocation(InternalScopedString *buffer, const char *module,
|
||||
uptr offset, const char *strip_path_prefix);
|
||||
uptr offset, ModuleArch arch,
|
||||
const char *strip_path_prefix);
|
||||
|
||||
// Same as RenderFrame, but for data section (global variables).
|
||||
// Accepts %s, %l from above.
|
||||
|
@ -33,9 +33,11 @@ void AddressInfo::Clear() {
|
||||
function_offset = kUnknown;
|
||||
}
|
||||
|
||||
void AddressInfo::FillModuleInfo(const char *mod_name, uptr mod_offset) {
|
||||
void AddressInfo::FillModuleInfo(const char *mod_name, uptr mod_offset,
|
||||
ModuleArch mod_arch) {
|
||||
module = internal_strdup(mod_name);
|
||||
module_offset = mod_offset;
|
||||
module_arch = mod_arch;
|
||||
}
|
||||
|
||||
SymbolizedStack::SymbolizedStack() : next(nullptr), info() {}
|
||||
|
@ -31,6 +31,7 @@ struct AddressInfo {
|
||||
|
||||
char *module;
|
||||
uptr module_offset;
|
||||
ModuleArch module_arch;
|
||||
|
||||
static const uptr kUnknown = ~(uptr)0;
|
||||
char *function;
|
||||
@ -43,7 +44,7 @@ struct AddressInfo {
|
||||
AddressInfo();
|
||||
// Deletes all strings and resets all fields.
|
||||
void Clear();
|
||||
void FillModuleInfo(const char *mod_name, uptr mod_offset);
|
||||
void FillModuleInfo(const char *mod_name, uptr mod_offset, ModuleArch arch);
|
||||
};
|
||||
|
||||
// Linked list of symbolized frames (each frame is described by AddressInfo).
|
||||
@ -65,6 +66,8 @@ struct DataInfo {
|
||||
// (de)allocated using sanitizer internal allocator.
|
||||
char *module;
|
||||
uptr module_offset;
|
||||
ModuleArch module_arch;
|
||||
|
||||
char *file;
|
||||
uptr line;
|
||||
char *name;
|
||||
@ -143,7 +146,8 @@ class Symbolizer final {
|
||||
static Symbolizer *PlatformInit();
|
||||
|
||||
bool FindModuleNameAndOffsetForAddress(uptr address, const char **module_name,
|
||||
uptr *module_offset);
|
||||
uptr *module_offset,
|
||||
ModuleArch *module_arch);
|
||||
ListOfModules modules_;
|
||||
// If stale, need to reload the modules before looking up addresses.
|
||||
bool modules_fresh_;
|
||||
|
@ -124,8 +124,8 @@ class LLVMSymbolizer : public SymbolizerTool {
|
||||
bool SymbolizeData(uptr addr, DataInfo *info) override;
|
||||
|
||||
private:
|
||||
const char *SendCommand(bool is_data, const char *module_name,
|
||||
uptr module_offset);
|
||||
const char *FormatAndSendCommand(bool is_data, const char *module_name,
|
||||
uptr module_offset, ModuleArch arch);
|
||||
|
||||
LLVMSymbolizerProcess *symbolizer_process_;
|
||||
static const uptr kBufferSize = 16 * 1024;
|
||||
|
@ -64,11 +64,13 @@ SymbolizedStack *Symbolizer::SymbolizePC(uptr addr) {
|
||||
BlockingMutexLock l(&mu_);
|
||||
const char *module_name;
|
||||
uptr module_offset;
|
||||
ModuleArch arch;
|
||||
SymbolizedStack *res = SymbolizedStack::New(addr);
|
||||
if (!FindModuleNameAndOffsetForAddress(addr, &module_name, &module_offset))
|
||||
if (!FindModuleNameAndOffsetForAddress(addr, &module_name, &module_offset,
|
||||
&arch))
|
||||
return res;
|
||||
// Always fill data about module name and offset.
|
||||
res->info.FillModuleInfo(module_name, module_offset);
|
||||
res->info.FillModuleInfo(module_name, module_offset, arch);
|
||||
for (auto &tool : tools_) {
|
||||
SymbolizerScope sym_scope(this);
|
||||
if (tool.SymbolizePC(addr, res)) {
|
||||
@ -82,11 +84,14 @@ bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
|
||||
BlockingMutexLock l(&mu_);
|
||||
const char *module_name;
|
||||
uptr module_offset;
|
||||
if (!FindModuleNameAndOffsetForAddress(addr, &module_name, &module_offset))
|
||||
ModuleArch arch;
|
||||
if (!FindModuleNameAndOffsetForAddress(addr, &module_name, &module_offset,
|
||||
&arch))
|
||||
return false;
|
||||
info->Clear();
|
||||
info->module = internal_strdup(module_name);
|
||||
info->module_offset = module_offset;
|
||||
info->module_arch = arch;
|
||||
for (auto &tool : tools_) {
|
||||
SymbolizerScope sym_scope(this);
|
||||
if (tool.SymbolizeData(addr, info)) {
|
||||
@ -100,8 +105,9 @@ bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc, const char **module_name,
|
||||
uptr *module_address) {
|
||||
BlockingMutexLock l(&mu_);
|
||||
const char *internal_module_name = nullptr;
|
||||
ModuleArch arch;
|
||||
if (!FindModuleNameAndOffsetForAddress(pc, &internal_module_name,
|
||||
module_address))
|
||||
module_address, &arch))
|
||||
return false;
|
||||
|
||||
if (module_name)
|
||||
@ -134,12 +140,14 @@ void Symbolizer::PrepareForSandboxing() {
|
||||
|
||||
bool Symbolizer::FindModuleNameAndOffsetForAddress(uptr address,
|
||||
const char **module_name,
|
||||
uptr *module_offset) {
|
||||
uptr *module_offset,
|
||||
ModuleArch *module_arch) {
|
||||
const LoadedModule *module = FindModuleForAddress(address);
|
||||
if (module == nullptr)
|
||||
return false;
|
||||
*module_name = module->full_name();
|
||||
*module_offset = address - module->base_address();
|
||||
*module_arch = module->arch();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -197,6 +205,8 @@ class LLVMSymbolizerProcess : public SymbolizerProcess {
|
||||
buffer[length - 2] == '\n';
|
||||
}
|
||||
|
||||
// When adding a new architecture, don't forget to also update
|
||||
// script/asan_symbolize.py and sanitizer_common.h.
|
||||
void GetArgV(const char *path_to_binary,
|
||||
const char *(&argv)[kArgVMax]) const override {
|
||||
#if defined(__x86_64h__)
|
||||
@ -284,7 +294,8 @@ void ParseSymbolizePCOutput(const char *str, SymbolizedStack *res) {
|
||||
top_frame = false;
|
||||
} else {
|
||||
cur = SymbolizedStack::New(res->info.address);
|
||||
cur->info.FillModuleInfo(res->info.module, res->info.module_offset);
|
||||
cur->info.FillModuleInfo(res->info.module, res->info.module_offset,
|
||||
res->info.module_arch);
|
||||
last->next = cur;
|
||||
last = cur;
|
||||
}
|
||||
@ -317,8 +328,10 @@ void ParseSymbolizeDataOutput(const char *str, DataInfo *info) {
|
||||
}
|
||||
|
||||
bool LLVMSymbolizer::SymbolizePC(uptr addr, SymbolizedStack *stack) {
|
||||
if (const char *buf = SendCommand(/*is_data*/ false, stack->info.module,
|
||||
stack->info.module_offset)) {
|
||||
AddressInfo *info = &stack->info;
|
||||
const char *buf = FormatAndSendCommand(
|
||||
/*is_data*/ false, info->module, info->module_offset, info->module_arch);
|
||||
if (buf) {
|
||||
ParseSymbolizePCOutput(buf, stack);
|
||||
return true;
|
||||
}
|
||||
@ -326,8 +339,9 @@ bool LLVMSymbolizer::SymbolizePC(uptr addr, SymbolizedStack *stack) {
|
||||
}
|
||||
|
||||
bool LLVMSymbolizer::SymbolizeData(uptr addr, DataInfo *info) {
|
||||
if (const char *buf =
|
||||
SendCommand(/*is_data*/ true, info->module, info->module_offset)) {
|
||||
const char *buf = FormatAndSendCommand(
|
||||
/*is_data*/ true, info->module, info->module_offset, info->module_arch);
|
||||
if (buf) {
|
||||
ParseSymbolizeDataOutput(buf, info);
|
||||
info->start += (addr - info->module_offset); // Add the base address.
|
||||
return true;
|
||||
@ -335,11 +349,19 @@ bool LLVMSymbolizer::SymbolizeData(uptr addr, DataInfo *info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *LLVMSymbolizer::SendCommand(bool is_data, const char *module_name,
|
||||
uptr module_offset) {
|
||||
const char *LLVMSymbolizer::FormatAndSendCommand(bool is_data,
|
||||
const char *module_name,
|
||||
uptr module_offset,
|
||||
ModuleArch arch) {
|
||||
CHECK(module_name);
|
||||
internal_snprintf(buffer_, kBufferSize, "%s\"%s\" 0x%zx\n",
|
||||
is_data ? "DATA " : "", module_name, module_offset);
|
||||
const char *is_data_str = is_data ? "DATA " : "";
|
||||
if (arch == kModuleArchUnknown) {
|
||||
internal_snprintf(buffer_, kBufferSize, "%s\"%s\" 0x%zx\n", is_data_str,
|
||||
module_name, module_offset);
|
||||
} else {
|
||||
internal_snprintf(buffer_, kBufferSize, "%s\"%s:%s\" 0x%zx\n", is_data_str,
|
||||
module_name, ModuleArchToString(arch), module_offset);
|
||||
}
|
||||
return symbolizer_process_->SendCommand(buffer_);
|
||||
}
|
||||
|
||||
|
@ -388,6 +388,8 @@ void DumpProcessMap() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void PrintModuleMap() { }
|
||||
|
||||
void DisableCoreDumperIfNecessary() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
___sanitizer_free_hook
|
||||
___sanitizer_malloc_hook
|
||||
___sanitizer_symbolize_code
|
||||
___sanitizer_symbolize_data
|
||||
___sanitizer_symbolize_demangle
|
||||
___sanitizer_symbolize_flush
|
@ -1,4 +1,5 @@
|
||||
__tsan_init
|
||||
__tsan_flush_memory
|
||||
__tsan_read*
|
||||
__tsan_write*
|
||||
__tsan_vptr*
|
||||
|
@ -28,6 +28,10 @@ void __tsan_init() {
|
||||
Initialize(cur_thread());
|
||||
}
|
||||
|
||||
void __tsan_flush_memory() {
|
||||
FlushShadowMemory();
|
||||
}
|
||||
|
||||
void __tsan_read16(void *addr) {
|
||||
MemoryRead(cur_thread(), CALLERPC, (uptr)addr, kSizeLog8);
|
||||
MemoryRead(cur_thread(), CALLERPC, (uptr)addr + 8, kSizeLog8);
|
||||
|
@ -32,6 +32,8 @@ extern "C" {
|
||||
// before any instrumented code is executed and before any call to malloc.
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_init();
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_flush_memory();
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read1(void *addr);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read2(void *addr);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read4(void *addr);
|
||||
|
@ -358,6 +358,8 @@ void PrintReport(const ReportDesc *rep) {
|
||||
ReportErrorSummary(rep_typ_str, frame->info);
|
||||
}
|
||||
|
||||
if (common_flags()->print_module_map == 2) PrintModuleMap();
|
||||
|
||||
Printf("==================\n");
|
||||
}
|
||||
|
||||
|
@ -404,6 +404,8 @@ void Initialize(ThreadState *thr) {
|
||||
int Finalize(ThreadState *thr) {
|
||||
bool failed = false;
|
||||
|
||||
if (common_flags()->print_module_map == 1) PrintModuleMap();
|
||||
|
||||
if (flags()->atexit_sleep_ms > 0 && ThreadCount(thr) > 1)
|
||||
SleepForMillis(flags()->atexit_sleep_ms);
|
||||
|
||||
|
@ -157,7 +157,7 @@ static void RenderLocation(InternalScopedString *Buffer, Location Loc) {
|
||||
common_flags()->strip_path_prefix);
|
||||
else if (Info.module)
|
||||
RenderModuleLocation(Buffer, Info.module, Info.module_offset,
|
||||
common_flags()->strip_path_prefix);
|
||||
Info.module_arch, common_flags()->strip_path_prefix);
|
||||
else
|
||||
Buffer->append("%p", Info.address);
|
||||
return;
|
||||
|
1
contrib/compiler-rt/lib/ubsan/weak_symbols.txt
Normal file
1
contrib/compiler-rt/lib/ubsan/weak_symbols.txt
Normal file
@ -0,0 +1 @@
|
||||
___ubsan_default_options
|
Loading…
x
Reference in New Issue
Block a user