public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Darwin: Fix i686 bootstrap when the assembler supports GOTOFF in data.
@ 2020-09-17 16:53 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 16:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e16b0b4dbff0f21604897bf971eb5f9540711fb3

commit e16b0b4dbff0f21604897bf971eb5f9540711fb3
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sun Mar 29 10:04:03 2020 +0100

    Darwin: Fix i686 bootstrap when the assembler supports GOTOFF in data.
    
    When we use an assembler that supports " .long XX@GOTOFF", the current
    combination of configuration parameters and conditional compilation
    (when building an i686-darwin compiler with mdynamic-no-pic) assume that
    it's OK to put jump tables in the .const section.
    
    However, when we encounter a weak function with a jump table, this
    produces relocations that directly access the weak symbol section from
    the .const section - which is deemed illegal by the linker (since that
    would mean that the weak symbol could not be replaced).
    
    Arguably, this is a limitation (maybe even a bug) in the linker - but
    it seems that we'd have to change the ABI to fix it - since it would
    require some annotation (maybe just using a special section for the
    jump tables) to tell the linker that this specific circumstance is OK
    because the direct access to the weak symbol can only occur from that
    symbol itself.
    
    The fix is to force jump tables into the text section for all X86 Darwin
    versions (PIC code already had this change).
    
    We also need to backport 263764 'reorder MACHO and HAVE_GOTOFF_IN_DATA
    tests', since this causes us to emit @GOTOFF relocations which are not
    useable by the Darwin linker.
    
    gcc/ChangeLog:
    
    2020-03-29  Iain Sandoe  <iain@sandoe.co.uk>
    
            Backport from master.
            2018-08-22  Iain Sandoe  <iain@sandoe.co.uk>
    
            * config/i386/i386.c (ix86_output_addr_diff_elt): Move the MACH-O
            specific test before the one for HAVE_AS_GOTOFF_IN_DATA.
    
            Backport from master.
            2020-03-22  Iain Sandoe  <iain@sandoe.co.uk>
    
            * config/i386/darwin.h (JUMP_TABLES_IN_TEXT_SECTION): Remove
            references to Darwin.
            * config/i386/i386.h (JUMP_TABLES_IN_TEXT_SECTION): Define this
            unconditionally and comment on why.

Diff:
---
 gcc/ChangeLog            | 16 ++++++++++++++++
 gcc/config/i386/darwin.h | 10 ++++++++++
 gcc/config/i386/i386.c   |  4 ++--
 gcc/config/i386/i386.h   |  5 ++---
 4 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9defd8408c2..7bdf4d03742 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,19 @@
+2020-03-29  Iain Sandoe  <iain@sandoe.co.uk>
+
+	Backport from master.
+	2018-08-22  Iain Sandoe  <iain@sandoe.co.uk>
+
+	* config/i386/i386.c (ix86_output_addr_diff_elt): Move the MACH-O
+	specific test before the one for HAVE_AS_GOTOFF_IN_DATA.
+
+	Backport from master.
+	2020-03-22  Iain Sandoe  <iain@sandoe.co.uk>
+
+	* config/i386/darwin.h (JUMP_TABLES_IN_TEXT_SECTION): Remove
+	references to Darwin.
+	* config/i386/i386.h (JUMP_TABLES_IN_TEXT_SECTION): Define this
+	unconditionally and comment on why.
+
 2020-03-24  John David Anglin  <danglin@gcc.gnu.org>
 
 	PR lto/94249
diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index 2d0dc1f2605..3a844a55cd6 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -236,6 +236,16 @@ along with GCC; see the file COPYING3.  If not see
 #undef TARGET_ASM_OUTPUT_IDENT
 #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
 
+/* We always want jump tables in the text section:
+   * for PIC code, we need the subtracted symbol to be defined at
+     assembly-time.
+   * for mdynamic-no-pic, we cannot support jump tables in the .const
+     section for weak functions, this looks to ld64 like direct access
+     to the weak symbol from an anonymous atom.  */
+
+#undef JUMP_TABLES_IN_TEXT_SECTION
+#define JUMP_TABLES_IN_TEXT_SECTION 1
+
 /* Darwin profiling -- call mcount.  */
 #undef FUNCTION_PROFILER
 #define FUNCTION_PROFILER(FILE, LABELNO)				\
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 5d2e3945f6e..2fe0c8bc4f8 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -19922,8 +19922,6 @@ ix86_output_addr_diff_elt (FILE *file, int value, int rel)
   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
     fprintf (file, "%s%s%d-%s%d\n",
 	     directive, LPREFIX, value, LPREFIX, rel);
-  else if (HAVE_AS_GOTOFF_IN_DATA)
-    fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
 #if TARGET_MACHO
   else if (TARGET_MACHO)
     {
@@ -19932,6 +19930,8 @@ ix86_output_addr_diff_elt (FILE *file, int value, int rel)
       putc ('\n', file);
     }
 #endif
+  else if (HAVE_AS_GOTOFF_IN_DATA)
+    fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
   else
     asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n",
 		 GOT_SYMBOL_NAME, LPREFIX, value);
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index aba63fb7a80..63a54558a65 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2254,11 +2254,10 @@ extern int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER];
 
 /* Under some conditions we need jump tables in the text section,
    because the assembler cannot handle label differences between
-   sections.  This is the case for x86_64 on Mach-O for example.  */
+   sections.  */
 
 #define JUMP_TABLES_IN_TEXT_SECTION \
-  (flag_pic && ((TARGET_MACHO && TARGET_64BIT) \
-   || (!TARGET_64BIT && !HAVE_AS_GOTOFF_IN_DATA)))
+  (flag_pic && !(TARGET_64BIT || HAVE_AS_GOTOFF_IN_DATA))
 
 /* Switch to init or fini section via SECTION_OP, emit a call to FUNC,
    and switch back.  For x86 we do this only to save a few bytes that


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-17 16:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 16:53 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Darwin: Fix i686 bootstrap when the assembler supports GOTOFF in data Jakub Jelinek

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).