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

guard every file requiring elf/dwarf (#1524)

Summary:
Pull Request resolved: https://github.com/facebook/folly/pull/1524

In particular, every file in `folly/experimental/symbolizer/` and `folly/experimental/exception_tracer/`.

Permits including `folly/experimental/exception_tracer/` in the cmake build.

Closes: https://github.com/facebook/folly/pull/1524.

Reviewed By: luciang

Differential Revision: D24797973

fbshipit-source-id: 664febf885432795e54827e580cfe9eac1e75fba
parent 57fc0cfb
......@@ -174,7 +174,7 @@ find_package(Backtrace)
set(FOLLY_HAVE_BACKTRACE ${Backtrace_FOUND})
set(FOLLY_HAVE_DWARF ${LIBDWARF_FOUND})
if (NOT WIN32)
if (NOT WIN32 AND NOT APPLE)
set(FOLLY_USE_SYMBOLIZER ON)
endif()
message(STATUS "Setting FOLLY_USE_SYMBOLIZER: ${FOLLY_USE_SYMBOLIZER}")
......
......@@ -149,7 +149,6 @@ auto_sources(hfiles "*.h" "RECURSE" "${FOLLY_DIR}")
REMOVE_MATCHES_FROM_LISTS(files hfiles
MATCHES
"^${FOLLY_DIR}/build/"
"^${FOLLY_DIR}/experimental/exception_tracer/"
"^${FOLLY_DIR}/logging/example/"
"^${FOLLY_DIR}/(.*/)?test/"
"^${FOLLY_DIR}/tools/"
......
......@@ -22,6 +22,8 @@
#include <exception>
#include <typeinfo>
#if defined(__GLIBCXX__)
#include <unwind.h>
namespace __cxxabiv1 {
......@@ -57,3 +59,5 @@ __cxa_eh_globals* __cxa_get_globals_fast(void) noexcept;
#endif
} // namespace __cxxabiv1
#endif // defined(__GLIBCXX__)
......@@ -29,6 +29,8 @@
#include <folly/experimental/exception_tracer/StackTrace.h>
#include <folly/experimental/symbolizer/Symbolizer.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
using namespace folly::exception_tracer;
namespace {
......@@ -140,3 +142,5 @@ struct Initializer {
Initializer initializer;
} // namespace
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -21,6 +21,10 @@
#include <folly/experimental/exception_tracer/ExceptionTracer.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
#if defined(__GLIBCXX__)
namespace folly {
namespace exception_tracer {
......@@ -41,3 +45,7 @@ std::ostream& operator<<(std::ostream& out, const ExceptionStats& stats);
} // namespace exception_tracer
} // namespace folly
#endif // defined(__GLIBCXX__)
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -22,6 +22,10 @@
#include <folly/experimental/exception_tracer/StackTrace.h>
#include <folly/experimental/symbolizer/Symbolizer.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
#if defined(__GLIBCXX__)
using namespace folly::exception_tracer;
namespace {
......@@ -117,3 +121,7 @@ struct Initializer {
Initializer initializer;
} // namespace
#endif // defined(__GLIBCXX__)
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -20,8 +20,6 @@
#include <exception>
#include <iostream>
#include <dlfcn.h>
#include <glog/logging.h>
#include <folly/CppAttributes.h>
......@@ -33,6 +31,10 @@
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
#if defined(__GLIBCXX__)
#include <dlfcn.h>
namespace {
using namespace ::folly::exception_tracer;
......@@ -66,7 +68,6 @@ void printExceptionInfo(
}
out << " (" << info.frames.size()
<< (info.frames.size() == 1 ? " frame" : " frames") << ")\n";
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
try {
size_t frameCount = info.frames.size();
......@@ -93,7 +94,6 @@ void printExceptionInfo(
} catch (...) {
out << "\n !!! caught unexpected exception\n";
}
#endif
}
namespace {
......@@ -247,4 +247,6 @@ void installHandlers() {
} // namespace exception_tracer
} // namespace folly
#endif // defined(__GLIBCXX__)
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -16,8 +16,6 @@
#include <folly/experimental/exception_tracer/ExceptionTracerLib.h>
#include <dlfcn.h>
#include <vector>
#include <folly/Indestructible.h>
......@@ -25,6 +23,10 @@
#include <folly/SharedMutex.h>
#include <folly/Synchronized.h>
#if defined(__GLIBCXX__)
#include <dlfcn.h>
namespace __cxxabiv1 {
extern "C" {
......@@ -152,3 +154,5 @@ void rethrow_exception(std::exception_ptr ep) {
}
} // namespace std
#endif // defined(__GLIBCXX__)
......@@ -19,6 +19,8 @@
#include <exception>
#include <typeinfo>
#if defined(__GLIBCXX__)
namespace folly {
namespace exception_tracer {
......@@ -49,3 +51,5 @@ void registerCxaEndCatchCallback(CxaEndCatchType callback);
void registerRethrowExceptionCallback(RethrowExceptionType callback);
} // namespace exception_tracer
} // namespace folly
#endif // defined(__GLIBCXX__)
......@@ -23,6 +23,8 @@
#include <folly/experimental/exception_tracer/StackTrace.h>
#include <folly/experimental/symbolizer/Symbolizer.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
namespace folly {
namespace exception_tracer {
namespace {
......@@ -182,3 +184,5 @@ ExceptionInfo getAsyncTrace(const std::exception& ex) {
} // namespace exception_tracer
} // namespace folly
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -19,6 +19,8 @@
#include <folly/ExceptionWrapper.h>
#include <folly/experimental/exception_tracer/ExceptionTracer.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
namespace folly {
namespace exception_tracer {
......@@ -36,3 +38,5 @@ ExceptionInfo getAsyncTrace(const exception_wrapper& ew);
} // namespace exception_tracer
} // namespace folly
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -23,6 +23,8 @@
#include <folly/experimental/exception_tracer/ExceptionCounterLib.h>
#include <folly/portability/GTest.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
struct MyException {};
// clang-format off
......@@ -131,3 +133,5 @@ TEST(ExceptionCounter, multyThreads) {
t.join();
}
}
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -24,6 +24,8 @@
#include <folly/experimental/exception_tracer/ExceptionTracer.h>
#include <folly/portability/GFlags.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
void recurse(int level) {
if (level == 0) {
throw std::runtime_error("");
......@@ -54,6 +56,8 @@ BENCHMARK(ExceptionTracer, iters) {
}
}
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
......
......@@ -19,6 +19,8 @@
#include <folly/experimental/exception_tracer/ExceptionTracer.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
// clang-format off
[[noreturn]] void bar() {
throw std::runtime_error("hello");
......@@ -97,3 +99,9 @@ int main(int /* argc */, char* /* argv */[]) {
baz();
// no return because baz() is [[noreturn]]
}
#else // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
int main(int /* argc */, char* /* argv */[]) {}
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -19,6 +19,8 @@
#include <folly/experimental/exception_tracer/SmartExceptionTracer.h>
#include <folly/portability/GTest.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
using namespace folly::exception_tracer;
[[noreturn]] FOLLY_NOINLINE void testThrowException() {
......@@ -143,3 +145,5 @@ TEST(SmartExceptionTracer, AsyncStackTrace) {
}
}
}
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -99,7 +99,7 @@ int main(int argc, char* argv[]) {
#else // FOLLY_HAVE_DWARF && FOLLY_HAVE_ELF
int main(int argc, char* argv[]) {
int main(int, char*[]) {
return 1;
}
......
......@@ -28,6 +28,7 @@
#include <folly/Synchronized.h>
#include <folly/container/EvictingCacheMap.h>
#include <folly/experimental/symbolizer/Dwarf.h>
#include <folly/experimental/symbolizer/ElfCache.h>
#include <folly/experimental/symbolizer/StackTrace.h>
#include <folly/experimental/symbolizer/SymbolizePrinter.h>
#include <folly/experimental/symbolizer/SymbolizedFrame.h>
......@@ -37,10 +38,6 @@
namespace folly {
namespace symbolizer {
class ElfCacheBase;
class ElfCache;
class Symbolizer;
/**
* Get stack trace into a given FrameArray, return true on success (and
* set frameCount to the actual frame count, which may be > N) and false
......
......@@ -22,6 +22,8 @@
#include <folly/experimental/symbolizer/test/SymbolizerTestUtils.h>
#include <folly/portability/GFlags.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
namespace {
using namespace folly::symbolizer;
......@@ -71,6 +73,8 @@ BENCHMARK(DwarfFindAddressFullWithInline, n) {
run(folly::symbolizer::LocationInfoMode::FULL_WITH_INLINE, n);
}
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
......
......@@ -16,13 +16,13 @@
#include <folly/experimental/symbolizer/Elf.h>
#include <sys/auxv.h>
#include <folly/FileUtil.h>
#include <folly/experimental/TestUtil.h>
#include <folly/experimental/symbolizer/detail/Debug.h>
#include <folly/portability/GTest.h>
#if FOLLY_HAVE_ELF
using folly::symbolizer::ElfFile;
// Add some symbols for testing. Note that we have to be careful with type
......@@ -107,3 +107,5 @@ TEST_F(ElfTest, FailToOpenLargeFilename) {
elfFile->openNoThrow(largeNonExistingName.c_str()));
EXPECT_EQ(ElfFile::kSuccess, elfFile->openNoThrow(kDefaultElf));
}
#endif
......@@ -29,6 +29,8 @@
#include <folly/portability/GTest.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
using namespace folly;
using namespace folly::symbolizer;
......@@ -327,3 +329,5 @@ FOLLY_NOINLINE folly::coro::Task<void> co_funcA0() {
TEST(StackTraceTest, AsyncStackTraceSimple) {
folly::coro::blockingWait(co_funcA0());
}
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......@@ -30,6 +30,8 @@
#include <folly/portability/GTest.h>
#include <folly/test/TestUtils.h>
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
namespace folly {
namespace symbolizer {
namespace test {
......@@ -481,6 +483,8 @@ TEST(Dwarf, FindParameterNames) {
} // namespace symbolizer
} // namespace folly
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
// Can't use initFacebookLight since that would install its own signal handlers
// Can't use initFacebookNoSignals since we cannot depend on common
int main(int argc, char** argv) {
......
......@@ -16,9 +16,13 @@
#pragma once
#if defined(__ELF__) && (defined(__x86_64__) || defined(__i386__)) && \
#include <folly/portability/Config.h>
#if FOLLY_HAVE_ELF && (defined(__x86_64__) || defined(__i386__)) && \
!FOLLY_DISABLE_SDT
#define FOLLY_HAS_STD 1
#include <folly/tracing/StaticTracepoint-ELFx86.h>
#define FOLLY_SDT(provider, name, ...) \
......@@ -34,6 +38,8 @@
#else
#define FOLLY_HAVE_STD 0
#define FOLLY_SDT(provider, name, ...) \
do { \
} while (0)
......@@ -43,4 +49,5 @@
#define FOLLY_SDT_IS_ENABLED(provider, name) (false)
#define FOLLY_SDT_DEFINE_SEMAPHORE(provider, name)
#define FOLLY_SDT_DECLARE_SEMAPHORE(provider, name)
#endif
......@@ -35,6 +35,8 @@
#include <folly/portability/Unistd.h>
#include <folly/tracing/test/StaticTracepointTestModule.h>
#if FOLLY_HAS_STD
static const std::string kUSDTSubsectionName = FOLLY_SDT_NOTE_NAME;
static const int kUSDTNoteType = FOLLY_SDT_NOTE_TYPE;
static const size_t kAddrWidth = sizeof(void*);
......@@ -428,3 +430,5 @@ TEST(StaticTracepoint, TestSemaphoreExtern) {
CHECK_EQ(v * v, folly::test::staticTracepointTestFunc(v));
EXPECT_FALSE(FOLLY_SDT_IS_ENABLED(folly, test_semaphore_extern));
}
#endif
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