+ change_decl_assembler_name (decl, newname);
+ }
+ else
+ /* We have to add this to the rename list even if there's already
+ a global value that doesn't meet the above criteria, because in
+ C++ "struct foo {...};" puts "foo" in the current namespace but
+ does *not* conflict with a subsequent declaration of a function
+ or variable foo. See g++.dg/other/pragma-re-2.C. */
+ add_to_renaming_pragma_list (oldname, newname);
+}
+
+/* This is called from here and from ia64.c. */
+void
+add_to_renaming_pragma_list (tree oldname, tree newname)
+{
+ tree previous = purpose_member (oldname, pending_redefine_extname);
+ if (previous)
+ {
+ if (TREE_VALUE (previous) != newname)
+ warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
+ "conflict with previous #pragma redefine_extname");
+ return;
+ }
+
+ pending_redefine_extname
+ = tree_cons (oldname, newname, pending_redefine_extname);
+}
+
+static GTY(()) tree pragma_extern_prefix;
+
+/* #pragma extern_prefix "prefix" */
+static void
+handle_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
+{
+ tree prefix, x;
+ enum cpp_ttype t;
+
+ if (pragma_lex (&prefix) != CPP_STRING)
+ GCC_BAD ("malformed #pragma extern_prefix, ignored");
+ t = pragma_lex (&x);
+ if (t != CPP_EOF)
+ warning (OPT_Wpragmas, "junk at end of %<#pragma extern_prefix%>");
+
+ if (targetm.handle_pragma_extern_prefix)
+ /* Note that the length includes the null terminator. */
+ pragma_extern_prefix = (TREE_STRING_LENGTH (prefix) > 1 ? prefix : NULL);
+ else if (warn_unknown_pragmas > in_system_header)
+ warning (OPT_Wunknown_pragmas,
+ "#pragma extern_prefix not supported on this target");
+}
+
+/* Hook from the front ends to apply the results of one of the preceding
+ pragmas that rename variables. */
+
+tree
+maybe_apply_renaming_pragma (tree decl, tree asmname)
+{
+ tree *p, t;
+
+ /* The renaming pragmas are only applied to declarations with
+ external linkage. */
+ if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
+ || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
+ || !has_c_linkage (decl))
+ return asmname;
+
+ /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
+ but we may warn about a rename that conflicts. */
+ if (DECL_ASSEMBLER_NAME_SET_P (decl))
+ {
+ const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+ oldname = targetm.strip_name_encoding (oldname);
+
+ if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
+ warning (OPT_Wpragmas, "asm declaration ignored due to "
+ "conflict with previous rename");
+
+ /* Take any pending redefine_extname off the list. */
+ for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
+ if (DECL_NAME (decl) == TREE_PURPOSE (t))
+ {
+ /* Only warn if there is a conflict. */
+ if (strcmp (IDENTIFIER_POINTER (TREE_VALUE (t)), oldname))
+ warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
+ "conflict with previous rename");
+
+ *p = TREE_CHAIN (t);
+ break;
+ }
+ return 0;
+ }
+
+ /* Find out if we have a pending #pragma redefine_extname. */
+ for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
+ if (DECL_NAME (decl) == TREE_PURPOSE (t))
+ {
+ tree newname = TREE_VALUE (t);
+ *p = TREE_CHAIN (t);
+
+ /* If we already have an asmname, #pragma redefine_extname is
+ ignored (with a warning if it conflicts). */
+ if (asmname)
+ {
+ if (strcmp (TREE_STRING_POINTER (asmname),
+ IDENTIFIER_POINTER (newname)) != 0)
+ warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
+ "conflict with __asm__ declaration");
+ return asmname;
+ }
+
+ /* Otherwise we use what we've got; #pragma extern_prefix is
+ silently ignored. */
+ return build_string (IDENTIFIER_LENGTH (newname),
+ IDENTIFIER_POINTER (newname));
+ }
+
+ /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
+ if (asmname)
+ return asmname;
+
+ /* If #pragma extern_prefix is in effect, apply it. */
+ if (pragma_extern_prefix)
+ {
+ const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
+ size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
+
+ const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
+ size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
+
+ char *newname = (char *) alloca (plen + ilen + 1);
+
+ memcpy (newname, prefix, plen);
+ memcpy (newname + plen, id, ilen + 1);
+
+ return build_string (plen + ilen, newname);
+ }
+
+ /* Nada. */
+ return 0;
+}