Commit e90879cf authored by Lewis Baker's avatar Lewis Baker Committed by Facebook GitHub Bot

Change the way getDetachedRootAsyncStackFrame() calculates the address of detached_task()

Summary:
The previous implementation was calculating an address within the
detached_task() function by just adding the constant +2 to the
function-pointer. This was causing some issues with some of the
tools used to optimise binaries.

Reworked this implementation to instead actually return a true
return-address obtained from the compiler builtin so that it's
hopefully less problematic for those tools.

Reviewed By: maksfb

Differential Revision: D24506346

fbshipit-source-id: c41bd55ab09ebc70d040d355556ed4992243c14f
parent 23e90e57
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
#include <folly/tracing/AsyncStack.h> #include <folly/tracing/AsyncStack.h>
#include <folly/BenchmarkUtil.h>
#include <folly/Likely.h> #include <folly/Likely.h>
#include <glog/logging.h> #include <glog/logging.h>
...@@ -133,8 +134,21 @@ ScopedAsyncStackRoot::~ScopedAsyncStackRoot() { ...@@ -133,8 +134,21 @@ ScopedAsyncStackRoot::~ScopedAsyncStackRoot() {
namespace folly { namespace folly {
[[noreturn]] static void detached_task() { FOLLY_NOINLINE static void* get_return_address() noexcept {
LOG(FATAL) << "The detached_task() dummy function should never be called"; return FOLLY_ASYNC_STACK_RETURN_ADDRESS();
}
// This function is a special function that returns an address
// that can be used as a return-address and that will resolve
// debug-info to itself.
FOLLY_NOINLINE static void* detached_task() noexcept {
void* p = get_return_address();
// Add this after the call to prevent the compiler from
// turning the call to get_return_address() into a tailcall.
folly::doNotOptimizeAway(p);
return p;
} }
AsyncStackRoot& getCurrentAsyncStackRoot() noexcept { AsyncStackRoot& getCurrentAsyncStackRoot() noexcept {
...@@ -145,7 +159,7 @@ AsyncStackRoot& getCurrentAsyncStackRoot() noexcept { ...@@ -145,7 +159,7 @@ AsyncStackRoot& getCurrentAsyncStackRoot() noexcept {
static AsyncStackFrame makeDetachedRootFrame() noexcept { static AsyncStackFrame makeDetachedRootFrame() noexcept {
AsyncStackFrame frame; AsyncStackFrame frame;
frame.setReturnAddress(reinterpret_cast<char*>(&detached_task) + 2); frame.setReturnAddress(detached_task());
return frame; return frame;
} }
......
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