From patchwork Thu Nov 22 14:45:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 201055 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 AF4262C008F for ; Fri, 23 Nov 2012 01:45:54 +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=1354200356; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type:Content-Disposition:User-Agent:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=11jfx+IryBbvx5pOjxDvfsc+X88=; b=Dz3+6Qbf5sWEetiNKnjmETzM3RqHZsIobYAw941X0KzWGxrxA/tvHzDjBR5gN7 64hI4nRsxwUxlCp5S3Aj9ZY2HuLFSrUjo0aKT8Z+sm0vPs+BOpXrUxcOZK32sVCv eXx21SslE6zg/LQkArcs+K99+KL4Qb9BCU8+AbRCjFOEU= 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:Received:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=w90/APE79j47qkEcJ0M8GNHrg9Ya8+rNdc3zZ96p8B1QJOQLZ4roWMSALP2Ssz aHszLaQ00Nl2ojI7Mgt2YySuRvVBA/GKkQtldwzV9j6yhC25hpU8mSY7do6unspU uQUCS/zSuavLEQWUMqmCIKMZEEECIPQwyJAig2RAwd9qs=; Received: (qmail 28859 invoked by alias); 22 Nov 2012 14:45:50 -0000 Received: (qmail 28851 invoked by uid 22791); 22 Nov 2012 14:45:50 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-ie0-f175.google.com (HELO mail-ie0-f175.google.com) (209.85.223.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Nov 2012 14:45:44 +0000 Received: by mail-ie0-f175.google.com with SMTP id qd14so6806782ieb.20 for ; Thu, 22 Nov 2012 06:45:43 -0800 (PST) Received: by 10.50.104.232 with SMTP id gh8mr3504724igb.45.1353595543768; Thu, 22 Nov 2012 06:45:43 -0800 (PST) Received: from gnu-tools-1.localdomain (76-220-57-190.lightspeed.sntcca.sbcglobal.net. [76.220.57.190]) by mx.google.com with ESMTPS id yf6sm2378835igb.0.2012.11.22.06.45.42 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Nov 2012 06:45:43 -0800 (PST) Received: by gnu-tools-1.localdomain (Postfix, from userid 1000) id 2657E1A1224; Thu, 22 Nov 2012 06:45:41 -0800 (PST) Date: Thu, 22 Nov 2012 06:45:41 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: PATCH: PR driver/55374: [asan] Wrong linking order of libasan and libstdc++ Message-ID: <20121122144540.GA23841@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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, libasan should come first before any language-specific adjustment/addition. Otherwise, we got g++ -fsanitize=address -static-libasan ... /usr/local/bin/ld: error: /export/build/gnu/gcc-asan/build-x86_64-linux/prev-x86_64-unknown-linux-gnu/libsanitizer/asan/.libs/libasan.a(asan_new_delete.o): multiple definition of 'operator delete(void*)' /usr/local/bin/ld: /export/build/gnu/gcc-asan/build-x86_64-linux/prev-x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.a(del_op.o): previous definition here This patch adds prepend_lang_specific_driver to prepend command line before language-specific adjustment/addition of flags. OK to install? Thanks. H.J. --- 2012-11-22 H.J. Lu PR driver/55374 * gcc.c (prepend_lang_specific_driver): New function. (process_command): Use it. diff --git a/gcc/gcc.c b/gcc/gcc.c index 0f8bcea..41474aa 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -3604,6 +3604,80 @@ set_option_handlers (struct cl_option_handlers *handlers) handlers->handlers[2].mask = CL_TARGET; } +/* Prepend command line before language-specific adjustment/addition of + flags. */ + +void +prepend_lang_specific_driver (struct cl_decoded_option **in_decoded_options, + unsigned int *in_decoded_options_count, + int *in_added_libraries) +{ + unsigned int i, argc; + + /* The new argument list will be contained in this. */ + struct cl_decoded_option *new_decoded_options; + + /* The argument list. */ + struct cl_decoded_option *decoded_options; + + bool add_libasan = false; + bool static_libasan = false; + + argc = *in_decoded_options_count; + decoded_options = *in_decoded_options; + + for (i = 1; i < argc; i++) + switch (decoded_options[i].opt_index) + { + case OPT_fsanitize_address: + add_libasan = true; + break; + case OPT_static_libasan: + static_libasan = true; + break; + } + + if (add_libasan) + { + /* Add -lasan before language-specific adjustment/addition. */ + unsigned int added_argc; + + added_argc = 1; +#ifdef HAVE_LD_STATIC_DYNAMIC + if (static_libasan) + added_argc += 2; +#endif + + new_decoded_options = XNEWVEC (struct cl_decoded_option, + argc + added_argc); + + i = 0; + do + { + new_decoded_options[i] = decoded_options[i]; + i++; + } + while (i < argc); + +#ifdef HAVE_LD_STATIC_DYNAMIC + if (static_libasan) + generate_option (OPT_Wl_, LD_STATIC_OPTION, 1, CL_DRIVER, + &new_decoded_options[i++]); +#endif + generate_option (OPT_l, "asan", 1, CL_DRIVER, + &new_decoded_options[i++]); +#ifdef HAVE_LD_STATIC_DYNAMIC + if (static_libasan) + generate_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1, CL_DRIVER, + &new_decoded_options[i++]); +#endif + + *in_decoded_options_count = i; + *in_decoded_options = new_decoded_options; + *in_added_libraries = 1; + } +} + /* Create the vector `switches' and its contents. Store its length in `n_switches'. */ @@ -3695,6 +3769,11 @@ process_command (unsigned int decoded_options_count, or an automatically created GCC_EXEC_PREFIX from decoded_options[0].arg. */ + /* Prepend command line before language-specific adjustment/addition of + flags. */ + prepend_lang_specific_driver (&decoded_options, &decoded_options_count, + &added_libraries); + /* Do language-specific adjustment/addition of flags. */ lang_specific_driver (&decoded_options, &decoded_options_count, &added_libraries);