aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2019-10-07 20:14:26 +0000
committerIain Sandoe <iain@sandoe.co.uk>2019-10-07 20:14:26 +0000
commit7e76544bf7569408b1a740fa67b4aa28e4dba362 (patch)
tree77c3c0f3baa914515e1bbe50035a456e446c0d4d
parent0b282bd49d2e78d23f58e5c35ce1071ab26e52be (diff)
[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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@276674 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog19
-rw-r--r--gcc/config/darwin.c47
-rw-r--r--gcc/config/darwin.h25
-rw-r--r--gcc/config/i386/darwin.h6
-rw-r--r--gcc/config/rs6000/darwin.h3
5 files changed, 71 insertions, 29 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7d8aa956633..021d4060397 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,22 @@
+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>
* config/msp430/msp430.c (msp430_file_end): s/msp_/msp430_/
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 56739823946..45e0d744adb 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -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
structure to symbol. See indirect_data for the code that handles
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. */
typedef struct GTY(()) cdtor_record {
@@ -249,7 +249,7 @@ name_needs_quotes (const char *name)
int
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;
/* If a symbol references local and is not an extern to this
@@ -258,7 +258,7 @@ machopic_symbol_defined_p (rtx sym_ref)
{
/* If the symbol references a variable and the variable is a
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);
if (!decl)
@@ -797,8 +797,7 @@ machopic_indirect_call_target (rtx target)
if (MACHOPIC_INDIRECT
&& GET_CODE (XEXP (target, 0)) == SYMBOL_REF
- && !(SYMBOL_REF_FLAGS (XEXP (target, 0))
- & MACHO_SYMBOL_FLAG_DEFINED))
+ && ! MACHO_SYMBOL_DEFINED_P (XEXP (target, 0)))
{
rtx sym_ref = XEXP (target, 0);
const char *stub_name = machopic_indirection_name (sym_ref,
@@ -1167,14 +1166,14 @@ machopic_output_indirection (machopic_indirection **slot, FILE *asm_out_file)
assemble_name (asm_out_file, sym_name);
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
the non-lazy symbol pointer data structure when they are
defined. This allows the runtime to rebind newer instances
of the translation unit with the original instance of the
symbol. */
- if ((SYMBOL_REF_FLAGS (symbol) & MACHO_SYMBOL_STATIC)
+ if (MACHO_SYMBOL_STATIC_P (symbol)
&& machopic_symbol_defined_p (symbol))
init = gen_rtx_SYMBOL_REF (Pmode, sym_name);
@@ -1205,23 +1204,37 @@ machopic_operand_p (rtx op)
&& XINT (XEXP (op, 0), 1) == UNSPEC_MACHOPIC_OFFSET);
}
-/* This function records whether a given name corresponds to a defined
- or undefined function or variable, for machopic_classify_ident to
- use later. */
+/* This function:
+ computes and caches a series of flags that characterise the symbol's
+ 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
-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);
- if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
+ if (! VAR_OR_FUNCTION_DECL_P (decl))
return;
- sym_ref = XEXP (rtl, 0);
- if (TREE_CODE (decl) == VAR_DECL)
+ rtx sym_ref = XEXP (rtl, 0);
+ if (VAR_P (decl))
SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_VARIABLE;
if (!DECL_EXTERNAL (decl)
@@ -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;
if (! TREE_PUBLIC (decl))
- SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_STATIC;
+ SYMBOL_REF_FLAGS (sym_ref) |= MACHO_SYMBOL_FLAG_STATIC;
}
void
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 93dc638f8bb..39c54cc7208 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -812,21 +812,30 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
#undef TARGET_ASM_MARK_DECL_PRESERVED
#define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
-/* Set on a symbol with SYMBOL_FLAG_FUNCTION or
- MACHO_SYMBOL_FLAG_VARIABLE to indicate that the function or
- 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. */
+/* Any port using this header needs to define the first available
+ subtarget symbol bit: SYMBOL_FLAG_SUBT_DEP. */
-#define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_MACH_DEP)
-#define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_MACH_DEP) << 1)
+/* Is a variable. */
+#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
generation is being used and the symbol refers to a static symbol
that should be rebound from new instances of a translation unit to
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. */
diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index 385d2536920..bdb36f00959 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -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
- used in Mach-O. */
-#undef MACHO_SYMBOL_FLAG_VARIABLE
-#define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)
+/* First available SYMBOL flag bit for use by subtargets. */
+#define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP << 5)
#undef MACHOPIC_NL_SYMBOL_PTR_SECTION
#define MACHOPIC_NL_SYMBOL_PTR_SECTION \
diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h
index a626325c2d0..1081967bd61 100644
--- a/gcc/config/rs6000/darwin.h
+++ b/gcc/config/rs6000/darwin.h
@@ -506,6 +506,9 @@ do { \
this will need to be modified similar to the x86 case. */
#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. */
#define RS6000_USE_DWARF_NUMBERING