Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eEPiQ-00083Z-Ad for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Nov 2017 01:08:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eEPiP-0008Ni-Ue for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Nov 2017 01:08:37 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eEPiP-0008NY-Mm for pgsql-bugs@lists.postgresql.org; Tue, 14 Nov 2017 01:08:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eEPiN-0004yV-35 for pgsql-bugs@postgresql.org; Tue, 14 Nov 2017 01:08:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vAE18TGN010397; Mon, 13 Nov 2017 20:08:29 -0500 From: Tom Lane To: Dmitry Dolgov <9erthalion6@gmail.com> cc: Andres Freund , Peter Eisentraut , Michael Paquier , Vincent Lachenal , PostgreSQL mailing lists Subject: Re: [BUGS] BUG #14897: Segfault on statitics SQL request In-reply-to: References: <20171110185747.31519.28038@wrigleys.postgresql.org> <1415.1510340891@sss.pgh.pa.us> <5652.1510344738@sss.pgh.pa.us> <7710.1510346813@sss.pgh.pa.us> <10197.1510349123@sss.pgh.pa.us> <14075.1510352167@sss.pgh.pa.us> <17617.1510355215@sss.pgh.pa.us> <3192.1510508352@sss.pgh.pa.us> Comments: In-reply-to Dmitry Dolgov <9erthalion6@gmail.com> message dated "Mon, 13 Nov 2017 17:35:45 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <10395.1510621709.1@sss.pgh.pa.us> Date: Mon, 13 Nov 2017 20:08:29 -0500 Message-ID: <10396.1510621709@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Dmitry Dolgov <9erthalion6@gmail.com> writes: > I've managed to reproduce this on Ubuntu. I tried multiple gcc versions, > and for gcc-5.4 everything is fine, for gcc-6.4 there is an issue. I found out I can reproduce this on Fedora 26 as well; I'd been fat-fingering the test somehow. The place where it is actually crashing for me is in int8_avg_combine(), and *the struct that is misaligned is one that has been passed back from a worker process*. This means that the problem is even worse than we thought before, because there is no reasonable way that the code that palloc'd that struct within the current process would know that it needs more than MAXALIGN alignment. It is not hard to think of other cases where an int128-containing struct might get passed through code that doesn't know what is in it. So what I am now thinking is that the only practical answer is to stop gcc from believing that it is safe to use 16-aligned instructions on int128's. (Some reading on the net suggests that the actual performance penalty for that is minimal anyway on modern Intel chips.) It looks like we can do that with very little code impact by attaching alignment pragmas to the typedefs for [u]int128: typedef PG_INT128_TYPE int128 #if defined(pg_attribute_aligned) pg_attribute_aligned(8) #endif ; typedef unsigned PG_INT128_TYPE uint128 #if defined(pg_attribute_aligned) pg_attribute_aligned(8) #endif ; When I do that, the coredump goes away for me. Moreover, this seems like an easily back-patchable fix, and we do need to do something back to 9.5. Now, one small problem is that c.h defines pg_attribute_aligned further down than where these typedefs currently appear. This seems to me to indicate that we ought to rethink the contents, or at least the ordering, of the "sections" in c.h. I wonder if anyone has any strong opinions about exactly how to do that. regards, tom lane