From patchwork Wed Feb 8 09:41:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 140098 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 8E80BB71A8 for ; Wed, 8 Feb 2012 20:41:34 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1329298899; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=3qUp5NmiBHZhTbyyvaSz3LlY0eU=; b=olzKpfSP6OXAf6Jz4u67J6JShwTBTEYIh4p4xnJvIlBeN2H4f/HtRBG5LMfOBk +yPqC1xjXnmaS3DvmS3Dp6D7WWKjEufpd4CbfLZx4h7A2td1HR/0DsujpadiUILk iEWQrbB2j/u6Mw1ZhvwN4TtFfOyByOiQK2nNJFOcX9nro= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=UON7G3Eh/SjU76RebcHSNAM2UyJqdXRxDNEYTgcH8ieXWjvRXzcumo3innWW+p tP286AxefIZsex9ONZZwZgV/A00IwuGDrGHx4C3NMxjm8SZ9esG783qMM5Xvyjuf p1ePUZnXJI5zBsu3HUhAOLVC0XlDXULdiQUP5WvapUdBE=; Received: (qmail 24262 invoked by alias); 8 Feb 2012 09:41:30 -0000 Received: (qmail 24252 invoked by uid 22791); 8 Feb 2012 09:41:29 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Feb 2012 09:41:10 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q189f7vv026096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 8 Feb 2012 04:41:07 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q189f6Pn021033; Wed, 8 Feb 2012 04:41:07 -0500 Received: from [0.0.0.0] (ovpn-113-40.phx2.redhat.com [10.3.113.40]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q189f3xC018335; Wed, 8 Feb 2012 04:41:04 -0500 Message-ID: <4F32432F.4040503@redhat.com> Date: Tue, 07 Feb 2012 23:41:03 -1000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20120131 Thunderbird/10.0 MIME-Version: 1.0 To: Jakub Jelinek CC: Sandra Loosemore , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] fix PR51910, take 2 References: <4F2B5E4A.50401@codesourcery.com> <20120203092717.GC18768@tyan-ft48-01.lab.bos.redhat.com> In-Reply-To: <20120203092717.GC18768@tyan-ft48-01.lab.bos.redhat.com> 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 On 02/02/2012 11:27 PM, Jakub Jelinek wrote: > Anyway, here is the tweaking all the symbols that demangle the same > equally patch (untested so far) as an alternative. On the example it > unfortunately causes also the D2 dtor into the link which wasn't there > otherwise (and with -Wl,--no-demangle). While D2 dtors are generally small, > perhaps it will sometimes force into the link also ctor or dtor variants > that couldn't be aliased together. Hmm, I wrote up something quite similar on the plane. One difference is that mine synchronizes .rpo files that start with some variants chosen and others not. Does this make sense to you? > I wonder if it wouldn't be better to just use a linker plugin for -frepo > if the linker supports plugins. Probably. But I don't feel motivated to write it. Jason commit 1f4b0d273cfd81948762d3922cdafac40a06a2cf Author: Jason Merrill Date: Thu Feb 2 00:07:44 2012 -0500 PR c++/51910 * tlink.c (demangled_hash_entry): Change mangled to a VEC. (demangle_new_symbols): Fill it. (scan_linker_output): Walk it. (start_tweaking): Split out from scan_linker_output. (maybe_tweak): Update sym->chosen. * Makefile.in (COLLECT2_OBJS): Add vec.o and gcc-none.o diff --git a/gcc/Makefile.in b/gcc/Makefile.in index c9ecc4b..486538d 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1946,7 +1946,7 @@ gcc-ranlib.c: gcc-ar.c gcc-nm.c: gcc-ar.c cp $^ $@ -COLLECT2_OBJS = collect2.o collect2-aix.o tlink.o +COLLECT2_OBJS = collect2.o collect2-aix.o tlink.o vec.o ggc-none.o COLLECT2_LIBS = @COLLECT2_LIBS@ collect2$(exeext): $(COLLECT2_OBJS) $(LIBDEPS) # Don't try modifying collect2 (aka ld) in place--it might be linking this. diff --git a/gcc/testsuite/g++.dg/template/repo10.C b/gcc/testsuite/g++.dg/template/repo10.C new file mode 100644 index 0000000..c92f7a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/repo10.C @@ -0,0 +1,16 @@ +// PR c++/51910 +// { dg-options -frepo } +// { dg-require-host-local "" } +// { dg-skip-if "dkms are not final links" { vxworks_kernel } } +// { dg-final cleanup-repo-files } + +template +struct Foo +{ + virtual ~Foo() { } +}; + +int main( int, char*[] ) +{ + Foo test; +} diff --git a/gcc/tlink.c b/gcc/tlink.c index f054047..67c7086 100644 --- a/gcc/tlink.c +++ b/gcc/tlink.c @@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "collect2.h" #include "filenames.h" #include "diagnostic-core.h" +#include "vec.h" /* TARGET_64BIT may be defined to use driver specific functionality. */ #undef TARGET_64BIT @@ -67,10 +68,14 @@ typedef struct file_hash_entry int tweaking; } file; +typedef const char *str; +DEF_VEC_P(str); +DEF_VEC_ALLOC_P(str,heap); + typedef struct demangled_hash_entry { const char *key; - const char *mangled; + VEC(str,heap) *mangled; } demangled; /* Hash and comparison functions for these hash tables. */ @@ -435,9 +440,15 @@ maybe_tweak (char *line, file *f) sym->tweaked = 1; if (line[0] == 'O') - line[0] = 'C'; + { + line[0] = 'C'; + sym->chosen = 1; + } else - line[0] = 'O'; + { + line[0] = 'O'; + sym->chosen = 0; + } } } @@ -598,10 +609,34 @@ demangle_new_symbols (void) continue; dem = demangled_hash_lookup (p, true); - dem->mangled = sym->key; + VEC_safe_push (str, heap, dem->mangled, sym->key); } } +/* We want to tweak symbol SYM. Return true if all is well, false on + error. */ + +static bool +start_tweaking (symbol *sym) +{ + if (sym && sym->tweaked) + { + error ("'%s' was assigned to '%s', but was not defined " + "during recompilation, or vice versa", + sym->key, sym->file->key); + return 0; + } + if (sym && !sym->tweaking) + { + if (tlink_verbose >= 2) + fprintf (stderr, _("collect: tweaking %s in %s\n"), + sym->key, sym->file->key); + sym->tweaking = 1; + file_push (sym->file); + } + return true; +} + /* Step through the output of the linker, in the file named FNAME, and adjust the settings for each symbol encountered. */ @@ -616,8 +651,11 @@ scan_linker_output (const char *fname) { char *p = line, *q; symbol *sym; + demangled *dem = 0; int end; int ok = 0; + unsigned ix; + str s; /* On darwin9, we might have to skip " in " lines as well. */ if (skip_next_in_line @@ -662,7 +700,6 @@ scan_linker_output (const char *fname) /* Try a mangled name in quotes. */ { char *oldq = q + 1; - demangled *dem = 0; q = 0; /* On darwin9, we look for "foo" referenced from:\n\(.* in .*\n\)* */ @@ -718,9 +755,7 @@ scan_linker_output (const char *fname) { *q = 0; dem = demangled_hash_lookup (p, false); - if (dem) - sym = symbol_hash_lookup (dem->mangled, false); - else + if (!dem) { if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX))) @@ -730,24 +765,43 @@ scan_linker_output (const char *fname) } } - if (sym && sym->tweaked) + if (dem) + { + /* We found a demangled name. If this is the name of a + constructor or destructor, there can be several mangled names + that match it, so choose or unchoose all of them. If some are + chosen and some not, leave the later ones that don't match + alone for now; either this will cause the link to suceed, or + on the next attempt we will switch all of them the other way + and that will cause it to succeed. */ + int chosen = 0; + int len = VEC_length (str, dem->mangled); + ok = true; + FOR_EACH_VEC_ELT (str, dem->mangled, ix, s) + { + sym = symbol_hash_lookup (s, false); + if (ix == 0) + chosen = sym->chosen; + else if (sym->chosen != chosen) + /* Mismatch. */ + continue; + /* Avoid an error about re-tweaking when we guess wrong in + the case of mismatch. */ + if (len > 1) + sym->tweaked = false; + ok = start_tweaking (sym); + } + } + else + ok = start_tweaking (sym); + + obstack_free (&temporary_obstack, temporary_firstobj); + + if (!ok) { - error ("'%s' was assigned to '%s', but was not defined " - "during recompilation, or vice versa", - sym->key, sym->file->key); fclose (stream); return 0; } - if (sym && !sym->tweaking) - { - if (tlink_verbose >= 2) - fprintf (stderr, _("collect: tweaking %s in %s\n"), - sym->key, sym->file->key); - sym->tweaking = 1; - file_push (sym->file); - } - - obstack_free (&temporary_obstack, temporary_firstobj); } fclose (stream);