Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fvO6x-0001Yd-DE for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Aug 2018 14:39:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fvO6s-0006RO-V1 for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Aug 2018 14:39:46 +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 1fvO6s-0006R7-O7 for pgsql-hackers@lists.postgresql.org; Thu, 30 Aug 2018 14:39:46 +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 1fvO6l-0001VT-Dn for pgsql-hackers@postgresql.org; Thu, 30 Aug 2018 14:39:45 +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 w7UEdQwP007322; Thu, 30 Aug 2018 10:39:26 -0400 From: Tom Lane To: Fabien COELHO cc: Michael Banck , pgsql-hackers Subject: Re: pg_verify_checksums and -fno-strict-aliasing In-reply-to: References: <1535618100.1286.3.camel@credativ.de> Comments: In-reply-to Fabien COELHO message dated "Thu, 30 Aug 2018 13:25:14 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7320.1535639966.1@sss.pgh.pa.us> Date: Thu, 30 Aug 2018 10:39:26 -0400 Message-ID: <7321.1535639966@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Fabien COELHO writes: >> If I add -fno-strict-aliasing to $CFLAGS, the problem goes away. >> Is this something to worry about, or just pilot error cause I am not >> using the same $CFLAGS as for the rest of the build? I originally >> noticed this problem with my external fork of pg_verify_checksums. > It looks like the code is using aliasing where the standard says it should > not, which breaks compiler optimization, and the added options tells the > compiler to not assume that the code conforms to the standard... Actually, this code is just plain broken: char buf[BLCKSZ]; PageHeader header = (PageHeader) buf; There is no guarantee that a local char[] array is aligned on anything stronger than a byte boundary, and if it isn't, word-sized accesses to *header are going to fail on machines with strict alignment rules. I suppose that that is really what Michael's compiler is moaning about. I rather suspect that this hasn't been tested on anything but Intel hardware, which is famously misalignment-tolerant. The lack of any apparent regression test infrastructure for it isn't leaving a warm feeling about how much the buildfarm is testing it. (The right fix, of course, is to malloc the work buffer rather than put it on the stack.) regards, tom lane