Skip to content

AddressSanitizerClangVsGCC (5.0 vs 7.1)

chefmax edited this page Jun 4, 2018 · 8 revisions

Clang 5.0 vs GCC 7.1

This page describes differences in AddressSanitizer between Clang and GCC (both runtime and compiler parts). In general, most differences are caused by different compiler part implementations in Clang and GCC.

The library part is periodically merged from LLVM to GCC and doesn't contain serious incompatibilities (although GCC still needs some local workarounds, see below).

The comparison was performed for relatively fresh versions of mentioned tools:

Clang: clang version 5.0 r304761 (http://llvm.org/viewvc/llvm-project/cfe?view=revision&revision=304761)
LLVM: LLVM version 5.0 r304775 (http://llvm.org/viewvc/llvm-project?view=revision&revision=304775)
Compiler-rt: r304744 (http://llvm.org/viewvc/llvm-project/compiler-rt?view=revision&revision=304744)

GCC: gcc version 7.1.1 r247506 (https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=247506)

Feature:

std containers overflow detection

Cons and Pros:

Support new kinds of bugs detection.


Feature:

dynamic alloca overflow detection

  • LLVM: yes
  • GCC: compiler support missing, but available in GCC 8
  • Bugs/ML:
Cons and Pros:

Support new kinds of bugs detection.


Feature:

using private aliases for globals

Cons and Pros:

GCC flaws:

  • false negatives on global variables when copy relocations are involved.

LLVM flaws:

  • we need to re-link our binaries against each time we add/remove sanitized library.
  • false positives or internal ASan CHECK failures can occur when mixing instrumented code with non-instrumented.
  • mixing instrumented code with non-instrumented is not safe in default mode.

Feature:

ODR violation detection

Cons and Pros:

GCC flaws:

  • GCC needs ODR indicators to make ODR violation detection work.

LLVM flaws:

  • false positives or internal ASan CHECK failures can occur when mixing instrumented code with non-instrumented.

Feature:

symbol size changing for global variables

Cons and Pros:

In Clang, ASan changes size of global variables by appending redzone size to it. This is an ABI change and may cause runtime errors when/if other shared modules have been linked against non-sanitized version of the library. However, given that Clang should support not only ELF format (e.g. Windows and OS/X use different ones), it's complicated to make sure that target linker won't cut out right redzone for global variables if not include it in symbol itself. GCC ASan generally supports ELF only, so it doesn't have such problems.


Feature:

adaptive global redzone sizes

  • LLVM: yes
  • GCC: no
  • Bugs/ML:
Cons and Pros:

Possible better layout for global variables in Clang.


Feature:

KASan support

Cons and Pros:

Use Asan for kernel. Linux kernel still cannot be built via clang for most targets (for x86{,_64} you still need apply special patches).


Feature:

asan_experiments support

Cons and Pros:

This feature is experimental. The experiments can be used to evaluate potential optimizations that remove instrumentation (assess false negatives). This way we can figure out, what optimization causes false negatives in much easier way.


Feature:

invalid pointer pairs detection

Cons and Pros:

This feature is experimental. Instrument <, <=, >, >=, - with pointer operands. Used to enable detection of invalid comparison operators on pointers.


Feature:

default runtime library linkage

Cons and Pros:

Dynamic linkage cons:

  • Worse performance (ASAN run-time is called via PLT even in the main executable)
  • Issue 147 (on Google Code) (can't use -static-libstdc++-Harder deployment (need to carry the DSO around)
  • __asan_init is not called from preinit_array and so there is a risk that an instrumented code will get called before __asan_init (may cause SEGV at startup; still unlikely)

Dynamic linkage proc:

  • Smaller disk usage and memory footprint when multiple processes are running with ASan.
  • Potential ability to bring old ASAN-ified binaries to new systems
  • Ability to LD_PRELOAD ASAN-DSO

Feature:

use explicit list of exported symbols

Cons and Pros:

In GCC, statically sanitized executables don't export ASan symbols. In particular, if executable is linked with -static-libasan, it won't export libasan public API (__asan_reportXYZ, etc.), causing dlopens of sanitized shared libraries to fail. Clang uses --dynamic-list link option to export public symbols and avoid such errors.


Feature:

asan_symbolize script

  • LLVM: yes
  • GCC: no
  • Bugs/ML:
Cons and Pros:

The script itself is a useful feature, perhaps it should be embedded to GCC source tree as well.


Feature:

ARM ABI for frame pointer extracting

Cons and Pros:

GCC needs a special patch to handle the issue.


Feature:

support ASan blacklist file

Cons and Pros:

Clang is more flexible in controlling instrumentation.


Feature:

support sanitizer coverage

Cons and Pros:

In Clang, ASan has good integration with fast and lightweight fuzzing library Libfuzzer (http://llvm.org/docs/LibFuzzer.html). In GCC, ASan is integrated with AFL only (http://lcamtuf.coredump.cx/afl/).


Feature:

support old Linux kernels (< 3.0)

  • LLVM: no
  • GCC: yes
  • Bugs/ML:
Cons and Pros:

In GCC, ASan works for older Linux kernels. GCC uses local workarounds in libsanitizer to support this feature.


Feature:

symbolizer implementation

  • LLVM: LLVM symbolizer
  • GCC: Libbacktrace
  • Bugs/ML:
Cons and Pros:

GCC uses embedded libbacktrace library for symbolization that's statically linked with libasan. LLVM needs a separate llvm-symbolizer binary to print nice reports.

Feature:

Support for no_sanitize attribute

Cons and Pros:

In LLVM it's possible to disable custom UBSan checker (e.g. float-divide-by-zero). GCC 8+ will support such functionality as well.


Feature:

Instrument function call arguments whose address is taken

Cons and Pros:

LLVM can find more bugs in function arguments


Feature:

Support for dead stripping of globals on Linux

Cons and Pros:

Allows linker to perform dead stripping of globals and their ASan metadata.

Clone this wiki locally