From patchwork Fri Feb 12 14:56:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Baylis X-Patchwork-Id: 61863 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp871748lbl; Fri, 12 Feb 2016 06:56:46 -0800 (PST) X-Received: by 10.66.235.129 with SMTP id um1mr2684483pac.17.1455289006055; Fri, 12 Feb 2016 06:56:46 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id fl1si20468836pad.15.2016.02.12.06.56.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2016 06:56:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-421330-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-421330-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-421330-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=Nopbwwoha7lwa/iPdhWDPDhnHVso5ql5jD9RHfWYQ2J DHBbmJckfUwQPLanUmZ7wKjv0/19K3lNpCnZ4hlVy2vdkshxb/bhhcLcXqA0meE3 Auv5JcMIPPBAxbS2K7j0IUjWegWM5KiP/qcCrQLRjIRe3QYGktohBu55SU6pK5Rs = 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 :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=sMuCO70R4ucyUAOgjrkUbJM6+Qs=; b=ppX99PxqjWNCoHaQu eDrXMhmjpHrny31/BZF2eWgalsElYz0z200Cd4ddjiKwjkbQwr2aNiYCTRyhhnoC en7/6QRlrc2audZgwNRHrKg7afwhgdJE4siCm1lP8pAhkHjUybnQYCJntdKYDquB ul0sxTve/2170FoIH0nR0Mky8s= Received: (qmail 25333 invoked by alias); 12 Feb 2016 14:56:34 -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 25302 invoked by uid 89); 12 Feb 2016 14:56:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=pool, H*c:sk:94eb2c0, sk:gen_rtx, tip X-HELO: mail-ob0-f171.google.com Received: from mail-ob0-f171.google.com (HELO mail-ob0-f171.google.com) (209.85.214.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 12 Feb 2016 14:56:32 +0000 Received: by mail-ob0-f171.google.com with SMTP id gc3so23185741obb.3 for ; Fri, 12 Feb 2016 06:56:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=xn3ylDJu4ALX1OxxHRRo/ApKhXFcW0lvyA3kuhdfCJU=; b=LhJ5HgxJjkmFNKLVsFFKsYQMXMJHEI+lyWZbrquT6eCeqGLii005wPXMvR165ibD+N fu+FHxIP5AtwVhXAenlNHTN2Q34Zu6OSpgjEjlJjB+vK9wCGwKHNeC+GI4DXuA0+mbqW Rxi2MG9jzsZgesGEXGeMmwksEUgFadG7bRByvxEZqA4vwE3OpL7BQ+0rrBLWLmPlxqY0 i7DYCjWGqxuWzDit8OnOtFDkDvWNZc1v1j44Q4nyqMkdUYBE46jXAmzLGR9NKliKWXTk ieZhrgypp6cSks4ni+RtCKQKkcmKRTSQUUgCK1YrdWqva+dWWQ/B24m1kRVv5pw8ED6u NVkQ== X-Gm-Message-State: AG10YOR6MU0dQUa41ZSgniYtmWeLkGbil0I/jD9cvA/BMshw6+wADI3646lvcPRQTev7ooMzSMzSJYZQIE0urmQN MIME-Version: 1.0 X-Received: by 10.202.243.193 with SMTP id r184mr1583196oih.24.1455288990452; Fri, 12 Feb 2016 06:56:30 -0800 (PST) Received: by 10.202.224.4 with HTTP; Fri, 12 Feb 2016 06:56:30 -0800 (PST) Date: Fri, 12 Feb 2016 14:56:30 +0000 Message-ID: Subject: [PATCH ARM] RFC: PR69770 -mlong-calls does not affect calls to __gnu_mcount_nc generated by -pg From: Charles Baylis To: Kyrylo Tkachov , Ramana Radhakrishnan , Richard Earnshaw Cc: GCC Patches X-IsSubscribed: yes When compiling with -mlong-calls and -pg, calls to the __gnu_mcount_nc function are not generated as long calls. This is encountered when building an allyesconfig Linux kernel because the Linux build system generates very large sections by partial linking a large number of object files. This causes link failures, which don't go away with -mlong-calls due to this bug. (However, with this patch linking still fails due to calls in inline asm) For example: extern void g(void); int f() { g(); return 0; } compiles to: push {r4, lr} push {lr} bl __gnu_mcount_nc ;// not a long call ldr r3, .L2 blx r3 ;// a long call to g() mov r0, #0 pop {r4, pc} The call to __gnu_mcount_nc is generated from ARM_FUNCTION_PROFILER in config/arm/bpabi.h. For targets without MOVW/MOVT, the long call sequence requires a load from the literal pool, and it is too late to set up a literal pool entry from within ARM_FUNCTION_PROFILER. My approach to fix this is to modify the prologue generation to load the address of __gnu_mcount_nc into ip, so that it is ready when the call is generated. This patch only implements the fix for ARM and Thumb-2. A similar fix is possible for Thumb-1, but requires more slightly complex changes to the prologue generation to make sure there is a low register available. This feels like a bit of a hack to me, so ideas for a cleaner solution are welcome, if none, is this acceptable for trunk now, or should it wait until GCC 7? >From 34993396a43fcfc263db5b02b2d1837c490f52ad Mon Sep 17 00:00:00 2001 From: Charles Baylis Date: Thu, 11 Feb 2016 18:07:00 +0000 Subject: [PATCH] [ARM] PR69770 fix -mlong-calls with -pg gcc/ChangeLog: 2016-02-12 Charles Baylis * config/arm/arm.c (arm_expand_prologue): Load address of __gnu_mcount_nc in r12 if profiling and long calls are enabled. * config/arm/bpabi.h (ARM_FUNCTION_PROFILER): Emit long call to __gnu_mcount_nc long calls are enabled. (ARM_FUNCTION_PROFILER_SUPPORTS_LONG_CALLS): New define. gcc/testsuite/ChangeLog: 2016-02-12 Charles Baylis * gcc.target/arm/pr69770.c: New test. Change-Id: I4c639a5edf32fa8c67324d37faee1cb4ddd57a5c diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 27aecf7..9ce9a58 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -21739,6 +21739,15 @@ arm_expand_prologue (void) arm_load_pic_register (mask); } + if (crtl->profile && TARGET_LONG_CALLS + && ARM_FUNCTION_PROFILER_SUPPORTS_LONG_CALLS) + { + rtx tmp = gen_rtx_SET (gen_rtx_REG (SImode, IP_REGNUM), + gen_rtx_SYMBOL_REF (Pmode, "__gnu_mcount_nc")); + emit_insn (tmp); + emit_insn (gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, IP_REGNUM))); + } + /* If we are profiling, make sure no instructions are scheduled before the call to mcount. Similarly if the user has requested no scheduling in the prolog. Similarly if we want non-call exceptions diff --git a/gcc/config/arm/bpabi.h b/gcc/config/arm/bpabi.h index 82128ef..b734a24 100644 --- a/gcc/config/arm/bpabi.h +++ b/gcc/config/arm/bpabi.h @@ -173,11 +173,21 @@ #undef NO_PROFILE_COUNTERS #define NO_PROFILE_COUNTERS 1 +#undef ARM_FUNCTION_PROFILER_SUPPORTS_LONG_CALLS +#define ARM_FUNCTION_PROFILER_SUPPORTS_LONG_CALLS 1 #undef ARM_FUNCTION_PROFILER #define ARM_FUNCTION_PROFILER(STREAM, LABELNO) \ { \ - fprintf (STREAM, "\tpush\t{lr}\n"); \ - fprintf (STREAM, "\tbl\t__gnu_mcount_nc\n"); \ + if (TARGET_LONG_CALLS && TARGET_32BIT) \ + { \ + fprintf (STREAM, "\tpush\t{lr}\n"); \ + /* arm_expand_prolog() has already set up ip to contain the */ \ + /* address of __gnu_mcount_nc. */ \ + fprintf (STREAM, "\tblx\tip\n"); \ + } else { \ + fprintf (STREAM, "\tpush\t{lr}\n"); \ + fprintf (STREAM, "\tbl\t__gnu_mcount_nc\n"); \ + } \ } #undef SUBTARGET_FRAME_POINTER_REQUIRED diff --git a/gcc/testsuite/gcc.target/arm/pr69770.c b/gcc/testsuite/gcc.target/arm/pr69770.c new file mode 100644 index 0000000..61e5c6d --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr69770.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-pg -mlong-calls" } */ + +extern void g(void); + +int f() { g(); return 0; } + +/* { dg-final { scan-assembler-not "bl\[ \t\]+__gnu_mcount_nc" } } */ +/* { dg-final { scan-assembler "__gnu_mcount_nc" } } */ -- 1.9.1