This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
More Mach-O workarounds
- From: Geoffrey Keating <gkeating at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 26 Jul 2003 18:46:31 -0700 (PDT)
- Subject: More Mach-O workarounds
In a previous message, I discussed Mach-O. One of its other
problems is that it doesn't support zero-sized objects.
I'd have liked to make the new macro a hook, but then you'd have had
two of the three being a macro and the other a hook. To make them all
hooks is, unfortunately, longer than I could spend on this problem---I
could have done it, but wouldn't have had time to test it on all the
affected platforms.
Bootstrapped & tested on powerpc-darwin.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/gcc-zerosizevar.patch=====================
2003-07-26 Geoffrey Keating <geoffk@apple.com>
* varasm.c (output_constant_def_contents): Use
ASM_DECLARE_CONSTANT_NAME if defined.
* doc/tm.texi (Label Output): Document ASM_DECLARE_CONSTANT_NAME.
* config/darwin.h (ASM_DECLARE_OBJECT_NAME): Ensure zero-sized
objects get at least one byte to prevent assembler problems.
(ASM_DECLARE_CONSTANT_NAME): New.
Index: testsuite/ChangeLog
2003-07-26 Geoffrey Keating <geoffk@apple.com>
* gcc.c-torture/compile/zero-strct-2.c: New test.
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.376
diff -u -p -u -p -r1.376 varasm.c
--- varasm.c 25 Jul 2003 09:52:26 -0000 1.376
+++ varasm.c 27 Jul 2003 01:37:44 -0000
@@ -2547,6 +2547,7 @@ output_constant_def_contents (rtx symbol
{
tree exp = SYMBOL_REF_DECL (symbol);
const char *label = XSTR (symbol, 0);
+ HOST_WIDE_INT size;
/* Make sure any other constants whose addresses appear in EXP
are assigned label numbers. */
@@ -2571,17 +2572,20 @@ output_constant_def_contents (rtx symbol
ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
}
- /* Output the label itself. */
+ size = int_size_in_bytes (TREE_TYPE (exp));
+ if (TREE_CODE (exp) == STRING_CST)
+ size = MAX (TREE_STRING_LENGTH (exp), size);
+
+ /* Do any machine/system dependent processing of the constant. */
+#ifdef ASM_DECLARE_CONSTANT_NAME
+ ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
+#else
+ /* Standard thing is just output label for the constant. */
ASM_OUTPUT_LABEL (asm_out_file, label);
+#endif /* ASM_DECLARE_CONSTANT_NAME */
/* Output the value of EXP. */
- output_constant (exp,
- (TREE_CODE (exp) == STRING_CST
- ? MAX (TREE_STRING_LENGTH (exp),
- int_size_in_bytes (TREE_TYPE (exp)))
- : int_size_in_bytes (TREE_TYPE (exp))),
- align);
-
+ output_constant (exp, size, align);
}
/* A constant which was deferred in its original location has been
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.249
diff -u -p -u -p -r1.249 tm.texi
--- doc/tm.texi 20 Jul 2003 16:29:57 -0000 1.249
+++ doc/tm.texi 27 Jul 2003 01:37:46 -0000
@@ -6634,6 +6634,22 @@ You may wish to use @code{ASM_OUTPUT_TYP
@code{ASM_OUTPUT_SIZE_DIRECTIVE} in the definition of this macro.
@end defmac
+@defmac ASM_DECLARE_CONSTANT_NAME (@var{stream}, @var{name}, @var{exp}, @var{size})
+A C statement (sans semicolon) to output to the stdio stream
+@var{stream} any text necessary for declaring the name @var{name} of a
+constant which is being defined. This macro is responsible for
+outputting the label definition (perhaps using
+@code{ASM_OUTPUT_LABEL}). The argument @var{exp} is the
+value of the constant, and @var{size} is the size of the constant
+in bytes. @var{name} will be an internal label.
+
+If this macro is not defined, then the @var{name} is defined in the
+usual manner as a label (by means of @code{ASM_OUTPUT_LABEL}).
+
+You may wish to use @code{ASM_OUTPUT_TYPE_DIRECTIVE} in the definition
+of this macro.
+@end defmac
+
@defmac ASM_DECLARE_REGISTER_GLOBAL (@var{stream}, @var{decl}, @var{regno}, @var{name})
A C statement (sans semicolon) to output to the stdio stream
@var{stream} any text necessary for claiming a register @var{regno}
Index: config/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.h,v
retrieving revision 1.57
diff -u -p -u -p -r1.57 darwin.h
--- config/darwin.h 16 Jul 2003 19:05:53 -0000 1.57
+++ config/darwin.h 27 Jul 2003 01:37:46 -0000
@@ -356,18 +356,22 @@ do { text_section (); \
#undef ASM_DECLARE_OBJECT_NAME
#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
do { \
- const char *xname = NAME; \
- if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
- xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
- if ((TREE_STATIC (DECL) \
- && (!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)) \
+ const char *xname = NAME; \
+ if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
+ xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
+ if ((TREE_STATIC (DECL) \
+ && (!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)) \
(* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false); \
- ASM_OUTPUT_LABEL (FILE, xname); \
+ ASM_OUTPUT_LABEL (FILE, xname); \
+ /* Darwin doesn't support zero-size objects, so give them a \
+ byte. */ \
+ if (tree_low_cst (DECL_SIZE_UNIT (DECL), 1) == 0) \
+ assemble_zeros (1); \
} while (0)
#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
@@ -387,6 +391,15 @@ do { text_section (); \
/* Avoid generating stubs for functions we've just defined by \
outputting any required stub name label now. */ \
machopic_output_possible_stub_label (FILE, xname); \
+ } while (0)
+
+#define ASM_DECLARE_CONSTANT_NAME(FILE, NAME, EXP, SIZE) \
+ do { \
+ ASM_OUTPUT_LABEL (FILE, NAME); \
+ /* Darwin doesn't support zero-size objects, so give them a \
+ byte. */ \
+ if ((SIZE) == 0) \
+ assemble_zeros (1); \
} while (0)
/* Wrap new method names in quotes so the assembler doesn't gag.
Index: testsuite/gcc.c-torture/compile/zero-strct-2.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/zero-strct-2.c
diff -N testsuite/gcc.c-torture/compile/zero-strct-2.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/zero-strct-2.c 27 Jul 2003 01:37:48 -0000
@@ -0,0 +1,2 @@
+struct { } foo = { };
+void * bar(void) { return &foo; }
============================================================