]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Darwin: Fix i686 bootstrap when the assembler supports GOTOFF in data.
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 23 Mar 2020 17:10:05 +0000 (17:10 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Mon, 23 Mar 2020 17:14:34 +0000 (17:14 +0000)
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).

gcc/ChangeLog:

2020-03-23  Iain Sandoe  <iain@sandoe.co.uk>

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.

gcc/ChangeLog
gcc/config/i386/darwin.h
gcc/config/i386/i386.h

index 91bcc48cecab8316b89f742ec7a3dc81b4c45963..c19e3fd08e2786c54e4b8f52263028a35aa30ebe 100644 (file)
@@ -1,3 +1,13 @@
+2020-03-23  Iain Sandoe  <iain@sandoe.co.uk>
+
+       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-19  Jonathan Wakely  <jwakely@redhat.com>
 
        Backport from mainline
index bdb36f0095961a44672b8b9e3305e9629bca24f9..c099a6238d83c1f3838829fcecd22c6dcd3e62ca 100644 (file)
@@ -239,6 +239,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)                               \
index 14e5a392f62c9be02a6f0e26a9060822aa3f1dc8..441213eebb876b97db0ac223f5cc4f597a9b41da 100644 (file)
@@ -2232,11 +2232,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