This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C ASSEMBLER_NAME patch
- From: Geoffrey Keating <gkeating at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 17 Jul 2003 14:50:17 -0700 (PDT)
- Subject: C ASSEMBLER_NAME patch
This patch:
- fixes 11498, and adds the appropriate testcase
- undoes Mark's patch which broke IMI
- ought to fix the problem with crtstuff.c by suppressing name
mangling when compiling only one translation unit
- ensures that DECL_ASSEMBLER_NAME is set only once, unless asm("") is
in use (I'm still trying to track down all the places that would
need to change to prevent that).
Bootstrapped & tested with --enable-intermodule on powerpc-darwin.
Note that there is one ongoing problem with this patch. It sets the
name of the function the first time that DECL_ASSEMBLER_NAME is
called. If DECL_ASSEMBLER_NAME gets called before the declaration
is fully parsed, the object can get the wrong name. I'm trying to
think of ways to add checking code to detect this...
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/gcc-imimangle.patch=======================
2003-07-17 Geoffrey Keating <geoffk@apple.com>
* Makefile.in (c-opts.o): Add $(LANGHOOKS_DEF_H).
(langhooks.o): Add $(GGC_H), gt-langhooks.h.
(GTFILES): Add langhooks.c.
(gt-langhooks.h): New.
* c-common.h (c_static_assembler_name): Prototype.
* c-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Define.
* objc/objc-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Define.
* c-opts.c: Include langhooks-def.h.
(c_static_assembler_name): New.
* langhooks.c: Include ggc.h. Include gt-langhooks.h.
(var_labelno): New.
(lhd_set_decl_assembler_name): Give static objects with context
unique names.
* varasm.c (var_labelno): Delete.
(make_decl_rtl): Don't change the assembler name once it's set.
Index: testsuite/ChangeLog
2003-07-17 Geoffrey Keating <geoffk@apple.com>
* gcc.c-torture/compile/mangle-1.c: New file.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1116
diff -u -p -u -p -r1.1116 Makefile.in
--- Makefile.in 14 Jul 2003 05:17:14 -0000 1.1116
+++ Makefile.in 17 Jul 2003 21:30:24 -0000
@@ -1324,7 +1324,8 @@ c-pretty-print.o : c-pretty-print.c c-pr
c-opts.o : c-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
c-pragma.h flags.h toplev.h langhooks.h tree-inline.h diagnostic.h \
- intl.h debug.h $(C_COMMON_H) opts.h options.h $(PARAMS_H)
+ intl.h debug.h $(C_COMMON_H) opts.h options.h $(PARAMS_H) \
+ $(LANGHOOKS_DEF_H)
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
$< $(OUTPUT_OPTION) @TARGET_SYSTEM_ROOT_DEFINE@
@@ -1463,7 +1464,7 @@ convert.o: convert.c $(CONFIG_H) $(SYSTE
langhooks.o : langhooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) toplev.h \
tree-inline.h $(RTL_H) insn-config.h $(INTEGRATE_H) langhooks.h \
- $(LANGHOOKS_DEF_H) flags.h
+ $(LANGHOOKS_DEF_H) flags.h $(GGC_H) gt-langhooks.h
tree.o : tree.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) flags.h function.h \
toplev.h $(GGC_H) $(HASHTAB_H) $(TARGET_H) output.h $(TM_P_H) langhooks.h \
real.h gt-tree.h
@@ -2019,7 +2020,7 @@ GTFILES = $(srcdir)/input.h $(srcdir)/co
$(srcdir)/fold-const.c $(srcdir)/function.c \
$(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \
$(srcdir)/profile.c $(srcdir)/ra-build.c $(srcdir)/regclass.c \
- $(srcdir)/reg-stack.c $(srcdir)/cfglayout.c \
+ $(srcdir)/reg-stack.c $(srcdir)/cfglayout.c $(srcdir)/langhooks.c \
$(srcdir)/sdbout.c $(srcdir)/stmt.c $(srcdir)/stor-layout.c \
$(srcdir)/stringpool.c $(srcdir)/tree.c $(srcdir)/varasm.c \
$(out_file) \
@@ -2038,7 +2039,7 @@ gt-expr.h gt-sdbout.h gt-optabs.h gt-bit
gt-dwarf2out.h gt-ra-build.h gt-reg-stack.h gt-dwarf2asm.h \
gt-dbxout.h gt-c-common.h gt-c-decl.h gt-c-parse.h \
gt-c-pragma.h gt-c-objc-common.h gtype-c.h gt-input.h gt-cfglayout.h \
-gt-stringpool.h : s-gtype ; @true
+gt-stringpool.h gt-langhooks.h : s-gtype ; @true
gtyp-gen.h: Makefile
echo "/* This file is machine generated. Do not edit. */" > tmp-gtyp.h
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.190
diff -u -p -u -p -r1.190 c-common.h
--- c-common.h 11 Jul 2003 08:33:02 -0000 1.190
+++ c-common.h 17 Jul 2003 21:30:24 -0000
@@ -894,6 +894,7 @@ extern void check_function_format (int *
extern void set_Wformat (int);
extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
+extern void c_static_assembler_name (tree);
extern void c_common_insert_default_attributes (tree);
extern int c_common_handle_option (size_t code, const char *arg, int value);
extern void c_common_handle_filename (const char *filename);
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.109
diff -u -p -u -p -r1.109 c-lang.c
--- c-lang.c 11 Jul 2003 08:33:03 -0000 1.109
+++ c-lang.c 17 Jul 2003 21:30:25 -0000
@@ -71,6 +71,8 @@ enum c_language_kind c_language = clk_c;
#define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
#undef LANG_HOOKS_STATICP
#define LANG_HOOKS_STATICP c_staticp
+#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
+#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME c_static_assembler_name
#undef LANG_HOOKS_NO_BODY_BLOCKS
#define LANG_HOOKS_NO_BODY_BLOCKS true
#undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 c-opts.c
--- c-opts.c 15 Jul 2003 05:48:15 -0000 1.74
+++ c-opts.c 17 Jul 2003 21:30:25 -0000
@@ -37,6 +37,7 @@ Software Foundation, 59 Temple Place - S
#include "debug.h" /* For debug_hooks. */
#include "opts.h"
#include "options.h"
+#include "langhooks-def.h"
#ifndef DOLLARS_IN_IDENTIFIERS
# define DOLLARS_IN_IDENTIFIERS true
@@ -1249,6 +1251,22 @@ c_common_finish (void)
fatal_error ("when writing output to %s: %m", out_fname);
}
+/* A wrapper around lhd_set_decl_assembler_name that gives static
+ variables their C names if they are at the top level and only one
+ translation unit is being compiled, for backwards compatibility
+ with certain bizzare assembler hacks (like crtstuff.c). */
+
+void
+c_static_assembler_name (tree decl)
+{
+ if (num_in_fnames == 1
+ && TREE_STATIC (decl) && !TREE_PUBLIC (decl) && DECL_CONTEXT (decl)
+ && TREE_CODE (DECL_CONTEXT (decl)) == TRANSLATION_UNIT_DECL)
+ SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
+ else
+ lhd_set_decl_assembler_name (decl);
+}
+
/* Either of two environment variables can specify output of
dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
Index: langhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.c,v
retrieving revision 1.45
diff -u -p -u -p -r1.45 langhooks.c
--- langhooks.c 6 Jul 2003 09:56:04 -0000 1.45
+++ langhooks.c 17 Jul 2003 21:30:25 -0000
@@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. */
#include "flags.h"
#include "langhooks.h"
#include "langhooks-def.h"
+#include "ggc.h"
/* Do nothing; in many cases the default hook. */
@@ -136,6 +137,11 @@ lhd_warn_unused_global_decl (tree decl)
return true;
}
+/* Number for making the label on the next
+ static variable internal to a function. */
+
+static GTY(()) int var_labelno;
+
/* Set the DECL_ASSEMBLER_NAME for DECL. */
void
lhd_set_decl_assembler_name (tree decl)
@@ -149,12 +155,28 @@ lhd_set_decl_assembler_name (tree decl)
&& (TREE_STATIC (decl)
|| DECL_EXTERNAL (decl)
|| TREE_PUBLIC (decl))))
- /* By default, assume the name to use in assembly code is the
- same as that used in the source language. (That's correct
- for C, and GCC used to set DECL_ASSEMBLER_NAME to the same
- value as DECL_NAME in build_decl, so this choice provides
- backwards compatibility with existing front-ends. */
- SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
+ {
+ /* By default, assume the name to use in assembly code is the
+ same as that used in the source language. (That's correct
+ for C, and GCC used to set DECL_ASSEMBLER_NAME to the same
+ value as DECL_NAME in build_decl, so this choice provides
+ backwards compatibility with existing front-ends.
+
+ Can't use just the variable's own name for a variable whose
+ scope is less than the whole compilation. Concatenate a
+ distinguishing number. */
+ if (!TREE_PUBLIC (decl) && DECL_CONTEXT (decl))
+ {
+ const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
+ char *label;
+
+ ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
+ var_labelno++;
+ SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
+ }
+ else
+ SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
+ }
else
/* Nobody should ever be asking for the DECL_ASSEMBLER_NAME of
these DECLs -- unless they're in language-dependent code, in
@@ -456,3 +478,5 @@ write_global_declarations (void)
/* Clean up. */
free (vec);
}
+
+#include "gt-langhooks.h"
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.372
diff -u -p -u -p -r1.372 varasm.c
--- varasm.c 11 Jul 2003 21:20:18 -0000 1.372
+++ varasm.c 17 Jul 2003 21:30:28 -0000
@@ -114,11 +114,6 @@ struct varasm_status GTY(())
static GTY(()) int const_labelno;
-/* Number for making the label on the next
- static variable internal to a function. */
-
-static GTY(()) int var_labelno;
-
/* Carry information from ASM_DECLARE_OBJECT_NAME
to ASM_FINISH_DECLARE_OBJECT. */
@@ -750,11 +745,7 @@ decode_reg_name (const char *asmspec)
void
make_decl_rtl (tree decl, const char *asmspec)
{
- int top_level = (DECL_CONTEXT (decl) == NULL_TREE
- || (TREE_CODE (DECL_CONTEXT (decl))
- == TRANSLATION_UNIT_DECL));
const char *name = 0;
- const char *new_name = 0;
int reg_number;
rtx x;
@@ -794,8 +785,6 @@ make_decl_rtl (tree decl, const char *as
return;
}
- new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
-
reg_number = decode_reg_name (asmspec);
if (reg_number == -2)
{
@@ -804,9 +793,11 @@ make_decl_rtl (tree decl, const char *as
char *starred = alloca (strlen (asmspec) + 2);
starred[0] = '*';
strcpy (starred + 1, asmspec);
- new_name = starred;
+ SET_DECL_ASSEMBLER_NAME (decl, get_identifier (starred));
}
+ name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+
if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
{
/* First detect errors in declaring global registers. */
@@ -877,28 +868,6 @@ make_decl_rtl (tree decl, const char *as
/* Variables can't be both common and weak. */
if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
DECL_COMMON (decl) = 0;
-
- /* Can't use just the variable's own name for a variable
- whose scope is less than the whole file, unless it's a member
- of a local class (which will already be unambiguous).
- Concatenate a distinguishing number. */
- if (!top_level && !TREE_PUBLIC (decl)
- && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
- && asmspec == 0
- && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
- {
- char *label;
-
- ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
- var_labelno++;
- new_name = label;
- }
-
- if (name != new_name)
- {
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
- name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
- }
x = gen_rtx_SYMBOL_REF (Pmode, name);
SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
Index: objc/objc-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-lang.c,v
retrieving revision 1.34
diff -u -p -u -p -r1.34 objc-lang.c
--- objc/objc-lang.c 9 Jul 2003 14:37:15 -0000 1.34
+++ objc/objc-lang.c 17 Jul 2003 21:30:46 -0000
@@ -69,6 +69,8 @@ enum c_language_kind c_language = clk_ob
#define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
#undef LANG_HOOKS_STATICP
#define LANG_HOOKS_STATICP c_staticp
+#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
+#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME c_static_assembler_name
#undef LANG_HOOKS_NO_BODY_BLOCKS
#define LANG_HOOKS_NO_BODY_BLOCKS true
#undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
Index: testsuite/gcc.c-torture/compile/mangle-1.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/mangle-1.c
diff -N testsuite/gcc.c-torture/compile/mangle-1.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/mangle-1.c 17 Jul 2003 21:31:19 -0000
@@ -0,0 +1,9 @@
+int foo(void)
+{
+ static int x asm ("x") = 3;
+ return x++;
+}
+
+int X2 asm ("x.0") = 4;
+int X3 asm ("_x.0") = 5;
+
============================================================