Unbreak ASan runtime in the simulators.
authorDan Liew <dan@su-root.co.uk>
Tue, 21 Apr 2020 00:22:35 +0000 (17:22 -0700)
committerDan Liew <dan@su-root.co.uk>
Tue, 21 Apr 2020 02:08:08 +0000 (19:08 -0700)
commit7039773b240b6eee00b5be5bc325c5c57501788a
treecce416e5368485f35ef89d743d9e9e3e77ff88b9
parentf0019d4ff29c31ba12e5ecd145552a266d1ffe37
Unbreak ASan runtime in the simulators.

Summary:
861b69faee5df8d4e13ef316c7474a10e4069e81 (rdar://problem/58789439) while
fixing symbolization for TSan completely broke ASan's runtime for the
simulators.

The problem with the previous patch is that the memory passed to
`putenv()` was poisoned and when passed to `putenv()` it tripped
an interceptor for `strchr()` which saw the memory was poisoned and
raised an ASan issue.

The memory was poisoned because `AtosSymbolizerProcess` objects
are created using ASan's internal allocator. Memory from this
allocator gets poisoned with `kAsanInternalHeapMagic`.

To workaround this, this patch makes the memory for the environment
variable entry a global variable that isn't poisoned.

This pass also adds a `DCHECK(getenv(K_ATOS_ENV_VAR))` because the
following DCHECK would crash because `internal_strcmp()` doesn't
work on nullptr.

rdar://problem/62067724

Reviewers: kubamracek, yln

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78525
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cpp