This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch for irix .globl directives
Roger Sayle <roger@eyesopen.com> writes:
> I'm not sure that this is correct. I suspect that in addition to the
> test for DECL_BUILT_IN, you also need the equivalent of builtin.c's
> CALLED_AS_BUILT_IN. This is because both "sqrt" and "__builtin_sqrt"
> are marked as builtins, but you want to output the external for sqrt.
>
> In fact, we probably want to emit an external for "sqrt" in both cases,
> checking DECL_ASSEMBLER_NAME_SET_P, which will be false for built-ins
> that don't have a library presence, and the name of the library routine
> to call otherwise.
>
> I also think we should move that logic into the machine independent
> parts of the code, rather than bury in ASM_OUTPUT_EXTERNAL.
OK, here's a patch to do that. It adds a new helper function to
varasm.c since the condition seems a bit too complex to check in-line.
The function is based on the builtins.c test that you mention, checking
both for alloca() and for any builtin function whose assembler name
starts with "__builtin_".
There's also the question of what should be done with target-specific
builtins. I just left them alone on the basis that the backend should
know whether they need any declarations. The MIPS port doesn't have
any anyway.
Bootstrapped on mips-sgi-irix6.5. Tested gcc, g77 and objc for o32, no
regressions compared to the previous patch (so the earlier g77 and objc
execution failures stay fixed). I checked that uses of __builtin_cos()
would still cause cos to be declared, and so on. OK to install?
Richard
* varasm.c (incorporeal_function_p): New.
(assemble_external): Use it as a filter.
* config/mips/mips.c (mips_output_external): Don't check for builtin
functions here.
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.398
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.398 varasm.c
*** varasm.c 13 Nov 2003 02:07:52 -0000 1.398
--- varasm.c 6 Dec 2003 14:42:22 -0000
*************** static HOST_WIDE_INT const_alias_set;
*** 137,142 ****
--- 137,145 ----
static const char *strip_reg_name (const char *);
static int contains_pointers_p (tree);
+ #ifdef ASM_OUTPUT_EXTERNAL
+ static bool incorporeal_function_p (tree);
+ #endif
static void decode_addr_const (tree, struct addr_const *);
static hashval_t const_desc_hash (const void *);
static int const_desc_eq (const void *, const void *);
*************** contains_pointers_p (tree type)
*** 1599,1604 ****
--- 1602,1630 ----
}
}
+ #ifdef ASM_OUTPUT_EXTERNAL
+ /* True if DECL is a function decl for which no out-of-line copy exists.
+ It is assumed that DECL's assembler name has been set. */
+
+ static bool
+ incorporeal_function_p (tree decl)
+ {
+ if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
+ {
+ const char *name;
+
+ if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
+ && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
+ return true;
+
+ name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+ if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
+ return true;
+ }
+ return false;
+ }
+ #endif
+
/* Output something to declare an external symbol to the assembler.
(Most assemblers don't need this, so we normally output nothing.)
Do nothing if DECL is not external. */
*************** assemble_external (tree decl ATTRIBUTE_U
*** 1619,1625 ****
rtx rtl = DECL_RTL (decl);
if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
! && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
{
/* Some systems do require some output. */
SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
--- 1645,1652 ----
rtx rtl = DECL_RTL (decl);
if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
! && !SYMBOL_REF_USED (XEXP (rtl, 0))
! && !incorporeal_function_p (decl))
{
/* Some systems do require some output. */
SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
Index: config/mips/mips.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.c,v
retrieving revision 1.347
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.347 mips.c
--- config/mips/mips.c 2 Dec 2003 22:30:28 -0000 1.347
+++ config/mips/mips.c 3 Dec 2003 22:12:08 -0000
@@ -5564,9 +5564,7 @@ mips_output_external (FILE *file ATTRIBU
extern_head = p;
}
- if (TARGET_IRIX && mips_abi == ABI_32
- && TREE_CODE (decl) == FUNCTION_DECL
- && !DECL_BUILT_IN (decl))
+ if (TARGET_IRIX && mips_abi == ABI_32 && TREE_CODE (decl) == FUNCTION_DECL)
{
p = (struct extern_list *) ggc_alloc (sizeof (struct extern_list));
p->next = extern_head;