From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14375 invoked by alias); 26 Oct 2017 20:57:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 14365 invoked by uid 89); 26 Oct 2017 20:57:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS,URIBL_RED autolearn=ham version=3.3.2 spammy=mel, nios 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; Thu, 26 Oct 2017 20:57:21 +0000 Received: from svr-orw-mbx-03.mgc.mentorg.com ([147.34.90.203]) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1e7pDK-0002sp-Uu from Sandra_Loosemore@mentor.com for gcc-patches@gcc.gnu.org; Thu, 26 Oct 2017 13:57:18 -0700 Received: from [127.0.0.1] (147.34.91.1) by svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Thu, 26 Oct 2017 13:57:16 -0700 To: "gcc-patches@gcc.gnu.org" From: Sandra Loosemore Subject: [patch, nios2] add -mgprel-sec= option Message-ID: <59F24C2A.10502@codesourcery.com> Date: Thu, 26 Oct 2017 21:04:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020403060906020109070908" X-ClientProxiedBy: SVR-ORW-MBX-06.mgc.mentorg.com (147.34.90.206) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-SW-Source: 2017-10/txt/msg02008.txt.bz2 --------------020403060906020109070908 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 299 I've committed this patch, which allows users to specify additional data sections (beyond the normal small-data sections) where GP-relative addressing can be used. It's intended for use on bare-metal nios2-elf targets in conjunction with section attributes and a custom linker script. -Sandra --------------020403060906020109070908 Content-Type: text/x-log; name="gcc-mgprel.log" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-mgprel.log" Content-length: 489 2017-10-26 Sandra Loosemore gcc/ * config/nios2/nios2.c: Include xregex.h. (nios2_gprel_sec_regex): New. (nios2_option_overide): Initialize it. Don't allow GP-relative addressing with PIC. (nios2_small_section_name_p): Check for regex match. * config/nios2/nios2.opt (mgprel-sec=): New option. * doc/invoke.texi (Option Summary): Add -mgprel-sec. (Nios II Options): Document -mgprel-sec. gcc/testsuite/ * gcc.target/nios2/gpopt-gprel-sec.c: New. --------------020403060906020109070908 Content-Type: text/x-patch; name="gcc-mgprel.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-mgprel.patch" Content-length: 5158 diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c index f5963d4..3aade7b 100644 --- a/gcc/config/nios2/nios2.c +++ b/gcc/config/nios2/nios2.c @@ -49,6 +49,7 @@ #include "stor-layout.h" #include "builtins.h" #include "tree-pass.h" +#include "xregex.h" /* This file should be included last. */ #include "target-def.h" @@ -103,6 +104,9 @@ static int custom_code_index[256]; /* Set to true if any conflicts (re-use of a code between 0-255) are found. */ static bool custom_code_conflict = false; +/* State for command-line options. */ +regex_t nios2_gprel_sec_regex; + /* Definition of builtin function types for nios2. */ @@ -1371,6 +1375,23 @@ nios2_option_override (void) nios2_gpopt_option = gpopt_local; } + /* GP-relative addressing doesn't make sense for PIC. */ + if (flag_pic) + { + if (nios2_gpopt_option != gpopt_none) + error ("-mgpopt not supported with PIC."); + if (nios2_gprel_sec) + error ("-mgprel-sec= not supported with PIC."); + } + + /* Process -mgprel-sec=. */ + if (nios2_gprel_sec) + { + if (regcomp (&nios2_gprel_sec_regex, nios2_gprel_sec, + REG_EXTENDED | REG_NOSUB)) + error ("-mgprel-sec= argument is not a valid regular expression."); + } + /* If we don't have mul, we don't have mulx either! */ if (!TARGET_HAS_MUL && TARGET_HAS_MULX) target_flags &= ~MASK_HAS_MULX; @@ -2268,7 +2289,9 @@ nios2_small_section_name_p (const char *section) return (strcmp (section, ".sbss") == 0 || strncmp (section, ".sbss.", 6) == 0 || strcmp (section, ".sdata") == 0 - || strncmp (section, ".sdata.", 7) == 0); + || strncmp (section, ".sdata.", 7) == 0 + || (nios2_gprel_sec + && regexec (&nios2_gprel_sec_regex, section, 0, NULL, 0) == 0)); } /* Return true if EXP should be placed in the small data section. */ diff --git a/gcc/config/nios2/nios2.opt b/gcc/config/nios2/nios2.opt index 08cb935..d08405e 100644 --- a/gcc/config/nios2/nios2.opt +++ b/gcc/config/nios2/nios2.opt @@ -586,3 +586,7 @@ Enable generation of R2 BMX instructions. mcdx Target Report Mask(HAS_CDX) Enable generation of R2 CDX instructions. + +mgprel-sec= +Target RejectNegative Joined Var(nios2_gprel_sec) Init(NULL) +Regular expression matching additional GP-addressible small-data section names. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 3a87956..0dafdb6 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -948,6 +948,7 @@ Objective-C and Objective-C++ Dialects}. @emph{Nios II Options} @gccoptlist{-G @var{num} -mgpopt=@var{option} -mgpopt -mno-gpopt @gol +-mgprel-sec=@var{regexp} @gol -mel -meb @gol -mno-bypass-cache -mbypass-cache @gol -mno-cache-volatile -mcache-volatile @gol @@ -21165,6 +21166,18 @@ GOT data sections. In this case, the 16-bit offset for GP-relative addressing may not be large enough to allow access to the entire small data section. +@item -mgprel-sec=@var{regexp} +@opindex mgprel-sec +This option specifies additional section names that can be accessed via +GP-relative addressing. It is most useful in conjunction with +@code{section} attributes on variable declarations +(@pxref{Common Variable Attributes}) and a custom linker script. +The @var{regexp} is a POSIX Extended Regular Expression. + +This option does not affect the behavior of the @option{-G} option, and +and the specified sections are in addition to the standard @code{.sdata} +and @code{.sbss} small-data sections that are recognized by @option{-mgpopt}. + @item -mel @itemx -meb @opindex mel diff --git a/gcc/testsuite/gcc.target/nios2/gpopt-gprel-sec.c b/gcc/testsuite/gcc.target/nios2/gpopt-gprel-sec.c new file mode 100644 index 0000000..1083fe6 --- /dev/null +++ b/gcc/testsuite/gcc.target/nios2/gpopt-gprel-sec.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O -mgpopt=local -mgprel-sec=\\.frog.+" } */ + +extern int a __attribute__ ((section (".frog1"))); +static volatile int b __attribute__ ((section (".frog2"))) = 1; +extern int c __attribute__ ((section (".data"))); +static volatile int d __attribute__ ((section (".data"))) = 2; + +extern int e; +static volatile int f = 3; + +volatile int g __attribute__ ((weak)) = 4; + +extern int h[100]; +static int i[100]; +static int j[100] __attribute__ ((section (".sdata"))); + +typedef int (*ftype) (int); +extern int foo (int); + +extern int bar (int, int*, int*, int*, ftype); + +int baz (void) +{ + return bar (a + b + c + d + e + f + g, h, i, j, foo); +} + +/* { dg-final { scan-assembler "%gprel\\(a\\)" } } */ +/* { dg-final { scan-assembler "%gprel\\(b\\)" } } */ +/* { dg-final { scan-assembler-not "%gprel\\(c\\)" } } */ +/* { dg-final { scan-assembler-not "%gprel\\(d\\)" } } */ +/* { dg-final { scan-assembler-not "%gprel\\(e\\)" } } */ +/* { dg-final { scan-assembler "%gprel\\(f\\)" } } */ +/* { dg-final { scan-assembler-not "%gprel\\(g\\)" } } */ +/* { dg-final { scan-assembler-not "%gprel\\(h\\)" } } */ +/* { dg-final { scan-assembler-not "%gprel\\(i\\)" } } */ +/* { dg-final { scan-assembler "%gprel\\(j\\)" } } */ +/* { dg-final { scan-assembler-not "%gprel\\(foo\\)" } } */ --------------020403060906020109070908--