From patchwork Fri Jul 12 14:54:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 258759 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 1554B2C034F for ; Sat, 13 Jul 2013 00:54:39 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=a4xyGyKGLyKfp3NGWV2mkHxRGRmvDNBKCkkv2OSwO/Ml3pfJwvGPU eWmUhrMAyTZfaYqSG0DF9eGzVWablJsMDn+9rScdEREoQlwrrvh9lXAjddHCc2F9 shFmaBs026pjOyAaZipBFRA1/HFCFqZtXBMV+lPuzLh3UvD+Ctt4NE= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=XDZT30CtgreBog9vNa6fvWEMPv4=; b=slTczTQoVBEQZlK7u59p 7eiWK6q5tjIP7VIiQdf8XUkhcAqqIZRswzgjuE+u7GBIKfmvYD5AgxaXUPA7L5dO v8nOf0r65fNQ6whtAFr6LAlPyMZa41Cjbnt0FzuWiX1Yieb4QVl9royP71sfrAP6 A3GHe7jfdUvOyRg/Z0YT0B0= Received: (qmail 3873 invoked by alias); 12 Jul 2013 14:54:32 -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 3836 invoked by uid 89); 12 Jul 2013 14:54:25 -0000 X-Spam-SWARE-Status: No, score=-6.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 12 Jul 2013 14:54:24 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 12 Jul 2013 16:54:22 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1Uxejl-0007YR-MQ for gcc-patches@gcc.gnu.org; Fri, 12 Jul 2013 16:54:21 +0200 Date: Fri, 12 Jul 2013 16:54:21 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Call GNU ld with -O* Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Found: No Hello, this patch makes the driver pass -O2 to GNU ld if gcc was called with -O3 (or more), -Ofast or -Os. Is there a cleaner way to test (optimize > 2 || optimize_size) in the driver? I did a bootstrap on x86_64-unknown-linux-gnu and then manually tested by looking at the -v output. I tried a -O3 bootstrap, but even setting CFLAGS, BOOT_CFLAGS, CFLAGS_FOT_TARGET, and the same 3 versions with CXXFLAGS and LDFLAGS, most stuff still used the default -O2 -g. And most libraries that are part of gcc explicitly use -Wl,-O1 for linking already. 2013-07-12 Marc Glisse PR driver/44080 * gcc.c (LINK_OPT_SPEC): New macro. (LINK_COMMAND_SPEC): Use it. Index: gcc.c =================================================================== --- gcc.c (revision 200921) +++ gcc.c (working copy) @@ -715,36 +715,45 @@ proper position among the other output f /* Linker command line options for -fsanitize= late on the command line. */ #ifndef SANITIZER_SPEC #define SANITIZER_SPEC "\ %{!nostdlib:%{!nodefaultlibs:%{fsanitize=address:" LIBASAN_SPEC "\ %{static:%ecannot specify -static with -fsanitize=address}\ %{fsanitize=thread:%e-fsanitize=address is incompatible with -fsanitize=thread}}\ %{fsanitize=thread:" LIBTSAN_SPEC "\ %{!pie:%{!shared:%e-fsanitize=thread linking must be done with -pie or -shared}}}}}" #endif +/* GNU ld has -O1 and gold -O2, but we only pass it with -O3, -Os or -Ofast. */ +#ifndef LINK_OPT_SPEC +#if HAVE_GNU_LD +#define LINK_OPT_SPEC "%{O*:%{!O0:%{!O1:%{!O2:%{!Og:%{!O:-O2}}}}}} " +#else +#define LINK_OPT_SPEC "" +#endif +#endif + /* -u* was put back because both BSD and SysV seem to support it. */ /* %{static:} simply prevents an error message if the target machine doesn't handle -static. */ /* We want %{T*} after %{L*} and %D so that it can be used to specify linker scripts which exist in user specified directories, or in standard directories. */ /* We pass any -flto flags on to the linker, which is expected to understand them. In practice, this means it had better be collect2. */ /* %{e*} includes -export-dynamic; see comment in common.opt. */ #ifndef LINK_COMMAND_SPEC #define LINK_COMMAND_SPEC "\ %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ %(linker) " \ LINK_PLUGIN_SPEC \ "%{flto|flto=*:%