Linux PARISC architecture development
 help / color / mirror / Atom feed
* [parisc-linux] pa __builtin_return_addr
@ 2001-05-05 12:41 Alan Modra
  2001-05-06 16:25 ` [parisc-linux] " law
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2001-05-05 12:41 UTC (permalink / raw)
  To: Jeffrey A Law; +Cc: gcc-bugs, parisc-linux

Hi Jeff,
  I stumbled on this one a couple of hours ago, and haven't figured out
a good fix yet.

cat >builtin_ret.c <<EOF
void *foo (void) { return __builtin_return_address (0); }
EOF
gcc -O -S -mno-space-regs builtin_ret.c

gives (trimming somewhat)
foo:
        bv %r0(%r2)
        ldw -20(%r30),%r28	# Oops, we never stored r2 at -20(%r30)

The fix I have in mind is to add some communication between
builtins.c:expand_builtin_return_addr and pa.c:hppa_expand_prologue.
eg. add a field to struct machine_function, and set it in
pa.c:return_addr_rtx to indicate that r2 must be saved.


A similar problem occurs with
cat >builtin_frame.c <<EOF
void *foo (void) { return __builtin_frame_address (1); }
EOF
gcc -O -S builtin_frame.c

foo:
        bv %r0(%r2)
        ldw 0(%r30),%r28	# Oops, we haven't saved a frame pointer.

We ought to be able to make __builtin_frame_address (n) work reliably for
n = 0 and n = 1 by something similar to the fix I'm proposing for the
return address problem.  ie. set a "frame_pointer_needed" flag in
struct machine_function.

-- 
Alan Modra

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

* [parisc-linux] Re: pa __builtin_return_addr
  2001-05-05 12:41 [parisc-linux] pa __builtin_return_addr Alan Modra
@ 2001-05-06 16:25 ` law
  0 siblings, 0 replies; 2+ messages in thread
From: law @ 2001-05-06 16:25 UTC (permalink / raw)
  To: Alan Modra; +Cc: gcc-bugs, parisc-linux

  In message <Pine.LNX.4.30.0105052051010.7143-100000@mullet.itr.unisa.edu.au>y
ou write:
  > Hi Jeff,
  >   I stumbled on this one a couple of hours ago, and haven't figured out
  > a good fix yet.
  > 
  > cat >builtin_ret.c <<EOF
  > void *foo (void) { return __builtin_return_address (0); }
  > EOF
  > gcc -O -S -mno-space-regs builtin_ret.c
  > 
  > gives (trimming somewhat)
  > foo:
  >         bv %r0(%r2)
  >         ldw -20(%r30),%r28	# Oops, we never stored r2 at -20(%r30)
  > 
  > The fix I have in mind is to add some communication between
  > builtins.c:expand_builtin_return_addr and pa.c:hppa_expand_prologue.
  > eg. add a field to struct machine_function, and set it in
  > pa.c:return_addr_rtx to indicate that r2 must be saved.
The "right" way to handle this would be to have return_addr_rtx return
%r2 in the case where %r2 isn't ever saved into the stack.  However, I
don't know if we can reliably determine if %r2 is saved into the stack
at the point where we call return_addr_rtx.

If we can't reliably make that determination, then we can just force
%r2 to be saved into the stack if we ever call __builtin_return_address.

  > A similar problem occurs with
  > cat >builtin_frame.c <<EOF
  > void *foo (void) { return __builtin_frame_address (1); }
  > EOF
  > gcc -O -S builtin_frame.c
  > 
  > foo:
  >         bv %r0(%r2)
  >         ldw 0(%r30),%r28	# Oops, we haven't saved a frame pointer.
  > 
  > We ought to be able to make __builtin_frame_address (n) work reliably for
  > n = 0 and n = 1 by something similar to the fix I'm proposing for the
  > return address problem.  ie. set a "frame_pointer_needed" flag in
  > struct machine_function.
I disagree about the solutoin for this one.  I believe it should be 
possible to derive the frame address from the stack pointer fairly
easily since the difference between the stack and frame pointer is
a constant.

jeff

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

end of thread, other threads:[~2001-05-06 16:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-05 12:41 [parisc-linux] pa __builtin_return_addr Alan Modra
2001-05-06 16:25 ` [parisc-linux] " law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox