Commit 2161a445 by Iain Sandoe Committed by Iain Sandoe

[Darwin, machopic 0/n] Initial tidy of Mach-O symbol handling.

We want to improve the detection and caching of symbol-properties
so that (a) we can make the compiler's output match the platform
norms (b) we can improve efficiency by checking flags instead of
inspecting strings. (c) The fix for PR71767 was a largish hammer
and we want to reduce the number of symbols that are made linker-
visible.

This first patch is largely typographical changes with no functional
difference intended:

- Tries to ensure that there's no overlap between the symbols used in
the Mach-O case and those declared in the i386 or rs6000 port trees.

 - Some improvement to comments.

- Makes the naming of the symbol flags consistent with other uses.
 
 - Provides a predicate macro for each use.
 
gcc/ChangeLog:

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

	* config/darwin.c (machopic_symbol_defined_p): Use symbol flag
	predicates instead of accessing bits directly.
	(machopic_indirect_call_target): Likewise.
	(machopic_output_indirection): Likewise.
	(darwin_encode_section_info): Improve description.  Use renamed
	symbol flags.  Use predicate macros for variables and functions.
	* config/darwin.h:
	Rename MACHO_SYMBOL_VARIABLE to MACHO_SYMBOL_FLAG_VARIABLE.
	Rename MACHO_SYMBOL_DEFINED to MACHO_SYMBOL_FLAG_DEFINED.
	Rename MACHO_SYMBOL_STATIC to MACHO_SYMBOL_FLAG_STATIC.
	(MACHO_SYMBOL_VARIABLE_P): New.
	(MACHO_SYMBOL_DEFINED_P):New.
	(MACHO_SYMBOL_STATIC_P): New.
	* config/i386/darwin.h (MACHO_SYMBOL_FLAG_VARIABLE): Delete.
	(SYMBOL_FLAG_SUBT_DEP): New.
	* config/rs6000/darwin.h (SYMBOL_FLAG_SUBT_DEP): New.

From-SVN: r276674
parent 8a896995
2019-10-07 Iain Sandoe <iain@sandoe.co.uk>
* config/darwin.c (machopic_symbol_defined_p): Use symbol flag
predicates instead of accessing bits directly.
(machopic_indirect_call_target): Likewise.
(machopic_output_indirection): Likewise.
(darwin_encode_section_info): Improve description. Use renamed
symbol flags. Use predicate macros for variables and functions.
* config/darwin.h:
Rename MACHO_SYMBOL_VARIABLE to MACHO_SYMBOL_FLAG_VARIABLE.
Rename MACHO_SYMBOL_DEFINED to MACHO_SYMBOL_FLAG_DEFINED.
Rename MACHO_SYMBOL_STATIC to MACHO_SYMBOL_FLAG_STATIC.
(MACHO_SYMBOL_VARIABLE_P): New.
(MACHO_SYMBOL_DEFINED_P):New.
(MACHO_SYMBOL_STATIC_P): New.
* config/i386/darwin.h (MACHO_SYMBOL_FLAG_VARIABLE): Delete.
(SYMBOL_FLAG_SUBT_DEP): New.
* config/rs6000/darwin.h (SYMBOL_FLAG_SUBT_DEP): New.
2019-10-07 Jozef Lawrynowicz <jozef.l@mittosystems.com> 2019-10-07 Jozef Lawrynowicz <jozef.l@mittosystems.com>
* config/msp430/msp430.c (msp430_file_end): s/msp_/msp430_/ * config/msp430/msp430.c (msp430_file_end): s/msp_/msp430_/
......
...@@ -76,7 +76,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -76,7 +76,7 @@ along with GCC; see the file COPYING3. If not see
setting the second word in the .non_lazy_symbol_pointer data setting the second word in the .non_lazy_symbol_pointer data
structure to symbol. See indirect_data for the code that handles structure to symbol. See indirect_data for the code that handles
the extra indirection, and machopic_output_indirection and its use the extra indirection, and machopic_output_indirection and its use
of MACHO_SYMBOL_STATIC for the code that handles @code{static} of MACHO_SYMBOL_FLAG_STATIC for the code that handles @code{static}
symbol indirection. */ symbol indirection. */
typedef struct GTY(()) cdtor_record { typedef struct GTY(()) cdtor_record {
...@@ -249,7 +249,7 @@ name_needs_quotes (const char *name) ...@@ -249,7 +249,7 @@ name_needs_quotes (const char *name)
int int
machopic_symbol_defined_p (rtx sym_ref) machopic_symbol_defined_p (rtx sym_ref)
{ {
if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED) if (MACHO_SYMBOL_DEFINED_P (sym_ref))
return true; return true;
/* If a symbol references local and is not an extern to this /* If a symbol references local and is not an extern to this
...@@ -258,7 +258,7 @@ machopic_symbol_defined_p (rtx sym_ref) ...@@ -258,7 +258,7 @@ machopic_symbol_defined_p (rtx sym_ref)
{ {
/* If the symbol references a variable and the variable is a /* If the symbol references a variable and the variable is a
common symbol, then this symbol is not defined. */ common symbol, then this symbol is not defined. */
if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_VARIABLE) if (MACHO_SYMBOL_VARIABLE_P (sym_ref))
{ {
tree decl = SYMBOL_REF_DECL (sym_ref); tree decl = SYMBOL_REF_DECL (sym_ref);
if (!decl) if (!decl)
...@@ -797,8 +797,7 @@ machopic_indirect_call_target (rtx target) ...@@ -797,8 +797,7 @@ machopic_indirect_call_target (rtx target)
if (MACHOPIC_INDIRECT if (MACHOPIC_INDIRECT
&& GET_CODE (XEXP (target, 0)) == SYMBOL_REF && GET_CODE (XEXP (target, 0)) == SYMBOL_REF
&& !(SYMBOL_REF_FLAGS (XEXP (target, 0)) && ! MACHO_SYMBOL_DEFINED_P (XEXP (target, 0)))
& MACHO_SYMBOL_FLAG_DEFINED))
{ {
rtx sym_ref = XEXP (target, 0); rtx sym_ref = XEXP (target, 0);
const char *stub_name = machopic_indirection_name (sym_ref, const char *stub_name = machopic_indirection_name (sym_ref,
...@@ -1167,14 +1166,14 @@ machopic_output_indirection (machopic_indirection **slot, FILE *asm_out_file) ...@@ -1167,14 +1166,14 @@ machopic_output_indirection (machopic_indirection **slot, FILE *asm_out_file)
assemble_name (asm_out_file, sym_name); assemble_name (asm_out_file, sym_name);
fprintf (asm_out_file, "\n"); fprintf (asm_out_file, "\n");
/* Variables that are marked with MACHO_SYMBOL_STATIC need to /* Variables that are marked with MACHO_SYMBOL_FLAG_STATIC need to
have their symbol name instead of 0 in the second entry of have their symbol name instead of 0 in the second entry of
the non-lazy symbol pointer data structure when they are the non-lazy symbol pointer data structure when they are
defined. This allows the runtime to rebind newer instances defined. This allows the runtime to rebind newer instances
of the translation unit with the original instance of the of the translation unit with the original instance of the
symbol. */ symbol. */
if ((SYMBOL_REF_FLAGS (symbol) & MACHO_SYMBOL_STATIC) if (MACHO_SYMBOL_STATIC_P (symbol)
&& machopic_symbol_defined_p (symbol)) && machopic_symbol_defined_p (symbol))
init = gen_rtx_SYMBOL_REF (Pmode, sym_name); init = gen_rtx_SYMBOL_REF (Pmode, sym_name);
...@@ -1205,23 +1204,37 @@ machopic_operand_p (rtx op) ...@@ -1205,23 +1204,37 @@ machopic_operand_p (rtx op)
&& XINT (XEXP (op, 0), 1) == UNSPEC_MACHOPIC_OFFSET); && XINT (XEXP (op, 0), 1) == UNSPEC_MACHOPIC_OFFSET);
} }
/* This function records whether a given name corresponds to a defined /* This function:
or undefined function or variable, for machopic_classify_ident to computes and caches a series of flags that characterise the symbol's
use later. */ properties that affect Mach-O code gen (including accidental cases
from older toolchains).
TODO:
Here we also need to do enough analysis to determine if a symbol's
name needs to be made linker-visible. This is more tricky - since
it depends on whether we've previously seen a global weak definition
in the same section.
*/
void void
darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED) darwin_encode_section_info (tree decl, rtx rtl, int first)
{ {
rtx sym_ref; /* Careful not to prod global register variables. */
if (!MEM_P (rtl))
return;
/* Do the standard encoding things first. */ /* Do the standard encoding things first; this sets:
SYMBOL_FLAG_FUNCTION,
SYMBOL_FLAG_LOCAL, (binds_local_p)
TLS_MODEL, SYMBOL_FLAG_SMALL
SYMBOL_FLAG_EXTERNAL. */
default_encode_section_info (decl, rtl, first); default_encode_section_info (decl, rtl, first);
if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL) if (! VAR_OR_FUNCTION_DECL_P (decl))
return; return;
sym_ref = XEXP (rtl, 0); rtx sym_ref = XEXP (rtl, 0);
if (TREE_CODE (decl) == VAR_DECL) if (VAR_P (decl))
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE; SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE;
if (!DECL_EXTERNAL (decl) if (!DECL_EXTERNAL (decl)
...@@ -1234,7 +1247,7 @@ darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED) ...@@ -1234,7 +1247,7 @@ darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED; SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_DEFINED;
if (! TREE_PUBLIC (decl)) if (! TREE_PUBLIC (decl))
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC; SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_STATIC;
} }
void void
......
...@@ -812,21 +812,30 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; ...@@ -812,21 +812,30 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
#undef TARGET_ASM_MARK_DECL_PRESERVED #undef TARGET_ASM_MARK_DECL_PRESERVED
#define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved #define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
/* Set on a symbol with SYMBOL_FLAG_FUNCTION or /* Any port using this header needs to define the first available
MACHO_SYMBOL_FLAG_VARIABLE to indicate that the function or subtarget symbol bit: SYMBOL_FLAG_SUBT_DEP. */
variable has been defined in this translation unit.
When porting Mach-O to new architectures you need to make
sure these aren't clobbered by the backend. */
#define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_MACH_DEP) /* Is a variable. */
#define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_MACH_DEP) << 1) #define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_SUBT_DEP)
#define MACHO_SYMBOL_VARIABLE_P(RTX) \
((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_VARIABLE) != 0)
/* 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
translation unit. */
#define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_SUBT_DEP) << 2)
#define MACHO_SYMBOL_DEFINED_P(RTX) \
((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_DEFINED) != 0)
/* Set on a symbol to indicate when fix-and-continue style code /* Set on a symbol to indicate when fix-and-continue style code
generation is being used and the symbol refers to a static symbol generation is being used and the symbol refers to a static symbol
that should be rebound from new instances of a translation unit to that should be rebound from new instances of a translation unit to
the original instance of the data. */ the original instance of the data. */
#define MACHO_SYMBOL_STATIC ((SYMBOL_FLAG_MACH_DEP) << 2) #define MACHO_SYMBOL_FLAG_STATIC ((SYMBOL_FLAG_SUBT_DEP) << 5)
#define MACHO_SYMBOL_STATIC_P(RTX) \
((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_STATIC) != 0)
/* Symbolic names for various things we might know about a symbol. */ /* Symbolic names for various things we might know about a symbol. */
......
...@@ -324,10 +324,8 @@ along with GCC; see the file COPYING3. If not see ...@@ -324,10 +324,8 @@ along with GCC; see the file COPYING3. If not see
} \ } \
} }
/* This needs to move since i386 uses the first flag and other flags are /* First available SYMBOL flag bit for use by subtargets. */
used in Mach-O. */ #define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP << 5)
#undef MACHO_SYMBOL_FLAG_VARIABLE
#define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)
#undef MACHOPIC_NL_SYMBOL_PTR_SECTION #undef MACHOPIC_NL_SYMBOL_PTR_SECTION
#define MACHOPIC_NL_SYMBOL_PTR_SECTION \ #define MACHOPIC_NL_SYMBOL_PTR_SECTION \
......
...@@ -506,6 +506,9 @@ do { \ ...@@ -506,6 +506,9 @@ do { \
this will need to be modified similar to the x86 case. */ this will need to be modified similar to the x86 case. */
#define TARGET_FOLD_BUILTIN SUBTARGET_FOLD_BUILTIN #define TARGET_FOLD_BUILTIN SUBTARGET_FOLD_BUILTIN
/* First available SYMBOL flag bit for use by subtargets. */
#define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP)
/* Use standard DWARF numbering for DWARF debugging information. */ /* Use standard DWARF numbering for DWARF debugging information. */
#define RS6000_USE_DWARF_NUMBERING #define RS6000_USE_DWARF_NUMBERING
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