From patchwork Thu Aug 15 12:45:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 2845139 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D50AC9F271 for ; Thu, 15 Aug 2013 12:47:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A378620395 for ; Thu, 15 Aug 2013 12:47:14 +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 C433920387 for ; Thu, 15 Aug 2013 12:47:09 +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 1V9wx5-0008TQ-HP; Thu, 15 Aug 2013 12:46:55 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V9wwy-0007Yo-FK; Thu, 15 Aug 2013 12:46:48 +0000 Received: from mail-ea0-f177.google.com ([209.85.215.177]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V9wwl-0007Ws-Bg for linux-arm-kernel@lists.infradead.org; Thu, 15 Aug 2013 12:46:37 +0000 Received: by mail-ea0-f177.google.com with SMTP id f15so337774eak.8 for ; Thu, 15 Aug 2013 05:46:13 -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=AJNtZRllMqeaMAOr8FCKbWMfFWOjipSMMEmSZcXXyBs=; b=akyKbEeNVq53oLUjhT9ZZii9gwiX4vwl0Q75aK3SVcbYgd0M6r6c5Ly09sFd+XvIIO UJt61VoSnrD6reWkFSL10hrxLR8GHGrTg16JdOa+9VTAz0r5ornRo4s2rvXGmQ1ymUWA fqHCP+BZn6R6Gvd7otdXlMnKzzMBRM/v1FUBi6ScKLgX3nD6g64d8RmU4Mbt+Yuv0HuX jfuOfEQsLS9+by/hNI+OHNCbchCwgOZ6iuXIn1pZmfDXdpfFhu+qLA6IWm0eDFoIdd8K bqA1weOqfT5VXzrp1XzyE9/lT2nD994kBeciAksa2cKQdTB4/kMlVeaxmIgoZJZG1pOT YBjQ== X-Gm-Message-State: ALoCoQm1tADYS4CQCNFA7PHHkDF6PRdn+0oxU8a6Fhmz/COVg18kyu3zo0XOh7KZVC6V/0ctuWnv X-Received: by 10.14.8.72 with SMTP id 48mr22751676eeq.25.1376570773284; Thu, 15 Aug 2013 05:46:13 -0700 (PDT) Received: from ards-mac-mini.homenet.telecomitalia.it (host107-28-dynamic.12-79-r.retail.telecomitalia.it. [79.12.28.107]) by mx.google.com with ESMTPSA id bq1sm84246822eeb.9.2013.08.15.05.46.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 Aug 2013 05:46:12 -0700 (PDT) From: Ard Biesheuvel To: linux@arm.linux.org.uk Subject: [PATCH] ARM: add workaround for ambiguous C99 stdint.h types Date: Thu, 15 Aug 2013 14:45:46 +0200 Message-Id: <1376570746-18831-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-20130815_084635_590626_5E311AFB X-CRM114-Status: GOOD ( 10.98 ) X-Spam-Score: -2.6 (--) Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel 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=-7.0 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 The C99 types uintXX_t that are usually defined in 'stdint.h' are not as unambiguous on ARM as you would expect. For the types below, there is a difference on ARM between GCC built for bare metal ARM, GCC built for glibc and the kernel itself, which results in build errors if you try to build with -ffreestanding and include 'stdint.h' (such as when you include 'arm_neon.h' in order to use NEON intrinsics) As the typedefs for these types in 'stdint.h' are based on builtin defines supplied by GCC, we can tweak these to align with the kernel's idea of those types, so 'linux/types.h' and 'stdint.h' can be safely included from the same source file (provided that -ffreestanding is used). int32_t uint32_t uintptr_t bare metal GCC long unsigned long unsigned long glibc GCC int unsigned int unsigned int kernel int unsigned int unsigned long Signed-off-by: Ard Biesheuvel Acked-by: Nicolas Pitre --- Hello Russell, Would you please consider merging this patch? It allows NEON intrinsics code to access kernel data structures (that typically depend on linux/types.h), avoiding the need for messy workarounds. No other kernel code uses these macros, so nothing else should be affected. Regards, Ard. arch/arm/include/asm/types.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 arch/arm/include/asm/types.h diff --git a/arch/arm/include/asm/types.h b/arch/arm/include/asm/types.h new file mode 100644 index 0000000..c4f0bca --- /dev/null +++ b/arch/arm/include/asm/types.h @@ -0,0 +1,40 @@ +#ifndef _ASM_TYPES_H +#define _ASM_TYPES_H + +#include + +/* + * The C99 types uintXX_t that are usually defined in 'stdint.h' are not as + * unambiguous on ARM as you would expect. For the types below, there is a + * difference on ARM between GCC built for bare metal ARM, GCC built for glibc + * and the kernel itself, which results in build errors if you try to build with + * -ffreestanding and include 'stdint.h' (such as when you include 'arm_neon.h' + * in order to use NEON intrinsics) + * + * As the typedefs for these types in 'stdint.h' are based on builtin defines + * supplied by GCC, we can tweak these to align with the kernel's idea of those + * types, so 'linux/types.h' and 'stdint.h' can be safely included from the same + * source file (provided that -ffreestanding is used). + * + * int32_t uint32_t uintptr_t + * bare metal GCC long unsigned long unsigned long + * glibc GCC int unsigned int unsigned int + * kernel int unsigned int unsigned long + */ + +#ifdef __INT32_TYPE__ +#undef __INT32_TYPE__ +#define __INT32_TYPE__ int +#endif + +#ifdef __UINT32_TYPE__ +#undef __UINT32_TYPE__ +#define __UINT32_TYPE__ unsigned int +#endif + +#ifdef __UINTPTR_TYPE__ +#undef __UINTPTR_TYPE__ +#define __UINTPTR_TYPE__ unsigned long +#endif + +#endif /* _ASM_TYPES_H */