summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2017-09-21 22:55:45 +0930
committerAlan Modra <amodra@gcc.gnu.org>2017-09-21 22:55:45 +0930
commitc0ced9e080eca19fdd48bae7e959908ce3ab31c7 (patch)
tree1c8560e78b817786440bdfb38b31bda0bc11fd44 /gcc
parent24b0a9e2315ce74ccfa1bbfb0c50957d8723b9a4 (diff)
downloadgcc-c0ced9e080eca19fdd48bae7e959908ce3ab31c7.tar.gz
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: r253070
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/config/rs6000/rs6000.c25
2 files changed, 19 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9a8afeb3c26..ce63706113f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2017-09-21 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-19 Martin Liska <mliska@suse.cz>
PR c++/81355
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 32433b294a0..be3912cdb8d 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -22314,24 +22314,23 @@ debug_stack_info (rs6000_stack_t *info)
rtx
rs6000_return_addr (int count, rtx frame)
{
- /* Currently we don't optimize very well between prolog and body
- code and for PIC code the code can be actually quite bad, so
- don't try to be too clever here. */
+ /* We can't use get_hard_reg_initial_val for LR when count == 0 if LR
+ is trashed by the prologue, as it is for PIC on ABI_V4 and Darwin. */
if (count != 0
|| ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) && flag_pic))
{
cfun->machine->ra_needs_full_frame = 1;
- return
- gen_rtx_MEM
- (Pmode,
- memory_address
- (Pmode,
- plus_constant (Pmode,
- copy_to_reg
- (gen_rtx_MEM (Pmode,
- memory_address (Pmode, frame))),
- RETURN_ADDRESS_OFFSET)));
+ if (count == 0)
+ /* FRAME is set to frame_pointer_rtx by the generic code, but that
+ is good for loading 0(r1) only when !FRAME_GROWS_DOWNWARD. */
+ frame = stack_pointer_rtx;
+ rtx prev_frame_addr = memory_address (Pmode, frame);
+ rtx prev_frame = copy_to_reg (gen_rtx_MEM (Pmode, prev_frame_addr));
+ rtx lr_save_off = plus_constant (Pmode,
+ prev_frame, RETURN_ADDRESS_OFFSET);
+ rtx lr_save_addr = memory_address (Pmode, lr_save_off);
+ return gen_rtx_MEM (Pmode, lr_save_addr);
}
cfun->machine->ra_need_lr = 1;