From 64041397b306cad2ea8b550e8e144392f0402e2e Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Sat, 2 Feb 2019 10:13:43 +0900 Subject: [PATCH] Use `static` to define CheckStackTrace on non-GNU (#429) for `&CheckStackAddress`, VisualStudio emits address of a trampoline like PLT, not the actual address of `CheckStackTrace`. We need address of `CheckStackTrace` to guess the address range of the function. `static` function seems to return the actual address of the function. Fixes #421 --- src/stacktrace_unittest.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/stacktrace_unittest.cc b/src/stacktrace_unittest.cc index c6ab638..77d3429 100644 --- a/src/stacktrace_unittest.cc +++ b/src/stacktrace_unittest.cc @@ -180,6 +180,15 @@ static void ATTRIBUTE_NOINLINE CheckStackTrace1(int i) { CheckStackTrace2(j); DECLARE_ADDRESS_LABEL(end); } +#ifndef __GNUC__ +// On non-GNU environment, we use the address of `CheckStackTrace` to +// guess the address range of this function. This guess is wrong for +// non-static function on Windows. This is probably because +// `&CheckStackTrace` returns the address of a trampoline like PLT, +// not the actual address of `CheckStackTrace`. +// See https://github.com/google/glog/issues/421 for the detail. +static +#endif void ATTRIBUTE_NOINLINE CheckStackTrace(int i) { INIT_ADDRESS_RANGE(CheckStackTrace, start, end, &expected_range[5]); DECLARE_ADDRESS_LABEL(start);