Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ task:
# print_stacktraces=1,verbosity=2, duh
# detect_leaks=0: too many uninteresting leak errors in short-lived binaries
UBSAN_OPTIONS: print_stacktrace=1:disable_coredump=0:abort_on_error=1:verbosity=2
ASAN_OPTIONS: print_stacktrace=1:disable_coredump=0:abort_on_error=1:detect_leaks=0:detect_stack_use_after_return=0
ASAN_OPTIONS: print_stacktrace=1:disable_coredump=0:abort_on_error=1:detect_leaks=0

# SANITIZER_FLAGS is set in the tasks below
CFLAGS: -Og -ggdb -fno-sanitize-recover=all $SANITIZER_FLAGS
Expand Down
22 changes: 19 additions & 3 deletions src/backend/utils/misc/stack_depth.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ set_stack_base(void)
/*
* Set up reference point for stack depth checking. On recent gcc we use
* __builtin_frame_address() to avoid a warning about storing a local
* variable's address in a long-lived variable.
* variable's address in a long-lived variable. This is also important
* with address sanitizer, see comment in stack_is_too_deep().
*/
#ifdef HAVE__BUILTIN_FRAME_ADDRESS
stack_base_ptr = __builtin_frame_address(0);
Expand Down Expand Up @@ -108,13 +109,28 @@ check_stack_depth(void)
bool
stack_is_too_deep(void)
{
#ifndef HAVE__BUILTIN_FRAME_ADDRESS
char stack_top_loc;
#endif
ssize_t stack_depth;
char *stack_address;

/*
* With address sanitizer's stack-use-after-return check, stack variables
* are moved to heap allocations, to allow to detect references to the
* memory at a later time. That would break our stack-depth check. Luckily
* __builtin_frame_address() works correctly, even under asan.
*/
#ifndef HAVE__BUILTIN_FRAME_ADDRESS
stack_address = &stack_top_loc;
#else
stack_address = (char *) __builtin_frame_address(0);
#endif

/*
* Compute distance from reference point to my local variables
* Compute distance from reference point to my stack frame.
*/
stack_depth = (ssize_t) (stack_base_ptr - &stack_top_loc);
stack_depth = (ssize_t) (stack_base_ptr - stack_address);

/*
* Take abs value, since stacks grow up on some machines, down on others
Expand Down