Skip to content

Commit

Permalink
Wrap abort in folly::init
Browse files Browse the repository at this point in the history
Summary:
Some upstream changes in glog are causing issues, so wrap abort in a way that produces a pointer that has the right attribute.
Fixes: facebook#1759

Reviewed By: yfeldblum

Differential Revision: D35730113

fbshipit-source-id: 6dba08f90cd543a78567f18fd8b809835605a574
  • Loading branch information
Orvid authored and facebook-github-bot committed Apr 23, 2022
1 parent 7e735a3 commit 5363745
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion folly/init/Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ void init(int* argc, char*** argv, bool removeFlags) {
init(argc, argv, options);
}

#if FOLLY_USE_SYMBOLIZER
// Newer versions of glog require the function passed to InstallFailureFunction
// to be noreturn. But glog spells that in multiple possible ways, depending on
// platform. But glog's choice of spelling does not match how the
// noreturn-ability of std::abort is spelled. Some compilers consider this a
// type mismatch on the function-ptr type. To fix the type mismatch, we wrap
// std::abort and mimic the condition and the spellings from glog here.
#if defined(__GNUC__)
__attribute__((noreturn))
#else
[[noreturn]]
#endif
static void
wrapped_abort() {
abort();
}
#endif

void init(int* argc, char*** argv, InitOptions options) {
#if !defined(_WIN32)
// Install the handler now, to trap errors received during startup.
Expand Down Expand Up @@ -76,7 +94,7 @@ void init(int* argc, char*** argv, InitOptions options) {

#if FOLLY_USE_SYMBOLIZER
// Don't use glog's DumpStackTraceAndExit; rely on our signal handler.
google::InstallFailureFunction(abort);
google::InstallFailureFunction(wrapped_abort);

// Actually install the callbacks into the handler.
folly::symbolizer::installFatalSignalCallbacks();
Expand Down

0 comments on commit 5363745

Please sign in to comment.