Commit a3fc4326 by Iain Sandoe Committed by Iain Sandoe

[Darwin, machopic 2/n] Compute and cache indirection rules.

This caches a check for the requirement to indirect a symbol in the Darwin
ABI, and uses it where needed.  We also ensure that we place the indirection
pointers into the non-lazy symbol pointers section.  Other placements have
occurred with various platform toolchains - but these seem to have been
unintentional so we match current platform toolchains.

gcc/ChangeLog:

2019-10-08  Iain Sandoe  <iain@sandoe.co.uk>

	* config/darwin.c (machopic_indirect_data_reference): Check for
	required indirections before making direct access to defined
	values.
	(machopic_output_indirection): Place the indirected pointes for
	required indirections into the non-lazy symbol pointers section.
	(darwin_encode_section_info):
	* config/darwin.h (MACHO_SYMBOL_FLAG_MUST_INDIRECT): New.
	(MACHO_SYMBOL_MUST_INDIRECT_P): New.

From-SVN: r276708
parent fe42ae7c
2019-10-08 Iain Sandoe <iain@sandoe.co.uk>
* config/darwin.c (machopic_indirect_data_reference): Check for
required indirections before making direct access to defined
values.
(machopic_output_indirection): Place the indirected pointes for
required indirections into the non-lazy symbol pointers section.
(darwin_encode_section_info):
* config/darwin.h (MACHO_SYMBOL_FLAG_MUST_INDIRECT): New.
(MACHO_SYMBOL_MUST_INDIRECT_P): New.
2019-10-08 Uroš Bizjak <ubizjak@gmail.com> 2019-10-08 Uroš Bizjak <ubizjak@gmail.com>
PR target/91994 PR target/91994
......
...@@ -665,7 +665,7 @@ machopic_indirect_data_reference (rtx orig, rtx reg) ...@@ -665,7 +665,7 @@ machopic_indirect_data_reference (rtx orig, rtx reg)
/* some other cpu -- writeme! */ /* some other cpu -- writeme! */
gcc_unreachable (); gcc_unreachable ();
} }
else if (defined) else if (defined && ! MACHO_SYMBOL_MUST_INDIRECT_P (orig))
{ {
rtx offset = NULL; rtx offset = NULL;
if (DARWIN_PPC || HAVE_lo_sum) if (DARWIN_PPC || HAVE_lo_sum)
...@@ -1120,6 +1120,7 @@ machopic_output_indirection (machopic_indirection **slot, FILE *asm_out_file) ...@@ -1120,6 +1120,7 @@ machopic_output_indirection (machopic_indirection **slot, FILE *asm_out_file)
machopic_output_stub (asm_out_file, sym, stub); machopic_output_stub (asm_out_file, sym, stub);
} }
else if (! indirect_data (symbol) else if (! indirect_data (symbol)
&& ! MACHO_SYMBOL_MUST_INDIRECT_P (symbol)
&& ! MACHO_SYMBOL_HIDDEN_VIS_P (symbol) && ! MACHO_SYMBOL_HIDDEN_VIS_P (symbol)
&& (machopic_symbol_defined_p (symbol) && (machopic_symbol_defined_p (symbol)
|| SYMBOL_REF_LOCAL_P (symbol))) || SYMBOL_REF_LOCAL_P (symbol)))
...@@ -1238,11 +1239,17 @@ darwin_encode_section_info (tree decl, rtx rtl, int first) ...@@ -1238,11 +1239,17 @@ darwin_encode_section_info (tree decl, rtx rtl, int first)
if (VAR_P (decl)) if (VAR_P (decl))
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE; SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE;
/* Only really common if there's no initialiser. */
bool really_common_p = (DECL_COMMON (decl)
&& (DECL_INITIAL (decl) == NULL
|| (!in_lto_p
&& DECL_INITIAL (decl) == error_mark_node)));
/* For Darwin, if we have specified visibility and it's not the default /* For Darwin, if we have specified visibility and it's not the default
that's counted 'hidden'. */ that's counted 'hidden'. */
if (DECL_VISIBILITY_SPECIFIED (decl) if (DECL_VISIBILITY_SPECIFIED (decl)
&& DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT) && DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT)
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_HIDDEN_VIS; SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_HIDDEN_VIS;
if (!DECL_EXTERNAL (decl) if (!DECL_EXTERNAL (decl)
&& (!TREE_PUBLIC (decl) || !DECL_WEAK (decl)) && (!TREE_PUBLIC (decl) || !DECL_WEAK (decl))
...@@ -1255,6 +1262,12 @@ darwin_encode_section_info (tree decl, rtx rtl, int first) ...@@ -1255,6 +1262,12 @@ darwin_encode_section_info (tree decl, rtx rtl, int first)
if (! TREE_PUBLIC (decl)) if (! TREE_PUBLIC (decl))
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_STATIC; SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_STATIC;
/* Short cut check for Darwin 'must indirect' rules. */
if (really_common_p
|| (DECL_WEAK (decl) && ! MACHO_SYMBOL_HIDDEN_VIS_P (sym_ref))
|| lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_MUST_INDIRECT;
} }
void void
......
...@@ -820,6 +820,15 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; ...@@ -820,6 +820,15 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
#define MACHO_SYMBOL_VARIABLE_P(RTX) \ #define MACHO_SYMBOL_VARIABLE_P(RTX) \
((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_VARIABLE) != 0) ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_VARIABLE) != 0)
/* Set on a symbol that must be indirected, even when there is a
definition in the TU. The ABI mandates that common symbols are so
indirected, as are weak. If 'fix-and-continue' is operational then
data symbols might also be. */
#define MACHO_SYMBOL_FLAG_MUST_INDIRECT ((SYMBOL_FLAG_SUBT_DEP) << 1)
#define MACHO_SYMBOL_MUST_INDIRECT_P(RTX) \
((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_MUST_INDIRECT) != 0)
/* Set on a symbol with SYMBOL_FLAG_FUNCTION or MACHO_SYMBOL_FLAG_VARIABLE /* Set on a symbol with SYMBOL_FLAG_FUNCTION or MACHO_SYMBOL_FLAG_VARIABLE
to indicate that the function or variable is considered defined in this to indicate that the function or variable is considered defined in this
translation unit. */ translation unit. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment