Home

fsanitizeaddress

fsanitizeaddress is the compiler option -fsanitize=address used to enable AddressSanitizer, a runtime memory error detector included in the Clang/LLVM toolchain and supported by GCC in compatible versions. It instruments C and C++ programs to find a range of memory corruption bugs, including heap- and stack-based buffer overflows, use-after-free, use-after-return, and double-free, by reporting errors when a forbidden memory access occurs.

AddressSanitizer works by instrumenting code and using a separate shadow memory to track the state of application

Usage and limitations: The flag is usually combined with -g for debugging information and with -O1 or

Output and interpretation: When a bug is detected, AddressSanitizer prints a diagnostic message indicating the error

memory.
Each
region
of
user
memory
has
a
corresponding
shadow
byte
that
encodes
whether
the
area
is
addressable,
red
zones,
or
freed.
The
instrumented
code
checks
every
memory
access
against
this
shadow
memory
and
raises
an
error
if
an
access
is
invalid.
A
runtime
library
(libasan)
handles
reporting,
aborting
on
errors,
and
producing
diagnostics
such
as
stack
traces,
the
faulty
access,
and
allocation/deallocation
points.
The
approach
typically
incurs
noticeable
performance
and
memory
overhead
during
execution.
higher,
sometimes
with
-fno-omit-frame-pointer.
It
is
most
effective
when
the
program
is
built
with
debugging
symbols
and
run
under
representative
workloads.
It
may
not
be
fully
compatible
with
all
platforms,
third-party
libraries,
or
code
loaded
dynamically,
and
can
produce
false
positives
in
rare
environments.
It
is
intended
for
development
and
testing
rather
than
production
deployment.
type
(for
example,
heap-buffer-overflow
or
use-after-free),
a
stack
trace,
and
details
about
the
allocation
and
deallocation
sites.
This
information
helps
locate
the
bug
and
reproduce
it
with
failing
input.