Commit e6cb263e authored by Karthik Kamath's avatar Karthik Kamath Committed by Daniel Black

MDEV-15961: Fix stacktraces under FreeBSD (aarch64)

Largely based on MySQL commit
https://github.com/mysql/mysql-server/commit/75271e51d60bce8683423b208cbb43b11ca6060e

MySQL Ref:
    BUG#24566529: BACKPORT BUG#23575445 TO 5.6

    (cut)
    Also, the PTR_SANE macro which tries to check if a pointer
    is invalid (used when printing pointer values in stack traces)
    gave false negatives on OSX/FreeBSD. On these platforms we
    now simply check if the pointer is non-null. This also removes
    a sbrk() deprecation warning when building on OS X. (It was
    before only disabled with building using XCode).

Removed execinfo path of MySQL patch that was already included.

sbrk doesn't exist on FreeBSD aarch64.

Removed HAVE_BSS_START based detection and replaced with __linux__
as it doesn't exist on OSX, Solaris or Windows.  __bss_start
exists on mutiple Linux architectures.

Tested on FreeBSD and Linux x86_64. Being in FreeBSD ports for 2
years implies a good testing there on all FreeBSD architectures there
too. MySQL-8.0.21 code is functionally identical to original commit.
parent beec8404
...@@ -35,7 +35,6 @@ SET(HAVE_BFILL CACHE INTERNAL "") ...@@ -35,7 +35,6 @@ SET(HAVE_BFILL CACHE INTERNAL "")
SET(HAVE_BMOVE CACHE INTERNAL "") SET(HAVE_BMOVE CACHE INTERNAL "")
SET(HAVE_BSD_SIGNALS CACHE INTERNAL "") SET(HAVE_BSD_SIGNALS CACHE INTERNAL "")
SET(HAVE_BSEARCH 1 CACHE INTERNAL "") SET(HAVE_BSEARCH 1 CACHE INTERNAL "")
SET(HAVE_BSS_START CACHE INTERNAL "")
SET(HAVE_BZERO CACHE INTERNAL "") SET(HAVE_BZERO CACHE INTERNAL "")
SET(HAVE_CHOWN CACHE INTERNAL "") SET(HAVE_CHOWN CACHE INTERNAL "")
SET(HAVE_CLOCK_GETTIME CACHE INTERNAL "") SET(HAVE_CLOCK_GETTIME CACHE INTERNAL "")
......
...@@ -312,7 +312,6 @@ ...@@ -312,7 +312,6 @@
/* Symbols we may use */ /* Symbols we may use */
#cmakedefine HAVE_SYS_ERRLIST 1 #cmakedefine HAVE_SYS_ERRLIST 1
/* used by stacktrace functions */ /* used by stacktrace functions */
#cmakedefine HAVE_BSS_START 1
#cmakedefine HAVE_BACKTRACE 1 #cmakedefine HAVE_BACKTRACE 1
#cmakedefine HAVE_BACKTRACE_SYMBOLS 1 #cmakedefine HAVE_BACKTRACE_SYMBOLS 1
#cmakedefine HAVE_BACKTRACE_SYMBOLS_FD 1 #cmakedefine HAVE_BACKTRACE_SYMBOLS_FD 1
......
...@@ -935,14 +935,6 @@ CHECK_CXX_SOURCE_COMPILES(" ...@@ -935,14 +935,6 @@ CHECK_CXX_SOURCE_COMPILES("
HAVE_ABI_CXA_DEMANGLE) HAVE_ABI_CXA_DEMANGLE)
ENDIF() ENDIF()
CHECK_C_SOURCE_COMPILES("
int main(int argc, char **argv)
{
extern char *__bss_start;
return __bss_start ? 1 : 0;
}"
HAVE_BSS_START)
CHECK_C_SOURCE_COMPILES(" CHECK_C_SOURCE_COMPILES("
int main() int main()
{ {
......
...@@ -34,19 +34,19 @@ ...@@ -34,19 +34,19 @@
#include <execinfo.h> #include <execinfo.h>
#endif #endif
#ifdef __linux__
#define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end) #define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end)
static char *heap_start; static char *heap_start;
#ifdef HAVE_BSS_START
extern char *__bss_start; extern char *__bss_start;
#endif #else
#define PTR_SANE(p) (p)
#endif /* __linux */
void my_init_stacktrace() void my_init_stacktrace()
{ {
#ifdef HAVE_BSS_START #ifdef __linux__
heap_start = (char*) &__bss_start; heap_start = (char*) &__bss_start;
#endif #endif /* __linux__ */
} }
#ifdef __linux__ #ifdef __linux__
...@@ -149,15 +149,15 @@ static int safe_print_str(const char *addr, int max_len) ...@@ -149,15 +149,15 @@ static int safe_print_str(const char *addr, int max_len)
int my_safe_print_str(const char* val, int max_len) int my_safe_print_str(const char* val, int max_len)
{ {
#ifdef __linux__
char *heap_end; char *heap_end;
#ifdef __linux__
// Try and make use of /proc filesystem to safely print memory contents. // Try and make use of /proc filesystem to safely print memory contents.
if (!safe_print_str(val, max_len)) if (!safe_print_str(val, max_len))
return 0; return 0;
#endif
heap_end= (char*) sbrk(0); heap_end= (char*) sbrk(0);
#endif
if (!PTR_SANE(val)) if (!PTR_SANE(val))
{ {
......
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