I'm trying to build my code with clang memory sanitizer. I get following error when execuatable starts:
thread #1, name = 'esp_exec-N', stop reason = signal SIGSEGV: invalid address (fault address: 0x555643df5c8)
frame #0: 0x000055555b7806ae esp_exec-N`calloc(n=1, size=32) at mem_turbo.c:592:8
589 size_t bytes = n * size;
590 void *obj;
591
->592 if (!mem_initialized) {
593 mem_initialize();
594 }
595
Then I read the address of mem_initialized
(lldb) ta v &mem_initialized
(int *) &mem_initialized = 0x00005555643df5c8
The first 20 bits of the pionter value was truncated(one less 5)
after disassamble, I can find following sections in object file, the value of the pointer was truncated here.
0x55555b7806a1 <+81>: movabsq $0x500000000000, %r13 ; imm = 0x500000000000
0x55555b7806ab <+91>: xorq %r13, %rcx
->0x55555b7806ae <+94>: movl (%rcx), %ecx
clang version: 9.0.1
full compile command of this object:
clang -I. -I../include -I../../include -I../../../snps/include -I/slowfs/swe101/yinliu/esp_main_msan_test/tcl/headers -I/slowfs/swe101/yinliu/esp_main_msan_test/tcl/tcl8.6/include -fPIC -g -fPIE -fsanitize=memory -fsanitize-memory-track-origins -pie -fno-omit-frame-pointer -g -m64 -DMEM_USE_MMAP -o /slowfs/swe101/yinliu/esp_main_msan_test/objroot/common/memory/mem/obj-linux64/mem_turbo-N.o -DINNO_OPT -DNDEBUG -c -DSynopsys_Optimize -DSynopsys_amd64 -DSynopsys_linux64 -DSynopsys_linux -msse2 -mfpmath=sse -fno-omit-frame-pointer -fno-dollars-in-identifiers -Wall -Wpointer-arith -Wnested-externs -Wmissing-prototypes -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-local-typedefs -Wno-parentheses-equality -Wno-writable-strings -Wno-unused-private-field -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wno-undefined-var-template -Wno-trigraphs -Wno-unused-local-typedef -Wno-mismatched-tags -Wno-unused-variable -Wno-unused-const-variable -fnew-alignment=8 -Wno-error -Wno-implicit-fallthrough -Wno-deprecated-register -Wno-varargs -Wno-return-type -Wno-self-assign -Wno-c++17-extensions mem_turbo.c
If I remove the memory sanitizer related build options, the pointer trunction was gone. But I need them in this case.