From patchwork Thu Aug 12 13:04:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jack Howarth X-Patchwork-Id: 61589 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 B29A4B70A6 for ; Thu, 12 Aug 2010 23:04:28 +1000 (EST) Received: (qmail 7927 invoked by alias); 12 Aug 2010 13:04:22 -0000 Received: (qmail 7771 invoked by uid 22791); 12 Aug 2010 13:04:18 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from bromo.med.uc.edu (HELO bromo.med.uc.edu) (129.137.3.146) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Thu, 12 Aug 2010 13:04:05 +0000 Received: from bromo.med.uc.edu (localhost.localdomain [127.0.0.1]) by bromo.med.uc.edu (Postfix) with ESMTP id 7196FB004B; Thu, 12 Aug 2010 09:04:03 -0400 (EDT) Received: (from howarth@localhost) by bromo.med.uc.edu (8.14.3/8.14.3/Submit) id o7CD43ZU024188; Thu, 12 Aug 2010 09:04:03 -0400 Date: Thu, 12 Aug 2010 09:04:03 -0400 From: Jack Howarth To: gcc-patches@gcc.gnu.org Cc: mikestump@comcast.net, iains@gcc.gnu.org Subject: [PATCH][Revisedx2] Add remove-outfile and use on darwin Message-ID: <20100812130403.GA24186@bromo.med.uc.edu> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) 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 Currently on darwin, passing -ldl, -lm or -lpthread (which are all aliases for -lSystem) results in the libSystem being promoted earlier into the order of linkage. This interferes with the logic behind libgcc_ext which expects libSystem to be linked last. The attached patch adds the missing remove-outfile spec function and uses it from LINK_SPEC to remove any instances of -ldl, -lm or Bootstrapped and regression tested on x86_64-apple-darwin10. Okay for gcc trunk and gcc 4.5.2? Jack 2010-08-12 Jack Howarth * gcc.c (spec_function): Add remove-outfile. (remove_outfile_spec_function): New function. * config/darwin.h (LINK_SPEC): Add removal of -ldl, -lm and -lpthread. * invoke.texi (replace-outfile): Document. Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 163182) +++ gcc/doc/invoke.texi (working copy) @@ -9613,6 +9613,15 @@ %@{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)@} @end smallexample +@item @code{remove-outfile} +The @code{remove-outfile} spec function takes one argument. It removes +all occurrences of its argument from the outfiles array. Here is a small +example of its usage: + +@smallexample +%:remove-outfile(-lm) +@end smallexample + @item @code{print-asm-header} The @code{print-asm-header} function takes no arguments and simply prints a banner like: Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 163182) +++ gcc/gcc.c (working copy) @@ -379,6 +379,7 @@ static const char *if_exists_spec_function (int, const char **); static const char *if_exists_else_spec_function (int, const char **); static const char *replace_outfile_spec_function (int, const char **); +static const char *remove_outfile_spec_function (int, const char **); static const char *version_compare_spec_function (int, const char **); static const char *include_spec_function (int, const char **); static const char *find_file_spec_function (int, const char **); @@ -1677,6 +1678,7 @@ { "if-exists", if_exists_spec_function }, { "if-exists-else", if_exists_else_spec_function }, { "replace-outfile", replace_outfile_spec_function }, + { "remove-outfile", remove_outfile_spec_function }, { "version-compare", version_compare_spec_function }, { "include", include_spec_function }, { "find-file", find_file_spec_function }, @@ -8357,6 +8359,27 @@ return NULL; } +/* remove-outfile built-in spec function. + * + * This looks for the first argument in the outfiles array's name and + * removes it. */ + +static const char * +remove_outfile_spec_function (int argc, const char **argv) +{ + int i; + /* Must have exactly one argument. */ + if (argc != 1) + abort (); + + for (i = 0; i < n_infiles; i++) + { + if (outfiles[i] && !strcmp (outfiles[i], argv[0])) + outfiles[i] = NULL; + } + return NULL; +} + /* Given two version numbers, compares the two numbers. A version number must match the regular expression ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))* Index: gcc/config/darwin.h =================================================================== --- gcc/config/darwin.h (revision 163182) +++ gcc/config/darwin.h (working copy) @@ -303,6 +303,9 @@ so put a * after their names so all of them get passed. */ #define LINK_SPEC \ "%{static}%{!static:-dynamic} \ + %:remove-outfile(-ldl) \ + %:remove-outfile(-lm) \ + %:remove-outfile(-lpthread) \ %{fgnu-runtime: %{static|static-libgcc: \ %:replace-outfile(-lobjc libobjc-gnu.a%s); \ :%:replace-outfile(-lobjc -lobjc-gnu ) } }\