Commit db54c6bf authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Mark _r_debug imports as weak

Summary:
[Folly] Mark `_r_debug` imports as weak imports. `_r_debug` is available in `<link.h>` but is not a portable API, so detect whether it is available at runtime and use it only if it is available.

Fixes: https://github.com/facebook/folly/issues/1373.

Reviewed By: Orvid

Differential Revision: D21911715

fbshipit-source-id: 660c0bc90d405d9a43826e7bdfc3b04480728b66
parent 7d367a68
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
* *
* Note that declaring it with `extern "C"` results in linkage conflicts. * Note that declaring it with `extern "C"` results in linkage conflicts.
*/ */
extern struct r_debug _r_debug; FOLLY_ATTR_WEAK extern struct r_debug _r_debug;
namespace folly { namespace folly {
namespace symbolizer { namespace symbolizer {
...@@ -83,6 +83,10 @@ void setSymbolizedFrame( ...@@ -83,6 +83,10 @@ void setSymbolizedFrame(
} // namespace } // namespace
bool Symbolizer::isAvailable() {
return &_r_debug != nullptr;
}
Symbolizer::Symbolizer( Symbolizer::Symbolizer(
ElfCacheBase* cache, ElfCacheBase* cache,
LocationInfoMode mode, LocationInfoMode mode,
...@@ -101,6 +105,9 @@ size_t Symbolizer::symbolize( ...@@ -101,6 +105,9 @@ size_t Symbolizer::symbolize(
FOLLY_SAFE_CHECK(addrCount <= frameCount, "Not enough frames."); FOLLY_SAFE_CHECK(addrCount <= frameCount, "Not enough frames.");
size_t remaining = addrCount; size_t remaining = addrCount;
if (&_r_debug == nullptr) {
return 0;
}
if (_r_debug.r_version != 1) { if (_r_debug.r_version != 1) {
return 0; return 0;
} }
......
...@@ -89,6 +89,8 @@ class Symbolizer { ...@@ -89,6 +89,8 @@ class Symbolizer {
public: public:
static constexpr auto kDefaultLocationInfoMode = LocationInfoMode::FAST; static constexpr auto kDefaultLocationInfoMode = LocationInfoMode::FAST;
static bool isAvailable();
explicit Symbolizer(LocationInfoMode mode = kDefaultLocationInfoMode) explicit Symbolizer(LocationInfoMode mode = kDefaultLocationInfoMode)
: Symbolizer(nullptr, mode) {} : Symbolizer(nullptr, mode) {}
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <folly/experimental/TestUtil.h> #include <folly/experimental/TestUtil.h>
#include <folly/experimental/symbolizer/StackTrace.h> #include <folly/experimental/symbolizer/StackTrace.h>
#include <folly/experimental/symbolizer/Symbolizer.h> #include <folly/experimental/symbolizer/Symbolizer.h>
#include <folly/test/TestUtils.h>
#include <boost/regex.hpp> #include <boost/regex.hpp>
...@@ -209,6 +210,8 @@ FOLLY_NOINLINE void baz(FrameArray<frames>& addresses) { ...@@ -209,6 +210,8 @@ FOLLY_NOINLINE void baz(FrameArray<frames>& addresses) {
} // namespace } // namespace
TEST(StackTraceTest, TerseFileAndLineStackTracePrinterOutput) { TEST(StackTraceTest, TerseFileAndLineStackTracePrinterOutput) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(LocationInfoMode::FULL); Symbolizer symbolizer(LocationInfoMode::FULL);
FrameArray<frames> addresses; FrameArray<frames> addresses;
StringSymbolizePrinter printer(SymbolizePrinter::TERSE_FILE_AND_LINE); StringSymbolizePrinter printer(SymbolizePrinter::TERSE_FILE_AND_LINE);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <folly/experimental/symbolizer/SymbolizedFrame.h> #include <folly/experimental/symbolizer/SymbolizedFrame.h>
#include <folly/experimental/symbolizer/test/SymbolizerTestUtils.h> #include <folly/experimental/symbolizer/test/SymbolizerTestUtils.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
#include <folly/test/TestUtils.h>
namespace folly { namespace folly {
namespace symbolizer { namespace symbolizer {
...@@ -33,6 +34,8 @@ namespace test { ...@@ -33,6 +34,8 @@ namespace test {
void foo() {} void foo() {}
TEST(Symbolizer, Single) { TEST(Symbolizer, Single) {
SKIP_IF(!Symbolizer::isAvailable());
// It looks like we could only use .debug_aranges with "-g2", with // It looks like we could only use .debug_aranges with "-g2", with
// "-g1 -gdwarf-aranges", the code has to fallback to line-tables to // "-g1 -gdwarf-aranges", the code has to fallback to line-tables to
// get the file name. // get the file name.
...@@ -70,6 +73,8 @@ class ElfCacheTest : public testing::Test { ...@@ -70,6 +73,8 @@ class ElfCacheTest : public testing::Test {
FrameArray<100> goldenFrames; FrameArray<100> goldenFrames;
void ElfCacheTest::SetUp() { void ElfCacheTest::SetUp() {
SKIP_IF(!Symbolizer::isAvailable());
bar(goldenFrames); bar(goldenFrames);
Symbolizer symbolizer; Symbolizer symbolizer;
symbolizer.symbolize(goldenFrames); symbolizer.symbolize(goldenFrames);
...@@ -106,6 +111,8 @@ TEST_F(ElfCacheTest, SignalSafeElfCache) { ...@@ -106,6 +111,8 @@ TEST_F(ElfCacheTest, SignalSafeElfCache) {
} }
TEST(SymbolizerTest, SymbolCache) { TEST(SymbolizerTest, SymbolCache) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL, 100); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL, 100);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -190,6 +197,8 @@ class ClassWithInlineFunctions { ...@@ -190,6 +197,8 @@ class ClassWithInlineFunctions {
}; };
TEST(SymbolizerTest, InlineFunctionBasic) { TEST(SymbolizerTest, InlineFunctionBasic) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -229,6 +238,8 @@ TEST(SymbolizerTest, InlineFunctionBasic) { ...@@ -229,6 +238,8 @@ TEST(SymbolizerTest, InlineFunctionBasic) {
} }
TEST(SymbolizerTest, InlineFunctionWithoutEnoughFrames) { TEST(SymbolizerTest, InlineFunctionWithoutEnoughFrames) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -261,6 +272,8 @@ TEST(SymbolizerTest, InlineFunctionWithoutEnoughFrames) { ...@@ -261,6 +272,8 @@ TEST(SymbolizerTest, InlineFunctionWithoutEnoughFrames) {
} }
TEST(SymbolizerTest, InlineFunctionInLexicalBlock) { TEST(SymbolizerTest, InlineFunctionInLexicalBlock) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -286,6 +299,8 @@ TEST(SymbolizerTest, InlineFunctionInLexicalBlock) { ...@@ -286,6 +299,8 @@ TEST(SymbolizerTest, InlineFunctionInLexicalBlock) {
} }
TEST(SymbolizerTest, InlineFunctionInDifferentCompilationUnit) { TEST(SymbolizerTest, InlineFunctionInDifferentCompilationUnit) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -304,6 +319,8 @@ TEST(SymbolizerTest, InlineFunctionInDifferentCompilationUnit) { ...@@ -304,6 +319,8 @@ TEST(SymbolizerTest, InlineFunctionInDifferentCompilationUnit) {
} }
TEST(SymbolizerTest, InlineClassMemberFunction) { TEST(SymbolizerTest, InlineClassMemberFunction) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -321,6 +338,8 @@ TEST(SymbolizerTest, InlineClassMemberFunction) { ...@@ -321,6 +338,8 @@ TEST(SymbolizerTest, InlineClassMemberFunction) {
} }
TEST(SymbolizerTest, StaticInlineClassMemberFunction) { TEST(SymbolizerTest, StaticInlineClassMemberFunction) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -337,6 +356,8 @@ TEST(SymbolizerTest, StaticInlineClassMemberFunction) { ...@@ -337,6 +356,8 @@ TEST(SymbolizerTest, StaticInlineClassMemberFunction) {
} }
TEST(SymbolizerTest, InlineClassMemberFunctionInDifferentFile) { TEST(SymbolizerTest, InlineClassMemberFunctionInDifferentFile) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -354,6 +375,8 @@ TEST(SymbolizerTest, InlineClassMemberFunctionInDifferentFile) { ...@@ -354,6 +375,8 @@ TEST(SymbolizerTest, InlineClassMemberFunctionInDifferentFile) {
} }
TEST(SymbolizerTest, StaticInlineClassMemberFunctionInDifferentFile) { TEST(SymbolizerTest, StaticInlineClassMemberFunctionInDifferentFile) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 0);
FrameArray<100> frames; FrameArray<100> frames;
...@@ -371,6 +394,8 @@ TEST(SymbolizerTest, StaticInlineClassMemberFunctionInDifferentFile) { ...@@ -371,6 +394,8 @@ TEST(SymbolizerTest, StaticInlineClassMemberFunctionInDifferentFile) {
// No inline frames should be filled because of no extra frames. // No inline frames should be filled because of no extra frames.
TEST(SymbolizerTest, InlineFunctionBasicNoExtraFrames) { TEST(SymbolizerTest, InlineFunctionBasicNoExtraFrames) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 100); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 100);
FrameArray<8> frames; FrameArray<8> frames;
inlineBar<8>(frames); inlineBar<8>(frames);
...@@ -385,6 +410,8 @@ TEST(SymbolizerTest, InlineFunctionBasicNoExtraFrames) { ...@@ -385,6 +410,8 @@ TEST(SymbolizerTest, InlineFunctionBasicNoExtraFrames) {
} }
TEST(SymbolizerTest, InlineFunctionWithCache) { TEST(SymbolizerTest, InlineFunctionWithCache) {
SKIP_IF(!Symbolizer::isAvailable());
Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 100); Symbolizer symbolizer(nullptr, LocationInfoMode::FULL_WITH_INLINE, 100);
FrameArray<100> frames; FrameArray<100> frames;
......
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