#include "reload.h"
#include "function.h"
#include "ggc.h"
+#include "langhooks.h"
#include "darwin-protos.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 *));
+static void update_stubs PARAMS ((const char *));
int
name_needs_quotes (name)
{
int c;
while ((c = *name++) != '\0')
- if (!isalnum (c) && c != '_')
+ if (! ISIDNUM (c))
return 1;
return 0;
}
else if (name[1] == 'T')
return MACHOPIC_DEFINED_FUNCTION;
+ /* It is possible that someone is holding a "stale" name, which has
+ since been defined. See if there is a "defined" name (i.e,
+ different from NAME only in having a '!D_' or a '!T_' instead of
+ a '!d_' or '!t_' prefix) in the identifier hash tables. If so, say
+ that this identifier is defined. */
+ else if (name[1] == 'd' || name[1] == 't')
+ {
+ char *new_name;
+ new_name = (char *)alloca (strlen (name) + 1);
+ strcpy (new_name, name);
+ new_name[1] = (name[1] == 'd') ? 'D' : 'T';
+ if (maybe_get_identifier (new_name) != NULL)
+ return (name[1] == 'd') ? MACHOPIC_DEFINED_DATA
+ : MACHOPIC_DEFINED_FUNCTION;
+ }
+
for (temp = machopic_defined_list; temp != NULL_TREE; temp = TREE_CHAIN (temp))
{
if (ident == TREE_VALUE (temp))
char *
machopic_function_base_name ()
{
- static char *name = NULL;
+ static const char *name = NULL;
static const char *current_name;
current_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
const char *name;
{
tree temp, ident = get_identifier (name);
-
+ const char *tname;
+
for (temp = machopic_stubs;
temp != NULL_TREE;
temp = TREE_CHAIN (temp))
{
if (ident == TREE_VALUE (temp))
return IDENTIFIER_POINTER (TREE_PURPOSE (temp));
+ tname = IDENTIFIER_POINTER (TREE_VALUE (temp));
+ if (strcmp (name, tname) == 0)
+ return IDENTIFIER_POINTER (TREE_PURPOSE (temp));
+ /* A library call name might not be section-encoded yet, so try
+ it against a stripped name. */
+ if (name[0] != '!'
+ && tname[0] == '!'
+ && strcmp (name, tname + 4) == 0)
+ return IDENTIFIER_POINTER (TREE_PURPOSE (temp));
}
STRIP_NAME_ENCODING (name, name);
return ptr_ref;
}
-/* For MACHOPIC_INDIRECT_CALL_TARGET below, we need to beware of:
-
- extern "C" { int f(); }
- struct X { int f(); int g(); };
- int X::f() { ::f(); }
- int X::g() { ::f(); f();}
-
- This is hairy. Both calls to "::f()" need to be indirect (i.e., to
- appropriate symbol stubs), but since MACHOPIC_NAME_DEFINED_P calls
- GET_IDENTIFIER which treats "f" as "X::f", and "X::f" is indeed (being)
- defined somewhere in "X"'s inheritance hierarchy, MACHOPIC_NAME_DEFINED_P
- returns TRUE when called with "f", which means that
- MACHOPIC_INDIRECT_CALL_TARGET uses an "internal" call instead of an
- indirect one as it should.
-
- Our quick-n-dirty solution to this is to call the following
- FUNC_NAME_MAYBE_SCOPED routine which (only for C++) checks whether
- FNAME -- the name of the function which we're calling -- is NOT a
- mangled C++ name, AND if the current function being compiled is a
- method, and if so, use an "external" or "indirect" call.
-
- Note that this function will be called ONLY when MACHOPIC_INDIRECT_TARGET_P
- has already indicated that the target is NOT indirect.
-
- This conservative solution will sometimes make indirect calls where
- it might have been possible to make direct ones.
-
- FUNC_NAME_MAYBE_SCOPED returns 1 to indicate a "C" name (not scoped),
- which in turns means we should create a stub for an indirect call.
- */
-
-static int is_cplusplus = -1;
-
-static int
-func_name_maybe_scoped (fname)
- const char *fname;
-{
-
- if (is_cplusplus < 0)
- is_cplusplus = (strcmp (lang_identify (), "cplusplus") == 0);
-
- if (is_cplusplus)
- {
- /* If we have a method, then check whether the function we're trying to
- call is a "C" function. If so, we should use an indirect call.
-
- It turns out to be hard to tell whether "we have a method", since
- static member functions have a TREE_CODE of FUNCTION_TYPE, as do
- namespace-level non-member functions. So here, we always look for
- an extern-"C"-like name, and make stubs for them no matter the
- calling context. This is temporary, and leaves nagging suspicion
- that improvements should be possible here. (I.e., I suspect that
- it can still sometimes make stubs where it needn't.) */
-
- /* if (1 || TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE) */
- {
- /* If fname is of the form "f__1X" or "f__Fv", it's C++. */
- while (*fname == '_') ++fname; /* skip leading underscores */
- while (*fname != 0)
- {
- if (fname[0] == '_' && fname[1] == '_'
- && (fname[2] == 'F' || (fname[2] >= '0' && fname[2] <= '9')))
- return 0;
- ++fname;
- }
- /* Not a C++ mangled name: must be "C", in which case play safe. */
- return 1;
- }
- }
- return 0;
-}
-
/* Transform TARGET (a MEM), which is a function call target, to the
corresponding symbol_stub if necessary. Return a new MEM. */
enum machine_mode mode = GET_MODE (XEXP (target, 0));
const char *name = XSTR (XEXP (target, 0), 0);
- if (!machopic_name_defined_p (name) || func_name_maybe_scoped (name))
+ /* If the name is already defined, we need do nothing. */
+ if (name[0] == '!' && name[1] == 'T')
+ return target;
+
+ if (!machopic_name_defined_p (name))
{
const char *stub_name = machopic_stub_name (name);
temp != NULL_TREE;
temp = TREE_CHAIN (temp))
{
- char *sym_name = IDENTIFIER_POINTER (TREE_VALUE (temp));
- char *stub_name = IDENTIFIER_POINTER (TREE_PURPOSE (temp));
+ const char *sym_name = IDENTIFIER_POINTER (TREE_VALUE (temp));
+ const char *stub_name = IDENTIFIER_POINTER (TREE_PURPOSE (temp));
char *sym;
char *stub;
if (! TREE_USED (temp))
continue;
+ /* If the symbol is actually defined, we don't need a stub. */
+ if (sym_name[0] == '!' && sym_name[1] == 'T')
+ continue;
+
STRIP_NAME_ENCODING (sym_name, sym_name);
sym = alloca (strlen (sym_name) + 2);
)
{
data_section ();
- assemble_align (UNITS_PER_WORD * BITS_PER_UNIT);
+ assemble_align (GET_MODE_ALIGNMENT (Pmode));
assemble_label (lazy_name);
assemble_integer (gen_rtx (SYMBOL_REF, Pmode, sym_name),
- GET_MODE_SIZE (Pmode), 1);
+ GET_MODE_SIZE (Pmode),
+ GET_MODE_ALIGNMENT (Pmode), 1);
}
else
{
assemble_name (asm_out_file, sym_name);
fprintf (asm_out_file, "\n");
- assemble_integer (const0_rtx, GET_MODE_SIZE (Pmode), 1);
+ assemble_integer (const0_rtx, GET_MODE_SIZE (Pmode),
+ GET_MODE_ALIGNMENT (Pmode), 1);
}
}
}
char code = '\0';
int defined = 0;
rtx sym_ref;
- char *orig_str, *new_str;
+ const char *orig_str;
+ char *new_str;
size_t len, new_len;
if ((TREE_CODE (decl) == FUNCTION_DECL
&& !DECL_EXTERNAL (decl)
&& ((TREE_STATIC (decl)
&& (!DECL_COMMON (decl) || !TREE_PUBLIC (decl)))
- || DECL_INITIAL (decl)))
+ || (DECL_INITIAL (decl)
+ && DECL_INITIAL (decl) != error_mark_node)))
defined = 1;
if (TREE_CODE (decl) == FUNCTION_DECL)
memcpy (new_str, orig_str, len);
new_str[1] = code;
XSTR (sym_ref, 0) = ggc_alloc_string (new_str, len);
- /* The non-lazy pointer list may have captured references to the
- old encoded name, change them. */
- update_non_lazy_ptrs (XSTR (sym_ref, 0));
}
else
{
memcpy (new_str + 4, orig_str, len);
XSTR (sym_ref, 0) = ggc_alloc_string (new_str, new_len);
}
+ /* The non-lazy pointer list may have captured references to the
+ old encoded name, change them. */
+ if (TREE_CODE (decl) == VAR_DECL)
+ update_non_lazy_ptrs (XSTR (sym_ref, 0));
+ else
+ update_stubs (XSTR (sym_ref, 0));
}
/* Scan the list of non-lazy pointers and update any recorded names whose
update_non_lazy_ptrs (name)
const char *name;
{
- char *name1, *name2;
+ const char *name1, *name2;
tree temp;
STRIP_NAME_ENCODING (name1, name);
}
}
}
+
+/* Function NAME is being defined, and its label has just been output.
+ If there's already a reference to a stub for this function, we can
+ just emit the stub label now and we don't bother emitting the stub later. */
+
+void
+machopic_output_possible_stub_label (file, name)
+ FILE *file;
+ const char *name;
+{
+ tree temp;
+
+
+ /* Ensure we're looking at a section-encoded name. */
+ if (name[0] != '!' || (name[1] != 't' && name[1] != 'T'))
+ return;
+
+ for (temp = machopic_stubs;
+ temp != NULL_TREE;
+ temp = TREE_CHAIN (temp))
+ {
+ const char *sym_name;
+
+ sym_name = IDENTIFIER_POINTER (TREE_VALUE (temp));
+ if (sym_name[0] == '!' && sym_name[1] == 'T'
+ && ! strcmp (name+2, sym_name+2))
+ {
+ ASM_OUTPUT_LABEL (file, IDENTIFIER_POINTER (TREE_PURPOSE (temp)));
+ /* Avoid generating a stub for this. */
+ TREE_USED (temp) = 0;
+ break;
+ }
+ }
+}
+
+/* Scan the list of stubs and update any recorded names whose
+ stripped name matches the argument. */
+
+static void
+update_stubs (name)
+ const char *name;
+{
+ const char *name1, *name2;
+ tree temp;
+
+ STRIP_NAME_ENCODING (name1, name);
+
+ for (temp = machopic_stubs;
+ 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;
+ }
+ }
+ }
+}
+
+void
+machopic_asm_out_constructor (symbol, priority)
+ rtx symbol;
+ int priority ATTRIBUTE_UNUSED;
+{
+ if (flag_pic)
+ mod_init_section ();
+ else
+ constructor_section ();
+ assemble_align (POINTER_SIZE);
+ assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+
+ if (!flag_pic)
+ fprintf (asm_out_file, ".reference .constructors_used\n");
+}
+
+void
+machopic_asm_out_destructor (symbol, priority)
+ rtx symbol;
+ int priority ATTRIBUTE_UNUSED;
+{
+ if (flag_pic)
+ mod_term_section ();
+ else
+ destructor_section ();
+ assemble_align (POINTER_SIZE);
+ assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+
+ if (!flag_pic)
+ fprintf (asm_out_file, ".reference .destructors_used\n");
+}