From owner-svn-src-all@freebsd.org Sat Jul 18 22:46:47 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0637D9A46AF; Sat, 18 Jul 2015 22:46:47 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [87.251.56.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B9DD015FA; Sat, 18 Jul 2015 22:46:46 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:7b8:3a7::6c6f:d633:aff8:f50b] (unknown [IPv6:2001:7b8:3a7:0:6c6f:d633:aff8:f50b]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 153E329B32; Sun, 19 Jul 2015 00:46:44 +0200 (CEST) Subject: Re: svn commit: r285644 - head/contrib/sqlite3 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2102\)) Content-Type: multipart/signed; boundary="Apple-Mail=_AD697A35-FC2E-4EBC-B5A4-301229BDBE3B"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Pgp-Agent: GPGMail 2.5 From: Dimitry Andric In-Reply-To: <55A98763.1030705@FreeBSD.org> Date: Sun, 19 Jul 2015 00:46:51 +0200 Cc: Peter Jeremy , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Message-Id: <4C37A5C7-027C-4A75-B236-E8A512EB3FB9@FreeBSD.org> References: <201507162207.t6GM7ECT009955@repo.freebsd.org> <20150717222631.GD36150@server.rulingia.com> <55A98763.1030705@FreeBSD.org> To: Pedro Giffuni X-Mailer: Apple Mail (2.2102) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2015 22:46:47 -0000 --Apple-Mail=_AD697A35-FC2E-4EBC-B5A4-301229BDBE3B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On 18 Jul 2015, at 00:53, Pedro Giffuni wrote: >=20 > On 07/17/15 17:26, Peter Jeremy wrote: >> On 2015-Jul-16 22:07:14 +0000, "Pedro F. Giffuni" = wrote: >>> Log: >> ... >>> sqlite: clean a couple of invocations of memcpy(3) >>> Found almost accidentally by our native gcc when enhanced with >>> FORTIFY_SOURCE. >> ... >>> - memcpy((void *)&aHdr[1], (void *)&pWal->hdr, = sizeof(WalIndexHdr)); >>> + memcpy((void *)&aHdr[1], (const void *)&pWal->hdr, = sizeof(WalIndexHdr)); >>> walShmBarrier(pWal); >>> - memcpy((void *)&aHdr[0], (void *)&pWal->hdr, = sizeof(WalIndexHdr)); >>> + memcpy((void *)&aHdr[0], (const void *)&pWal->hdr, = sizeof(WalIndexHdr)); >> If the compiler complained about that, the compiler is broken. >=20 > The change was rather collateral (read cosmetical) to the real warning > which remains unfixed. >=20 > The compiler warning is this: > ... > =3D=3D=3D> lib/libsqlite3 (obj,depend,all,install) > cc1: warnings being treated as errors > /scratch/tmp/pfg/head/lib/libsqlite3/../../contrib/sqlite3/sqlite3.c: = In function 'walIndexWriteHdr': > = /scratch/tmp/pfg/head/lib/libsqlite3/../../contrib/sqlite3/sqlite3.c:49490= : warning: passing argument 1 of 'memcpy' discards qualifiers from = pointer target type > = /scratch/tmp/pfg/head/lib/libsqlite3/../../contrib/sqlite3/sqlite3.c:49492= : warning: passing argument 1 of 'memcpy' discards qualifiers from = pointer target type > --- sqlite3.So --- > *** [sqlite3.So] Error code 1 > ... >=20 > make[6]: stopped in /scratch/tmp/pfg/head/lib/libsqlite3 >=20 > It only happens when using the experimental FORTIFY_SOURCE support = [1], > and it only happens with gcc (the base one is the only tested). >=20 > Yes, I am suspecting a compiler bug but gcc has been really useful to = find > bugs in fortify_source. Actually, it is right to warn about this, as the casts drop a volatile specifier: 49482 static void walIndexWriteHdr(Wal *pWal){ 49483 volatile WalIndexHdr *aHdr =3D walIndexHdr(pWal); ... 49490 memcpy((void *)&aHdr[1], (void *)&pWal->hdr, = sizeof(WalIndexHdr)); 49491 walShmBarrier(pWal); 49492 memcpy((void *)&aHdr[0], (void *)&pWal->hdr, = sizeof(WalIndexHdr)); If you compile this with clang, and a high enough WARNS level, it tells you where the problem is: contrib/sqlite3/sqlite3.c:49490:18: error: cast from 'volatile struct = WalIndexHdr *' to 'void *' drops volatile qualifier = [-Werror,-Wcast-qual] memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr)); ^ contrib/sqlite3/sqlite3.c:49492:18: error: cast from 'volatile struct = WalIndexHdr *' to 'void *' drops volatile qualifier = [-Werror,-Wcast-qual] memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr)); ^ Similar with newer versions of gcc: contrib/sqlite3/sqlite3.c:49490:10: error: cast discards 'volatile' = qualifier from pointer target type [-Werror=3Dcast-qual] memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr)); ^ contrib/sqlite3/sqlite3.c:49492:10: error: cast discards 'volatile' = qualifier from pointer target type [-Werror=3Dcast-qual] memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr)); ^ Removing all the casts does not help, with base gcc it still gives: contrib/sqlite3/sqlite3.c:49490: warning: passing argument 1 of 'memcpy' = discards qualifiers from pointer target type contrib/sqlite3/sqlite3.c:49492: warning: passing argument 1 of 'memcpy' = discards qualifiers from pointer target type and with clang: contrib/sqlite3/sqlite3.c:49490:10: error: passing 'volatile WalIndexHdr = *' (aka 'volatile struct WalIndexHdr *') to parameter of type 'void *' = discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] memcpy(&aHdr[1], &pWal->hdr, sizeof(WalIndexHdr)); ^~~~~~~~ /usr/include/string.h:62:31: note: passing argument to parameter here void *memcpy(void * __restrict, const void * __restrict, size_t); ^ contrib/sqlite3/sqlite3.c:49492:10: error: passing 'volatile WalIndexHdr = *' (aka 'volatile struct WalIndexHdr *') to parameter of type 'void *' = discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] memcpy(&aHdr[0], &pWal->hdr, sizeof(WalIndexHdr)); ^~~~~~~~ /usr/include/string.h:62:31: note: passing argument to parameter here void *memcpy(void * __restrict, const void * __restrict, size_t); ^ >> 'const' >> is a promise to the caller that the given parameter will not be = modified >> by the callee. There's no requirement that the passed argument be = const. >> As bde commented, the casts are all spurious. >=20 > And since this is contrib'ed code I am not going through the > code churn but upstream has been notified. I don't think it is likely that upstream will go through the trouble of removing -Wcast-qual warnings. There are 152 of them in sqlite3.c. :-) -Dimitry --Apple-Mail=_AD697A35-FC2E-4EBC-B5A4-301229BDBE3B Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.27 iEYEARECAAYFAlWq12MACgkQsF6jCi4glqP+ggCaAve4tKxQxB/K+77ghkoZqqg9 qwUAoIwphCfBMHXgvhfZPesaPiOhtrdo =8QgW -----END PGP SIGNATURE----- --Apple-Mail=_AD697A35-FC2E-4EBC-B5A4-301229BDBE3B--