public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, LTO] add externally_visible attribute when necessary with -fwhole-program and resolution file.
@ 2010-06-09 15:02 Bingfeng Mei
  2010-06-09 15:13 ` Richard Guenther
  0 siblings, 1 reply; 27+ messages in thread
From: Bingfeng Mei @ 2010-06-09 15:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Guenther

Hi, 
This patch addresses issue discussed in 
http://gcc.gnu.org/ml/gcc/2010-05/msg00560.html
http://gcc.gnu.org/ml/gcc/2010-06/msg00317.html

With the patch, any declaration which is resolved as LDPR_PREVAILING_DEF
and compiled with -fwhole-program is annotated with
attribute "externally_visible" if it doesn't exist already. 
This eliminates the error-prone process of manual annotation
of the attribute when compiling mixed LTO/non-LTO applications. 

For the following test files:
a.c

#include <string.h>
#include <stdio.h>
extern int foo(int);
/* Called by b.c, should not be optimized by -fwhole-program */
void bar() 
{
  printf("bar\n");
}  
/* Not used by others, should be optimized out by -fwhole-program*/
void bar2()
{
  printf("bar2\n");
}
extern int src[], dst[];
int vvvvvv;
int main()
{ 
  int ret;
  vvvvvv = 12; 
  ret = foo(20);
  bar2();
  memcpy(dst, src, 100);
  return ret + 3;
}  

b.c

#include <stdio.h>
int src[100];
int dst[100];
extern int vvvvvv;
extern void bar();
int foo(int c)
{
  printf("Hello world: %d\n", c);
  bar();
  return 1000 + vvvvvv;
}

~/work/install-x86/bin/gcc  a.c -O2 -c  -flto
~/work/install-x86/bin/gcc  b.c -O2 -c 
ar cru libb.a b.o
~/work/install-x86/bin/gcc -flto a.o -L. -lb -O2 -fuse-linker-plugin -o f -fwhole-program

The code is compiled and linked correctly. bar & vvvvvv don't become static function
and cause link errors, whereas bar2 is inlined as expected. 


Bootstrapped and tested on x86_64-unknown-linux-gnu.

Cheers,
Bingfeng Mei

2010-06-09  Bingfeng Mei <bmei@broadcom.com>

	* lto-symbtab.c (lto_symtab_resolve_symbols): Add externally_visible
        attribute for declaration of LDPR_PREVAILING_DEF when compiling with
        -fwhole-program
        

Index: lto-symtab.c
===================================================================
--- lto-symtab.c        (revision 160463)
+++ lto-symtab.c        (working copy)
@@ -476,7 +476,19 @@

   /* If the chain is already resolved there is nothing else to do.  */
   if (e->resolution != LDPR_UNKNOWN)
-    return;
+    {
+      /* Add externally_visible attribute for declaration of LDPR_PREVAILING_DEF */
+      if (e->resolution == LDPR_PREVAILING_DEF && flag_whole_program)
+        {
+          if (!lookup_attribute ("externally_visible", DECL_ATTRIBUTES (e->decl)))
+            {
+              DECL_ATTRIBUTES (e->decl)
+                = tree_cons (get_identifier ("externally_visible"), NULL_TREE,
+                             DECL_ATTRIBUTES (e->decl));
+            }
+        }
+      return;
+    }

   /* Find the single non-replaceable prevailing symbol and
      diagnose ODR violations.  */

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

end of thread, other threads:[~2010-06-28 10:44 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-09 15:02 [PATCH, LTO] add externally_visible attribute when necessary with -fwhole-program and resolution file Bingfeng Mei
2010-06-09 15:13 ` Richard Guenther
2010-06-09 15:25   ` Bingfeng Mei
2010-06-09 15:33     ` Richard Guenther
2010-06-09 15:35       ` Bingfeng Mei
2010-06-09 15:32   ` Bingfeng Mei
2010-06-09 15:48     ` Richard Guenther
2010-06-10 10:30       ` Bingfeng Mei
2010-06-10 10:35         ` Richard Guenther
2010-06-10 15:31           ` Bingfeng Mei
2010-06-10 17:07             ` Richard Guenther
2010-06-10 17:10               ` Bingfeng Mei
2010-06-11  9:34                 ` Richard Guenther
2010-06-14 18:58                   ` Cary Coutant
2010-06-14 20:03                     ` Richard Guenther
2010-06-14  9:17       ` Bingfeng Mei
2010-06-14 10:10         ` Richard Guenther
2010-06-14 11:33           ` Bingfeng Mei
2010-06-14 15:36           ` Bingfeng Mei
2010-06-18  9:28           ` PING: " Bingfeng Mei
2010-06-18 16:46             ` Jan Hubicka
2010-06-18 16:56               ` Bingfeng Mei
2010-06-18 17:25                 ` Jan Hubicka
2010-06-21 13:15                   ` Bingfeng Mei
2010-06-28 10:10                   ` Bingfeng Mei
2010-06-28 10:25                     ` Jan Hubicka
2010-06-28 12:22                       ` Committed : " Bingfeng Mei

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).