From patchwork Wed Jan 11 16:28:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 9510599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D1A23606E1 for ; Wed, 11 Jan 2017 16:29:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B62D528478 for ; Wed, 11 Jan 2017 16:29:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAEB528498; Wed, 11 Jan 2017 16:29:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 656892859A for ; Wed, 11 Jan 2017 16:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030657AbdAKQ2z (ORCPT ); Wed, 11 Jan 2017 11:28:55 -0500 Received: from mail-wj0-f180.google.com ([209.85.210.180]:34629 "EHLO mail-wj0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758688AbdAKQ2w (ORCPT ); Wed, 11 Jan 2017 11:28:52 -0500 Received: by mail-wj0-f180.google.com with SMTP id tn15so106672486wjb.1 for ; Wed, 11 Jan 2017 08:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tQyXzVbqwEwRJtpPaDwDJTwOoudsJQeu41IJaI9OIeI=; b=WZWdrYvQOY0ORdkTZ3ycZIVO2DLoEfUDJ1iU9Q6oQch9AySwSEcRFy+CQ1mf1IutLH R7MhzOJpi0FogdgN0LnYzL5zPIObPPhR/3ENXYGxu/3lH1uv2JW7E9G/yGbGdnry/tOY 8k78Lw/jJNpuPrmjjIVpOgZycutGQZ0AhyRG0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tQyXzVbqwEwRJtpPaDwDJTwOoudsJQeu41IJaI9OIeI=; b=n65WFzyDaXbTp2ECEjUfvenF1LFPiddlFvFcFWvOh9lJ03A9fSJbo9E+qjQcjA634a WwkJXzTKNjAWSCVv2ru4kKJLDKJ557KJPOOHCgSOd8FUO734RMi6TMV8GlrtKK8DQyD3 WhZX0Flncy5HmYGmJ0HHLSUKYQEPJLV+pwe7zm1BHeQHAXq/W6vB6kfnd6wM5tN+QHtx C8dzshZ5ZZrT737IB/8QToUHtaOIfGjnVcVO6JH9GxuA2BTggm+tA7HwByV0sx0fI2dn FId+eCwuseTrcMPMg0slG2eKu7gM4TFXHAem3zv4S61jPm1BgtXNUlzmP4CBCbPlPcQW VEGw== X-Gm-Message-State: AIkVDXI+YCQZNJDt/NFUrMYryI3kaMP5WJ7Uue/0fFU2JvrC3R/1lksWRmgS2UujYaX/mcKC X-Received: by 10.194.93.37 with SMTP id cr5mr5735609wjb.95.1484152131135; Wed, 11 Jan 2017 08:28:51 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id lr10sm9229469wjb.6.2017.01.11.08.28.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 08:28:49 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id B1FA03E0664; Wed, 11 Jan 2017 16:28:48 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: drjones@redhat.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [kvm-unit-tests PATCH 1/6] libcflat: add PRI(dux)32 format types Date: Wed, 11 Jan 2017 16:28:36 +0000 Message-Id: <20170111162841.15569-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170111162841.15569-1-alex.bennee@linaro.org> References: <20170111162841.15569-1-alex.bennee@linaro.org> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So we can have portable formatting of uint32_t types. However there is a catch. Different compilers can use legally subtly different types though so we need to probe the compiler defined intdef.h first. Signed-off-by: Alex Bennée --- Makefile | 1 + configure | 13 +++++++++++++ lib/libcflat.h | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/Makefile b/Makefile index a32333b..9822d9a 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,7 @@ CFLAGS += $(fomit_frame_pointer) CFLAGS += $(fno_stack_protector) CFLAGS += $(fno_stack_protector_all) CFLAGS += $(wno_frame_address) +CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,) CXXFLAGS += $(CFLAGS) diff --git a/configure b/configure index 995c8fa..127868c 100755 --- a/configure +++ b/configure @@ -109,6 +109,18 @@ if [ -f $testdir/run ]; then ln -fs $testdir/run $testdir-run fi +# check if uint32_t needs a long format modifier +cat << EOF > lib_test.c +#include +EOF + +$cross_prefix$cc lib_test.c -E | grep "typedef" | grep "long" | grep "uint32_t" &> /dev/null +exit=$? +if [ $exit -eq 0 ]; then + u32_long=true +fi +rm -f lib_test.c + # check for dependent 32 bit libraries if [ "$arch" != "arm" ]; then cat << EOF > lib_test.c @@ -155,4 +167,5 @@ TEST_DIR=$testdir FIRMWARE=$firmware ENDIAN=$endian PRETTY_PRINT_STACKS=$pretty_print_stacks +U32_LONG_FMT=$u32_long EOF diff --git a/lib/libcflat.h b/lib/libcflat.h index 380395f..e80fc50 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -58,12 +58,21 @@ typedef _Bool bool; #define true 1 #if __SIZEOF_LONG__ == 8 +# define __PRI32_PREFIX # define __PRI64_PREFIX "l" # define __PRIPTR_PREFIX "l" #else +#if defined(__U32_LONG_FMT__) +# define __PRI32_PREFIX "l" +#else +# define __PRI32_PREFIX +#endif # define __PRI64_PREFIX "ll" # define __PRIPTR_PREFIX #endif +#define PRId32 __PRI32_PREFIX "d" +#define PRIu32 __PRI32_PREFIX "u" +#define PRIx32 __PRI32_PREFIX "x" #define PRId64 __PRI64_PREFIX "d" #define PRIu64 __PRI64_PREFIX "u" #define PRIx64 __PRI64_PREFIX "x"