From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 19 18:30:07 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id D911FC85; Tue, 19 Feb 2013 18:30:07 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 24EBCCD0; Tue, 19 Feb 2013 18:30:06 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r1JITwqu022827; Tue, 19 Feb 2013 20:29:58 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r1JITwqu022827 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r1JITwWr022826; Tue, 19 Feb 2013 20:29:58 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 19 Feb 2013 20:29:58 +0200 From: Konstantin Belousov To: mdf@FreeBSD.org Subject: Re: Stupid question about integer sizes Message-ID: <20130219182958.GA2598@kib.kiev.ua> References: <77B93E04-9254-4EF1-8BDB-ED9214CEC2BC@sarenet.es> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Gv4AD2GulCTyUAWX" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-hackers@freebsd.org, Borja Marcos X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2013 18:30:07 -0000 --Gv4AD2GulCTyUAWX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 19, 2013 at 06:52:34AM -0800, mdf@FreeBSD.org wrote: > On Tue, Feb 19, 2013 at 5:11 AM, Borja Marcos wrote: > > > > Hello, > > > > I'm really sorry if this is a stupid question, but as far as I know, u_= int64_t defined in /usr/include/sys/types.h should *always* be > > a 64 bit unsigned integer, right? > > > > Seems there's a bug (or I need more and stronger coffee). Compiling a p= rogram on a 64 bit system with -m32 gets the 64 bit integer types wrong. > > > > % cat tachin.c > > #include > > #include > > > > > > main() > > { > > printf("sizeof uint64_t =3D %d\n", sizeof(uint64_t)); > > printf("sizeof u_int64_t =3D %d\n", sizeof(u_int64_t)); > > } > > > > > > > > uname -a > > FreeBSD splunk 9.1-RELEASE FreeBSD 9.1-RELEASE #14: Wed Jan 23 17:24:05= CET 2013 root@splunk:/usr/obj/usr/src/sys/SPLUNK amd64 > > > > % gcc -o tachin tachin.c > > % ./tachin > > sizeof uint64_t =3D 8 > > sizeof u_int64_t =3D 8 > > > > % ./tachin > > sizeof uint64_t =3D 4 <=3D=3D=3D=3D=3D=3D=3D WRON= G!! > > sizeof u_int64_t =3D 4 <=3D=3D=3D=3D=3D=3D=3D WRONG!! > > > > The same happens with clang. > > > > % clang -m32 -o tachin tachin.c > > tachin.c:5:1: warning: type specifier missing, defaults to 'int' [-Wimp= licit-int] > > main() > > ^~~~ > > 1 warning generated. > > % ./tachin > > sizeof uint64_t =3D 4 <=3D=3D=3D=3D=3D=3D=3D WRONG!! > > sizeof u_int64_t =3D 4 <=3D=3D=3D=3D=3D=3D=3D WRONG!! > > > > > > if I do the same on a i386 system (8.2-RELEASE, but it should be irrele= vant) the u_int64 types have the correct size. > > > > %gcc -o tachin tachin.c > > %./tachin > > sizeof uint64_t =3D 8 > > sizeof u_int64_t =3D 8 > > > > > > > > > > > > Am I missing anything? Seems like a too stupid problem to be a real bug= =2E Sorry if I am wrong. > > >=20 > Last I knew -m32 still wasn't quite supported on 9.1. This is fixed > in CURRENT. The problem in in the machine-dependent headers. > sys/types.h includes sys/_types.h which includes machine/_types.h. > But the machine alias can only point to one place; it's the amd64 > headers since you're running the amd64 kernel. > sys/amd64/include/_types.h defines __uint64_t as unsigned long, which > is correct in 64-bit mode but wrong in 32-bit mode. >=20 > On CURRENT there is a merge x86/_types.h which uses #ifdef guards to > define __uint64_t as unsigned long or unsigned long long, depending on > __LP64__, so that the size is correct on a 32-bit compiler invocation. Yes, but there are still some unconverted headers, mostly related to the machine context and signal handlers. Quick look: machine/sigframe.h (probably not much useful for usermode) machine/ucontext.h machine/frame.h (again, usermode most likely does not need it) machine/signal.h machine/elf.h libm machdep headers. --Gv4AD2GulCTyUAWX Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJRI8SlAAoJEJDCuSvBvK1BIycP/2WSzY6Rmm6DHDbB2hNk6JO/ LukeoIigKcNjrUCvhlaroiz5GrqW4lmLk23z2M0YZVrXdkmOL2HBmXcu2ce78+Oi K+BtxI4uG6h+q4eTUntWVuCTPfb2Xe7TKzF16pfYzBfKZMZpZk+8H5jlSBjJ5cGO uKacLVkn9adhD8Icoswt+9caDX+a34Zg7mOxkiDJ90xUL8yIXOSfJn6gwSzNihSa SBE/xhw0QRI+CdZdatxqz7t+YR9NIv2xnw13/CV1UKZB6OTz3i49MuMHuCKPnHiZ vlCm0v5nG1Fr3S0Hd56IrbUyvNfqlh2iXZNEeQcjLskXMJ7ZfYxt1uvKBdGm14rE 51MEG5EwxWF09z+RKJ032+6NmosajL7guFM//xd02+xu54sEf+Z8TMBdV7kHF1Js EHEb6kzXiqkJg+qHBrKLx/4y+50O7WyPCABnPBkzJwBxDSz9LOsuXApLZXBUwWaN /mSE8aKMGIWvt+LmqhnS45u4MPXnPtNwi7Z9u4w7jOE4wpgh2+ZiTlDGL/XChPQk KEiF8MPTbQ9lhhCgxiFpMLHD1N7Jjc6EDJpBcDGOn8NVF0/c+fcCw3S05o/8OGX4 3wbP8OHsasFN59emn09ShX2kAjcWBN5IfPbTnc8RI28ApJtU5QuuFrKi/+zk754Q FT0H4PYQPEtlHIOGs7W3 =02kY -----END PGP SIGNATURE----- --Gv4AD2GulCTyUAWX--