From patchwork Mon Aug 4 18:39:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 4673111 Return-Path: X-Original-To: patchwork-linux-sparse@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 3C1C0C0338 for ; Mon, 4 Aug 2014 18:45:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 43B7B2013D for ; Mon, 4 Aug 2014 18:45:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1735520136 for ; Mon, 4 Aug 2014 18:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751232AbaHDSpS (ORCPT ); Mon, 4 Aug 2014 14:45:18 -0400 Received: from mdfmta010.mxout.tch.inty.net ([91.221.169.51]:52765 "EHLO smtp.demon.co.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751046AbaHDSpR (ORCPT ); Mon, 4 Aug 2014 14:45:17 -0400 X-Greylist: delayed 363 seconds by postgrey-1.27 at vger.kernel.org; Mon, 04 Aug 2014 14:45:17 EDT Received: from mdfmta010.tch.inty.net (unknown [127.0.0.1]) by mdfmta010.tch.inty.net (Postfix) with ESMTP id EC91E400AF8; Mon, 4 Aug 2014 19:39:10 +0100 (BST) Received: from mdfmta010.tch.inty.net (unknown [127.0.0.1]) by mdfmta010.tch.inty.net (Postfix) with ESMTP id A2CF8400AF1; Mon, 4 Aug 2014 19:39:10 +0100 (BST) Received: from [192.168.254.10] (unknown [80.176.147.220]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mdfmta010.tch.inty.net (Postfix) with ESMTP; Mon, 4 Aug 2014 19:39:10 +0100 (BST) Message-ID: <53DFD350.6080701@ramsay1.demon.co.uk> Date: Mon, 04 Aug 2014 19:39:12 +0100 From: Ramsay Jones User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Christopher Li CC: Sparse Mailing-list Subject: [PATCH 07/10] Add support for multiarch system header files X-MDF-HostID: 19 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Signed-off-by: Ramsay Jones --- Makefile | 3 +++ cgcc | 10 ++++++++++ lib.c | 18 +++++++++++++++++- sparse.1 | 6 ++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1795905..36061e3 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,9 @@ HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes') GCC_BASE = $(shell $(CC) --print-file-name=) BASIC_CFLAGS = -DGCC_BASE=\"$(GCC_BASE)\" +MULTIARCH_TRIPLET = $(shell $(CC) -print-multiarch 2>/dev/null) +BASIC_CFLAGS += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\" + ifeq ($(HAVE_GCC_DEP),yes) BASIC_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d endif diff --git a/cgcc b/cgcc index c075e5f..ed35e39 100755 --- a/cgcc +++ b/cgcc @@ -11,6 +11,7 @@ my $gendeps = 0; my $do_check = 0; my $do_compile = 1; my $gcc_base_dir; +my $multiarch_dir; my $verbose = 0; while (@ARGV) { @@ -44,6 +45,12 @@ while (@ARGV) { next; } + if (/^-multiarch-dir$/) { + $multiarch_dir = shift @ARGV; + die ("$0: missing argument for -multiarch-dir option") if !$multiarch_dir; + next; + } + # If someone adds "-E", don't pre-process twice. $do_compile = 0 if $_ eq '-E'; @@ -66,8 +73,11 @@ if ($do_check) { } $gcc_base_dir = qx($cc -print-file-name=) if !$gcc_base_dir; + chomp($gcc_base_dir); # possibly remove '\n' from compiler $check .= " -gcc-base-dir " . $gcc_base_dir if $gcc_base_dir; + $check .= " -multiarch-dir " . $multiarch_dir if $multiarch_dir; + print "$check\n" if $verbose; if ($do_compile) { system ($check); diff --git a/lib.c b/lib.c index 9c7767e..0b62dcb 100644 --- a/lib.c +++ b/lib.c @@ -59,6 +59,7 @@ int gcc_minor = __GNUC_MINOR__; int gcc_patchlevel = __GNUC_PATCHLEVEL__; static const char *gcc_base_dir = GCC_BASE; +static const char *multiarch_dir = MULTIARCH_TRIPLET; struct token *skip_to(struct token *token, int op) { @@ -363,6 +364,14 @@ static char **handle_switch_M(char *arg, char **next) return next; } +static char **handle_multiarch_dir(char *arg, char **next) +{ + multiarch_dir = *++next; + if (!multiarch_dir) + die("missing argument for -multiarch-dir option"); + return next; +} + static char **handle_switch_m(char *arg, char **next) { if (!strcmp(arg, "m64")) { @@ -371,7 +380,8 @@ static char **handle_switch_m(char *arg, char **next) arch_m64 = 0; } else if (!strcmp(arg, "msize-long")) { arch_msize_long = 1; - } + } else if (!strcmp(arg, "multiarch-dir")) + return handle_multiarch_dir(arg, next); return next; } @@ -881,6 +891,12 @@ void create_builtin_stream(void) add_pre_buffer("#weak_define __GNUC_MINOR__ %d\n", gcc_minor); add_pre_buffer("#weak_define __GNUC_PATCHLEVEL__ %d\n", gcc_patchlevel); + /* add the multiarch include directories, if any */ + if (multiarch_dir && *multiarch_dir) { + add_pre_buffer("#add_system \"/usr/include/%s\"\n", multiarch_dir); + add_pre_buffer("#add_system \"/usr/local/include/%s\"\n", multiarch_dir); + } + /* We add compiler headers path here because we have to parse * the arguments to get it, falling back to default. */ add_pre_buffer("#add_system \"%s/include\"\n", gcc_base_dir); diff --git a/sparse.1 b/sparse.1 index 54da09b..a305a21 100644 --- a/sparse.1 +++ b/sparse.1 @@ -335,6 +335,12 @@ Sparse does not issue these warnings by default. .B \-gcc-base-dir \fIdir\fR Look for compiler-provided system headers in \fIdir\fR/include/ and \fIdir\fR/include-fixed/. . +.TP +.B \-multiarch-dir \fIdir\fR +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). +. .SH OTHER OPTIONS .TP .B \-ftabstop=WIDTH