From patchwork Wed Jun 9 14:46:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bingfeng Mei X-Patchwork-Id: 55100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D0DADB7D59 for ; Thu, 10 Jun 2010 00:47:32 +1000 (EST) Received: (qmail 7635 invoked by alias); 9 Jun 2010 14:47:28 -0000 Received: (qmail 7583 invoked by uid 22791); 9 Jun 2010 14:47:19 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mms2.broadcom.com (HELO mms2.broadcom.com) (216.31.210.18) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Jun 2010 14:47:09 +0000 Received: from [10.16.192.224] by mms2.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Wed, 09 Jun 2010 07:46:58 -0700 X-Server-Uuid: D3C04415-6FA8-4F2C-93C1-920E106A2031 Received: from SJEXCHCCR02.corp.ad.broadcom.com ([10.16.192.130]) by SJEXCHHUB01.corp.ad.broadcom.com ([10.16.192.224]) with mapi; Wed, 9 Jun 2010 07:46:58 -0700 From: "Bingfeng Mei" To: "gcc-patches@gcc.gnu.org" cc: "Richard Guenther" Date: Wed, 9 Jun 2010 07:46:49 -0700 Subject: [PATCH, LTO] add externally_visible attribute when necessary with -fwhole-program and resolution file. Message-ID: <7FB04A5C213E9943A72EE127DB74F0ADA66675B3BB@SJEXCHCCR02.corp.ad.broadcom.com> x-cr-puzzleid: {A645EE86-BF53-40AB-8F3F-82390FA65D13} x-cr-hashedpuzzle: BU2v CvOy D1zp Ex7K FBOL Fz/i HG+X HdRo Iveu J8q1 MAhI MprJ T7Cl VGHk Vrl7 WAaV; 2; ZwBjAGMALQBwAGEAdABjAGgAZQBzAEAAZwBjAGMALgBnAG4AdQAuAG8AcgBnADsAcgBpAGMAaABhAHIAZAAuAGcAdQBlAG4AdABoAGUAcgBAAGcAbQBhAGkAbAAuAGMAbwBtAA==; Sosha1_v1; 7; {A645EE86-BF53-40AB-8F3F-82390FA65D13}; YgBtAGUAaQBAAGIAcgBvAGEAZABjAG8AbQAuAGMAbwBtAA==; Wed, 09 Jun 2010 14:46:49 GMT; WwBQAEEAVABDAEgALAAgAEwAVABPAF0AIABhAGQAZAAgAGUAeAB0AGUAcgBuAGEAbABsAHkAXwB2AGkAcwBpAGIAbABlACAAYQB0AHQAcgBpAGIAdQB0AGUAIAB3AGgAZQBuACAAbgBlAGMAZQBzAHMAYQByAHkAIAB3AGkAdABoACAALQBmAHcAaABvAGwAZQAtAHAAcgBvAGcAcgBhAG0AIABhAG4AZAAgAHIAZQBzAG8AbAB1AHQAaQBvAG4AIABmAGkAbABlAC4A MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 #include 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 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 * 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. */