From patchwork Wed Feb 18 08:25:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 440831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D834314009B for ; Wed, 18 Feb 2015 19:26:15 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; q=dns; s=default; b=WMcwUgVZjk7XVa0h bldf91cL4JQ1KJKsdmP7ek/TQcLbH2vSKxRsYTlwJlopJ4Qo16pmBYfWCU8CMwDO RnrhBVK1L+2vQng0Z4f7S5oHhvKRfmcbH7Ux1Obv1LfHR9zSF0mJ8l/NJWJcEl5W 2X04jLRhvWQwtd7n/yYjKyZ8iUk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=default; bh=BCyDPeTpEGxMG/fam6pxGA J+Q/4=; b=IalhyKF2lllrkUBqYL1pqS41nHGKV3QUdcviG6z8bwyMic0qVKpgvl kPkbbqAP4mUCG/PozPLlchZkpW86kE220ccSCJxRMIAQBIzH6n9a9aivZvprHf+l yRRbhrWdye+WG4LDYnnYYITSEozTWG+45cpMpVjT15tYexlTLV/yE= Received: (qmail 9448 invoked by alias); 18 Feb 2015 08:26:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9435 invoked by uid 89); 18 Feb 2015 08:26:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Feb 2015 08:26:06 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1YNzxK-0003KL-7T from Thomas_Schwinge@mentor.com ; Wed, 18 Feb 2015 00:26:02 -0800 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Wed, 18 Feb 2015 08:26:01 +0000 From: Thomas Schwinge To: GCC Patches CC: Bernd Schmidt , , Subject: nvptx mkoffload: For non-installed testing, look in all COMPILER_PATHs for GCC_INSTALL_NAME (was: nvptx offloading patches [4/n]) In-Reply-To: <5454CDF1.3070307@codesourcery.com> References: <5454CDF1.3070307@codesourcery.com> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/24.4.1 (i586-pc-linux-gnu) Date: Wed, 18 Feb 2015 09:25:57 +0100 Message-ID: <87fva3fwx6.fsf@kepler.schwinge.homeip.net> MIME-Version: 1.0 Hi! On Sat, 1 Nov 2014 13:11:29 +0100, Bernd Schmidt wrote: > [nvptx mkoffload] To support the --enable-offload-targets=nvptx-none=[install directory] configuration option, I committed the following to trunk in r220782 (and filed ): commit a7243b5200794d53b01d59fa69d467a0545db73f Author: tschwinge Date: Wed Feb 18 08:17:32 2015 +0000 nvptx mkoffload: For non-installed testing, look in all COMPILER_PATHs for GCC_INSTALL_NAME. gcc/ * config/nvptx/mkoffload.c (parse_env_var, free_array_of_ptrs) (access_check): New functions, copied from config/i386/intelmic-mkoffload.c. (main): For non-installed testing, look in all COMPILER_PATHs for GCC_INSTALL_NAME. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220782 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 +++ gcc/config/nvptx/mkoffload.c | 103 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) Grüße, Thomas diff --git gcc/ChangeLog gcc/ChangeLog index 180a605..0f144f5 100644 --- gcc/ChangeLog +++ gcc/ChangeLog @@ -1,5 +1,11 @@ 2015-02-18 Thomas Schwinge + * config/nvptx/mkoffload.c (parse_env_var, free_array_of_ptrs) + (access_check): New functions, copied from + config/i386/intelmic-mkoffload.c. + (main): For non-installed testing, look in all COMPILER_PATHs for + GCC_INSTALL_NAME. + * config/nvptx/nvptx.h (GOMP_SELF_SPECS): Define macro. 2015-02-18 Andrew Pinski diff --git gcc/config/nvptx/mkoffload.c gcc/config/nvptx/mkoffload.c index 96341b8..02c44b6 100644 --- gcc/config/nvptx/mkoffload.c +++ gcc/config/nvptx/mkoffload.c @@ -762,6 +762,78 @@ parse_file (Token *tok) return tok; } +/* Parse STR, saving found tokens into PVALUES and return their number. + Tokens are assumed to be delimited by ':'. */ +static unsigned +parse_env_var (const char *str, char ***pvalues) +{ + const char *curval, *nextval; + char **values; + unsigned num = 1, i; + + curval = strchr (str, ':'); + while (curval) + { + num++; + curval = strchr (curval + 1, ':'); + } + + values = (char **) xmalloc (num * sizeof (char *)); + curval = str; + nextval = strchr (curval, ':'); + if (nextval == NULL) + nextval = strchr (curval, '\0'); + + for (i = 0; i < num; i++) + { + int l = nextval - curval; + values[i] = (char *) xmalloc (l + 1); + memcpy (values[i], curval, l); + values[i][l] = 0; + curval = nextval + 1; + nextval = strchr (curval, ':'); + if (nextval == NULL) + nextval = strchr (curval, '\0'); + } + *pvalues = values; + return num; +} + +/* Auxiliary function that frees elements of PTR and PTR itself. + N is number of elements to be freed. If PTR is NULL, nothing is freed. + If an element is NULL, subsequent elements are not freed. */ +static void +free_array_of_ptrs (void **ptr, unsigned n) +{ + unsigned i; + if (!ptr) + return; + for (i = 0; i < n; i++) + { + if (!ptr[i]) + break; + free (ptr[i]); + } + free (ptr); + return; +} + +/* Check whether NAME can be accessed in MODE. This is like access, + except that it never considers directories to be executable. */ +static int +access_check (const char *name, int mode) +{ + if (mode == X_OK) + { + struct stat st; + + if (stat (name, &st) < 0 || S_ISDIR (st.st_mode)) + return -1; + } + + return access (name, mode); +} + static void process (FILE *in, FILE *out) { @@ -853,6 +925,37 @@ main (int argc, char **argv) driver_used = sprintf (driver, "%s/", gcc_path); sprintf (driver + driver_used, "%s", GCC_INSTALL_NAME); + bool found = false; + if (gcc_path == NULL) + found = true; + else if (access_check (driver, X_OK) == 0) + found = true; + else + { + /* Don't use alloca pointer with XRESIZEVEC. */ + driver = NULL; + /* Look in all COMPILER_PATHs for GCC_INSTALL_NAME. */ + char **paths = NULL; + unsigned n_paths; + n_paths = parse_env_var (getenv ("COMPILER_PATH"), &paths); + for (unsigned i = 0; i < n_paths; i++) + { + len = strlen (paths[i]) + 1 + strlen (GCC_INSTALL_NAME) + 1; + driver = XRESIZEVEC (char, driver, len); + sprintf (driver, "%s/%s", paths[i], GCC_INSTALL_NAME); + if (access_check (driver, X_OK) == 0) + { + found = true; + break; + } + } + free_array_of_ptrs ((void **) paths, n_paths); + } + + if (!found) + fatal_error (input_location, + "offload compiler %s not found", GCC_INSTALL_NAME); + /* We may be called with all the arguments stored in some file and passed with @file. Expand them into argv before processing. */ expandargv (&argc, &argv);