From patchwork Fri Apr 19 11:57:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Klose X-Patchwork-Id: 237930 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 800B22C0257 for ; Fri, 19 Apr 2013 21:58:09 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=IrSxYRBOjkqo7kvdZsqha5i7oczifvrqEqIyhWdcmg205X Sxh8yk6JkDL/J8NRe9Hnbket90EnKAh15Lp0BpRDsdBCUZnoGfHIBRYwt1pjRk7n 2FbOmQscJ/qVLEPysZ4ZsRo/ets44kGa1NYvu5EjIIa7i5lpjp0QfmUNAVRFQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=bi/HhRDcxOcnwZuDSZwkFsXAlZs=; b=AcE8/wPD0fGhWB8Ztt1i eVAsF0bOjezTkaLtkY8/s6jEsNRDzaZ9J3nUmfjx4tNuwXGNAkE/zHBZlayalRFi WCkcMImJDO/NpKE+99fUhSaks3idIFGnVpsGJld7l6tuTJ0nU7ZKTKB25PY37Rte OtSwV4LhVjG4yFTPaGmuwF8= Received: (qmail 3139 invoked by alias); 19 Apr 2013 11:58:02 -0000 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 Received: (qmail 3129 invoked by uid 89); 19 Apr 2013 11:58:02 -0000 X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from youngberry.canonical.com (HELO youngberry.canonical.com) (91.189.89.112) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 19 Apr 2013 11:58:01 +0000 Received: from dslb-088-073-088-137.pools.arcor-ip.net ([88.73.88.137] helo=[192.168.42.216]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1UT9x1-0000VG-8d for gcc-patches@gcc.gnu.org; Fri, 19 Apr 2013 11:57:59 +0000 Message-ID: <51713144.20705@ubuntu.com> Date: Fri, 19 Apr 2013 13:57:56 +0200 From: Matthias Klose User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130404 Thunderbird/17.0.5 MIME-Version: 1.0 To: GCC Patches Subject: [ada] [patch] gnatlink's order of options interfers with --as-needed X-Virus-Found: No The linux version of Build_Dynamic_Library passes all options and libraries in Options, which end up on the command line before the object files. So it looks like the signature of Build_Dynamic_Library should differentiate between options and libraries. Until it does, use the same approach as done for on irix, scanning the options for -l strings and moving them to Options_2, which end up behind the object files. Just copied from the irix variant (available up to 4.7). Ok for 4.7, 4.8 and the trunk? Matthias * mlib-tgt-specific-linux.adb (Build_Dynamic_Library): Move -l* strings from Options to Options_2. --- gcc/ada/mlib-tgt-specific-linux.adb +++ gcc/ada/mlib-tgt-specific-linux.adb @@ -81,19 +81,54 @@ Version_Arg : String_Access; Symbolic_Link_Needed : Boolean := False; + N_Options : Argument_List := Options; + Options_Last : Natural := N_Options'Last; + -- After moving -lxxx to Options_2, N_Options up to index Options_Last + -- will contain the Options to pass to MLib.Utl.Gcc. + + Real_Options_2 : Argument_List (1 .. Options'Length); + Real_Options_2_Last : Natural := 0; + -- Real_Options_2 up to index Real_Options_2_Last will contain the + -- Options_2 to pass to MLib.Utl.Gcc. + begin if Opt.Verbose_Mode then Write_Str ("building relocatable shared library "); Write_Line (Lib_Path); end if; + -- Move all -lxxx to Options_2 + + declare + Index : Natural := N_Options'First; + Arg : String_Access; + + begin + while Index <= Options_Last loop + Arg := N_Options (Index); + + if Arg'Length > 2 + and then Arg (Arg'First .. Arg'First + 1) = "-l" + then + Real_Options_2_Last := Real_Options_2_Last + 1; + Real_Options_2 (Real_Options_2_Last) := Arg; + N_Options (Index .. Options_Last - 1) := + N_Options (Index + 1 .. Options_Last); + Options_Last := Options_Last - 1; + + else + Index := Index + 1; + end if; + end loop; + end; + if Lib_Version = "" then Utl.Gcc (Output_File => Lib_Path, Objects => Ofiles, - Options => Options, + Options => N_Options (N_Options'First .. Options_Last), Driver_Name => Driver_Name, - Options_2 => No_Argument_List); + Options_2 => Real_Options_2 (1 .. Real_Options_2_Last)); else declare @@ -111,18 +146,18 @@ Utl.Gcc (Output_File => Lib_Version, Objects => Ofiles, - Options => Options & Version_Arg, + Options => N_Options (N_Options'First .. Options_Last) & Version_Arg, Driver_Name => Driver_Name, - Options_2 => No_Argument_List); + Options_2 => Real_Options_2 (1 .. Real_Options_2_Last)); Symbolic_Link_Needed := Lib_Version /= Lib_Path; else Utl.Gcc (Output_File => Lib_Dir & Directory_Separator & Lib_Version, Objects => Ofiles, - Options => Options & Version_Arg, + Options => N_Options (N_Options'First .. Options_Last) & Version_Arg, Driver_Name => Driver_Name, - Options_2 => No_Argument_List); + Options_2 => Real_Options_2 (1 .. Real_Options_2_Last)); Symbolic_Link_Needed := Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path; end if;