Don't use symbolizer on OSX
authorPhilip Jameson <pjameson@fb.com>
Thu, 31 Aug 2017 01:00:36 +0000 (18:00 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 31 Aug 2017 01:08:04 +0000 (18:08 -0700)
Summary:
When trying to build with targets files on OSX, I couldn't use the symbolizer because it needs StackTrace, which requires libunwind and elf. This makes it so that we only build on linux for now. This also makes it so that we set FOLLY_USE_SYMBOLIZER in autoconf, since that wasn't set before.

Does a few things surrounding usage of the symbolizer library:
- Introduce FOLLY_USE_SYMBOLIZER in folly-config.h and USE_SYMBOLIZER as an AM definition
-- Filter some code out of init and some other random libs that optionally need the symbolizer
- Fix libdwarf detection. Previously on a fresh ubuntu container, we didn't find libdwarf/dwarf.h, so we stopped trying before looking at dwarf.h

Reviewed By: yfeldblum

Differential Revision: D5644352

fbshipit-source-id: f0a3580c41122e5e8fdfd17a9fdbb0921be21401

folly/Makefile.am
folly/SingletonStackTrace.cpp
folly/configure.ac
folly/experimental/Makefile.am
folly/fibers/test/StackOverflow.cpp
folly/init/Init.cpp
folly/init/Makefile.am

index 18aa5bd43c611cf588be91eec2b551cf3cff1465..e42b0eafb074c1e3df39734d4d99c394df5a1ba8 100644 (file)
@@ -160,14 +160,6 @@ nobase_follyinclude_HEADERS = \
        experimental/observer/SimpleObservable-inl.h \
        experimental/ProgramOptions.h \
        experimental/ReadMostlySharedPtr.h \
-       experimental/symbolizer/Elf.h \
-       experimental/symbolizer/Elf-inl.h \
-       experimental/symbolizer/ElfCache.h \
-       experimental/symbolizer/Dwarf.h \
-       experimental/symbolizer/LineReader.h \
-       experimental/symbolizer/SignalHandler.h \
-       experimental/symbolizer/StackTrace.h \
-       experimental/symbolizer/Symbolizer.h \
        experimental/Select64.h \
        experimental/StampedPtr.h \
        experimental/StringKeyedCommon.h \
@@ -662,6 +654,27 @@ libfolly_la_SOURCES += \
        fibers/TimeoutController.cpp
 endif
 
+if USE_SYMBOLIZER
+nobase_follyinclude_HEADERS += \
+       experimental/symbolizer/Elf.h \
+       experimental/symbolizer/Elf-inl.h \
+       experimental/symbolizer/ElfCache.h \
+       experimental/symbolizer/Dwarf.h \
+       experimental/symbolizer/LineReader.h \
+       experimental/symbolizer/SignalHandler.h \
+       experimental/symbolizer/StackTrace.h \
+       experimental/symbolizer/Symbolizer.h
+
+libfolly_la_SOURCES += \
+       experimental/symbolizer/Elf.cpp \
+       experimental/symbolizer/ElfCache.cpp \
+       experimental/symbolizer/Dwarf.cpp \
+       experimental/symbolizer/LineReader.cpp \
+       experimental/symbolizer/SignalHandler.cpp \
+       experimental/symbolizer/StackTrace.cpp \
+       experimental/symbolizer/Symbolizer.cpp
+endif
+
 libfollybasesse42_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LT_VERSION)
 libfollybasesse42_la_CXXFLAGS = -msse4.2 -mpclmul
 
index 48bb72cf86c551c5d637b601cf79fb9ed371e969..f5d5f97b6898ba19869e3ea5bbd6ebb0f69c77ba 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+#include <folly/portability/Config.h>
+
+#ifdef FOLLY_USE_SYMBOLIZER
 #include <folly/Singleton.h>
-#include <folly/experimental/symbolizer/Symbolizer.h>
+#include <folly/experimental/symbolizer/Symbolizer.h> // @manual
 
 namespace folly {
 
@@ -53,5 +57,5 @@ SetStackTraceGetter setStackTraceGetter;
 SetStackTraceGetter __attribute__((__init_priority__(101))) setStackTraceGetter;
 #endif
 }
-
 }
+#endif
index 2d5ca29c1e76cf9cef29ceaa001635a14eb5d2c2..181f46872edf1a785d52357769d1a68f96f7b7ca 100644 (file)
@@ -547,12 +547,8 @@ AC_ARG_ENABLE([follytestmain],
    [use_follytestmain=${enableval}], [use_follytestmain=yes])
 
 # libdwarf used to install in /usr/include, now installs in /usr/include/libdwarf.
-AC_CHECK_HEADERS([libdwarf/dwarf.h dwarf.h], [break])
-# Check whether we have both the library and the header
 have_libdwarf=no
-AS_IF([test "x${ac_cv_header_libdwarf_dwarf_h}" = xyes], [have_libdwarf=yes])
-AS_IF([test "x${ac_cv_header_dwarf_h}" = xyes], [have_libdwarf=yes])
-
+AC_CHECK_HEADERS([libdwarf/dwarf.h dwarf.h], [have_libdwarf=yes])
 
 AC_ARG_ENABLE([mobile],
    AS_HELP_STRING([--enable-mobile],
@@ -567,6 +563,24 @@ AC_ARG_ENABLE([exception-tracer],
     AS_HELP_STRING([--enable-exception-tracer], [enables building exception tracer]),
     [build_exception_tracer=${enableval}], [build_exception_tracer=no])
 
+AC_ARG_ENABLE([symbolizer],
+    AS_HELP_STRING([--enable-symbolizer], [try to build symbolizer if possible]),
+    [folly_try_use_symbolizer=${enableval}], [folly_try_use_symbolizer=yes])
+
+folly_use_symbolizer=no
+if test "$folly_try_use_symbolizer" = yes; then
+  if test "$build_os" = "linux-gnu" && test "$have_libdwarf" = yes; then
+      AC_CHECK_HEADER(
+        [elf.h],
+        AC_CHECK_LIB([unwind], [backtrace], [folly_use_symbolizer=yes]),
+      )
+  fi
+fi
+if test "$folly_use_symbolizer" = yes; then
+  AC_DEFINE([USE_SYMBOLIZER], [1], [Define to 1 if we should use the symbolizer in init])
+fi
+
+
 # Include directory that contains "folly" so #include <folly/Foo.h> works
 AM_CPPFLAGS='-I$(top_srcdir)/..'
 AM_CPPFLAGS="$AM_CPPFLAGS $BOOST_CPPFLAGS $OPENSSL_INCLUDES"
@@ -594,6 +608,7 @@ AM_CONDITIONAL([FOLLY_TESTMAIN], [test "x${use_follytestmain}" = "xyes"])
 AM_CONDITIONAL([HAVE_LIBDWARF], [test "x${have_libdwarf}" = "xyes"])
 AM_CONDITIONAL([HAVE_BOOST_CONTEXT], [test "x${ax_cv_boost_context}" = "xyes"])
 AM_CONDITIONAL([EXCEPTION_TRACER], [test "x${build_exception_tracer}" = "xyes"])
+AM_CONDITIONAL([USE_SYMBOLIZER], [test "x${folly_use_symbolizer}" = "xyes"])
 
 # remove pkg-config deps from dependent libraries
 # (at least for pkg-config file purposes)
index b32b100369956e8229b1ac631fce0ec05916fc1d..51cee1ba0e038bbbe923142c383f2b398b9c0c8f 100644 (file)
@@ -1,4 +1,4 @@
-if HAVE_LIBDWARF
+if USE_SYMBOLIZER
 MAYBE_SYMBOLIZER = symbolizer
 endif
 if EXCEPTION_TRACER
index cd91fa2d17a0b8096c86d5e15ffa68c2241f9da9..3c0892c9aed6faae8ab99dc9206447c82d8d4dcf 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <folly/experimental/symbolizer/SignalHandler.h>
+
 #include <folly/fibers/FiberManagerMap.h>
 #include <folly/init/Init.h>
 
index d44a6d4416193ffcce7d80a21c21ba3562863e8c..50f132e5ba4f59f4e73b77498086a7c09ecb34c1 100644 (file)
 #include <glog/logging.h>
 
 #include <folly/Singleton.h>
+#include <folly/portability/Config.h>
 
 #ifdef FOLLY_USE_SYMBOLIZER
-#include <folly/experimental/symbolizer/SignalHandler.h>
+#include <folly/experimental/symbolizer/SignalHandler.h> // @manual
 #endif
 #include <folly/portability/GFlags.h>
 
index 4b6367e060b95303ce818905b0e9f552a519b54a..32aee329a4b0876f747acebff7410c0656f4a681 100644 (file)
@@ -2,10 +2,6 @@ SUBDIRS = .
 
 lib_LTLIBRARIES = libfollyinit.la
 
-if HAVE_LIBDWARF
-FOLLY_SYMBOLIZER=$(top_builddir)/experimental/symbolizer/libfollysymbolizer.la
-endif
-
 libfollyinit_la_SOURCES = Init.cpp
-libfollyinit_la_LIBADD = $(top_builddir)/libfolly.la $(FOLLY_SYMBOLIZER)
+libfollyinit_la_LIBADD = $(top_builddir)/libfolly.la
 libfollyinit_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LT_VERSION)