This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH,TARGET]PR21078,21080 Fix AVR builtin_return_address


Anatoly ,

I swapped byte order (using rotate). 3 byte PC devices now return lower 16 bits.
Used local label - though this just omits it from symbol table.
Reversed "if" so only one warning is emitted.


You cannot use gen_int_mode(HImode, stack_usage) - stack usage is unknown until prologue. Symbol is used to provide forward reference

Ok?




Anatoly Sokolov wrote:
Hi.

Return adderss are stored in stack as big-endian values, and therefore address returned by 'builtin_return_address' is big-endian values.
Whether there is possibility in the GCC to change byte order in 'builtin_return_address' return value?


Index: avr.c
===================================================================
--- avr.c (revision 154058)
+++ avr.c (working copy)
@@ -113,6 +113,7 @@
/* Current device.  */
const struct mcu_type_s *avr_current_device;

+
section *progmem_section;

/* AVR attributes. */

Remove this from patch.

+ if (AVR_3_BYTE_PC)
+ warning (0, "'builtin_return_address' contains only 2 bytes of address");
+
+ /* Can only return this functions return address. Others not supported. */
+ if (count)
+ return NULL;


Swap this 'if' statement.

+ r = gen_rtx_PLUS (Pmode, tem, gen_rtx_SYMBOL_REF (Pmode, "__stack_offset"));
+ r = memory_address (Pmode, r);
+ return gen_frame_mem (Pmode, r);


Try to make "__stack_offset" local variable, i.e. ".L__stack_offset".

Possibly to don't use label here?
- r = gen_rtx_PLUS (Pmode, tem, gen_rtx_SYMBOL_REF (Pmode, "__stack_offset"));
+r = gen_rtx_PLUS (Pmode, tem, gen_int_mode (cfun->machine->stack_usage, Pmode);


@@ -609,6 +632,7 @@
          RTX_FRAME_RELATED_P (insn) = 1;
          insn = emit_move_insn (pushbyte, tmp_reg_rtx);
          RTX_FRAME_RELATED_P (insn) = 1;
+         cfun->machine->stack_usage++;
        }

      /* Clear zero reg.  */
@@ -641,6 +666,7 @@
              /* Emit push of register to save.  */
              insn=emit_move_insn (pushbyte, gen_rtx_REG (QImode, reg));
              RTX_FRAME_RELATED_P (insn) = 1;
+             cfun->machine->stack_usage++;
            }
        }
      if (frame_pointer_needed)
@@ -650,6 +676,7 @@
              /* Push frame pointer.  */
       insn = emit_move_insn (pushword, frame_pointer_rtx);
              RTX_FRAME_RELATED_P (insn) = 1;
+             cfun->machine->stack_usage += 2;
     }

          if (!size)
@@ -756,6 +783,7 @@
  emit_insn (sp_plus_insns);
              else
  emit_insn (fp_plus_insns);
+  cfun->machine->stack_usage += size;
            }
        }
    }

Fix formating.

@@ -785,6 +813,11 @@
+ /* Create symbol stack offset here so all functions have it. Add 1 to stack usage <<<


@@ -857,4 +856,7 @@
+  <<<<<
+  /* Current function stack size.  */

Remove spaces in the end of line.

Anatoly.

----- Original Message ----- From: "Andrew Hutchinson" <andrewhutchinson@cox.net>
To: "Anatoly Sokolov" <aesok@post.ru>
Cc: <gcc-patches@gcc.gnu.org>; "Weddington, Eric" <Eric.Weddington@atmel.com>
Sent: Wednesday, November 11, 2009 8:11 PM
Subject: Re: [PATCH,TARGET]PR21078,21080 Fix AVR builtin_return_address



Changes made as requested.

Ok now?

Andy


Anatoly Sokolov wrote:
Hi Andy.

+/* Current function stack size.  */
+static int stack_usage;

Move 'stack_usage' variable in 'machine_function' struct.


+rtx +avr_return_addr_rtx (int count, rtx tem)

Change type of 'tem' to const_rtx.


Index: avr.h
===================================================================
--- avr.h (revision 154058)
+++ avr.h (working copy)
@@ -367,9 +367,10 @@
 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET)   \
  OFFSET = avr_initial_elimination_offset (FROM, TO)

-#define RETURN_ADDR_RTX(count, x) \
-  gen_rtx_MEM (Pmode, memory_address (Pmode, plus_constant (tem, 1)))
+/* Return address is located at frame+stack size+1.  */
+#define RETURN_ADDR_RTX(count, tem) avr_return_addr_rtx (count, tem)

Move comment before RETURN_ADDR_RTX macro from avr.h to avr.c file.


Ok, with this changes.

Anatoly.




Attachment: newreturnaddr.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]