[llvm-commits] [compiler-rt] r162987 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_symbolizer.cc sanitizer_symbolizer_linux.cc
Alexey Samsonov
samsonov at google.com
Fri Aug 31 04:07:52 PDT 2012
Author: samsonov
Date: Fri Aug 31 06:07:52 2012
New Revision: 162987
URL: http://llvm.org/viewvc/llvm-project?rev=162987&view=rev
Log:
[Sanitizer] Remove some calls to libc malloc from symbolizer
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=162987&r1=162986&r2=162987&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc Fri Aug 31 06:07:52 2012
@@ -182,6 +182,8 @@
uptr times_restarted_;
};
+static LowLevelAllocator symbolizer_allocator; // Linker initialized.
+
class Symbolizer {
public:
uptr SymbolizeCode(uptr addr, AddressInfo *frames, uptr max_frames) {
@@ -206,7 +208,6 @@
if (!external_symbolizer_->Restart()) {
ReportExternalSymbolizerError(
"WARNING: Failed to use and restart external symbolizer!\n");
- InternalFree(external_symbolizer_);
external_symbolizer_ = 0;
break;
}
@@ -220,7 +221,7 @@
int input_fd, output_fd;
if (!StartSymbolizerSubprocess(path_to_symbolizer, &input_fd, &output_fd))
return false;
- void *mem = InternalAlloc(sizeof(ExternalSymbolizer));
+ void *mem = symbolizer_allocator.Allocate(sizeof(ExternalSymbolizer));
external_symbolizer_ = new(mem) ExternalSymbolizer(path_to_symbolizer,
input_fd, output_fd);
return true;
@@ -229,8 +230,8 @@
private:
LoadedModule *FindModuleForAddress(uptr address) {
if (modules_ == 0) {
- modules_ = (LoadedModule*)InternalAlloc(
- kMaxNumberOfModuleContexts * sizeof(LoadedModule));
+ modules_ = (LoadedModule*)(symbolizer_allocator.Allocate(
+ kMaxNumberOfModuleContexts * sizeof(LoadedModule)));
CHECK(modules_);
n_modules_ = GetListOfModules(modules_, kMaxNumberOfModuleContexts);
CHECK_GT(n_modules_, 0);
@@ -254,11 +255,10 @@
}
static const uptr kMaxNumberOfModuleContexts = 4096;
- // Array of module descriptions is leaked.
- LoadedModule *modules_;
+ LoadedModule *modules_; // Array of module descriptions is leaked.
uptr n_modules_;
- ExternalSymbolizer *external_symbolizer_;
+ ExternalSymbolizer *external_symbolizer_; // Leaked.
};
static Symbolizer symbolizer; // Linker initialized.
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc?rev=162987&r1=162986&r2=162987&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc Fri Aug 31 06:07:52 2012
@@ -121,19 +121,19 @@
DlIteratePhdrData *data = (DlIteratePhdrData*)arg;
if (data->current_n == data->max_n)
return 0;
- char *module_name = 0;
+ InternalScopedBuffer<char> module_name(kMaxPathLength);
+ module_name[0] = '\0';
if (data->current_n == 0) {
// First module is the binary itself.
- module_name = (char*)InternalAlloc(kMaxPathLength);
uptr module_name_len = readlink("/proc/self/exe",
- module_name, kMaxPathLength);
+ module_name, module_name.size());
CHECK_NE(module_name_len, (uptr)-1);
- CHECK_LT(module_name_len, kMaxPathLength);
+ CHECK_LT(module_name_len, module_name.size());
module_name[module_name_len] = '\0';
} else if (info->dlpi_name) {
- module_name = internal_strdup(info->dlpi_name);
+ internal_strncpy(module_name, info->dlpi_name, module_name.size());
}
- if (module_name == 0 || module_name[0] == '\0')
+ if (module_name[0] == '\0')
return 0;
void *mem = &data->modules[data->current_n];
LoadedModule *cur_module = new(mem) LoadedModule(module_name,
@@ -147,7 +147,6 @@
cur_module->addAddressRange(cur_beg, cur_end);
}
}
- InternalFree(module_name);
return 0;
}
More information about the llvm-commits
mailing list