Is building in Debug or Release preferred with address sanitizer?

1,805 views
Skip to first unread message

steve_a...@hotmail.com

unread,
Apr 10, 2019, 7:08:03 PM4/10/19
to address-sanitizer
Is it better to have all the optimization in place that a release build does vs. a debug build?

We ship release builds however our ASAN and production builds use different compilers so we already have optimization differences between the two builds.

I saw in the FAQ (https://github.com/google/sanitizers/wiki/AddressSanitizer) somebody had a known problem that wasn't detected and the statement was maybe it was optimized out.
  • Q: Why didn't ASan report an obviously invalid memory access in my code?

  • A1: If your errors is too obvious, compiler might have already optimized it out by the time Asan runs.

If that is really the case I would prefer a debug build so issues are fixed in both release and debug.

If you had to pick one build type which would you use to find the most issues?

Konstantin Serebryany

unread,
Apr 10, 2019, 8:17:15 PM4/10/19
to address-sanitizer
One thing to avoid is -O0 (fully disabled optimizations) where asan will be too slow. 
If I had to choose one configuration I would go with "-fsanitize=address -g -fno-omit-frame-pointers" 
and -O1 or -O2 w/o any other flags, especially without -D_NDEBUG which disables assertions.  
The choice between -O1 and -O2 should be based on performance -- use -O1 if it's fast enough for you, otherwise use -O2 

hth, 

--kcc 

--
You received this message because you are subscribed to the Google Groups "address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to address-saniti...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

steve_a...@hotmail.com

unread,
Apr 11, 2019, 9:06:33 AM4/11/19
to address-sanitizer
I forgot to mention, using CMake which lets us set the build type to Debug, Release, RelWithDebInfo, MinSizeRel and use either Debug or RelWithDebInfo as the build type (taking the default optimizations).
 
I did verbose output and noted the following:
  • RelWithDebInfo = -g -fsanitize=address -fno-omit-frame-pointer -O2 -DNDEBUG
  • Debug = -g -fsanitize=address -fno-omit-frame-pointer
also doing several alignment checks in both.

Speed (build and check time) has not been a concern with either build type (unless we add in fast_unwind_on_malloc=0 and/or malloc_context_size=60 temporarily) and we are not shipping the results of this build to anyone but rather it is a quality type build.

I agree that the asserts have value and why I wanted the debug build but trying to convince others if it makes sense or not.
Reply all
Reply to author
Forward
0 new messages