mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Delete ASAN
It hasn't been helpful enough to be justify the maintenance burden. What actually does help is mprotect(), kprintf(), --ftrace and --strace which can always be counted upon to work correctly. We aren't losing much with this change. Support for ASAN on AARCH64 was never implemented. Applying ASAN to the core libc runtimes was disabled many months ago. If there is some way to have an ASAN runtime for user programs that is less invasive we can potentially consider reintroducing support. But now is premature.
This commit is contained in:
parent
6ffed14b9c
commit
d1d4388201
198 changed files with 130 additions and 2954 deletions
|
@ -46,8 +46,9 @@
|
|||
* @param st is open symbol table for current executable
|
||||
* @return -1 w/ errno if error happened
|
||||
*/
|
||||
dontinstrument dontasan int PrintBacktraceUsingSymbols(
|
||||
int fd, const struct StackFrame *bp, struct SymbolTable *st) {
|
||||
dontinstrument int PrintBacktraceUsingSymbols(int fd,
|
||||
const struct StackFrame *bp,
|
||||
struct SymbolTable *st) {
|
||||
size_t gi;
|
||||
intptr_t addr;
|
||||
const char *name;
|
||||
|
|
111
libc/log/leaks.c
111
libc/log/leaks.c
|
@ -16,117 +16,10 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/cxxabi.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/cmpxchg.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
__static_yoink("GetSymbolByAddr");
|
||||
|
||||
#define MAXLEAKS 1000
|
||||
|
||||
static bool once;
|
||||
static bool hasleaks;
|
||||
|
||||
static dontasan void CheckLeak(void *x, void *y, size_t n, void *a) {
|
||||
if (n) {
|
||||
if (IsAsan()) {
|
||||
if (__asan_get_heap_size(x) && !__asan_is_leaky(x)) {
|
||||
hasleaks = true;
|
||||
}
|
||||
} else {
|
||||
hasleaks = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static dontasan void OnMemory(void *x, void *y, size_t n, void *a) {
|
||||
static int i;
|
||||
if (n) {
|
||||
if (MAXLEAKS) {
|
||||
if (i < MAXLEAKS) {
|
||||
++i;
|
||||
kprintf("%p %,lu bytes [dlmalloc]", x, n);
|
||||
if (__asan_is_leaky(x)) {
|
||||
kprintf(" [leaky]");
|
||||
}
|
||||
__asan_print_trace(x);
|
||||
kprintf("\n");
|
||||
} else if (i == MAXLEAKS) {
|
||||
++i;
|
||||
kprintf("etc. etc.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static dontasan bool HasLeaks(void) {
|
||||
malloc_inspect_all(CheckLeak, 0);
|
||||
return hasleaks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for memory leaks.
|
||||
*
|
||||
* This function needs to call __cxa_finalize(). Therefore any runtime
|
||||
* services that depend on malloc() cannot be used, after calling this
|
||||
* function.
|
||||
*/
|
||||
dontasan void CheckForMemoryLeaks(void) {
|
||||
struct mallinfo mi;
|
||||
if (!IsAsan())
|
||||
return; // we need traces to exclude leaky
|
||||
if (!GetSymbolTable()) {
|
||||
kprintf("CheckForMemoryLeaks() needs the symbol table\n");
|
||||
return;
|
||||
}
|
||||
if (!_cmpxchg(&once, false, true)) {
|
||||
kprintf("CheckForMemoryLeaks() may only be called once\n");
|
||||
exit(0);
|
||||
}
|
||||
_pthread_unwind(_pthread_self());
|
||||
__cxa_thread_finalize();
|
||||
_pthread_unkey(__get_tls());
|
||||
_pthread_ungarbage();
|
||||
__cxa_finalize(0);
|
||||
STRACE("checking for memory leaks% m");
|
||||
if (!IsAsan()) {
|
||||
/* TODO(jart): How can we make this work without ASAN? */
|
||||
return;
|
||||
}
|
||||
malloc_trim(0);
|
||||
if (HasLeaks()) {
|
||||
mi = mallinfo();
|
||||
kprintf("\n"
|
||||
"UNFREED MEMORY\n"
|
||||
"%s\n"
|
||||
"max allocated space %,*d\n"
|
||||
"total allocated space %,*d\n"
|
||||
"total free space %,*d\n"
|
||||
"releasable space %,*d\n"
|
||||
"mmaped space %,*d\n"
|
||||
"non-mmapped space %,*d\n"
|
||||
"\n",
|
||||
__argv[0], 16l, mi.usmblks, 16l, mi.uordblks, 16l, mi.fordblks, 16l,
|
||||
mi.hblkhd, 16l, mi.keepcost, 16l, mi.arena);
|
||||
if (!IsAsan()) {
|
||||
kprintf("# NOTE: Use `make -j8 MODE=dbg` for malloc() backtraces\n");
|
||||
}
|
||||
malloc_inspect_all(OnMemory, 0);
|
||||
kprintf("\n");
|
||||
/* __print_maps(); */
|
||||
/* PrintGarbage(); */
|
||||
_Exit(78);
|
||||
}
|
||||
void CheckForMemoryLeaks(void) {
|
||||
// TODO(jart): give me a new lease on life
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/describebacktrace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue