From patchwork Wed Dec 8 01:54:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 74621 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 20827B70AA for ; Wed, 8 Dec 2010 12:54:43 +1100 (EST) Received: (qmail 12942 invoked by alias); 8 Dec 2010 01:54:41 -0000 Received: (qmail 12932 invoked by uid 22791); 8 Dec 2010 01:54:40 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from hiauly1.hia.nrc.ca (HELO hiauly1.hia.nrc.ca) (132.246.10.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Dec 2010 01:54:35 +0000 Received: by hiauly1.hia.nrc.ca (Postfix, from userid 1000) id 16FCE4CFC; Tue, 7 Dec 2010 20:54:32 -0500 (EST) Date: Tue, 7 Dec 2010 20:54:32 -0500 From: John David Anglin To: gcc-patches@gcc.gnu.org Subject: [committed] Fix handling of function sections on PA Message-ID: <20101208015431.GA13736@hiauly1.hia.nrc.ca> Reply-To: John David Anglin MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-09) 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 The patch below fixes two regressions introduced by commit r167085. The first is the middle-end no longer supports targets without named sections. default_function_section is elf specific. I have no idea why this change was made during stage3. The patch author has refused to discuss the regressions caused by the commit. The second is the commit placed nested functions into text.unlikely by default. The pa backend assumes nonlocal labels are in the same section as the containing function. Accessing a nonlocal label in a different section would require a dynamic relocation. There doesn't seem any reason to support this extra inefficiency, so the suggestion of Jakub Jelinek has been adopted to force nested functions into the same section as the containing function. The new sections introduced by commit r167085 had the potential to break call branch handling on the PA. The branch emitted for a call depends on the distance to the beginning of the current section. The code currently handles unnamed text sections and function sections. After examining the situation, I concluded that the new sections only result in an over estimate of the branch distance to the beginning of the current section. flag_function_sections appears to be handled correctly. The concern that I had was whether or not to use default_function_section on PA elf targets. Tested on hppa2.0w-hp-hpux11.11, hppa64-hp-hpux11.11 and hppa-unknown-linux-gnu. Committed to trunk. Dave Index: config/pa/pa.c =================================================================== --- config/pa/pa.c (revision 167472) +++ config/pa/pa.c (working copy) @@ -181,6 +181,7 @@ static rtx pa_internal_arg_pointer (void); static bool pa_can_eliminate (const int, const int); static void pa_conditional_register_usage (void); +static section *pa_function_section (tree, enum node_frequency, bool, bool); /* The following extra sections are only used for SOM. */ static GTY(()) section *som_readonly_data_section; @@ -388,6 +389,8 @@ #define TARGET_CAN_ELIMINATE pa_can_eliminate #undef TARGET_CONDITIONAL_REGISTER_USAGE #define TARGET_CONDITIONAL_REGISTER_USAGE pa_conditional_register_usage +#undef TARGET_ASM_FUNCTION_SECTION +#define TARGET_ASM_FUNCTION_SECTION pa_function_section struct gcc_target targetm = TARGET_INITIALIZER; @@ -10200,4 +10203,27 @@ fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; } +/* Target hook for function_section. */ + +static section * +pa_function_section (tree decl, enum node_frequency freq, + bool startup, bool exit) +{ + /* Put functions in text section if target doesn't have named sections. */ + if (!targetm.have_named_sections) + return text_section; + + /* Force nested functions into the same section as the containing + function. */ + if (decl + && DECL_SECTION_NAME (decl) == NULL_TREE + && DECL_CONTEXT (decl) != NULL_TREE + && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL + && DECL_SECTION_NAME (DECL_CONTEXT (decl)) == NULL_TREE) + return function_section (DECL_CONTEXT (decl)); + + /* Otherwise, use the default function section. */ + return default_function_section (decl, freq, startup, exit); +} + #include "gt-pa.h"