From 8fae9be1d8eb4bb49075331473727cd2daebb0a3 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 4 Mar 2015 14:44:06 -0800 Subject: [PATCH] Add default_binds_local_p_2 and use it for x86 With copy relocation, address of protected data defined in the shared library may be external. In this case, TARGET_BINDS_LOCAL_P should return false. --- gcc/config/i386/i386.c | 3 +++ gcc/output.h | 1 + gcc/varasm.c | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index ab8f03a..41a487a 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -51878,6 +51878,9 @@ ix86_initialize_bounds (tree var, tree lb, tree ub, tree *stmts) #if TARGET_MACHO #undef TARGET_BINDS_LOCAL_P #define TARGET_BINDS_LOCAL_P darwin_binds_local_p +#else +#undef TARGET_BINDS_LOCAL_P +#define TARGET_BINDS_LOCAL_P default_binds_local_p_2 #endif #if TARGET_DLLIMPORT_DECL_ATTRIBUTES #undef TARGET_BINDS_LOCAL_P diff --git a/gcc/output.h b/gcc/output.h index 217d979..53e47d0 100644 --- a/gcc/output.h +++ b/gcc/output.h @@ -586,6 +586,7 @@ extern void default_asm_output_anchor (rtx); extern bool default_use_anchors_for_symbol_p (const_rtx); extern bool default_binds_local_p (const_tree); extern bool default_binds_local_p_1 (const_tree, int); +extern bool default_binds_local_p_2 (const_tree); extern void default_globalize_label (FILE *, const char *); extern void default_globalize_decl_name (FILE *, tree); extern void default_emit_unwind_label (FILE *, tree, int, int); diff --git a/gcc/varasm.c b/gcc/varasm.c index 8173207..87ac646 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -6803,7 +6803,8 @@ resolution_local_p (enum ld_plugin_symbol_resolution resolution) } static bool -default_binds_local_p_2 (const_tree exp, bool shlib, bool weak_dominate) +default_binds_local_p_3 (const_tree exp, bool shlib, bool weak_dominate, + bool extern_protected_data) { /* A non-decl is an entry in the constant pool. */ if (!DECL_P (exp)) @@ -6849,6 +6850,9 @@ default_binds_local_p_2 (const_tree exp, bool shlib, bool weak_dominate) or if we have a definition for the symbol. We cannot infer visibility for undefined symbols. */ if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT + && (TREE_CODE (exp) == FUNCTION_DECL + || !extern_protected_data + || DECL_VISIBILITY (exp) != VISIBILITY_PROTECTED) && (DECL_VISIBILITY_SPECIFIED (exp) || defined_locally)) return true; @@ -6884,13 +6888,21 @@ default_binds_local_p_2 (const_tree exp, bool shlib, bool weak_dominate) bool default_binds_local_p (const_tree exp) { - return default_binds_local_p_2 (exp, flag_shlib != 0, true); + return default_binds_local_p_3 (exp, flag_shlib != 0, true, false); +} + +/* Similar to default_binds_local_p, but protected data may be + external. */ +bool +default_binds_local_p_2 (const_tree exp) +{ + return default_binds_local_p_3 (exp, flag_shlib != 0, true, true); } bool default_binds_local_p_1 (const_tree exp, int shlib) { - return default_binds_local_p_2 (exp, shlib != 0, false); + return default_binds_local_p_3 (exp, shlib != 0, false, false); } /* Return true when references to DECL must bind to current definition in -- 1.9.3