Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wSEin-0033Fn-2t for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2026 13:54:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wSEik-008Pr2-2n for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2026 13:54:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wSEik-008Pqu-1u for pgsql-hackers@lists.postgresql.org; Wed, 27 May 2026 13:54:55 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wSEij-000000011M7-3Zcm for pgsql-hackers@postgresql.org; Wed, 27 May 2026 13:54:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 64RDspuF465156; Wed, 27 May 2026 09:54:51 -0400 From: Tom Lane To: Andres Freund cc: pgsql-hackers@postgresql.org Subject: Re: Make stack depth check work with asan's use-after-return In-reply-to: <2kk4z4odvuyrg7qlwjd7ft4eron4cle4btb33v4qatgsdkayir@gj6e62rgsel4> References: <2kk4z4odvuyrg7qlwjd7ft4eron4cle4btb33v4qatgsdkayir@gj6e62rgsel4> Comments: In-reply-to Andres Freund message dated "Wed, 27 May 2026 09:23:13 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <465154.1779890091.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 27 May 2026 09:54:51 -0400 Message-ID: <465155.1779890091@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > The reason for that breakage is that with the stack-use-after-return log= ic, > stack variables are moved to heap allocations, to allow to detect refere= nces > 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 th= e > stack. +1. It was a little weird that we adopted __builtin_frame_address() to measure the location of the stack bottom but not the stack top. So I think this is good cleanup even if ASAN weren't forcing it. I might write the comments a bit differently, in particular I suggest changing - * Compute distance from reference point to my local variables + * Compute distance from reference point to my stack frame regards, tom lane