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