From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Mon, 30 Sep 2019 15:01:43 -0700 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5196C877A66; Mon, 30 Sep 2019 22:01:42 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-121-111.rdu2.redhat.com [10.10.121.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id B69F92634D; Mon, 30 Sep 2019 22:01:32 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH 1/1] BaseTools: use stdint.h for GCC ProcessorBind.h typedefs To: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , devel@edk2.groups.io, leif.lindholm@linaro.org Cc: Ard Biesheuvel , Bob Feng , Liming Gao References: <20190926192818.31119-1-leif.lindholm@linaro.org> From: "Laszlo Ersek" Message-ID: Date: Tue, 1 Oct 2019 00:01:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Mon, 30 Sep 2019 22:01:42 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 09/27/19 12:06, Philippe Mathieu-Daud=C3=A9 wrote: > On 9/26/19 9:28 PM, Leif Lindholm wrote: >> The AArch64 definitions of UINT64/INT64 differ from the X64 ones. >> Since this is on the tool side, doing like X64 and picking the >> definitions from stdint.h feels like a better idea than hardcoding >> them. So copy the pattern from X64/ProcesorBind.h. >=20 > Typo: X64/ProcessorBind.h ('s' missing). >=20 >> >> Cc: Ard Biesheuvel >> Cc: Bob Feng >> Cc: Liming Gao >> Cc: Laszlo Ersek >> Signed-off-by: Leif Lindholm >> --- >> >> This was triggered by one of the Risc-V patches which may need to end = up >> being modified to the point where this issue goes away, but the curren= t >> situation seems suboptimal. (Do you use %llx or %lx to print an Elf64_= Addr >> on a 64-bit LP architecture?) >=20 > What is the answer? :) For a hosted C99 program, you cast it to uint64_t, and print it with "%"PRIx64 (Note: "uint64_t" is an optional type, per C99. """ However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a two=E2=80=99s complement representation, it shall define the corresponding typedef names. """ The existence of Elf64_Addr suggests the implementation is like that, hence we can assume "uint64_t". Otherwise, we'd have to use "uint_least64_t" and "%"PRIxLEAST64.) When restricted to C89, you can only use "%lx" and "unsigned long", and you also have to rely on -- for example -- SUSv2 (from 1997 -- the last Single Unix Spec defined in terms of C89), for ensuring / selecting the XBS5_LP64_OFF64, or XBS5_LPBIG_OFFBIG compilation environments. (SUSv2 defines uint64_t, so you could use that in itself, but SUSv2 defines no matching format string macros, for printing uint64_t.) How you print a 64-bit unsigned integer in Visual Studio, I can't say. It's not fully C99 conformant, it's likely also not SUSv2 conformant (in case we wanted to rely on C89 + SUSv2); so I have no idea. It's likely documented in MSDN or some place similar. Thanks Laszlo >=20 >> >> BaseTools/Source/C/Include/AArch64/ProcessorBind.h | 26 ++++++++++---= ------- >> 1 file changed, 13 insertions(+), 13 deletions(-) >> >> diff --git a/BaseTools/Source/C/Include/AArch64/ProcessorBind.h b/Base= Tools/Source/C/Include/AArch64/ProcessorBind.h >> index bfaf1e28e446..dfa725b2e363 100644 >> --- a/BaseTools/Source/C/Include/AArch64/ProcessorBind.h >> +++ b/BaseTools/Source/C/Include/AArch64/ProcessorBind.h >> @@ -41,21 +41,21 @@ >> typedef signed char INT8; >> #else >> // >> - // Assume standard AARCH64 alignment. >> + // Use ANSI C 2000 stdint.h integer width declarations >> // >> - typedef unsigned long long UINT64; >> - typedef long long INT64; >> - typedef unsigned int UINT32; >> - typedef int INT32; >> - typedef unsigned short UINT16; >> - typedef unsigned short CHAR16; >> - typedef short INT16; >> - typedef unsigned char BOOLEAN; >> - typedef unsigned char UINT8; >> - typedef char CHAR8; >> - typedef signed char INT8; >> + #include >> + typedef uint8_t BOOLEAN; >> + typedef int8_t INT8; >> + typedef uint8_t UINT8; >> + typedef int16_t INT16; >> + typedef uint16_t UINT16; >> + typedef int32_t INT32; >> + typedef uint32_t UINT32; >> + typedef int64_t INT64; >> + typedef uint64_t UINT64; >> + typedef char CHAR8; >> + typedef uint16_t CHAR16; >> =20 >> - #define UINT8_MAX 0xff >> #endif >> =20 >> /// >> >=20 > Reviewed-by: Philippe Mathieu-Daude >=20