AddressSanitizer 簡介和示例

AddressSanitizer 是檢測C/C++內(nèi)存錯誤的工具。
這個工具很快泻云。插入指令的程序的平均速度減慢約為2倍(請參閱AddressSanitizerPerformance Numbers)。
該工具由一個編譯器指令插入模塊(目前為LLVM傳遞)和一個替換malloc函數(shù)的運行時庫組成锅减。
該工具適用于x86脆诉、ARM甚亭、MIPS(所有體系結(jié)構(gòu)的32位和64位版本)、PowerPC64库说。支持的操作系統(tǒng)有Linux狂鞋、Darwin(OS X和iOS模擬器)、FreeBSD潜的、Android骚揍。

編譯配置

export ASAN_OPTIONS=check_initialization_order=true:strict_init_order=true:detect_stack_use_after_return=1

釋放后使用 heap-use-after-free

g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

main.cpp

#include <iostream>

int main(int argc, char **argv) {
    int *array = new int[100];
    delete [] array;
    return array[argc];  // BOOM
}
$./main
=================================================================
==253799==ERROR: AddressSanitizer: heap-use-after-free on address 0x614000000044 at pc 0x558fc320e309 bp 0x7ffc3c6a3260 sp 0x7ffc3c6a3250
READ of size 4 at 0x614000000044 thread T0
    #0 0x558fc320e308 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
    #1 0x7f0df87c9082 in __libc_start_main ../csu/libc-start.c:308
    #2 0x558fc320e1cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)

0x614000000044 is located 4 bytes inside of 400-byte region [0x614000000040,0x6140000001d0)
freed by thread T0 here:
    #0 0x7f0df8df36ef in operator delete[](void*) ../../../../src/libsanitizer/asan/asan_new_delete.cc:168
    #1 0x558fc320e2bc in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5
    #2 0x7f0df87c9082 in __libc_start_main ../csu/libc-start.c:308

previously allocated by thread T0 here:
    #0 0x7f0df8df2787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107
    #1 0x558fc320e2a5 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:4
    #2 0x7f0df87c9082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: heap-use-after-free /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6 in main
Shadow bytes around the buggy address:
  0x0c287fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c287fff8000: fa fa fa fa fa fa fa fa[fd]fd fd fd fd fd fd fd
  0x0c287fff8010: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c287fff8020: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c287fff8030: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
  0x0c287fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==253799==ABORTING

堆緩沖區(qū)溢出 heap-buffer-overflow

g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

main.cpp

#include <iostream>

int main(int argc, char **argv) {
    int *array = new int[100];
    array[0] = 0;
    int res = array[argc + 100];  // BOOM
    delete [] array;
    return res;
}
$./main
=================================================================
==253933==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6140000001d4 at pc 0x56361465435b bp 0x7ffca4f01170 sp 0x7ffca4f01160
READ of size 4 at 0x6140000001d4 thread T0
    #0 0x56361465435a in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
    #1 0x7fa7e4f60082 in __libc_start_main ../csu/libc-start.c:308
    #2 0x5636146541ed in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11ed)

0x6140000001d4 is located 4 bytes to the right of 400-byte region [0x614000000040,0x6140000001d0)
allocated by thread T0 here:
    #0 0x7fa7e5589787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107
    #1 0x5636146542c5 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:4
    #2 0x7fa7e4f60082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6 in main
Shadow bytes around the buggy address:
  0x0c287fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c287fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c287fff8030: 00 00 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa
  0x0c287fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==253933==ABORTING

堆棧緩沖區(qū)溢出 stack-buffer-overflow

g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

main.cpp

int main(int argc, char **argv) {
    int stack_array[100];
    stack_array[1] = 0;
    return stack_array[argc + 100];  // BOOM
}
$./main
=================================================================
==254014==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffe071bd14 at pc 0x55a0f99743f4 bp 0x7fffe071bb30 sp 0x7fffe071bb20
READ of size 4 at 0x7fffe071bd14 thread T0
    #0 0x55a0f99743f3 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
    #1 0x7fd9ce1cb082 in __libc_start_main ../csu/libc-start.c:308
    #2 0x55a0f99741ed in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11ed)

Address 0x7fffe071bd14 is located in stack of thread T0 at offset 452 in frame
    #0 0x55a0f99742b8 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:3

  This frame has 1 object(s):
    [48, 448) 'stack_array' (line 4) <== Memory access at offset 452 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6 in main
Shadow bytes around the buggy address:
  0x10007c0db750: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007c0db760: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f1 f1
  0x10007c0db770: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007c0db780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007c0db790: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10007c0db7a0: 00 00[f3]f3 f3 f3 f3 f3 f3 f3 00 00 00 00 00 00
  0x10007c0db7b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007c0db7c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007c0db7d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007c0db7e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007c0db7f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==254014==ABORTING

全局緩沖區(qū)溢出 global-buffer-overflow

g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

main.cpp

int global_array[100] = {-1};
int main(int argc, char **argv) {
  return global_array[argc + 100];  // BOOM
}
$./main
=================================================================
==254097==ERROR: AddressSanitizer: global-buffer-overflow on address 0x555eb65421b4 at pc 0x555eb653f2ab bp 0x7ffd3c1e5500 sp 0x7ffd3c1e54f0
READ of size 4 at 0x555eb65421b4 thread T0
    #0 0x555eb653f2aa in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:7
    #1 0x7eff22dcb082 in __libc_start_main ../csu/libc-start.c:308
    #2 0x555eb653f18d in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x118d)

0x555eb65421b4 is located 4 bytes to the right of global variable 'global_array' defined in 'main.cpp:5:5' (0x555eb6542020) of size 400
SUMMARY: AddressSanitizer: global-buffer-overflow /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:7 in main
Shadow bytes around the buggy address:
  0x0aac56ca03e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0aac56ca03f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0aac56ca0400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0aac56ca0410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0aac56ca0420: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0aac56ca0430: 00 00 00 00 00 00[f9]f9 f9 f9 f9 f9 00 00 00 00
  0x0aac56ca0440: 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0aac56ca0450: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0aac56ca0460: 01 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
  0x0aac56ca0470: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0aac56ca0480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==254097==ABORTING

return后使用 stack-use-after-return

g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

main.cpp

int *ptr;
__attribute__((noinline))
void FunctionThatEscapesLocalObject() {
  int local[100];
  ptr = &local[0];
}

int main(int argc, char **argv) {
  FunctionThatEscapesLocalObject();
  return ptr[argc];
}
$./main
=================================================================
==254255==ERROR: AddressSanitizer: stack-use-after-return on address 0x7f514b54e034 at pc 0x55ee93d46432 bp 0x7ffedaba1700 sp 0x7ffedaba16f0
READ of size 4 at 0x7f514b54e034 thread T0
    #0 0x55ee93d46431 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:13
    #1 0x7f514e90b082 in __libc_start_main ../csu/libc-start.c:308
    #2 0x55ee93d461cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)

Address 0x7f514b54e034 is located in stack of thread T0 at offset 52 in frame
    #0 0x55ee93d46298 in FunctionThatEscapesLocalObject() /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6

  This frame has 1 object(s):
    [48, 448) 'local' (line 7) <== Memory access at offset 52 is inside this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-return /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:13 in main
Shadow bytes around the buggy address:
  0x0feaa96a1bb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feaa96a1bc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feaa96a1bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feaa96a1be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feaa96a1bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0feaa96a1c00: f5 f5 f5 f5 f5 f5[f5]f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x0feaa96a1c10: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x0feaa96a1c20: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x0feaa96a1c30: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x0feaa96a1c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feaa96a1c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==254255==ABORTING

模塊外使用 stack-use-after-scope

g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

main.cpp

volatile int *p = 0;

int main() {
    {
        int x = 0;
        p = &x;
    }
    *p = 5;
    return 0;
}
$./main
=================================================================
==257062==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7f59030dc020 at pc 0x564bb2fb83a1 bp 0x7ffe4bc65f70 sp 0x7ffe4bc65f60
WRITE of size 4 at 0x7f59030dc020 thread T0
    #0 0x564bb2fb83a0 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:10
    #1 0x7f5906799082 in __libc_start_main ../csu/libc-start.c:308
    #2 0x564bb2fb81cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)

Address 0x7f59030dc020 is located in stack of thread T0 at offset 32 in frame
    #0 0x564bb2fb8298 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5

  This frame has 1 object(s):
    [32, 36) 'x' (line 7) <== Memory access at offset 32 is inside this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-scope /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:10 in main
Shadow bytes around the buggy address:
  0x0feba06137b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba06137c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba06137d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba06137e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba06137f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0feba0613800: f1 f1 f1 f1[f8]f3 f3 f3 00 00 00 00 00 00 00 00
  0x0feba0613810: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba0613820: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba0613830: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba0613840: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0feba0613850: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==257062==ABORTING

detected memory leaks

g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

main.cpp

#include <iostream>

void *p;

int main() {
    p = malloc(7);
    p = 0; // The memory is leaked here.
    return 0;
}
$./main

=================================================================
==257159==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x7fc06e071808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x555b0c6d825a in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
    #2 0x7fc06da4a082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).

初始化問題 Initialization order bugs

g++ test.cpp main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer

test.cpp

int foo() { return 42; }
int extern_global = foo();

main.cpp

#include <iostream>

extern int extern_global;
int __attribute__((noinline)) read_extern_global() {
    return extern_global;
}
int x = read_extern_global() + 1;
int main() {
    printf("%d\n", x);
    return 0;
}
$./main
=================================================================
==264374==ERROR: AddressSanitizer: initialization-order-fiasco on address 0x55e2925711e0 at pc 0x55e29256e3a8 bp 0x7ffd807a1ba0 sp 0x7ffd807a1b90
READ of size 4 at 0x55e2925711e0 thread T0
    #0 0x55e29256e3a7 in read_extern_global() /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5
    #1 0x55e29256e468 in __static_initialization_and_destruction_0 /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:7
    #2 0x55e29256e4c3 in _GLOBAL__sub_I__Z18read_extern_globalv /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:11
    #3 0x55e29256e55c in __libc_csu_init (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x155c)
    #4 0x7fb3e7e8400f in __libc_start_main ../csu/libc-start.c:264
    #5 0x55e29256e1cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)

0x55e2925711e0 is located 0 bytes inside of global variable 'extern_global' defined in 'test.cpp:6:5' (0x55e2925711e0) of size 4
  registered at:
    #0 0x7fb3e83d59bf in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cc:342
    #1 0x55e29256e363 in _sub_I_00099_1 (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x1363)
    #2 0x55e29256e55c in __libc_csu_init (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x155c)

SUMMARY: AddressSanitizer: initialization-order-fiasco /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5 in read_extern_global()
Shadow bytes around the buggy address:
  0x0abcd24a61e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0abcd24a61f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0abcd24a6200: 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9
  0x0abcd24a6210: 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9
  0x0abcd24a6220: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
=>0x0abcd24a6230: f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00[f6]f6 f6 f6
  0x0abcd24a6240: f6 f6 f6 f6 00 00 00 00 01 f9 f9 f9 f9 f9 f9 f9
  0x0abcd24a6250: 04 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
  0x0abcd24a6260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0abcd24a6270: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0abcd24a6280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==264374==ABORTING

參考

https://github.com/google/sanitizers/wiki/AddressSanitizer

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子信不,更是在濱河造成了極大的恐慌嘲叔,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件抽活,死亡現(xiàn)場離奇詭異硫戈,居然都是意外死亡,警方通過查閱死者的電腦和手機下硕,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門丁逝,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人梭姓,你說我怎么就攤上這事霜幼。” “怎么了誉尖?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵罪既,是天一觀的道長。 經(jīng)常有香客問我铡恕,道長琢感,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任探熔,我火速辦了婚禮驹针,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘祭刚。我一直安慰自己牌捷,他們只是感情好墙牌,可當(dāng)我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布涡驮。 她就那樣靜靜地躺著,像睡著了一般喜滨。 火紅的嫁衣襯著肌膚如雪捉捅。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天虽风,我揣著相機與錄音棒口,去河邊找鬼。 笑死辜膝,一個胖子當(dāng)著我的面吹牛无牵,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播厂抖,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼茎毁,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起七蜘,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤谭溉,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后橡卤,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體扮念,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年碧库,在試婚紗的時候發(fā)現(xiàn)自己被綠了柜与。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡嵌灰,死狀恐怖旅挤,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情伞鲫,我是刑警寧澤粘茄,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站秕脓,受9級特大地震影響柒瓣,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜吠架,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一芙贫、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧傍药,春花似錦磺平、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至俱诸,卻和暖如春菠劝,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背睁搭。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工赶诊, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人园骆。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓舔痪,卻偏偏與公主長得像,于是被迫代替她去往敵國和親锌唾。 傳聞我的和親對象是個殘疾皇子锄码,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,976評論 2 355

推薦閱讀更多精彩內(nèi)容