Commit 681e4677 authored by Philip Pronin's avatar Philip Pronin Committed by Sara Golemon

avoid using ifunc + ASan

Summary:
Code that is using ifunc dies with SIGSEGV on startup when used
with ASan.

Here is gdb output: {P2882504}

Seems like `ifunc` dispatch is happening before ASan is initialized,
but ASan instrumentation logic being called from there.

Test Plan:
built affected unicorn binaries with ASan, ran them, verified
there is no more SIGSEGV

Reviewed By: meyering@fb.com

FB internal diff: D1013420
parent b3cd8a1b
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "folly/Bits.h" #include "folly/Bits.h"
#include "folly/CpuId.h" #include "folly/CpuId.h"
#include "folly/Portability.h"
// None of this is necessary if we're compiling for a target that supports // None of this is necessary if we're compiling for a target that supports
// popcnt // popcnt
...@@ -32,8 +33,7 @@ int popcountll_builtin(unsigned long long x) { ...@@ -32,8 +33,7 @@ int popcountll_builtin(unsigned long long x) {
return __builtin_popcountll(x); return __builtin_popcountll(x);
} }
#if FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS)
#if FOLLY_HAVE_IFUNC
// Strictly speaking, these versions of popcount are usable without ifunc // Strictly speaking, these versions of popcount are usable without ifunc
// support. However, we would have to check, via CpuId, if the processor // support. However, we would have to check, via CpuId, if the processor
...@@ -63,7 +63,7 @@ extern "C" Type_popcountll* folly_popcountll_ifunc() { ...@@ -63,7 +63,7 @@ extern "C" Type_popcountll* folly_popcountll_ifunc() {
return folly::CpuId().popcnt() ? popcountll_inst : popcountll_builtin; return folly::CpuId().popcnt() ? popcountll_inst : popcountll_builtin;
} }
#endif // FOLLY_HAVE_IFUNC #endif // FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS)
} // namespace } // namespace
...@@ -73,7 +73,7 @@ namespace detail { ...@@ -73,7 +73,7 @@ namespace detail {
// Call folly_popcount_ifunc on startup to resolve to either popcount_inst // Call folly_popcount_ifunc on startup to resolve to either popcount_inst
// or popcount_builtin // or popcount_builtin
int popcount(unsigned int x) int popcount(unsigned int x)
#if FOLLY_HAVE_IFUNC #if FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS)
__attribute__((ifunc("folly_popcount_ifunc"))); __attribute__((ifunc("folly_popcount_ifunc")));
#else #else
{ return popcount_builtin(x); } { return popcount_builtin(x); }
...@@ -82,7 +82,7 @@ int popcount(unsigned int x) ...@@ -82,7 +82,7 @@ int popcount(unsigned int x)
// Call folly_popcount_ifunc on startup to resolve to either popcountll_inst // Call folly_popcount_ifunc on startup to resolve to either popcountll_inst
// or popcountll_builtin // or popcountll_builtin
int popcountll(unsigned long long x) int popcountll(unsigned long long x)
#if FOLLY_HAVE_IFUNC #if FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS)
__attribute__((ifunc("folly_popcountll_ifunc"))); __attribute__((ifunc("folly_popcountll_ifunc")));
#else #else
{ return popcountll_builtin(x); } { return popcountll_builtin(x); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment