This is an archive of the discontinued LLVM Phabricator instance.

sanitizers: compile with -O1 under debug
ClosedPublic

Authored by dvyukov on Aug 12 2021, 6:52 AM.

Details

Summary

Tsan's check_memcpy.c test was disabled under debug because it failed.
But it points to real issues and does not help to just disable it.
I tried to enable it and see what fail and the first hit was default ctor for:

struct ChainedOriginDepotDesc {
  u32 here_id;
  u32 prev_id;
};

initializing these fields to 0's help partially,
but compiler still emits memset before calling ctor.
I did not try to see what's the next failure, because if it fails
on such small structs, it won't be realistic to fix everything
and keep working.

Compile runtimes with -O1 under debug instead.
It seems to fix all current failures. At least I run check-tsan
under clang/gcc x debug/non-debug and all combinations passed.
-O1 does not usually use too aggressive optimizations
and sometimes even makes debugging easier because machine code
is not exceedingly verbose.

Diff Detail

Event Timeline

dvyukov created this revision.Aug 12 2021, 6:52 AM
dvyukov requested review of this revision.Aug 12 2021, 6:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2021, 6:52 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka added inline comments.Aug 12 2021, 12:07 PM
compiler-rt/CMakeLists.txt
381

Doc string says: COMPILER_RT_DEBUG "Build runtimes with full debug info", but we never use it for -g flag and only for -O

Why don't we use regular CMAKE_BUILD_TYPE for that?

compiler-rt/test/tsan/Linux/check_memcpy.c
6

I am not sure we can assume availability of c++filt
why not to match to the mangled name?

vitalybuka accepted this revision.Aug 12 2021, 1:37 PM
This revision is now accepted and ready to land.Aug 12 2021, 1:37 PM

When LLVM_OPTIMIZE_SANITIZED_BUILDS is on, the runtime also gets the -O1 option.

dvyukov updated this revision to Diff 366186.Aug 12 2021, 10:16 PM

don't use c++filt

dvyukov marked an inline comment as done.Aug 12 2021, 10:19 PM
dvyukov added inline comments.
compiler-rt/CMakeLists.txt
381

The main effect of COMPILER_RT_DEBUG for me was always defining SANITIZER_DEBUG=1.

Why don't we use regular CMAKE_BUILD_TYPE for that?

You mean why don't enable -O1 based on CMAKE_BUILD_TYPE?
The problem is that the runtime is miscompiled with -O0, it's not up to user to select or not select -O0/-O1.
And test/tsan/Linux/check_memcpy.c fails with -O0, so if there is some bot w/o CMAKE_BUILD_TYPE, it will fail after this change.

compiler-rt/test/tsan/Linux/check_memcpy.c
6

Removed c++filt

dvyukov marked an inline comment as done.Aug 12 2021, 10:20 PM

When LLVM_OPTIMIZE_SANITIZED_BUILDS is on, the runtime also gets the -O1 option.

See my reply to Vitaly.

This revision was automatically updated to reflect the committed changes.