From patchwork Tue Jul 18 21:59:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Roskin X-Patchwork-Id: 9849825 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 2AF18602C8 for ; Tue, 18 Jul 2017 21:59:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13133285FD for ; Tue, 18 Jul 2017 21:59:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0668D28600; Tue, 18 Jul 2017 21:59:51 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 72259285FF for ; Tue, 18 Jul 2017 21:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752849AbdGRV7s (ORCPT ); Tue, 18 Jul 2017 17:59:48 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:35724 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752762AbdGRV7q (ORCPT ); Tue, 18 Jul 2017 17:59:46 -0400 Received: by mail-oi0-f67.google.com with SMTP id h143so2084186oic.2 for ; Tue, 18 Jul 2017 14:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=kPLatA/C6qwL70F8A/7p6/YHtwJP2iFoc7mfJ7NkGTs=; b=f0bPrak6kedLbWYL1Aps+f7n4k2OV7Re5cYKglg0viSGX8YKfbojOulXWUMnRP1VIu zp1wuNQvZqwLwoDHluWWWs96jw5q1p1mZaS+A4RytV3FfN/c7SGITb4TzpaGmGODdn2W fi+hD3QA1Q/hEFW+wme6IFcNvkFm7tBGRFpuyw01Y0HtsKigAYIlWVUPvd2o28t+UxW7 q+BgJzmy6t9q7of2UoiTE3qo1LU0B4QZKTLbkO31jhHtknnQDnJ4FxlQhvoA8wkAZrEH +xjbAfqAXnKid22KGO7fSEmCw/nac7tdixuJzUrtEl0sp6sc4g4azqNaZEOnzyZE0NHi HaNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=kPLatA/C6qwL70F8A/7p6/YHtwJP2iFoc7mfJ7NkGTs=; b=P1F3Z/mWkPnIPzKRA3/uErmlT1HcSc5iVQ8USzbqk6EUVoR/UOI9coqjQtyxrNRe0S oBgzE7t/KWMBcgRXVhztulH0Y8IheItlDMdnMAtbyq5IAfkC9xc+hv7HsabAbpGAoT6m AA7+OIeAk3Yg3A2Hjidz3mshp7KQGOyzlQqjvEOELgBRGQBc60CVPm7ZyGIvm93uLWss YsbZyqhp/0FPCrW9JCJ4GTvN3CDjetLfJIK1fmtbU0qkWmur+Lj10Ddm7Ixw1sxNNLav g/FizvrZCstcsXTTxpD4yXi/6x31ims1Ub23Ed5DQy611k7ncBuRAMniuqsiSx7W4sR+ XMEw== X-Gm-Message-State: AIVw112SETILqN4pKXiVpawUkBi+RhainNa4t2nNK5IGmvrS2XjzyRXM IXoNI3p0iV6vrS1EgqWB7+1H77HLUbyd7B4= X-Received: by 10.202.88.134 with SMTP id m128mr2309798oib.183.1500415185689; Tue, 18 Jul 2017 14:59:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.76.214 with HTTP; Tue, 18 Jul 2017 14:59:45 -0700 (PDT) From: Pavel Roskin Date: Tue, 18 Jul 2017 14:59:45 -0700 Message-ID: Subject: [PATCH] Add -gcc-version option To: linux-sparse@vger.kernel.org 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 The option argument is parsed into major, minor and patchlevel versions, which are defined as __GNUC__, __GNUC_MINOR__, and __GNUC_PATCHLEVEL__ in the preprocessor. One possible use is running sparse compiled with the lastest gcc compiler on a Linux kernel that doesn't support that compiler. Signed-off-by: Pavel Roskin --- lib.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ sparse.1 | 7 +++++++ 2 files changed, 52 insertions(+) .B \-fdump-linearize[=only] diff --git a/lib.c b/lib.c index ce66a81..aff6862 100644 --- a/lib.c +++ b/lib.c @@ -24,6 +24,7 @@ */ #include #include +#include #include #include #include @@ -831,10 +832,54 @@ static char **handle_base_dir(char *arg, char **next) return next; } +static char **handle_gcc_version(char *arg, char **next) +{ + unsigned long gcc_major_ul, gcc_minor_ul = 0, gcc_patchlevel_ul = 0; + char *gcc_version, *p; + + gcc_version = *++next; + if (!gcc_version) + die("missing argument for -gcc-version option"); + + gcc_major_ul = strtoul(gcc_version, &p, 10); + if (gcc_major_ul > INT_MAX) + die("bad gcc major version"); + + if (*p == '\0') + goto good; + else if (*p != '.') + die("bad character after gcc major version"); + + gcc_minor_ul = strtoul(p + 1, &p, 10); + if (gcc_minor_ul > INT_MAX) + die("bad gcc minor version"); + + if (*p == '\0') + goto good; + else if (*p != '.') + die("bad character after gcc minor version"); + + gcc_patchlevel_ul = strtoul(p + 1, &p, 10); + if (gcc_patchlevel_ul > INT_MAX) + die("bad gcc patchlevel version"); + + if (*p != '\0') + die("bad character after gcc patchlevel version"); + +good: + gcc_major = gcc_major_ul; + gcc_minor = gcc_minor_ul; + gcc_patchlevel = gcc_patchlevel_ul; + + return next; +} + static char **handle_switch_g(char *arg, char **next) { if (!strcmp (arg, "gcc-base-dir")) return handle_base_dir(arg, next); + else if (!strcmp (arg, "gcc-version")) + return handle_gcc_version(arg, next); return next; } diff --git a/sparse.1 b/sparse.1 index b79c587..9f2c52d 100644 --- a/sparse.1 +++ b/sparse.1 @@ -355,6 +355,13 @@ Look for system headers in the multiarch subdirectory \fIdir\fR. The \fIdir\fR name would normally take the form of the target's normalized GNU triplet. (e.g. i386-linux-gnu). . +.TP +.B \-gcc-version \fIversion\fR +Simulate behavior of gcc of the specified version. At this time, this +switch only affects macros \fI__GNUC__\fR, \fI__GNUC_MINOR__\fR, and +\fI__GNUC_PATCHLEVEL__\fR. The default value is the version of gcc that +compiled sparse, or \fI2.95.0\fR if that information is missing. +. .SH DEBUG OPTIONS .TP