Commit 40eaf20c authored by Alisson Gusatti Azzolini's avatar Alisson Gusatti Azzolini Committed by Facebook Github Bot 0

Avoid external linkage call inside __ifunc__

Summary:
In debug mode, CpuId() ends up triggering external linkage from inside this __ifunc__.
However, in PIC, the relocation of external symbols are not ready yet, causing a segfault.

This only reproes in dynamic linking (PIC / so) and dbg mode.

Reviewed By: luciang

Differential Revision: D3895239

fbshipit-source-id: 2b7856c10abb5cfe24736d5bfac28e7e9d0e8272
parent c27a6839
...@@ -32,7 +32,13 @@ namespace folly { ...@@ -32,7 +32,13 @@ namespace folly {
*/ */
class CpuId { class CpuId {
public: public:
CpuId() { // Always inline in order for this to be usable from a __ifunc__.
// In shared library mde, a __ifunc__ runs at relocation time, while the
// PLT hasn't been fully populated yet; thus, ifuncs cannot use symbols
// with potentially external linkage. (This issue is less likely in opt
// mode since inlining happens more likely, and it doesn't happen for
// statically linked binaries which don't depend on the PLT)
FOLLY_ALWAYS_INLINE CpuId() {
#ifdef _MSC_VER #ifdef _MSC_VER
int reg[4]; int reg[4];
__cpuid(static_cast<int*>(reg), 0); __cpuid(static_cast<int*>(reg), 0);
...@@ -91,9 +97,12 @@ class CpuId { ...@@ -91,9 +97,12 @@ class CpuId {
#endif #endif
} }
#define X(name, r, bit) bool name() const { return (r) & (1U << bit); } #define X(name, r, bit) \
FOLLY_ALWAYS_INLINE bool name() const { \
return (r) & (1U << bit); \
}
// cpuid(1): Processor Info and Feature Bits. // cpuid(1): Processor Info and Feature Bits.
#define C(name, bit) X(name, f1c_, bit) #define C(name, bit) X(name, f1c_, bit)
C(sse3, 0) C(sse3, 0)
C(pclmuldq, 1) C(pclmuldq, 1)
......
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