namhyung / uftrace

Function graph tracer for C/C++/Rust/Python
https://uftrace.github.io/slide/
GNU General Public License v2.0
3.06k stars 473 forks source link

AddressSanitizer build error #439

Closed wlfans123 closed 5 years ago

wlfans123 commented 6 years ago

when I run AddressSanitizer Build, I got an error like below:

What's the solution?

Build command line:

CC=clang CXX=clang++ CFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address"  ./configure 

Error Log:

  LINK     libmcount/libmcount.so
/home/uftrace/libmcount/mcount.op: In function `mcount_guard_recursion':
/home/uftrace/libmcount/mcount.c:283: undefined reference to `__asan_report_load1'
/home/uftrace/libmcount/mcount.c:295: undefined reference to `__asan_report_store1'
/home/uftrace/libmcount/mcount.op: In function `mcount_trace_finish':
/home/uftrace/libmcount/mcount.c:270: undefined reference to `__asan_report_load8'
/home/uftrace/libmcount/mcount.c:271: undefined reference to `__asan_report_load8'
.....
/home/uftrace/arch/x86_64/symbol.c:116: undefined reference to `__asan_version_mismatch_check_v8'
/home/uftrace/arch/x86_64/symbol.c:116: undefined reference to `__asan_register_globals'
/home/uftrace/arch/x86_64/mcount-entry.op: In function `asan.module_dtor':
/home/uftrace/arch/x86_64/symbol.c:116: undefined reference to `__asan_unregister_globals'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:213: recipe for target '/home/uftrace/libmcount/libmcount.so' failed
make: *** [/home/uftrace/libmcount/libmcount.so] Error 1
namhyung commented 6 years ago

So do you want build uftrace itself with Asan, right? AFAIK Asan has a tricky requirements that might conflict with uftrace.

Anyway I guess it's because Asan added some references to its internal functions which will be resolved at runtime (so it's undefined now). Currently libmcount does not allow any undefined symbol. Does below patch fix your problem?

diff --git a/Makefile b/Makefile
index 7ba26e9f..98ae353a 100644
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,7 @@ TEST_CFLAGS        = $(COMMON_CFLAGS) -DUNIT_TEST
 UFTRACE_LDFLAGS    = $(COMMON_LDFLAGS) $(LDFLAGS_$@) $(LDFLAGS_uftrace)
 DEMANGLER_LDFLAGS  = $(COMMON_LDFLAGS) $(LDFLAGS_$@) $(LDFLAGS_demangler)
 SYMBOLS_LDFLAGS    = $(COMMON_LDFLAGS) $(LDFLAGS_$@) $(LDFLAGS_symbols)
-LIB_LDFLAGS        = $(COMMON_LDFLAGS) $(LDFLAGS_$@) $(LDFLAGS_lib) -Wl,--no-undefined
+LIB_LDFLAGS        = $(COMMON_LDFLAGS) $(LDFLAGS_$@) $(LDFLAGS_lib)
 TEST_LDFLAGS       = $(COMMON_LDFLAGS) -L$(objdir)/libtraceevent -ltraceevent

 ifeq ($(DEBUG), 1)
wlfans123 commented 6 years ago

No. Compilation succeeded.

But, When run uftrace, get a new error.

Error Log:

$:~/uftrace$ make install
  INSTALL  uftrace
  INSTALL  libmcount
  INSTALL  bash-completion
  GEN      uftrace.1
  GEN      uftrace-record.1
  GEN      uftrace-replay.1
  GEN      uftrace-live.1
  GEN      uftrace-report.1
  GEN      uftrace-recv.1
  GEN      uftrace-info.1
  GEN      uftrace-dump.1
  GEN      uftrace-graph.1
  GEN      uftrace-script.1
  GEN      uftrace-tui.1
  INSTALL  man-pages
$:~/uftrace/build/bin$ cp ../../tests/s-hello.c .
$:~/uftrace/build/bin$ gcc -pg s-hello.c 
$:~/uftrace/build/bin$ ./uftrace ./a.out 
./a.out: symbol lookup error: /home/user/uftrace/build/lib/libmcount-fast.so: undefined symbol: __asan_option_detect_stack_use_after_return
uftrace: /home/user/uftrace/cmds/record.c:1357:save_session_symbols
 ERROR: cannot find map files: No such file or directory
honggyukim commented 5 years ago

address sanitizer build is possible as follows:

$ make ASAN=1

I also made one of asan report in #803.

honggyukim commented 5 years ago

I think we can close this. Please use make ASAN=1.