public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Joey Ye" <joey.ye@arm.com>
To: <gcc-patches@gcc.gnu.org>
Subject: [patch] [arm] New option for PIC offset unfixed
Date: Tue, 12 Nov 2013 10:12:00 -0000	[thread overview]
Message-ID: <000001cedf74$bd1bf710$3753e530$@arm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 863 bytes --]

For RTOS who need to relocate executable, PC relative and GOTOFF cannot be
used as the offset between any sections won't be fixed. Only GOT can be
used, just as VxWorks RTP does.

This patch introduces a new option enable user to choose between fixed
offset or not. Enabled for VxWorks RTP to keep its behavior unchanged.

Tested with arm-none-eabi make and VxWorks RTP small case

OK to trunk?

ChangeLog:
2013-11-12  Joey Ye  <joey.ye@arm.com>

	* config/arm/arm.c (arm_option_override):  Error if
	-mpic-offset-unfixed without -fpic, and set for
	VxWorks RTP.
	(legitimize_pic_address): Use arm_pic_offset_unfixed.
	(arm_assemble_integer): Likewise.
	* config/arm/arm.h
	(TARGET_DEFAULT_PIC_OFFSET_UNFIXED): New macro.
	* config/arm/arm.opt (mpic-offset-unfixed): New option.
	* doc/invoke.texi (-mpic-offset-unfixed): Doc for new option.

[-- Attachment #2: pic_offset_fixed-1112.patch --]
[-- Type: application/octet-stream, Size: 2904 bytes --]

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 7757e86..81cd5e7 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -2504,6 +2504,12 @@ arm_option_override (void)
 	arm_pic_register = pic_register;
     }
 
+  if (TARGET_VXWORKS_RTP)
+    arm_pic_offset_unfixed = 1;
+
+  if (arm_pic_offset_unfixed != TARGET_DEFAULT_PIC_OFFSET_UNFIXED && !flag_pic)
+    error ("-mpic-offset-unfixed must be used with -fpic");
+
   /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores.  */
   if (fix_cm3_ldrd == 2)
     {
@@ -6020,7 +6026,7 @@ legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
 	   || (GET_CODE (orig) == SYMBOL_REF &&
 	       SYMBOL_REF_LOCAL_P (orig)))
 	  && NEED_GOT_RELOC
-	  && !TARGET_VXWORKS_RTP)
+	  && !arm_pic_offset_unfixed)
 	insn = arm_pic_static_addr (orig, reg);
       else
 	{
@@ -21498,7 +21504,7 @@ arm_assemble_integer (rtx x, unsigned int size, int aligned_p)
 	{
 	  /* See legitimize_pic_address for an explanation of the
 	     TARGET_VXWORKS_RTP check.  */
-	  if (TARGET_VXWORKS_RTP
+	  if (arm_pic_offset_unfixed
 	      || (GET_CODE (x) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (x)))
 	    fputs ("(GOT)", asm_out_file);
 	  else
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index 1781b75..17a672c 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -568,6 +568,10 @@ extern int prefer_neon_for_64bits;
 #define NEED_PLT_RELOC	0
 #endif
 
+#ifndef TARGET_DEFAULT_PIC_OFFSET_UNFIXED
+#define TARGET_DEFAULT_PIC_OFFSET_UNFIXED 0
+#endif
+
 /* Nonzero if we need to refer to the GOT with a PC-relative
    offset.  In other words, generate
 
diff --git a/gcc/config/arm/arm.opt b/gcc/config/arm/arm.opt
index 9b74038..acbe145 100644
--- a/gcc/config/arm/arm.opt
+++ b/gcc/config/arm/arm.opt
@@ -158,6 +158,10 @@ mlong-calls
 Target Report Mask(LONG_CALLS)
 Generate call insns as indirect calls, if necessary
 
+mpic-offset-unfixed
+Target Report Var(arm_pic_offset_unfixed) Init(TARGET_DEFAULT_PIC_OFFSET_UNFIXED)
+Assume inter-section offset is not the same between link time and run time.
+
 mpic-register=
 Target RejectNegative Joined Var(arm_pic_register_string)
 Specify the register to be used for PIC addressing
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 863e518..221db10 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -12120,6 +12120,12 @@ before execution begins.
 Specify the register to be used for PIC addressing.  The default is R10
 unless stack-checking is enabled, when R9 is used.
 
+@item -mpic-offset-unfixed
+@opindex mpic-offset-unfixed
+Assume that each sections can be relocated separately at load time.
+Therefore, prevent PC relative and GOTOFF style relocations.  This is on
+by default for the VxWorks RTP target.
+
 @item -mpoke-function-name
 @opindex mpoke-function-name
 Write the name of each function into the text section, directly

             reply	other threads:[~2013-11-12  6:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 10:12 Joey Ye [this message]
2013-11-12 13:37 ` Richard Earnshaw
2013-11-13  9:06   ` Joey Ye
2013-11-13 10:52     ` Richard Earnshaw
2013-11-13 11:16       ` Joey Ye
2013-11-13 11:46         ` Richard Earnshaw
2013-11-13 17:23           ` Joey Ye
2013-11-13 12:21         ` Richard Earnshaw
     [not found]           ` <45520D6299C11E4588128526465332BB3BDBAD147A@SAROVARA.Asiapac.Arm.com>
2013-11-13 18:00             ` Richard Earnshaw
2013-11-14 10:09 Joey Ye
2013-11-14 10:48 ` Richard Earnshaw
2013-11-14 12:53   ` Joey Ye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000001cedf74$bd1bf710$3753e530$@arm.com' \
    --to=joey.ye@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).