+2001-06-07 Stan Shebs <shebs@apple.com>
+
+ * 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 <mark@codesourcery.com>
* tree.h (DECL_SOURCE_FILE): Improve documentation.
#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"
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. */
&& 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);
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;
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. */
machopic_non_lazy_ptr_name (name)
const char *name;
{
+ char *temp_name;
tree temp, ident = get_identifier (name);
for (temp = machopic_non_lazy_pointers;
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;
return IDENTIFIER_POINTER (TREE_PURPOSE (temp));
}
+ STRIP_NAME_ENCODING (name, name);
+
{
char *buffer;
tree ptr_name;
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;
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;
}
}
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] == '&')
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;
+ }
+ }
+ }
+}
&& (!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)
#undef ASM_OUTPUT_LABELREF
#define ASM_OUTPUT_LABELREF(FILE,NAME) \
do { \
+ STRIP_NAME_ENCODING (NAME, NAME); \
if (NAME[0] == '&') \
{ \
int len = strlen (NAME); \
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))) \
#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); \
do { \
const char *symbol_ = (SYMBOL); \
char *buffer_ = (BUF); \
+ STRIP_NAME_ENCODING (symbol_, symbol_); \
if (symbol_[0] == '"') \
{ \
strcpy (buffer_, "\"L"); \