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.94.2) (envelope-from ) id 1rYatX-00GgjH-3b for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Feb 2024 00:07:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rYatV-00DBqw-Pr for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Feb 2024 00:06:57 +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.94.2) (envelope-from ) id 1rYatU-00DBqm-2w for pgsql-hackers@lists.postgresql.org; Sat, 10 Feb 2024 00:06:57 +0000 Received: from fout7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rYatQ-005xwW-U4 for pgsql-hackers@lists.postgresql.org; Sat, 10 Feb 2024 00:06:54 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 7FE281380096; Fri, 9 Feb 2024 19:06:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 09 Feb 2024 19:06:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1707523610; x=1707610010; bh=nhdXX+q7it bqlfMdTEMbbEoUwj/EEe/7oPkq4IMA3+s=; b=iLZeX4oFYONmyNKQokvMobRfJp JVPDvA8+co3w7I1YGf50/iSSPTC4kVR61uDPXWJ07wJCJg2Xx+uiM3kcZA9zsYPt TyYaCEv0poyYpPK0GT9gGH5cKnCEXR5jrNdg4oCS+5XuK1j1F3gTqa8dUwlBH8RZ 8QCnym/Wqp2mPLB+GDt15fAi24QDVp5muCrADte3seq/L62YylVNJgIk0D0Y32Uu /kjItF4wCAhizA9dpK/uF5k2LN7nXzUt8zK9ENCcbP4PH3aIYA2GpLnqXSrXC9NO +vdKzgaC+j52jRrHKnmakjZXFMj941gDiUB71b24cCW8nrbTGSEsbvS0gr5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1707523610; x=1707610010; bh=nhdXX+q7itbqlfMdTEMbbEoUwj/E Ee/7oPkq4IMA3+s=; b=q0dsgMluX1aqWcayusOMUJ5vU86LABQ3k8mWRx5Iurjc OdahmcmEDCXgcgFMCbvfERA7XTtqCdLBk46G6ZjrJci3XpD9zjxhzdVkgmM7akR9 4tLet30dXyfFYOGbhNMhlDJ/31FU57KMpfHaiahWcILR5Slrr+tDRD4Bf/xyycjg 66GHPvpxKOi3iPVLhiXWMxBLE69fZg/ky8d1stG3ptVGBkh09nnBRH/8k7tW6x4o rVXdtlZ1Yd8QFEVm1cXtlR4we67G+7OnYQiXzmYEVyvPD/53HHhH6AVb1VQzuVjK p6ZYcv8btkpMKe7DLRR4uvZ00hyA3ejdXFQvUoU2QQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrtdejgddujecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdefhedmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt jeenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeeuueevhffhhfeugfejhefgtedu geehgeetvdevjedufffgteeigeehteevgeelfeenucffohhmrghinhepghhnuhdrohhrgh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgt hhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Feb 2024 19:06:46 -0500 (EST) Date: Sat, 10 Feb 2024 09:06:35 +0900 From: Michael Paquier To: Ashutosh Bapat Cc: Alvaro Herrera , Bharath Rupireddy , vignesh C , torikoshia , PostgreSQL Hackers Subject: Re: Printing backtrace of postgres processes Message-ID: References: <202402090848.j6evnpunbehe@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="PSehf8HXfiFHmVeU" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --PSehf8HXfiFHmVeU Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 09, 2024 at 02:27:26PM +0530, Ashutosh Bapat wrote: > On Fri, Feb 9, 2024 at 2:18=E2=80=AFPM Alvaro Herrera wrote: >> Hmm, but the backtrace() manpage says >> >> =E2=80=A2 backtrace() and backtrace_symbols_fd() don't call mall= oc() explic=E2=80=90 >> itly, but they are part of libgcc, which gets loaded dynami= cally >> when first used. Dynamic loading usually triggers a call to = mal=E2=80=90 >> loc(3). If you need certain calls to these two functions t= o not >> allocate memory (in signal handlers, for example), you need to= make >> sure libgcc is loaded beforehand. >> >> and the patch ensures that libgcc is loaded by calling a dummy >> backtrace() at the start of the process. FWIW, anything I am reading about the matter freaks me out, including the dlopen() part in all the backends: https://www.gnu.org/software/libc/manual/html_node/Backtraces.html So I really question whether it is a good idea to assume if this will always be safe depending on the version of libgcc dealt with, increasing the impact area. Perhaps that's worrying too much, but it looks like one of these things where we'd better be really careful. > We defer actual action triggered by a signal till CHECK_FOR_INTERRUPTS > is called. I understand that we can't do that here since we want to > capture the backtrace at that moment and can't wait till next CFI. But > printing the backend can surely wait till next CFI right? Delaying the call of backtrace() to happen during a CFI() would be safe, yes, and writing data to stderr would not really be an issue as at least the data would be sent somewhere. That's less useful, but we do that for memory contexts. -- Michael --PSehf8HXfiFHmVeU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmXGvgsACgkQnvQgOdby QH05vQ/7BO4iff1PqNXRhAfY+0yIeaQMDg1wSMysZii+9x561ahMDOKoLw0jN+gN 0qqyom/iGvCOZpkv/8gXNqvgX0cRBUjIRlEcONVEFVSX1fUcuVXSfolw1wnlDj8N 8qCS8t2viJrUHjuFsarqNcBfl3KrtHmnKYFQSP+1xBE8pkKgawLePzbSzFx1KzKL F7UDZOkvnG+HvokVWJXQIWDsclhQ4cETgPkmxoo6FK1cLHaVo6MxklXWGv7jfasa ZvDMnFyxrXr0cDDcD0esUWljTDJRgURQm0PnnPPVpqqoK0vuYEb9YxOqbjUc4++D sz4NtausQTPSDCB0vsXQ6r4thiwfz1XjvGBPVtVDwjKWK6D+MFdBtOVonrVBv1vT F3PKnFPQVyNTsKRIX2IoCiAmZkvec4EZBOaBSncVV3Fljf6TSHq8hg0OaB1Hgafn BMEmpZnrIvDzJbVRY94SjEe09ThZGTtYeXRY8thcTe8EsXgbKhwe7JBo0zY2DuSj wGBYXs3no/lThG1keGBw87EXU5ZcwxYMQHlyq2vwWnOWsrGm4C/+EGCoTisR57YH AZcVPn7WEGZ2H8UZ5w2GGpBu3SmJQJVLkgQZl0DTP9EY2wCMzJzN3EcS+rpv7SM1 gFPV5ux9M5phLLjVSLni7cdrK3xxpLS9sEXPSTO8yM+UnK1wDJE= =f1I0 -----END PGP SIGNATURE----- --PSehf8HXfiFHmVeU--