Make stack depth check work with asan's use-after-return

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Make stack depth check work with asan's use-after-return
Date: 2026-05-27 13:23:13
Message-ID: 2kk4z4odvuyrg7qlwjd7ft4eron4cle4btb33v4qatgsdkayir@gj6e62rgsel4
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

When running asan without further options against the backend, random tests
fail because the stack-depth check fails. One can work around that by putting
detect_stack_use_after_return=0 into ASAN_OPTIONS (at least with gcc, clang
still uses a lot of stack, but i think that's a separate issue).

The reason for that breakage is that with the stack-use-after-return logic,
stack variables are moved to heap allocations, to allow to detect references
to the memory at a later time. That breaks our stack-depth check, which is why
we had to disable detect_stack_use_after_return in CI. Luckily
__builtin_frame_address() works correctly, even under asan, so use that.

I think we should backpatch this. I'd be worried about using
__builtin_frame_address(), but we already do, for the base address of the
stack.

Greetings,

Andres Freund

Attachment Content-Type Size
v2-0001-Make-stack-depth-check-work-with-asan-s-use-after.patch text/x-diff 2.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-05-27 13:54:51 Re: Make stack depth check work with asan's use-after-return
Previous Message Shlok Kyal 2026-05-27 13:03:06 Re: Support EXCEPT for ALL SEQUENCES publications