public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [lto][patch] Fix an undefined reference error
@ 2009-03-19 15:20 Rafael Espindola
  2009-03-19 15:32 ` Diego Novillo
  0 siblings, 1 reply; 2+ messages in thread
From: Rafael Espindola @ 2009-03-19 15:20 UTC (permalink / raw)
  To: GCC Patches; +Cc: Diego Novillo

[-- Attachment #1: Type: text/plain, Size: 906 bytes --]

When using the plugin and statically linking libc, things like

extern int printf (__const char *__restrict __format, ...);
int main(void) {
  printf("%s\n", "");
  return 0;
}

would produce undefined references. The problems is that this
is transformed to __builtin_puts and we don't add functions
starting with __builtin_ to the IL symbol table.

This patch fixes the problem by using the assembler name.
The assembler name of __builtin_puts is just puts.

2009-03-19  Rafael Avila de Espindola  <espindola@google.com>

	* builtins.c (is_builtin_name): New.
	(called_as_built_in): Use is_builtin_name.
	Make it static.
	* tree.h (is_builtin_name): New.
	(called_as_built_in): Remove.
	* varasm.c (incorporeal_function_p):
	Use is_builtin_name.

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

[-- Attachment #2: fix.patch --]
[-- Type: text/x-diff, Size: 2833 bytes --]

diff --git a/gcc/builtins.c b/gcc/builtins.c
index a29e8e8..ededccc 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -241,14 +241,9 @@ static tree do_mpfr_bessel_n (tree, tree, tree,
 static tree do_mpfr_remquo (tree, tree, tree);
 static tree do_mpfr_lgamma_r (tree, tree, tree);
 
-/* Return true if NODE should be considered for inline expansion regardless
-   of the optimization level.  This means whenever a function is invoked with
-   its "internal" name, which normally contains the prefix "__builtin".  */
-
 bool
-called_as_built_in (tree node)
+is_builtin_name (const char *name)
 {
-  const char *name = IDENTIFIER_POINTER (DECL_NAME (node));
   if (strncmp (name, "__builtin_", 10) == 0)
     return true;
   if (strncmp (name, "__sync_", 7) == 0)
@@ -256,6 +251,20 @@ called_as_built_in (tree node)
   return false;
 }
 
+/* Return true if NODE should be considered for inline expansion regardless
+   of the optimization level.  This means whenever a function is invoked with
+   its "internal" name, which normally contains the prefix "__builtin".  */
+
+static bool
+called_as_built_in (tree node)
+{
+  /* Note that we must use DECL_NAME, not DECL_ASSEMBLER_NAME_SET_P since
+     we want the name used to call the function, not the name it
+     will have. */
+  const char *name = IDENTIFIER_POINTER (DECL_NAME (node));
+  return is_builtin_name (name);
+}
+
 /* Return the alignment in bits of EXP, an object.
    Don't return more than MAX_ALIGN no matter what, ALIGN is the inital
    guessed alignment e.g. from type alignment.  */
diff --git a/gcc/tree.h b/gcc/tree.h
index e241fa9..4276b5b 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4924,7 +4924,7 @@ extern tree build_string_literal (int, const char *);
 extern bool validate_arglist (const_tree, ...);
 extern rtx builtin_memset_read_str (void *, HOST_WIDE_INT, enum machine_mode);
 extern int get_pointer_alignment (tree, unsigned int);
-extern bool called_as_built_in (tree);
+extern bool is_builtin_name(const char*);
 extern int get_object_alignment (tree, unsigned int, unsigned int);
 extern tree fold_call_stmt (gimple, bool);
 extern tree gimple_fold_builtin_snprintf_chk (gimple, tree, enum built_in_function);
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 1536355..6d9d018 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -2249,11 +2249,16 @@ 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;
 
-      if (called_as_built_in (decl))
+      gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
+      name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+
+      if (is_builtin_name (name))
 	return true;
     }
   return false;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [lto][patch] Fix an undefined reference error
  2009-03-19 15:20 [lto][patch] Fix an undefined reference error Rafael Espindola
@ 2009-03-19 15:32 ` Diego Novillo
  0 siblings, 0 replies; 2+ messages in thread
From: Diego Novillo @ 2009-03-19 15:32 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: GCC Patches

On Thu, Mar 19, 2009 at 10:51, Rafael Espindola <espindola@google.com> wrote:

> 2009-03-19  Rafael Avila de Espindola  <espindola@google.com>
>
>        * builtins.c (is_builtin_name): New.
>        (called_as_built_in): Use is_builtin_name.
>        Make it static.
>        * tree.h (is_builtin_name): New.
>        (called_as_built_in): Remove.
>        * varasm.c (incorporeal_function_p):
>        Use is_builtin_name.

OK.


Diego.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-03-19 15:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-19 15:20 [lto][patch] Fix an undefined reference error Rafael Espindola
2009-03-19 15:32 ` Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).