public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames
@ 2004-12-10 18:16 opensource at artnaseef dot com
  2004-12-10 18:19 ` [Bug c/18929] " opensource at artnaseef dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: opensource at artnaseef dot com @ 2004-12-10 18:16 UTC (permalink / raw)
  To: gcc-bugs

When compiling with the arm-linux compiler with optimization enabled, the 
compiler removes frame pointers from functions even when they are profiled.  
This leads to a segmentation fault with the glibc version of mcount when it 
attempts to determine the caller of a function from the current stack because 
mcount assumes the frame pointer is there.

It seems that optimized functions, on this platform, should not drop their frame 
pointers when profiling is enabled.

-- 
           Summary: Profiling optimized code causes segfaults on ARM due to
                    missing frames
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: opensource at artnaseef dot com
                CC: gcc-bugs at gcc dot gnu dot org,opensource at artnaseef
                    dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
@ 2004-12-10 18:19 ` opensource at artnaseef dot com
  2004-12-10 18:20 ` [Bug target/18929] " pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: opensource at artnaseef dot com @ 2004-12-10 18:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From opensource at artnaseef dot com  2004-12-10 18:19 -------
Created an attachment (id=7720)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7720&action=view)
recommended fix

This patch fixes the problem by forcing functions to keep their frame pointers
when compiled with profiling.  It maintains portability by using a macro, and
only defining it for the ARM architecture, that indicates when mcount requires
the frame pointer.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
  2004-12-10 18:19 ` [Bug c/18929] " opensource at artnaseef dot com
@ 2004-12-10 18:20 ` pinskia at gcc dot gnu dot org
  2004-12-10 18:40 ` opensource at artnaseef dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-10 18:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-10 18:20 -------
Does this work in 3.4.?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
  2004-12-10 18:19 ` [Bug c/18929] " opensource at artnaseef dot com
  2004-12-10 18:20 ` [Bug target/18929] " pinskia at gcc dot gnu dot org
@ 2004-12-10 18:40 ` opensource at artnaseef dot com
  2004-12-13 11:44 ` rearnsha at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: opensource at artnaseef dot com @ 2004-12-10 18:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From opensource at artnaseef dot com  2004-12-10 18:40 -------
Subject: Re:  Profiling optimized code causes segfaults
    on ARM due to missing frames

I have not tested it, but I don't see why not.  The patch is fairly short and straight-forward, I believe.

---------- Original Message -------------
Subject: [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
Date: 10 Dec 2004 18:20:04 -0000
From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: opensource@artnaseef.com



------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-10 18:20 -------
Does this work in 3.4.?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.
You are on the CC list for the bug, or are watching someone who is.





-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
                   ` (2 preceding siblings ...)
  2004-12-10 18:40 ` opensource at artnaseef dot com
@ 2004-12-13 11:44 ` rearnsha at gcc dot gnu dot org
  2004-12-13 15:28 ` opensource at artnaseef dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2004-12-13 11:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rearnsha at gcc dot gnu dot org  2004-12-13 11:44 -------
I don't think that patch is correct.  Please try the one from bug 3724:

http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/arm/linux-elf.h.diff?cvsroot=gcc&r1=1.39&r2=1.40

Also, please add a testcase if you want further investigation.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rearnsha at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
                   ` (3 preceding siblings ...)
  2004-12-13 11:44 ` rearnsha at gcc dot gnu dot org
@ 2004-12-13 15:28 ` opensource at artnaseef dot com
  2004-12-13 15:46   ` Richard Earnshaw
  2004-12-13 15:36 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 10+ messages in thread
From: opensource at artnaseef dot com @ 2004-12-13 15:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From opensource at artnaseef dot com  2004-12-13 15:28 -------
Subject: Re:  Profiling optimized code causes segfaults on
 ARM due to missing frames

Two things

  1. Why do you not think the  patch is correct?  It works great for 
me.  Without
     that information, I can only respond with "I think you are wrong," 
and that
     is not productive.

  2. The comment in the patch you show is that the Profiler clobbers the 
Link
     Register.  That is NOT this problem.

In this problem, the profiler causes a segmentation fault when it reads 
the wrong
return address off the stack and uses it as an invalid function 
address.  It does
not use the link register value.

To reproduce the problem:

  - Build an arm-linux toolchain

  - Compile a program with optimization and profiling (try -O2 and -pg).

     - Make sure the program includes a function for which the optimizer
       drops its frame pointer (this can easily be verified by looking at
       the assembly output of the compiler).

  - Run the program.

If a trace is needed, I will be able to produce one within a few days
and provide an example.  Note that this problem was quite easy for me
to reproduce, so I would expect reproducing it to be simple enough for
others.

Let me know if you have trouble reproducing it.

rearnsha at gcc dot gnu dot org wrote:

>------- Additional Comments From rearnsha at gcc dot gnu dot org  2004-12-13 11:44 -------
>I don't think that patch is correct.  Please try the one from bug 3724:
>
>http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/arm/linux-elf.h.diff?cvsroot=gcc&r1=1.39&r2=1.40
>
>Also, please add a testcase if you want further investigation.
>
>



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
                   ` (4 preceding siblings ...)
  2004-12-13 15:28 ` opensource at artnaseef dot com
@ 2004-12-13 15:36 ` pinskia at gcc dot gnu dot org
  2004-12-13 15:43 ` rearnsha at gcc dot gnu dot org
  2004-12-13 15:56 ` opensource at artnaseef dot com
  7 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-13 15:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-13 15:36 -------
(In reply to comment #5)
> Subject: Re:  Profiling optimized code causes segfaults on
>  ARM due to missing frames
> 
> Two things
> 
>   1. Why do you not think the  patch is correct?  It works great for 
> me.  Without
>      that information, I can only respond with "I think you are wrong," 
> and that
>      is not productive.
Here is why it is the correct fix, the patch you are asking to apply is a patch to the middle-end which 
works for all targets already and there is no reason to say we need a frame pointer when profiling.

The fix which Richard suggested (which by the way if you tried 3.4.0 you would see that it was fixed, 
like I had asked) is a target only fix, preventing the scheduling across to the profiling area for the 
function.  So this in turn a dup of bug 3724 which is fixed for 3.4.0.


*** This bug has been marked as a duplicate of 3724 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
                   ` (5 preceding siblings ...)
  2004-12-13 15:36 ` pinskia at gcc dot gnu dot org
@ 2004-12-13 15:43 ` rearnsha at gcc dot gnu dot org
  2004-12-13 15:56 ` opensource at artnaseef dot com
  7 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2004-12-13 15:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rearnsha at gcc dot gnu dot org  2004-12-13 15:43 -------
Subject: Re:  Profiling optimized code causes segfaults
	on ARM due to missing frames

On Mon, 2004-12-13 at 15:28, opensource at artnaseef dot com wrote:
> ------- Additional Comments From opensource at artnaseef dot com  2004-12-13 15:28 -------
> Subject: Re:  Profiling optimized code causes segfaults on
>  ARM due to missing frames
> 
> Two things
> 
>   1. Why do you not think the  patch is correct?  It works great for 
> me.  Without
>      that information, I can only respond with "I think you are wrong," 
> and that
>      is not productive.
> 
Because I don't think profiling should need the a frame pointer to
work.  If it does, then my feeling is that it's the profiling code
that's broken, not the compiler.  The layout of a stack frame is private
to the function that built it, and any code outside of that function
that tries to probe it is simply broken.

>   2. The comment in the patch you show is that the Profiler clobbers the 
> Link
>      Register.  That is NOT this problem.
> 

Well, that patch was never applied to the 3.3 branch.  The bug it refers
to was reported against 3.0, so there's a strong likelihood that it will
be needed in 3.3 as well.

> In this problem, the profiler causes a segmentation fault when it reads 
> the wrong
> return address off the stack and uses it as an invalid function 
> address.  It does
> not use the link register value.
> 
> To reproduce the problem:
> 
>   - Build an arm-linux toolchain
> 
>   - Compile a program with optimization and profiling (try -O2 and -pg).
> 
>      - Make sure the program includes a function for which the optimizer
>        drops its frame pointer (this can easily be verified by looking at
>        the assembly output of the compiler).
> 
>   - Run the program.
> 
> If a trace is needed, I will be able to produce one within a few days
> and provide an example.  Note that this problem was quite easy for me
> to reproduce, so I would expect reproducing it to be simple enough for
> others.

I'm not in the business of trying to second guess how you encountered a
problem.  If you want us to investigate a bug then you need to send us
precise instructions (including source code) so that we can reproduce
it.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-13 15:28 ` opensource at artnaseef dot com
@ 2004-12-13 15:46   ` Richard Earnshaw
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Earnshaw @ 2004-12-13 15:46 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs

On Mon, 2004-12-13 at 15:28, opensource at artnaseef dot com wrote:
> ------- Additional Comments From opensource at artnaseef dot com  2004-12-13 15:28 -------
> Subject: Re:  Profiling optimized code causes segfaults on
>  ARM due to missing frames
> 
> Two things
> 
>   1. Why do you not think the  patch is correct?  It works great for 
> me.  Without
>      that information, I can only respond with "I think you are wrong," 
> and that
>      is not productive.
> 
Because I don't think profiling should need the a frame pointer to
work.  If it does, then my feeling is that it's the profiling code
that's broken, not the compiler.  The layout of a stack frame is private
to the function that built it, and any code outside of that function
that tries to probe it is simply broken.

>   2. The comment in the patch you show is that the Profiler clobbers the 
> Link
>      Register.  That is NOT this problem.
> 

Well, that patch was never applied to the 3.3 branch.  The bug it refers
to was reported against 3.0, so there's a strong likelihood that it will
be needed in 3.3 as well.

> In this problem, the profiler causes a segmentation fault when it reads 
> the wrong
> return address off the stack and uses it as an invalid function 
> address.  It does
> not use the link register value.
> 
> To reproduce the problem:
> 
>   - Build an arm-linux toolchain
> 
>   - Compile a program with optimization and profiling (try -O2 and -pg).
> 
>      - Make sure the program includes a function for which the optimizer
>        drops its frame pointer (this can easily be verified by looking at
>        the assembly output of the compiler).
> 
>   - Run the program.
> 
> If a trace is needed, I will be able to produce one within a few days
> and provide an example.  Note that this problem was quite easy for me
> to reproduce, so I would expect reproducing it to be simple enough for
> others.

I'm not in the business of trying to second guess how you encountered a
problem.  If you want us to investigate a bug then you need to send us
precise instructions (including source code) so that we can reproduce
it.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/18929] Profiling optimized code causes segfaults on ARM due to missing frames
  2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
                   ` (6 preceding siblings ...)
  2004-12-13 15:43 ` rearnsha at gcc dot gnu dot org
@ 2004-12-13 15:56 ` opensource at artnaseef dot com
  7 siblings, 0 replies; 10+ messages in thread
From: opensource at artnaseef dot com @ 2004-12-13 15:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From opensource at artnaseef dot com  2004-12-13 15:55 -------
Subject: Re:  Profiling optimized code causes segfaults on
 ARM due to missing frames

Alright, since my instructions are not good enough for you, I will
put together an example.


rearnsha at gcc dot gnu dot org wrote:

>------- Additional Comments From rearnsha at gcc dot gnu dot org  2004-12-13 15:43 -------
>Subject: Re:  Profiling optimized code causes segfaults
>	on ARM due to missing frames
>
>On Mon, 2004-12-13 at 15:28, opensource at artnaseef dot com wrote:
>
>>------- Additional Comments From opensource at artnaseef dot com  2004-12-13 15:28 -------
>>Subject: Re:  Profiling optimized code causes segfaults on
>> ARM due to missing frames
>>
>>Two things
>>
>>  1. Why do you not think the  patch is correct?  It works great for 
>>me.  Without
>>     that information, I can only respond with "I think you are wrong," 
>>and that
>>     is not productive.
>>
>>
>Because I don't think profiling should need the a frame pointer to
>work.  If it does, then my feeling is that it's the profiling code
>that's broken, not the compiler.  The layout of a stack frame is private
>to the function that built it, and any code outside of that function
>that tries to probe it is simply broken.
>
>
>>  2. The comment in the patch you show is that the Profiler clobbers the 
>>Link
>>     Register.  That is NOT this problem.
>>
>>
>
>Well, that patch was never applied to the 3.3 branch.  The bug it refers
>to was reported against 3.0, so there's a strong likelihood that it will
>be needed in 3.3 as well.
>
>
>>In this problem, the profiler causes a segmentation fault when it reads 
>>the wrong
>>return address off the stack and uses it as an invalid function 
>>address.  It does
>>not use the link register value.
>>
>>To reproduce the problem:
>>
>>  - Build an arm-linux toolchain
>>
>>  - Compile a program with optimization and profiling (try -O2 and -pg).
>>
>>     - Make sure the program includes a function for which the optimizer
>>       drops its frame pointer (this can easily be verified by looking at
>>       the assembly output of the compiler).
>>
>>  - Run the program.
>>
>>If a trace is needed, I will be able to produce one within a few days
>>and provide an example.  Note that this problem was quite easy for me
>>to reproduce, so I would expect reproducing it to be simple enough for
>>others.
>>
>
>I'm not in the business of trying to second guess how you encountered a
>problem.  If you want us to investigate a bug then you need to send us
>precise instructions (including source code) so that we can reproduce
>it.
>
>
>



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18929


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-12-13 15:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-10 18:16 [Bug c/18929] New: Profiling optimized code causes segfaults on ARM due to missing frames opensource at artnaseef dot com
2004-12-10 18:19 ` [Bug c/18929] " opensource at artnaseef dot com
2004-12-10 18:20 ` [Bug target/18929] " pinskia at gcc dot gnu dot org
2004-12-10 18:40 ` opensource at artnaseef dot com
2004-12-13 11:44 ` rearnsha at gcc dot gnu dot org
2004-12-13 15:28 ` opensource at artnaseef dot com
2004-12-13 15:46   ` Richard Earnshaw
2004-12-13 15:36 ` pinskia at gcc dot gnu dot org
2004-12-13 15:43 ` rearnsha at gcc dot gnu dot org
2004-12-13 15:56 ` opensource at artnaseef dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).