From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1815 invoked by alias); 14 Mar 2002 22:16:07 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 1769 invoked by uid 71); 14 Mar 2002 22:16:03 -0000 Resent-Date: 14 Mar 2002 22:16:03 -0000 Resent-Message-ID: <20020314221603.1763.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, rittle@latour.rsch.comm.mot.com, jamesy@ibmoto.com Resent-Reply-To: gcc-gnats@gcc.gnu.org, edmar@motorola.com Received:(qmail 30642 invoked by uid 61); 14 Mar 2002 22:11:48 -0000 Message-Id:<20020314221148.30639.qmail@sources.redhat.com> Date: Thu, 14 Mar 2002 14:16:00 -0000 From: edmar@motorola.com Reply-To: edmar@motorola.com To: gcc-gnats@gcc.gnu.org Cc: rittle@latour.rsch.comm.mot.com, jamesy@ibmoto.com X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) X-GNATS-Notify:rittle@latour.rsch.comm.mot.com,jamesy@ibmoto.com Subject: target/5967: gcc bug when profiling nested functions on powerpc X-SW-Source: 2002-03/txt/msg00482.txt.bz2 List-Id: >Number: 5967 >Category: target >Synopsis: gcc bug when profiling nested functions on powerpc >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Thu Mar 14 14:16:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: edmar@motorola.com >Release: unknown-1.0 >Organization: >Environment: At least on 2.95.2, and 3.0.2. Linux PowerPC >Description: gcc version: When generating routine profiling header code, gcc conditionally inserts a move register (mr) instruction if the function being compiled "needs_context". The mr copies the register of the static chain pointer to r30 before the call to _mcount, and copies it back after the _mcount has returned. However, r30 is not checked to see if it is being used by the parent function. How found: Compiled glibc 2.1.3 using profiling options (with backport patch of dl-machine.h from glibc 2.2.5). When __printf_fp() (a child function of printf() that is called when a floating point format is invoked) is called, a segfault is seen. This is because __printf_fp() calls a nested function named hack_digit(). Example of brokenness: 1001014c : 1001014c: 7c 08 02 a6 mflr r0 10010150: 3d 80 10 05 lis r12,4101 10010154: 90 01 00 04 stw r0,4(r1) 10010158: 38 0c 20 78 addi r0,r12,8312 1001015c: 7d 7e 5b 78 mr r30,r11 10010160: 4b ff 9f 21 bl 1000a080 <_mcount> 10010164: 7f cb f3 78 mr r11,r30 10010168: 94 21 ff e0 stwu r1,-32(r1) 1001016c: 7c 08 02 a6 mflr r0 10010170: 93 c1 00 18 stw r30,24(r1) Specific code from gcc: from rs6000.c: void output_function_profiler (file, labelno) FILE *file; int labelno; { ... if (current_function_needs_context) asm_fprintf (file, "\tmr %s,%s\n", reg_names[30], reg_names[STATIC_CHAIN_REGNUM]); fprintf (file, "\tbl %s\n", RS6000_MCOUNT); if (current_function_needs_context) asm_fprintf (file, "\tmr %s,%s\n", reg_names[STATIC_CHAIN_REGNUM], reg_names[30]); ... >How-To-Repeat: compile with gcc 2.95.2 or gcc-3.0.2 on a Linux PowerPC: gcc -O2 -p -S prog.c them look at prog.s and note that r30 is live across the call to bar(), and bar clobbers r30 (profiling code). >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: application/octet-stream; name="prog.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="prog.c" dm9pZCBmb28gKGludCBzZWVkKQp7CiAgaW50IGk7CiAgaW50IHIxLCByMiwgcjMsIHI0LCByNSwg cjYsIHI3LCByOCwgcjk7CiAgaW50IHIxNCwgcjE1LCByMTYsIHIxNywgcjE4LCByMTksIHIyMCwK ICAgIHIyMSwgcjIyLCByMjMsIHIyNCwgcjI1LCByMjYsIHIyNywgcjI4LCByMjksIHIzMDsKICBp bnQgYmFyICh2b2lkKSB7IHJldHVybiByMzAgKiBpOyB9CgogIHIxID0gc2VlZCArIDE7CiAgcjIg PSBzZWVkICsgMjsKICByMyA9IHNlZWQgKyAzOwogIHI0ID0gc2VlZCArIDQ7CiAgcjUgPSBzZWVk ICsgNTsKICByNiA9IHNlZWQgKyA2OwogIHI3ID0gc2VlZCArIDc7CiAgcjggPSBzZWVkICsgODsK ICByOSA9IHNlZWQgKyA5OwogIHIxNCA9IHNlZWQgKyAxNDsKICByMTUgPSBzZWVkICsgMTU7CiAg cjE2ID0gc2VlZCArIDE2OwogIHIxNyA9IHNlZWQgKyAxNzsKICByMTggPSBzZWVkICsgMTg7CiAg cjE5ID0gc2VlZCArIDE5OwogIHIyMCA9IHIxNCArIHIxNSArIHIxOwogIHIyMSA9IHIxNiArIHIx NyArIHIyOwogIHIyMiA9IHIxOCArIHIxOSArIHIzOwogIHIyMyA9IHIyMCAqIDIgKyByNDsKICBy MjQgPSByMjEgKiAyICsgcjU7CiAgcjI1ID0gcjIyICogMiArIHI2OwogIHIyNiA9IHIyMyArIHIx NCArIHI3OwogIHIyNyA9IHIyNCArIHIxNSArIHI4OwogIHIyOCA9IHIyNSArIHIxNjsKICByMjkg PSByMjggLSByMjY7CiAgcjMwID0gcjI5ICsgcjI3OwoKICBpID0gYmFyICgpOwogIAogIHByaW50 ZiAoIiVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVkICVk ICVkICVkICVkICVkICVkICVkICVkICVkXG4iLAogICAgICAgICAgcjEsIHIyLCByMywgcjQsIHI1 LCByNiwgcjcsIHI4LCByOSwKICAgICAgICAgIHIxNCwgcjE1LCByMTYsIHIxNywgcjE4LCByMTks IHIyMCwgcjIxLCByMjIsCiAgICAgICAgICByMjMsIHIyNCwgcjI1LCByMjYsIHIyNywgcjI4LCBy MjksIHIzMCwgaSk7Cn0KCm1haW4gKCkKewogIGZvbygxMDApOwp9Cg==