From patchwork Mon Jan 30 00:08:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 138486 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 A99AFB6F9B for ; Mon, 30 Jan 2012 11:11:05 +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=1328487066; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=JuMRRbbFHkr8SnQEwLW1lXMCcg0=; b=RGjMZNvrHFSeRvK R9YUnUcIC0j/D3uVhdcnFWvnesNKa05SOfLCwr1t08kbZ9BA4GjM+H96eUF+EQb4 QT2w39qAQiRVw0NSeMfV8x9Nfom7Jn1Z1UkANe4JG3U4r9qckKMY4hV/+DPd02fd +iRI+Bw+E/Gp2xcyqpGWrAm6GsZA= 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:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=KJ1nLObgNkDeH2nt/+n04DD0FuG/JUqLoMrmDmGIPu6Ad8+N0v5VWjaz3sy5TO FWrFq/FFC/STbPJUGV+dcE/HrAtsnwBs9d+/Yf4Aym6tIBdH8hzIcsBCH1Be1Wv3 UpbgG08qEF3njdZvqfRDsvOfiphoV3kEkCAyrJftp8xAc=; Received: (qmail 23287 invoked by alias); 30 Jan 2012 00:10:59 -0000 Received: (qmail 23266 invoked by uid 22791); 30 Jan 2012 00:10:44 -0000 X-SWARE-Spam-Status: No, hits=-0.0 required=5.0 tests=AWL, BAYES_00, FROM_12LTRDOM, TW_CP, TW_RG X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 30 Jan 2012 00:10:30 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1RrepJ-0007j6-LQ from Sandra_Loosemore@mentor.com ; Sun, 29 Jan 2012 16:10:29 -0800 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Sun, 29 Jan 2012 16:10:15 -0800 Received: from [IPv6:::1] (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.1.289.1; Sun, 29 Jan 2012 16:10:28 -0800 Message-ID: <4F25DF6A.3060608@codesourcery.com> Date: Sun, 29 Jan 2012 17:08:10 -0700 From: Sandra Loosemore User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: CC: Jason Merrill , Jakub Jelinek Subject: [PATCH] Fix PR 51910, -frepo/linker demangling interaction 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 [Ooops, resending to include the attachment, this time....] As discussed in PR c++/51910, my patch from last summer http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01368.html to make HAVE_LD_DEMANGLE the default when using GNU ld exposed a bug in collect2's link-time -frepo handling -- it depends on the linker passing back mangled names of undefined symbols to collect2. This patch fixes that by explicitly adding --no-demangle to the options passed to the linker in the repository-processing loop. Then the original settings are restored for the final link, so that (for instance) if the user requested a map file or if there are messages for real link errors, they respect the user-specified demangling options. This patch therefore adds two extra link steps to the case where HAVE_LD_DEMANGLE is defined, there is repository information, and recompilation is necessary to resolve undefined symbols from the repository. In other cases it adds no overhead. Bootstrapped and regression-tested on i636 linux. OK to check in? -Sandra 2012-01-29 Sandra Loosemore Jason Merrill Jakub Jelinek PR c++/51910 gcc/ * tlink.c (do_tlink): Explicitly pass --no-demangle to linker for repo processing when HAVE_LD_DEMANGLE is defined. gcc/testsuite/ * g++.dg/torture/pr51910.C: New testcase. Index: gcc/tlink.c =================================================================== --- gcc/tlink.c (revision 183674) +++ gcc/tlink.c (working copy) @@ -777,23 +777,53 @@ do_tlink (char **ld_argv, char **object_ /* Until collect does a better job of figuring out which are object files, assume that everything on the command line could be. */ if (read_repo_files (ld_argv)) - while (exit && i++ < MAX_ITERATIONS) - { - if (tlink_verbose >= 3) - { - dump_file (ldout, stdout); - dump_file (lderrout, stderr); - } - demangle_new_symbols (); - if (! scan_linker_output (ldout) - && ! scan_linker_output (lderrout)) - break; - if (! recompile_files ()) - break; - if (tlink_verbose) - fprintf (stderr, _("collect: relinking\n")); - exit = tlink_execute ("ld", ld_argv, ldout, lderrout); - } + { + char **ld1_argv = ld_argv; + +#ifdef HAVE_LD_DEMANGLE + /* We must explicitly tell the linker not to demangle names + and re-do the initial link attempt, since repository processing + requires demangled error output from the linker. */ + int argc = 0; + while (ld_argv[argc]) + ++argc; + ld1_argv = XNEWVEC (char *, argc + 2); + memcpy (ld1_argv, ld_argv, sizeof (ld_argv[0]) * argc); + ld1_argv[argc] = CONST_CAST (char *, "--no-demangle"); + ld1_argv[argc + 1] = NULL; + if (tlink_verbose) + fprintf (stderr, _("collect: relinking\n")); + exit = tlink_execute ("ld", ld1_argv, ldout, lderrout); +#endif + + while (exit && i++ < MAX_ITERATIONS) + { + if (tlink_verbose >= 3) + { + dump_file (ldout, stdout); + dump_file (lderrout, stderr); + } + demangle_new_symbols (); + if (! scan_linker_output (ldout) + && ! scan_linker_output (lderrout)) + break; + if (! recompile_files ()) + break; + if (tlink_verbose) + fprintf (stderr, _("collect: relinking\n")); + exit = tlink_execute ("ld", ld1_argv, ldout, lderrout); + } + +#ifdef HAVE_LD_DEMANGLE + /* Now redo the final link with the original options so that + any remaining errors, the link map, etc are presented to + the user with the original mangling options.*/ + XDELETEVEC (ld1_argv); + if (tlink_verbose) + fprintf (stderr, _("collect: relinking\n")); + exit = tlink_execute ("ld", ld_argv, ldout, lderrout); +#endif + } } dump_file (ldout, stdout); Index: gcc/testsuite/g++.dg/torture/pr51910.C =================================================================== --- gcc/testsuite/g++.dg/torture/pr51910.C (revision 0) +++ gcc/testsuite/g++.dg/torture/pr51910.C (revision 0) @@ -0,0 +1,19 @@ +// PR c++/51910 +// Check that -frepo works in the presence of linker symbol demangling. +// +// { dg-options "-frepo -Wl,--demangle" } +// { dg-require-host-local "" } +// { dg-skip-if "dkms are not final links" { vxworks_kernel } } + +template +struct Foo +{ + virtual ~Foo() { } +}; + +int main( int, char*[] ) +{ + Foo test; +} + +// { dg-final { cleanup-repo-files } }