From patchwork Fri Jun 9 12:53:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 103478 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp193713qgd; Fri, 9 Jun 2017 05:55:20 -0700 (PDT) X-Received: by 10.101.85.69 with SMTP id t5mr42991315pgr.201.1497012920076; Fri, 09 Jun 2017 05:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497012920; cv=none; d=google.com; s=arc-20160816; b=nq4kL1XlruAiqX33gopc1ju3jd1OgidTjMxXrtLukMtihAtE3E5sGVBYEqlo4CxcBL ctjVFTNPEToZHw9LAnIToJFMGLIRiTwhhGhVZY6QtFNU8XynqM4Sx6u5sKf0Y9ZUrHUh AH0sZjGXNT43VKrFRQ3wcHX/RQcfYeZl9M2tpLVddR9PvQ6y3B3PpwuJuSVvamw4QhCx S+H3AaVBcsUutKWM/suFf2qgrshsFQXAoNQ9qgx/CrPf9HgOC96hgT4LOXEs8r7OQpus /yZ1C/ldpRSwU2LUD+0g+3EuiYLxeTT7VPka8WygzdeWsBr2JZdiaR0ZjUcZSbhl4sLr Bvog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=ddaVeDf3xY+goEOCT2CUQ9LbyPD02uxr3Ncpgvfyhso=; b=W0bkUhPydMCZCIc0pDVKKdYdF9QtasplXWgepSUDQHIQYnZ2/imclNlYUJjfW3WeM+ iWhG/aswLTPvAH7hDt/U39h/PLPV9OAuIeES0+2CXCZavfbcVnGSCo82NqVbjsSfIlEV VCAqt8IdZjq9ajnkiY7Uk8ClqqEl6feSIcM4XJ8AWS95wKzD50bHHXrtJR3XszNZpa6Y gOcjtgnVqJSXUwupXGEBJWFlRiYTCjPjkOXAk7bygQykO5MuvRMZShBQZO6k9ZXnQGgs fwHezJErbWUpfIseUhwGUPT4TPem/CnLn2rENKcN7YOve6PhQGmZq2qI4m5J/44ql6Wt 7Nfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-455522-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-455522-patch=linaro.org@gcc.gnu.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b80si927787pfb.79.2017.06.09.05.55.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Jun 2017 05:55:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-455522-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-455522-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-455522-patch=linaro.org@gcc.gnu.org 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:date:message-id:in-reply-to:references :in-reply-to:references:mime-version:content-type; q=dns; s= default; b=sZqyHx+rucNonHkuy6rvBEYXfZMIT+ociWn8PbeoMzzHIOZntT2Mb O7T711aQuVBiVgQUCpvYOX6jMTlIpzkROBoB8eHpY7IgUWJpIkOIiB7OhrbkUthp +Dwmb6kmt4SNqleCSBfz9VlqdpL2H7ie0wN49M+Pmmyh4QAU4gYCAs= 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:date:message-id:in-reply-to:references :in-reply-to:references:mime-version:content-type; s=default; bh=RBTCXxTWTjJQx3Ej2Q2ryq5Dlc8=; b=RA0XwThKKPT/G2fgv/OPwaQtMF9z Y7CObaX9d52EupL7nlpzJiupzNYKpijCvE5K+B5xns9RCAY0VtQSxq9yP8tbmdAp 3PqcD9zQEieL3dT3/1QL3xrHeOnJnilOE7doqbaFwnMbQKNcG2RmsnTMUT9i+KTF cOA3mVCWgZpGIIM= Received: (qmail 76266 invoked by alias); 9 Jun 2017 12:54:10 -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 72659 invoked by uid 89); 9 Jun 2017 12:54:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=opportunity X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Jun 2017 12:54:06 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8E69F15BF; Fri, 9 Jun 2017 05:54:09 -0700 (PDT) Received: from e105689-lin.cambridge.arm.com (e105689-lin.cambridge.arm.com [10.2.207.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A4853F3E1; Fri, 9 Jun 2017 05:54:08 -0700 (PDT) From: Richard Earnshaw To: gcc-patches@gcc.gnu.org Cc: Richard Earnshaw Subject: [PATCH 02/30] [arm] Rewrite -march and -mcpu options for passing to the assembler Date: Fri, 9 Jun 2017 13:53:31 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 The assembler does not understand all the '+' options accepted by the compiler. The best solution to this is to simply strip the extensions and just pass the raw architecture or cpu name through to the assembler. We will use .arch and .arch_extension directives anyway to turn on or off individual features. We already do something similar for big.little combinations and this just extends this principle a bit further. This patch also fixes a possible bug by ensuring that the limited string copy is correctly NUL-terminated. While messing with this code I've also taken the opportunity to clean up the duplicate definitions of EXTRA_SPEC_FUNCTIONS by moving it outside of the ifdef wrapper. * config/arm/arm.h (BIG_LITTLE_SPEC): Delete macro. (ASM_REWRITE_SPEC_FUNCTIONS): New macro. (BIG_LITTLE_CPU_SPEC_FUNCTIONS): Delete macro. (ASM_CPU_SPEC): Rewrite. (MCPU_MTUNE_NATIVE_FUNCTIONS): New macro. (EXTRA_SPEC_FUNCTIONS): Move outside of ifdef. Use MCPU_MTUNE_NATIVE_FUNCTIONS and ASM_REWRITE_SPEC_FUNCTIONS. Remove reference to BIG_LITTLE_CPU_SPEC_FUNCTIONS. * common/config/arm/arm-common.c (arm_rewrite_selected_cpu): Ensure copied string is NUL-terminated. Also strip any characters prefixed by '+'. (arm_rewrite_selected_arch): New function. (arm_rewrite_march): New function. --- gcc/common/config/arm/arm-common.c | 45 +++++++++++++++++++++++++++++++++++++- gcc/config/arm/arm.h | 42 +++++++++++++++++------------------ 2 files changed, 65 insertions(+), 22 deletions(-) diff --git a/gcc/common/config/arm/arm-common.c b/gcc/common/config/arm/arm-common.c index 7ecc68d..fd0c616 100644 --- a/gcc/common/config/arm/arm-common.c +++ b/gcc/common/config/arm/arm-common.c @@ -66,7 +66,7 @@ arm_except_unwind_info (struct gcc_options *opts) #define ARM_CPU_NAME_LENGTH 20 -/* Truncate NAME at the first '.' character seen, or return +/* Truncate NAME at the first '.' or '+' character seen, or return NAME unmodified. */ const char * @@ -76,12 +76,20 @@ arm_rewrite_selected_cpu (const char *name) char *arg_pos; strncpy (output_buf, name, ARM_CPU_NAME_LENGTH); + output_buf[ARM_CPU_NAME_LENGTH] = 0; + arg_pos = strchr (output_buf, '.'); /* If we found a '.' truncate the entry at that point. */ if (arg_pos) *arg_pos = '\0'; + arg_pos = strchr (output_buf, '+'); + + /* If we found a '+' truncate the entry at that point. */ + if (arg_pos) + *arg_pos = '\0'; + return output_buf; } @@ -98,6 +106,41 @@ arm_rewrite_mcpu (int argc, const char **argv) return arm_rewrite_selected_cpu (argv[argc - 1]); } +/* Truncate NAME at the first '+' character seen, or return + NAME unmodified. Similar to arm_rewrite_selected_cpu, but we must + preserve '.' as that is part of some architecture names. */ + +const char * +arm_rewrite_selected_arch (const char *name) +{ + static char output_buf[ARM_CPU_NAME_LENGTH + 1] = {0}; + char *arg_pos; + + strncpy (output_buf, name, ARM_CPU_NAME_LENGTH); + output_buf[ARM_CPU_NAME_LENGTH] = 0; + + arg_pos = strchr (output_buf, '+'); + + /* If we found a '+' truncate the entry at that point. */ + if (arg_pos) + *arg_pos = '\0'; + + return output_buf; +} + +/* Called by the driver to rewrite a name passed to the -march + argument in preparation to be passed to the assembler. The + names passed from the command line will be in ARGV, we want + to use the right-most argument, which should be in + ARGV[ARGC - 1]. ARGC should always be greater than 0. */ + +const char * +arm_rewrite_march (int argc, const char **argv) +{ + gcc_assert (argc); + return arm_rewrite_selected_arch (argv[argc - 1]); +} + struct arm_arch_core_flag { const char *const name; diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index f9e4356..d398b99 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -2219,42 +2219,42 @@ extern int making_const_table; instruction. */ #define MAX_LDM_STM_OPS 4 -#define BIG_LITTLE_SPEC \ - " %{mcpu=*:-mcpu=%:rewrite_mcpu(%{mcpu=*:%*})}" - extern const char *arm_rewrite_mcpu (int argc, const char **argv); -#define BIG_LITTLE_CPU_SPEC_FUNCTIONS \ - { "rewrite_mcpu", arm_rewrite_mcpu }, +extern const char *arm_rewrite_march (int argc, const char **argv); +#define ASM_CPU_SPEC_FUNCTIONS \ + { "rewrite_mcpu", arm_rewrite_mcpu }, \ + { "rewrite_march", arm_rewrite_march }, -#define ASM_CPU_SPEC \ - " %{mcpu=generic-*:-march=%*;" \ - " :%{march=*:-march=%*}}" \ - BIG_LITTLE_SPEC +#define ASM_CPU_SPEC \ + " %{mcpu=generic-*:-march=%:rewrite_march(%{mcpu=generic-*:%*});" \ + " march=*:-march=%:rewrite_march(%{march=*:%*});" \ + " mcpu=*:-mcpu=%:rewrite_mcpu(%{mcpu=*:%*})" \ + " }" extern const char *arm_target_thumb_only (int argc, const char **argv); -#define TARGET_MODE_SPEC_FUNCTIONS \ +#define TARGET_MODE_SPEC_FUNCTIONS \ { "target_mode_check", arm_target_thumb_only }, /* -mcpu=native handling only makes sense with compiler running on an ARM chip. */ #if defined(__arm__) extern const char *host_detect_local_cpu (int argc, const char **argv); -# define EXTRA_SPEC_FUNCTIONS \ - { "local_cpu_detect", host_detect_local_cpu }, \ - BIG_LITTLE_CPU_SPEC_FUNCTIONS \ - TARGET_MODE_SPEC_FUNCTIONS - -# define MCPU_MTUNE_NATIVE_SPECS \ - " %{march=native:%