From patchwork Thu Aug 8 11:06:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 2841020 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B2C23BF535 for ; Thu, 8 Aug 2013 11:07:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8356D20489 for ; Thu, 8 Aug 2013 11:07:39 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1D0A120441 for ; Thu, 8 Aug 2013 11:07:38 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7O46-0006BL-Vk; Thu, 08 Aug 2013 11:07:35 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7O44-00086S-N3; Thu, 08 Aug 2013 11:07:32 +0000 Received: from mail-wi0-f178.google.com ([209.85.212.178]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7O42-00085X-6n for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2013 11:07:30 +0000 Received: by mail-wi0-f178.google.com with SMTP id j17so423975wiw.11 for ; Thu, 08 Aug 2013 04:07:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0HenuFXJoHIazbCHc3EDIcwV3GQMHkk4j+2R8/gdgAo=; b=fxpNEVh6Ii9YO/FUcxRcIb4GBNzRu2ACFi50+XxECPs54HPcd/Jkr3PH9NEJyeP8we gxg8422CdsGZMbl9xDobMpwOWLUN14pc/TmM6oOEcfQeMR4MtG1OBhhQ3ey9jsY4APTN c2UWH8O50QtVzpTtILljstRf/ji7Q96qXSybPvq4wm+ZkL7zFz/+ThYE9Ifo7Cnc7CYc LoZnsF9osmZRSz9hAaK/+bH24s5PqD5LNXUFrWrpE09+ashkS9/Q9Go4UDpQpazlygzL eUdmP8+/7oJ3rhZ8F7SGtC+7A9mq1CepV/QhjRTJly+uSn5nqE5wEHMsSjQ7hsNNp2Nk rH9A== X-Gm-Message-State: ALoCoQk0C4rGG1maRP1SylpavqUZp9IFuIK/lDK3Y3aUM2HWKMTjRHUAKOGXcus+gX6bDpXM5Uow X-Received: by 10.180.109.10 with SMTP id ho10mr4783563wib.14.1375960026044; Thu, 08 Aug 2013 04:07:06 -0700 (PDT) Received: from ards-mac-mini.homenet.telecomitalia.it ([95.235.231.18]) by mx.google.com with ESMTPSA id em1sm17219604wib.3.2013.08.08.04.07.04 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 Aug 2013 04:07:05 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH] types.h: use GCC supplied typedefs if appropriate Date: Thu, 8 Aug 2013 13:06:50 +0200 Message-Id: <1375960010-4214-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.1.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130808_070730_339054_EFF9E27E X-CRM114-Status: GOOD ( 13.93 ) X-Spam-Score: -2.6 (--) Cc: Ard Biesheuvel , linux@arm.linux.org.uk, arnd@arndb.de, nico@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP GCC supplies a set of builtin defines that are meant to be used in the typedefs for types such as uint8_t, uint16_t etc. In fact, this is exactly what the stdint.h header does (of which GCC supplies its own version for freestanding builds). So in stdint.h, the types are defined as typedef __UINT16_TYPE__ uint16_t typedef __UINT32_TYPE__ uint32_t However, types.h in the kernel contains its own type definitions for these stdint.h types, and these do not depend on the GCC builtins. In the ARM world, both bare metal and glibc targeted versions of GCC are supported for building the kernel, and unfortunately, these do not agree on the definition of __UINT32_TYPE__ (likewise for __INT32_TYPE__ and __UINTPTR_TYPE__) - bare metal uses 'long unsigned int' - glibc GCC uses 'unsigned int' The result of this is that, while it is perfectly feasible in principle to support code that includes 'stdint.h' by compiling with -ffreestanding, (such as code using NEON intrinsics, whose header 'arm_neon.h' includes 'stdint.h'), in practice this breaks because we may end up with conflicting type definitions for uint32_t (and uintptr_t) depending on whether you are using bare metal GCC or glibc GCC. Arguably, this is a GCC issue because a) it does not pick up on the fact that 'typedef unsigned int uint32_t' and 'typedef long unsigned int uint32_t' are not in fact conflicting or b) it maintains this trivial difference between bare metal and glibc targeted build configs. However, even if I am aware that stdint.h support or matters related to it may be controversial subjects, fixing it in the kernel is not /that/ obtrusive, and solves matters for older GCCs as well, hence this RFC patch. Signed-off-by: Ard Biesheuvel --- include/linux/types.h | 55 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/include/linux/types.h b/include/linux/types.h index 4d118ba..40c5925 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -33,7 +33,11 @@ typedef __kernel_gid32_t gid_t; typedef __kernel_uid16_t uid16_t; typedef __kernel_gid16_t gid16_t; -typedef unsigned long uintptr_t; +#ifndef __UINTPTR_TYPE__ +#define __UINTPTR_TYPE__ unsigned long +#endif + +typedef __UINTPTR_TYPE__ uintptr_t; #ifdef CONFIG_UID16 /* This is defined by include/asm-{arch}/posix_types.h */ @@ -91,26 +95,51 @@ typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; +#ifndef __UINT8_TYPE__ +#define __UINT8_TYPE__ __u8 +#endif +#ifndef __INT8_TYPE__ +#define __INT8_TYPE__ __s8 +#endif +#ifndef __UINT16_TYPE__ +#define __UINT16_TYPE__ __u16 +#endif +#ifndef __INT16_TYPE__ +#define __INT16_TYPE__ __s16 +#endif +#ifndef __UINT32_TYPE__ +#define __UINT32_TYPE__ __u32 +#endif +#ifndef __INT32_TYPE__ +#define __INT32_TYPE__ __s32 +#endif +#ifndef __UINT64_TYPE__ +#define __UINT64_TYPE__ __u64 +#endif +#ifndef __INT64_TYPE__ +#define __INT64_TYPE__ __s64 +#endif + #ifndef __BIT_TYPES_DEFINED__ #define __BIT_TYPES_DEFINED__ -typedef __u8 u_int8_t; -typedef __s8 int8_t; -typedef __u16 u_int16_t; -typedef __s16 int16_t; -typedef __u32 u_int32_t; -typedef __s32 int32_t; +typedef __UINT8_TYPE__ u_int8_t; +typedef __INT8_TYPE__ int8_t; +typedef __UINT16_TYPE__ u_int16_t; +typedef __INT16_TYPE__ int16_t; +typedef __UINT32_TYPE__ u_int32_t; +typedef __INT32_TYPE__ int32_t; #endif /* !(__BIT_TYPES_DEFINED__) */ -typedef __u8 uint8_t; -typedef __u16 uint16_t; -typedef __u32 uint32_t; +typedef __UINT8_TYPE__ uint8_t; +typedef __UINT16_TYPE__ uint16_t; +typedef __UINT32_TYPE__ uint32_t; #if defined(__GNUC__) -typedef __u64 uint64_t; -typedef __u64 u_int64_t; -typedef __s64 int64_t; +typedef __UINT64_TYPE__ uint64_t; +typedef __UINT64_TYPE__ u_int64_t; +typedef __INT64_TYPE__ int64_t; #endif /* this is a special 64bit data type that is 8-byte aligned */