From patchwork Sun Feb 3 11:40:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10794621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EA456C2 for ; Sun, 3 Feb 2019 11:40:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F233D2BF02 for ; Sun, 3 Feb 2019 11:40:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E648D2BF08; Sun, 3 Feb 2019 11:40:56 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 5B7232BF02 for ; Sun, 3 Feb 2019 11:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727101AbfBCLkz (ORCPT ); Sun, 3 Feb 2019 06:40:55 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:46043 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727095AbfBCLkz (ORCPT ); Sun, 3 Feb 2019 06:40:55 -0500 Received: by mail-ed1-f65.google.com with SMTP id d39so8946923edb.12 for ; Sun, 03 Feb 2019 03:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xYbhwSBG/Ohbidt+Vlu23KzyJixzToKa5uAMglLP8JM=; b=N8cmkxYXfoKCloY1aupMZXq46HJCMoEvfPOrMNbqtTPlMfSxtygVn6BjZqfvtZvhE8 TXNsnkvUgUlSGiHFRMyplb+oTBcwbtIzXR4pjmZ32wleK8WNJI+uPlAh4zOcLJZ0bs6L T4VdGY6o3CucaH88i70YJRYeUn2NQJ2QK0RDe63CF8VnE+Y4YqrpcyyjxZFxe9h6utaY l60GcY+cpPACuZR3JqOxztRv6sv7x7pnKFuQueAA2xPmWQOKR6w1aGAK+w4mdMSvgEqV mSlKcVb/kQe00e+7TSqKI34Dk4OHYkUbmP2rrsUh8Jx1izetJ6fFHxRE77al0U8+t1O8 mCHw== 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=xYbhwSBG/Ohbidt+Vlu23KzyJixzToKa5uAMglLP8JM=; b=dyTQn03z2Avse5DShhyJl8RbWi9tHOfa2EvO7auTjC6xUtL2S0ierforn3C0FiAfxt igVBff0Y2ugKMlxaX/UA+7/s8DnnBPvWXyViRhkaoQhYZOyN2CsyM4e0yQcIOwe4goA6 rVRlmplYw5nOK3F5vnGgCHniJurSB7Anc2DCw/D+osPJbXWWchK7I/ftPTjMMAmqRJfg C/SsnpzO74pO7EcmVo+qqO+VSHupkZPx0ep03ClmJdyVoMafIjRgKlYgDYD6xtL5eNNS LK+331MDBOJ2fVrIqBcpUTxGKynvUsTcqMZock3+gFYEANLZusnouULWb8djMQHRymtp X01g== X-Gm-Message-State: AJcUukcpMs64pZzhGYVqZIVRsrU5GKeahmfBSrgd6ffSrmfoRv0Um3kd FoI5Uxhe+Q1R0qU45B9Y3BMGPAlm X-Google-Smtp-Source: ALg8bN5f/DHgVsU1AEaDMRePJpHtSHW7/OYB07eaHkbLXyqSaYztdK9qY5S9UzRcw2ui+gcax+9Nuw== X-Received: by 2002:a50:84a9:: with SMTP id 38mr46158140edq.185.1549194053369; Sun, 03 Feb 2019 03:40:53 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40eb:400:8844:a4ab:977c:31c3]) by smtp.gmail.com with ESMTPSA id k12sm2065810eja.60.2019.02.03.03.40.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 03:40:52 -0800 (PST) From: Luc Van Oostenryck To: Ramsay Jones Cc: linux-sparse@vger.kernel.org, Luc Van Oostenryck Subject: [PATCH v2] predefs: add arch-specific predefines Date: Sun, 3 Feb 2019 12:40:44 +0100 Message-Id: <20190203114044.50297-1-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.20.0 In-Reply-To: <45f521a1-46f5-78cf-f960-a028ab514c71@ramsayjones.plus.com> References: <45f521a1-46f5-78cf-f960-a028ab514c71@ramsayjones.plus.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Predefined macros like '__x86_64__', '__arm__', ... are used in systems headers (and surely at other places too). So, add them for all archs known to sparse (and remove the corresponding parts in cgcc, they are now redundant). Note: these are only tested on i386, x86-64, arm, arm64, mips64 (ABI O32), ppc, ppc64 (power7), ppc64el (power8) and sparc64, most of then on a not-so-new OS version. Signed-off-by: Luc Van Oostenryck --- Change since v1: -) add __PPC__, __PPC64__, __sparsev9__, __sparc64__ & __s390__ which were defined in cgcc but not sparse itself. -) remove redundant defs in cgcc cgcc | 18 +++++++--------- lib.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 17 deletions(-) diff --git a/cgcc b/cgcc index f3909ae89..a99a3a1c3 100755 --- a/cgcc +++ b/cgcc @@ -287,16 +287,16 @@ sub add_specs { " -D'__fastcall=__attribute__((__fastcall__))'" . " -D'__declspec(x)=__attribute__((x))'"; } elsif ($spec eq 'i386') { - return (' -D__i386=1 -D__i386__=1' . + return ( &float_types (1, 1, 21, [24,8], [53,11], [64,15])); } elsif ($spec eq 'sparc') { - return (' -D__sparc=1 -D__sparc__=1' . + return ( &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) . &float_types (1, 1, 33, [24,8], [53,11], [113,15]) . &define_size_t ($m64 ? "long unsigned int" : "unsigned int") . ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4')); } elsif ($spec eq 'sparc64') { - return (' -D__sparc=1 -D__sparc__=1 -D__sparcv9__=1 -D__sparc64__=1 -D__arch64__=1 -D__LP64__=1' . + return ( &integer_types (8, 16, 32, 64, 64, 128) . &float_types (1, 1, 33, [24,8], [53,11], [113,15]) . &define_size_t ("long unsigned int") . @@ -304,25 +304,23 @@ sub add_specs { } elsif ($spec eq 'x86_64') { return &float_types (1, 1, 33, [24,8], [53,11], [113,15]); } elsif ($spec eq 'ppc') { - return (' -D__powerpc__=1 -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' . + return (' -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' . &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) . &float_types (1, 1, 21, [24,8], [53,11], [113,15]) . &define_size_t ($m64 ? "long unsigned int" : "unsigned int") . ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4')); } elsif ($spec eq 'ppc64') { - return (' -D__powerpc__=1 -D__PPC__=1 -D_STRING_ARCH_unaligned=1' . - ' -D__powerpc64__=1 -D__PPC64__=1' . - ' -m64' . + return (' -D_STRING_ARCH_unaligned=1 -m64' . &float_types (1, 1, 21, [24,8], [53,11], [113,15])); } elsif ($spec eq 's390x') { - return (' -D__s390x__ -D__s390__ -D_BIG_ENDIAN' . + return (' -D_BIG_ENDIAN' . &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) . &float_types (1, 1, 36, [24,8], [53,11], [113,15]) . &define_size_t ("long unsigned int") . ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4')); } elsif ($spec eq 'arm') { chomp (my $gccmachine = `$cc -dumpmachine`); - my $cppsymbols = ' -D__arm__=1 -m32'; + my $cppsymbols = ' -m32'; if ($gccmachine eq 'arm-linux-gnueabihf') { $cppsymbols .= ' -D__ARM_PCS_VFP=1'; @@ -331,7 +329,7 @@ sub add_specs { return ($cppsymbols . &float_types (1, 1, 36, [24,8], [53,11], [53, 11])); } elsif ($spec eq 'aarch64') { - return (' -D__aarch64__=1 -m64' . + return (' -m64' . &float_types (1, 1, 36, [24,8], [53,11], [113,15])); } elsif ($spec eq 'host_os_specs') { my $os = `uname -s`; diff --git a/lib.c b/lib.c index 60fc33496..91d347109 100644 --- a/lib.c +++ b/lib.c @@ -1364,20 +1364,73 @@ static void predefined_macros(void) break; } - if (arch_m64 != ARCH_LP32) { -#if defined(__x86_64__) || defined(__x86_64) - predefine("__x86_64__", 1, "1"); - predefine("__x86_64", 1, "1"); -#endif - } - switch (arch_mach) { + case MACH_ARM64: + predefine("__aarch64__", 1, "1"); + break; + case MACH_ARM: + predefine("__arm__", 1, "1"); + break; + case MACH_M68K: + predefine("__m68k__", 1, "1"); + break; case MACH_MIPS64: + if (arch_m64 == ARCH_LP64) + predefine("__mips64", 1, "64"); + /* fall-through */ case MACH_MIPS32: + predefine("__mips", 1, "%d", ptr_ctype.bit_size); predefine("_MIPS_SZINT", 1, "%d", int_ctype.bit_size); predefine("_MIPS_SZLONG", 1, "%d", long_ctype.bit_size); predefine("_MIPS_SZPTR", 1, "%d", ptr_ctype.bit_size); break; + case MACH_PPC64: + if (arch_m64 == ARCH_LP64) { + predefine("__powerpc64__", 1, "1"); + predefine("__ppc64__", 1, "1"); + predefine("__PPC64__", 1, "1"); + } + /* fall-through */ + case MACH_PPC32: + predefine("__powerpc__", 1, "1"); + predefine("__powerpc", 1, "1"); + predefine("__ppc__", 1, "1"); + predefine("__PPC__", 1, "1"); + break; + case MACH_RISCV64: + case MACH_RISCV32: + predefine("__riscv", 1, "1"); + predefine("__riscv_xlen", 1, "%d", ptr_ctype.bit_size); + break; + case MACH_S390X: + predefine("__zarch__", 1, "1"); + predefine("__s390x__", 1, "1"); + predefine("__s390__", 1, "1"); + break; + case MACH_SPARC64: + if (arch_m64 == ARCH_LP64) { + predefine("__sparc_v9__", 1, "1"); + predefine("__sparcv9__", 1, "1"); + predefine("__sparcv9", 1, "1"); + predefine("__sparc64__", 1, "1"); + predefine("__arch64__", 1, "1"); + } + /* fall-through */ + case MACH_SPARC32: + predefine("__sparc__", 1, "1"); + predefine("__sparc", 1, "1"); + break; + case MACH_X86_64: + if (arch_m64 != ARCH_LP32) { + predefine("__x86_64__", 1, "1"); + predefine("__x86_64", 1, "1"); + break; + } + /* fall-through */ + case MACH_I386: + predefine("__i386__", 1, "1"); + predefine("__i386", 1, "1"); + break; } }