Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exjCf-00071V-Q1 for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Mar 2018 01:03:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1exjCc-00065N-KC for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Mar 2018 01:03:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exjCc-00065E-Dy for pgsql-bugs@lists.postgresql.org; Mon, 19 Mar 2018 01:03:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exjCY-0005y9-PJ for pgsql-bugs@lists.postgresql.org; Mon, 19 Mar 2018 01:03:05 +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 w2J12xDS020081; Sun, 18 Mar 2018 21:02:59 -0400 From: Tom Lane To: Tomas Vondra cc: marxin.liska@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15121: Multiple UBSAN errors In-reply-to: <7df78014-c931-6c75-6f92-ec48f390b2b9@2ndquadrant.com> References: <152140318583.11955.7731957058248462341@wrigleys.postgresql.org> <7df78014-c931-6c75-6f92-ec48f390b2b9@2ndquadrant.com> Comments: In-reply-to Tomas Vondra message dated "Mon, 19 Mar 2018 01:34:05 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20077.1521421379.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 18 Mar 2018 21:02:59 -0400 Message-ID: <20078.1521421379@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tomas Vondra writes: > On 03/18/2018 08:59 PM, PG Bug reporting form wrote: >> Building current trunk with -fsanitize=3Dundefined I see following erro= rs with >> make check: >> pg_crc32c_sse42.c:37:18: runtime error: load of misaligned address >> 0x7fffffffd484 for type 'const uint64', which requires 8 byte alignment >> 0x7fffffffd484: note: pointer points here > This comes from this call in pg_comp_crc32c_sse42 > crc =3D (uint32) _mm_crc32_u64(crc, *((const uint64 *) p)); > ... > So, not a bug. Agreed. That's Intel-only code so it doesn't need to be strict about alignment. >> arrayfuncs.c:3740:17: runtime error: member access within misaligned ad= dress >> 0x0000028b937c for type 'struct ExpandedObjectHeader', which requires 8= byte >> alignment > Again, the line numbers don't really match the code I have, but I guess > it's the same issue as for pg_comp_crc32c_sse42. This is apparently > related to array serialization, and I guess we have a compact structure > (intentionally, to make it smaller), and we accept the unaligned access. No, there's no intentional misalignment in the array stuff; if there were, it'd fail on alignment-picky hardware. What I think might be happening is that the compiler is taking the fact that the pointer is declared as AnyArrayType *, where typedef union AnyArrayType { ArrayType flt; ExpandedArrayHeader xpn; } AnyArrayType; to assume that the pointer must be aligned on an 8-byte boundary because ExpandedArrayHeader would require that, even if we're only accessing the "flt" member. Maybe that's a live problem, though we've seen no related trouble reports. It'd require the compiler to generate 8-byte-aligned instructions for accessing the ArrayType header, which doesn't seem all that probable. regards, tom lane