From patchwork Mon May 9 14:07:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 619924 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 3r3PNR4K5Kz9sBM for ; Tue, 10 May 2016 00:07:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=IK16dTjj; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=VCWMxlUsi17TWBjvE0eRHsIFx0MjFeFoVn1qPsFtp9ZDG9RoRp su7LKw0q87LU8cyoSTDT5D1T2hINVFn0FgOh4guXRZRTCUc4Oy6peecOG96h9sZl auOoQeLvCdzLtuQJfCYKw5OppUwqeBOuC6g/2Q+spZqBps6k5mYdetSr0= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=WtrIlQ+LugzBR/CZxfkHb/FbyxY=; b=IK16dTjjashSzXOhC5R6 snU4mpVH4g4yPvJHpkuxCgeOyX0WC2Usn9LN8C0sMsr1GSjVnyglNwnuRvH3nezs TYibWZEiIzXiVfOAVX0yic4yMdolf9AAhgA4hpTaMrfK/M4/dZDf+dN1K5S84zpV jf5QDngv0w28sz2s851xK+8= Received: (qmail 74967 invoked by alias); 9 May 2016 14:07:40 -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 74958 invoked by uid 89); 9 May 2016 14:07:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=singing, reserves, target_flags, flag_pic X-HELO: mail-qg0-f41.google.com Received: from mail-qg0-f41.google.com (HELO mail-qg0-f41.google.com) (209.85.192.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 09 May 2016 14:07:29 +0000 Received: by mail-qg0-f41.google.com with SMTP id f74so88897522qge.2 for ; Mon, 09 May 2016 07:07:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=T4QySAF4z9Hvcl/XMoeBIXk+Nh/s9Nfv+wGjAIU1lcA=; b=mLvfVGTpYuHSL7nZGqvWm5JlyDiktS79QDgYAPvHrkdsSetSxZ9DToMC+RkDQqZIQg uFs+Pfb5Cb0RjoTIHO/iWgHJN4jHV3jhJ0PSxdiWWvCBLxP6kQEiljwXSzGtZ9sWSXsd gRSG4SX+E3jCDGjxGnXRmjjq0FRRZmnAm+wh0sqmphiK6j89DNrtNs0LDbPCO0zyGj8F 1tEdr1eBX6ZaXOmTnQRFu+6yvcPu6F7AGwaMBTp6OuatReHE9guEJO1K9Ri/SVuvam4Z AXAO0mVaBbcDvKDOa4VUy9Vk/FNv7NA4lkizL9CbCcNQPbSuSQCN4PQJjyUIywMfjVDh wBmg== X-Gm-Message-State: AOPr4FUh+yIE17aVffJDEBuETuc/M9SXqlLM89wCc96R6mClwcZwHd7mqB5mIZGJtbGpLQ== X-Received: by 10.140.81.51 with SMTP id e48mr35068127qgd.3.1462802847368; Mon, 09 May 2016 07:07:27 -0700 (PDT) Received: from ?IPv6:2601:181:c003:1930:a2a8:cdff:fe3e:b48? ([2601:181:c003:1930:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id g184sm11918152qkb.7.2016.05.09.07.07.26 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 May 2016 07:07:26 -0700 (PDT) To: Richard Earnshaw , GCC Patches Cc: Joey Ye From: Nathan Sidwell Subject: [ARM] mno-pic-data-is-text-relative & msingle-pic-base Message-ID: Date: Mon, 9 May 2016 10:07:25 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 This patch comes from an off-list conversation between Joey & me. The context is with RTOSs not all singing & dancing dynamic objects and OSes. currently, the documentation for -mno-pic-data-is-text-relative (-mno-PDITR) says 'Assume that each data segments are relative to text segment at load time. Therefore, it permits addressing data using PC-relative operations. This option is on by default for targets other than VxWorks RTP.' However, if you use just this option, you still end up with a pic-register init sequence that presumes a fixed mapping. That's a surprise. Joey tells me its expected use is with -msingle-pic-base (-mSPB), which reserves a global register to point at the (single) GOT. That's what I had expected the -mno-PDITR option to have implied. Apparently there are legitimate reasons one might want the -mno-PDITR behaviour without -mSPB. I don't know what those are, perhaps Joey could clarify? Anyway, IMHO that is the rare case and the more common case is that one would want to have -mnoPDITR imply -mSPB. (The reverse probably doesn't apply.) This patch does 3 things. 1) have -mno-PDITR imply -mSPB, unless one has explictly provided -m[no-]SPB. 2) clarified the -m[no-]PDITR documentation. 3) Added some testcases -- there didn't appear to be any. ok? nathan 2016-05-09 Nathan Sidwell gcc/ * config/arm/arm.c (arm_option_override): Set MASK_SINGLE_PIC_BASE when -mno-pic-data-is-text-relative is in effect, by default. * doc/invoke.texi (mpic-data-is-text-relative): Document new behavior and clarify. gcc/testsuite/ * gcc.target/arm/data-rel-1.c: New. * gcc.target/arm/data-rel-2.c: New. * gcc.target/arm/data-rel-3.c: New. Index: config/arm/arm.c =================================================================== --- config/arm/arm.c (revision 235980) +++ config/arm/arm.c (working copy) @@ -3298,6 +3298,20 @@ arm_option_override (void) } } + if (TARGET_VXWORKS_RTP) + { + if (!global_options_set.x_arm_pic_data_is_text_relative) + arm_pic_data_is_text_relative = 0; + } + else if (flag_pic + && !arm_pic_data_is_text_relative + && !(global_options_set.x_target_flags & MASK_SINGLE_PIC_BASE)) + /* When text & data segments don't have a fixed displacement, the + intended use is with a single, read only, pic base register. + Unless the user explicitly requested not to do that, set + it. */ + target_flags |= MASK_SINGLE_PIC_BASE; + /* If stack checking is disabled, we can use r10 as the PIC register, which keeps r9 available. The EABI specifies r9 as the PIC register. */ if (flag_pic && TARGET_SINGLE_PIC_BASE) @@ -3329,10 +3343,6 @@ arm_option_override (void) arm_pic_register = pic_register; } - if (TARGET_VXWORKS_RTP - && !global_options_set.x_arm_pic_data_is_text_relative) - arm_pic_data_is_text_relative = 0; - /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */ if (fix_cm3_ldrd == 2) { Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 235980) +++ doc/invoke.texi (working copy) @@ -14197,9 +14197,12 @@ otherwise the default is @samp{R10}. @item -mpic-data-is-text-relative @opindex mpic-data-is-text-relative -Assume that each data segments are relative to text segment at load time. -Therefore, it permits addressing data using PC-relative operations. -This option is on by default for targets other than VxWorks RTP. +Assume that the displacement between the text and data segments is fixed +at static link time. This permits using PC-relative addressing +operations to access data known to be in the data segment. For +non-VxWorks RTP targets, this option is enabled by default. When +disabled on such targets, it will enable @option{-msingle-pic-base} by +default. @item -mpoke-function-name @opindex mpoke-function-name Index: testsuite/gcc.target/arm/data-rel-1.c =================================================================== --- testsuite/gcc.target/arm/data-rel-1.c (nonexistent) +++ testsuite/gcc.target/arm/data-rel-1.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-options "-fPIC -mno-pic-data-is-text-relative" } */ +/* { dg-final { scan-assembler-not "j-\\(.LPIC" } } */ +/* { dg-final { scan-assembler-not "_GLOBAL_OFFSET_TABLE_-\\(.LPIC" } } */ +/* { dg-final { scan-assembler "j\\(GOT\\)" } } */ +/* { dg-final { scan-assembler "(ldr|mov)\tr\[0-9\]+, \\\[?r9" } } */ + +static int j; + +int *Foo () +{ + return &j; +} Index: testsuite/gcc.target/arm/data-rel-2.c =================================================================== --- testsuite/gcc.target/arm/data-rel-2.c (nonexistent) +++ testsuite/gcc.target/arm/data-rel-2.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-options "-fPIC -mno-pic-data-is-text-relative -mno-single-pic-base" } */ +/* { dg-final { scan-assembler-not "j-\\(.LPIC" } } */ +/* { dg-final { scan-assembler "_GLOBAL_OFFSET_TABLE_-\\(.LPIC" } } */ +/* { dg-final { scan-assembler "j\\(GOT\\)" } } */ + +static int j; + +int *Foo () +{ + return &j; +} Index: testsuite/gcc.target/arm/data-rel-3.c =================================================================== --- testsuite/gcc.target/arm/data-rel-3.c (nonexistent) +++ testsuite/gcc.target/arm/data-rel-3.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-options "-fPIC -mpic-data-is-text-relative" } */ +/* { dg-final { scan-assembler "j-\\(.LPIC" } } */ +/* { dg-final { scan-assembler-not "_GLOBAL_OFFSET_TABLE_-\\(.LPIC" } } */ +/* { dg-final { scan-assembler-not "j\\(GOT\\)" } } */ + +static int j; + +int *Foo () +{ + return &j; +}