From df56a27fb81910e6521a69a0a153dc36591021f7 Mon Sep 17 00:00:00 2001 From: Stan Shebs Date: Fri, 8 Jun 2001 02:28:04 +0000 Subject: [PATCH] darwin.h (ENCODE_SECTION_INFO): Define. * config/darwin.h (ENCODE_SECTION_INFO): Define. (REDO_SECTION_INFO_P): Ditto. (STRIP_NAME_ENCODING): Ditto. (ASM_DECLARE_OBJECT_NAME): Use ENCODE_SECTION_INFO. (ASM_OUTPUT_ALIGNED_DECL_LOCAL): Ditto. (ASM_OUTPUT_LABELREF): Use STRIP_NAME_ENCODING. (GEN_LAZY_PTR_NAME_FOR_SYMBOL): Ditto. * config/darwin.c: No longer include c-tree.h. (machopic_classify_ident): Rewrite to use symbol encoding. (lookup_name_darwin): Remove. (machopic_non_lazy_ptr_name): Handle encoded symbols. (machopic_stub_name): Use STRIP_NAME_ENCODING. (machopic_validate_stub_or_non_lazy_ptr): Ditto. (machopic_finish): Ditto, remove test of decl. (update_non_lazy_ptrs): New function. (darwin_encode_section_info): New function. * config/darwin-protos.h: Declare it. * config/rs6000/rs6000.c (machopic_output_stub): Use STRIP_NAME_ENCODING. From-SVN: r42994 --- gcc/ChangeLog | 22 +++++ gcc/config/darwin-protos.h | 1 + gcc/config/darwin.c | 162 ++++++++++++++++++++++++++----------- gcc/config/darwin.h | 20 +++++ gcc/config/rs6000/rs6000.c | 3 + 5 files changed, 162 insertions(+), 46 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6634e5b73de..3ae51dd6037 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,25 @@ +2001-06-07 Stan Shebs + + * config/darwin.h (ENCODE_SECTION_INFO): Define. + (REDO_SECTION_INFO_P): Ditto. + (STRIP_NAME_ENCODING): Ditto. + (ASM_DECLARE_OBJECT_NAME): Use ENCODE_SECTION_INFO. + (ASM_OUTPUT_ALIGNED_DECL_LOCAL): Ditto. + (ASM_OUTPUT_LABELREF): Use STRIP_NAME_ENCODING. + (GEN_LAZY_PTR_NAME_FOR_SYMBOL): Ditto. + * config/darwin.c: No longer include c-tree.h. + (machopic_classify_ident): Rewrite to use symbol encoding. + (lookup_name_darwin): Remove. + (machopic_non_lazy_ptr_name): Handle encoded symbols. + (machopic_stub_name): Use STRIP_NAME_ENCODING. + (machopic_validate_stub_or_non_lazy_ptr): Ditto. + (machopic_finish): Ditto, remove test of decl. + (update_non_lazy_ptrs): New function. + (darwin_encode_section_info): New function. + * config/darwin-protos.h: Declare it. + * config/rs6000/rs6000.c (machopic_output_stub): Use + STRIP_NAME_ENCODING. + 2001-06-07 Mark Mitchell * tree.h (DECL_SOURCE_FILE): Improve documentation. diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h index b2326c050c0..10afb9a8b1d 100644 --- a/gcc/config/darwin-protos.h +++ b/gcc/config/darwin-protos.h @@ -51,6 +51,7 @@ extern void machopic_define_ident PARAMS ((tree)); extern void machopic_define_name PARAMS ((const char*)); extern int machopic_name_defined_p PARAMS ((const char*)); extern int machopic_ident_defined_p PARAMS ((tree)); +extern void darwin_encode_section_info PARAMS ((tree)); #endif /* TREE_CODE */ diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 3e2a0008ef5..509ff91262a 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -35,8 +35,6 @@ Boston, MA 02111-1307, USA. */ #include "tree.h" #include "expr.h" #include "reload.h" -/* need for IDENTIFIER_GLOBAL_VALUE and IDENTIFIER_LOCAL_VALUE */ -#include "c-tree.h" #include "function.h" #include "ggc.h" @@ -46,6 +44,7 @@ extern void machopic_output_stub PARAMS ((FILE *, const char *, const char *)); static int machopic_data_defined_p PARAMS ((const char *)); static int func_name_maybe_scoped PARAMS ((const char *)); +static void update_non_lazy_ptrs PARAMS ((const char *)); /* Make everything that used to go in the text section really go there. */ @@ -85,10 +84,11 @@ machopic_classify_ident (ident) && name[3] == 'J' && name[4] == 'C' && name[5] == '_')); - tree temp, decl = lookup_name_darwin (ident); + tree temp; - if (!decl) + if (name[0] != '!') { + /* Here if no special encoding to be found. */ if (lprefix) { const char *name = IDENTIFIER_POINTER (ident); @@ -114,36 +114,24 @@ machopic_classify_ident (ident) return MACHOPIC_UNDEFINED; } - /* variable declarations */ - else if (TREE_CODE (decl) == VAR_DECL) - { - if ((DECL_INITIAL (decl) - || TREE_STATIC (decl)) - && ! TREE_PUBLIC (decl)) - return MACHOPIC_DEFINED_DATA; - } + else if (name[1] == 'D') + return MACHOPIC_DEFINED_DATA; - /* function declarations */ - else if (TREE_CODE (decl) == FUNCTION_DECL - && (!DECL_EXTERNAL (decl))) - { - if (TREE_STATIC (decl) - || TREE_ASM_WRITTEN (decl)) - return MACHOPIC_DEFINED_FUNCTION; - } + else if (name[1] == 'T') + return MACHOPIC_DEFINED_FUNCTION; for (temp = machopic_defined_list; temp != NULL_TREE; temp = TREE_CHAIN (temp)) { if (ident == TREE_VALUE (temp)) { - if (TREE_CODE (decl) == FUNCTION_DECL) + if (name[1] == 'T') return MACHOPIC_DEFINED_FUNCTION; else return MACHOPIC_DEFINED_DATA; } } - if (TREE_CODE (decl) == FUNCTION_DECL) + if (name[1] == 't' || name[1] == 'T') { if (lprefix) return MACHOPIC_DEFINED_FUNCTION; @@ -218,20 +206,6 @@ machopic_define_name (name) machopic_define_ident (get_identifier (name)); } -tree -lookup_name_darwin (name) - tree name; -{ - tree val; - - if (!global_bindings_p() - && IDENTIFIER_LOCAL_VALUE (name)) - val = IDENTIFIER_LOCAL_VALUE (name); - else - val = IDENTIFIER_GLOBAL_VALUE (name); - return val; -} - /* This is a static to make inline functions work. The rtx representing the PIC base symbol always points to here. */ @@ -279,6 +253,7 @@ char * machopic_non_lazy_ptr_name (name) const char *name; { + char *temp_name; tree temp, ident = get_identifier (name); for (temp = machopic_non_lazy_pointers; @@ -289,6 +264,22 @@ machopic_non_lazy_ptr_name (name) return IDENTIFIER_POINTER (TREE_PURPOSE (temp)); } + STRIP_NAME_ENCODING (name, name); + + /* Try again, but comparing names this time. */ + for (temp = machopic_non_lazy_pointers; + temp != NULL_TREE; + temp = TREE_CHAIN (temp)) + { + if (TREE_VALUE (temp)) + { + temp_name = IDENTIFIER_POINTER (TREE_VALUE (temp)); + STRIP_NAME_ENCODING (temp_name, temp_name); + if (strcmp (name, temp_name) == 0) + return IDENTIFIER_POINTER (TREE_PURPOSE (temp)); + } + } + { char *buffer; tree ptr_name; @@ -345,6 +336,8 @@ machopic_stub_name (name) return IDENTIFIER_POINTER (TREE_PURPOSE (temp)); } + STRIP_NAME_ENCODING (name, name); + { char *buffer; tree ptr_name; @@ -384,7 +377,8 @@ machopic_validate_stub_or_non_lazy_ptr (name, validate_stub) const char *name; int validate_stub; { - tree temp, ident = get_identifier (name); + char *real_name; + tree temp, ident = get_identifier (name), id2; for (temp = (validate_stub ? machopic_stubs : machopic_non_lazy_pointers); temp != NULL_TREE; @@ -396,6 +390,10 @@ machopic_validate_stub_or_non_lazy_ptr (name, validate_stub) TREE_USED (temp) = 1; if (TREE_CODE (TREE_VALUE (temp)) == IDENTIFIER_NODE) TREE_SYMBOL_REFERENCED (TREE_VALUE (temp)) = 1; + STRIP_NAME_ENCODING (real_name, IDENTIFIER_POINTER (TREE_VALUE (temp))); + id2 = maybe_get_identifier (real_name); + if (id2) + TREE_SYMBOL_REFERENCED (id2) = 1; } } @@ -890,19 +888,11 @@ machopic_finish (asm_out_file) char *stub_name = IDENTIFIER_POINTER (TREE_PURPOSE (temp)); char *sym; char *stub; - tree decl = lookup_name_darwin (TREE_VALUE (temp)); if (! TREE_USED (temp)) continue; - /* Don't emit stubs for static inline functions which have not - been compiled. */ - if (decl - && TREE_CODE (decl) == FUNCTION_DECL - && DECL_INLINE (decl) - && ! TREE_PUBLIC (decl) - && ! TREE_ASM_WRITTEN (decl)) - continue; + STRIP_NAME_ENCODING (sym_name, sym_name); sym = alloca (strlen (sym_name) + 2); if (sym_name[0] == '*' || sym_name[0] == '&') @@ -1000,3 +990,83 @@ machopic_operand_p (op) return 0; } + +/* This function records whether a given name corresponds to a defined + or undefined function or variable, for machopic_classify_ident to + use later. */ + +void +darwin_encode_section_info (decl) + tree decl; +{ + char code = '\0'; + int defined = 0; + + if ((TREE_CODE (decl) == FUNCTION_DECL + || TREE_CODE (decl) == VAR_DECL) + && ((TREE_STATIC (decl) + && (!DECL_COMMON (decl) || !TREE_PUBLIC (decl))) + || DECL_INITIAL (decl))) + defined = 1; + + if (TREE_CODE (decl) == FUNCTION_DECL) + code = (defined ? 'T' : 't'); + else if (TREE_CODE (decl) == VAR_DECL) + code = (defined ? 'D' : 'd'); + + if (code != '\0') + { + rtx sym_ref = XEXP (DECL_RTL (decl), 0); + + if (*(XSTR (sym_ref, 0)) == '!') + { + (XSTR(sym_ref, 0))[1] = code; + update_non_lazy_ptrs (XSTR (sym_ref, 0)); + return; + } + + { + size_t len = strlen (XSTR (sym_ref, 0)); + size_t newlen = len + 4; + char *str = alloca (newlen); + + str[0] = '!'; + str[1] = code; + str[2] = '_'; + str[3] = '_'; + memcpy (str + 4, XSTR (sym_ref, 0), len + 1); + + XSTR (sym_ref, 0) = ggc_alloc_string (str, newlen); + } + } +} + +/* Scan the list of non-lazy pointers and update any recorded names whose + stripped name matches the argument. */ + +static void +update_non_lazy_ptrs (name) + const char *name; +{ + char *name1, *name2; + tree temp; + + STRIP_NAME_ENCODING (name1, name); + + for (temp = machopic_non_lazy_pointers; + temp != NULL_TREE; + temp = TREE_CHAIN (temp)) + { + char *sym_name = IDENTIFIER_POINTER (TREE_VALUE (temp)); + + if (*sym_name == '!') + { + STRIP_NAME_ENCODING (name2, sym_name); + if (strcmp (name1, name2) == 0) + { + IDENTIFIER_POINTER (TREE_VALUE (temp)) = name; + break; + } + } + } +} diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 8415f8f6459..b07678053e5 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -234,6 +234,10 @@ do { text_section (); \ && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \ || DECL_INITIAL (DECL)) \ machopic_define_name (xname); \ + if ((TREE_STATIC (DECL) \ + && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \ + || DECL_INITIAL (DECL)) \ + ENCODE_SECTION_INFO (DECL); \ ASM_OUTPUT_LABEL (FILE, xname); \ } while (0) @@ -243,6 +247,7 @@ do { text_section (); \ #undef ASM_OUTPUT_LABELREF #define ASM_OUTPUT_LABELREF(FILE,NAME) \ do { \ + STRIP_NAME_ENCODING (NAME, NAME); \ if (NAME[0] == '&') \ { \ int len = strlen (NAME); \ @@ -280,6 +285,10 @@ do { text_section (); \ fputs (".lcomm ", (FILE)); \ assemble_name ((FILE), (NAME)); \ fprintf ((FILE), ",%u,%u\n", (SIZE), floor_log2 ((ALIGN) / BITS_PER_UNIT)); \ + if ((DECL) && ((TREE_STATIC (DECL) \ + && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \ + || DECL_INITIAL (DECL))) \ + ENCODE_SECTION_INFO (DECL); \ if ((DECL) && ((TREE_STATIC (DECL) \ && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \ || DECL_INITIAL (DECL))) \ @@ -705,6 +714,16 @@ enum machopic_addr_class { #define MACHOPIC_JUST_INDIRECT (flag_pic == 1) #define MACHOPIC_PURE (flag_pic == 2) +#define ENCODE_SECTION_INFO(DECL) \ + darwin_encode_section_info (DECL) + +/* Be conservative and always redo the encoding. */ + +#define REDO_SECTION_INFO_P(DECL) (1) + +#define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \ + ((VAR) = ((SYMBOL_NAME[0] == '!') ? (SYMBOL_NAME) + 4 : (SYMBOL_NAME))) + #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH) \ do { \ const char *stub_ = (STUB); \ @@ -741,6 +760,7 @@ enum machopic_addr_class { do { \ const char *symbol_ = (SYMBOL); \ char *buffer_ = (BUF); \ + STRIP_NAME_ENCODING (symbol_, symbol_); \ if (symbol_[0] == '"') \ { \ strcpy (buffer_, "\"L"); \ diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 10b3b91cba2..3662fe88563 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -8406,6 +8406,9 @@ machopic_output_stub (file, symb, stub) char *local_label_0, *local_label_1, *local_label_2; static int label = 0; + /* Lose our funky encoding stuff so it doesn't contaminate the stub. */ + STRIP_NAME_ENCODING (symb, symb); + label += 1; length = strlen (stub); -- 2.30.2