Commit a24f02ff by Alan Modra Committed by Alan Modra

[RS6000] PR81996, __builtin_return_address(0) fails

rs6000_return_addr assumes that the stack link is at frame+0, which is
true for count>0.  For count==0, rs6000_return_addr is called with
frame==frame_pointer_rtx and the stack link is *not* at frame+0 if
-fstack-protector-all or -fsanitize=address because rs6000.h sets
FRAME_GROWS_DOWNWARD for those options.

	PR target/81996
	* gcc/config/rs6000/rs6000.c (rs6000_return_addr): Use
	stack_pointer_rtx for count 0.  Update comments.  Break up
	large rtl expression.

From-SVN: r252901
parent f26a27f3
2017-09-18 Alan Modra <amodra@gmail.com>
PR target/81996
* gcc/config/rs6000/rs6000.c (rs6000_return_addr): Use
stack_pointer_rtx for count 0. Update comments. Break up
large rtl expression.
2017-09-17 Daniel Santos <daniel.santos@pobox.com> 2017-09-17 Daniel Santos <daniel.santos@pobox.com>
config/i386/i386.c: (xlogue_layout::STUB_NAME_MAX_LEN): Increase to 20 config/i386/i386.c: (xlogue_layout::STUB_NAME_MAX_LEN): Increase to 20
......
...@@ -25009,24 +25009,23 @@ debug_stack_info (rs6000_stack_t *info) ...@@ -25009,24 +25009,23 @@ debug_stack_info (rs6000_stack_t *info)
rtx rtx
rs6000_return_addr (int count, rtx frame) rs6000_return_addr (int count, rtx frame)
{ {
/* Currently we don't optimize very well between prolog and body /* We can't use get_hard_reg_initial_val for LR when count == 0 if LR
code and for PIC code the code can be actually quite bad, so is trashed by the prologue, as it is for PIC on ABI_V4 and Darwin. */
don't try to be too clever here. */
if (count != 0 if (count != 0
|| ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) && flag_pic)) || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) && flag_pic))
{ {
cfun->machine->ra_needs_full_frame = 1; cfun->machine->ra_needs_full_frame = 1;
return if (count == 0)
gen_rtx_MEM /* FRAME is set to frame_pointer_rtx by the generic code, but that
(Pmode, is good for loading 0(r1) only when !FRAME_GROWS_DOWNWARD. */
memory_address frame = stack_pointer_rtx;
(Pmode, rtx prev_frame_addr = memory_address (Pmode, frame);
plus_constant (Pmode, rtx prev_frame = copy_to_reg (gen_rtx_MEM (Pmode, prev_frame_addr));
copy_to_reg rtx lr_save_off = plus_constant (Pmode,
(gen_rtx_MEM (Pmode, prev_frame, RETURN_ADDRESS_OFFSET);
memory_address (Pmode, frame))), rtx lr_save_addr = memory_address (Pmode, lr_save_off);
RETURN_ADDRESS_OFFSET))); return gen_rtx_MEM (Pmode, lr_save_addr);
} }
cfun->machine->ra_need_lr = 1; cfun->machine->ra_need_lr = 1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment