diff mbox

Removal of uses of MAX_REGISTER_SIZE

Message ID 7CF07197-4FED-4970-BB4B-2FE828E29A63@arm.com
State New
Headers show

Commit Message

Alan Hayward Jan. 24, 2017, 10:31 a.m. UTC
This patch replaces all current uses of MAX_REGISTER_SIZE with calls to
either register_size() when the register number is known, and
max_register_size() in all other cases.

It assumes that the patch "[PATCH 3/3] Calculate max register size" will be
approved, and follows the methods used in that series of 3 patches.

In a couple of cases I've moved variables outside a loop to prevent multiple
allocations.

Tested with "make check" on a build using enable-targets=all, and manually run
on x86 and aarch64.

Ok to commit?
Alan.

2017-01-24  Alan Hayward  <alan.hayward@arm.com>

	* aarch64-tdep.c (aarch64_store_return_value): Replace
	MAX_REGISTER_SIZE.
	(aarch64_pseudo_read_value): Likewise.
	(aarch64_pseudo_write): Likewise.
	* alpha-tdep.c (alpha_register_to_value): Likewise.
	(alpha_value_to_register): Likewise.
	* arm-tdep.c (arm_store_return_value): Likewise.
	* bfin-tdep.c (bfin_pseudo_register_read): Likewise.
	(bfin_pseudo_register_write): Likewise.
	* frame.c (frame_unwind_register_signed): Likewise.
	(frame_unwind_register_unsigned): Likewise.
	(get_frame_register_bytes): Likewise.
	(put_frame_register_bytes): Likewise.
	* frv-linux-tdep.c (frv_linux_supply_gregset): Likewise.
	* i386-tdep.c (i386_pseudo_register_read_into_value): Likewise.
	(i386_pseudo_register_write): Likewise.
	(i386_process_record): Likewise.
	* i387-tdep.c (i387_supply_xsave): Likewise.
	* ia64-tdep.c (ia64_register_to_value): Likewise.
	(ia64_value_to_register): Likewise.
	(examine_prologue): Likewise.
	(ia64_sigtramp_frame_prev_register): Likewise.
	(ia64_access_reg): Likewise.
	(ia64_access_rse_reg): Likewise.
	(ia64_libunwind_frame_prev_register): Likewise.
	(ia64_extract_return_value): Likewise.
	(ia64_store_return_value): Likewise.
	(ia64_push_dummy_call): Likewise.
	* m32r-tdep.c (m32r_push_dummy_call): Likewise.
	* m68k-linux-nat.c (fetch_register): Likewise.
	(store_register): Likewise.
	* gdb/mi/mi-main.c (register_changed_p): Likewise
	* mips-fbsd-tdep.c (mips_fbsd_supply_reg): Likewise.
	(mips_fbsd_collect_reg): Likewise.
	* mips-linux-tdep.c (supply_32bit_reg): Likewise.
	(mips_supply_gregset): Likewise.
	(mips_supply_fpregset): Likewise.
	(mips64_supply_gregset): Likewise.
	(mips64_fill_gregset): Likewise.
	(mips64_fill_fpregset): Likewise.
	* mips-tdep.c (mips_eabi_push_dummy_call): Likewise.
	(mips_o32_return_value): Likewise.
	(print_gp_register_row): Likewise.
	* mn10300-linux-tdep.c (am33_supply_gregset_method): Likewise.
	* mn10300-tdep.c (mn10300_extract_return_value): Likewise.
	(mn10300_push_dummy_call): Likewise.
	* ppc-linux-nat.c: Likewise.
	* ppc-sysv-tdep.c (ppc_sysv_abi_push_dummy_call): Likewise.
	(get_decimal_float_return_value): Likewise.
	(do_ppc_sysv_return_value): Likewise.
	(ppc64_sysv_abi_push_integer): Likewise.
	(ppc64_sysv_abi_push_freg): Likewise.
	(ppc64_sysv_abi_return_value_base): Likewise.
	(ppc64_sysv_abi_return_value): Likewise.
	* record-full.c (record_full_exec_insn): Likewise.
	(record_full_core_open_1): Likewise.
	(record_full_core_fetch_registers): Likewise.
	(record_full_core_store_registers): Likewise.
	(init_record_full_core_ops): Likewise.
	* remote-sim.c (gdbsim_fetch_register): Likewise.
	(gdbsim_store_register): Likewise.
	* rs6000-aix-tdep.c (rs6000_push_dummy_call): Likewise.
	* rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Likewise.
	* rs6000-nat.c: Likewise.
	* rs6000-tdep.c (rs6000_register_to_value): Likewise.
	(rs6000_value_to_register): Likewise.
	* sh-tdep.c (sh_pseudo_register_read): Likewise.
	(sh_pseudo_register_write): Likewise.
	* sh64-tdep.c (sh64_pseudo_register_read): Likewise.
	(sh64_pseudo_register_write): Likewise.
	* sol-thread.c (sol_thread_store_registers): Likewise.
	* stack.c (frame_info): Likewise.
	* target.c (debug_print_register): Likewise.
	* xtensa-tdep.c (xtensa_register_write_masked): Likewise.
	(xtensa_register_read_masked): Likewise.
	(xtensa_pseudo_register_read): Likewise.
	(xtensa_pseudo_register_write): Likewise.

Comments

Pedro Alves Jan. 27, 2017, 11:49 a.m. UTC | #1
On 01/24/2017 10:31 AM, Alan Hayward wrote:
> This patch replaces all current uses of MAX_REGISTER_SIZE with calls to
> either register_size() when the register number is known, and
> max_register_size() in all other cases.
> 
> It assumes that the patch "[PATCH 3/3] Calculate max register size" will be
> approved, and follows the methods used in that series of 3 patches.
> 
> In a couple of cases I've moved variables outside a loop to prevent multiple
> allocations.

The very first hunk calls alloca in a loop (I didn't look any
further).  This is unfortunately easy to get wrong with alloca.  (Not
just in this patch, but also future patches that might move things
around and add loops around allocas without noticing.)  Wish
the compiler warned about it and/or that C++ supported VLAs.  :-/

> index 801c03d5a0b5d205dc967cb0d53e299ea95eaa8f..a317c8f2bb192fc25689c84375b8c7bb327dd596 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -1982,7 +1982,8 @@ aarch64_store_return_value (struct type *type, struct regcache *regs,
>        for (i = 0; i < elements; i++)
>  	{
>  	  int regno = AARCH64_V0_REGNUM + i;
> -	  bfd_byte tmpbuf[MAX_REGISTER_SIZE];
> +	  bfd_byte *tmpbuf = (bfd_byte *) alloca (register_size (gdbarch,
> +								 regno));
> 
>  	  if (aarch64_debug)
>  	    {

Thanks,
Pedro Alves
Pedro Alves Jan. 27, 2017, 12:11 p.m. UTC | #2
On 01/24/2017 10:31 AM, Alan Hayward wrote:
>  aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
>  		      int regnum, const gdb_byte *buf)
>  {
> -  gdb_byte reg_buf[MAX_REGISTER_SIZE];
> +  gdb_byte *reg_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
> 
>    /* Ensure the register buffer is zero, we want gdb writes of the
>       various 'scalar' pseudo registers to behavior like architectural
>       writes, register width bytes are written the remainder are set to
>       zero.  */
> -  memset (reg_buf, 0, sizeof (reg_buf));
> +  memset (reg_buf, 0, sizeof (register_size (gdbarch, regnum)));

OK, I scrolled a bit further down to the third hunk.  This sizeof is 
clearly broken.  There may be more instances of this.

Makes me wonder whether this is the right approach.  :-/
(No, I don't have a formed opinion for what that would be.)

Thanks,
Pedro Alves
Yao Qi Feb. 1, 2017, 12:41 p.m. UTC | #3
On 17-01-27 12:11:09, Pedro Alves wrote:
> 
> Makes me wonder whether this is the right approach.  :-/
> (No, I don't have a formed opinion for what that would be.)
> 

Hi Pedro,
What do you mean by "this" here?  We can't take MAX_REGISTER_SIZE for
ever, as we may have bigger and bigger single register.  We do need a
gdbarch specific max register size.  Given there is no standard VLA in
C++, using alloca is the best way we can do so far.
diff mbox

Patch

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 801c03d5a0b5d205dc967cb0d53e299ea95eaa8f..a317c8f2bb192fc25689c84375b8c7bb327dd596 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -1982,7 +1982,8 @@  aarch64_store_return_value (struct type *type, struct regcache *regs,
       for (i = 0; i < elements; i++)
 	{
 	  int regno = AARCH64_V0_REGNUM + i;
-	  bfd_byte tmpbuf[MAX_REGISTER_SIZE];
+	  bfd_byte *tmpbuf = (bfd_byte *) alloca (register_size (gdbarch,
+								 regno));

 	  if (aarch64_debug)
 	    {
@@ -2236,7 +2237,7 @@  aarch64_pseudo_read_value (struct gdbarch *gdbarch,
 			   struct regcache *regcache,
 			   int regnum)
 {
-  gdb_byte reg_buf[MAX_REGISTER_SIZE];
+  gdb_byte *reg_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
   struct value *result_value;
   gdb_byte *buf;

@@ -2331,13 +2332,13 @@  static void
 aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  gdb_byte reg_buf[MAX_REGISTER_SIZE];
+  gdb_byte *reg_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   /* Ensure the register buffer is zero, we want gdb writes of the
      various 'scalar' pseudo registers to behavior like architectural
      writes, register width bytes are written the remainder are set to
      zero.  */
-  memset (reg_buf, 0, sizeof (reg_buf));
+  memset (reg_buf, 0, sizeof (register_size (gdbarch, regnum)));

   regnum -= gdbarch_num_regs (gdbarch);

diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index 4dd65c58cc2896ea6038399128e3eb376d1ee672..5d850db07da0d5f6d47795da970add58161d722c 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -244,7 +244,7 @@  alpha_register_to_value (struct frame_info *frame, int regnum,
 			int *optimizedp, int *unavailablep)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  gdb_byte in[MAX_REGISTER_SIZE];
+  gdb_byte *in = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   /* Convert to TYPE.  */
   if (!get_frame_register_bytes (frame, regnum, 0,
@@ -266,7 +266,8 @@  static void
 alpha_value_to_register (struct frame_info *frame, int regnum,
 			 struct type *valtype, const gdb_byte *in)
 {
-  gdb_byte out[MAX_REGISTER_SIZE];
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  gdb_byte *out = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   switch (TYPE_LENGTH (valtype))
     {
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 2bdfa57c2ff018f849fabecacfe44fec996c0505..8fe65a1647baf22ff1278a6dfc7e172d8382e2dc 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -8150,7 +8150,7 @@  arm_store_return_value (struct type *type, struct regcache *regs,

   if (TYPE_CODE (type) == TYPE_CODE_FLT)
     {
-      gdb_byte buf[MAX_REGISTER_SIZE];
+      gdb_byte *buf = (gdb_byte *) alloca (max_register_size (gdbarch));

       switch (gdbarch_tdep (gdbarch)->fp_model)
 	{
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 3df1ba387a323dc6827b1189432f8877d1833184..68848d1d700981d8f4b698fc122997284c964b57 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -689,7 +689,7 @@  static enum register_status
 bfin_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
 			   int regnum, gdb_byte *buffer)
 {
-  gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
+  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
   enum register_status status;

   if (regnum != BFIN_CC_REGNUM)
@@ -710,7 +710,7 @@  static void
 bfin_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int regnum, const gdb_byte *buffer)
 {
-  gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
+  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   if (regnum != BFIN_CC_REGNUM)
     internal_error (__FILE__, __LINE__,
diff --git a/gdb/frame.c b/gdb/frame.c
index d98003dee7c34a63bd25356e6674721664a4b2f3..10c905e9f5c2cabf303e8aaba22a7cd0df77a3ea 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1252,7 +1252,7 @@  frame_unwind_register_signed (struct frame_info *frame, int regnum)
   struct gdbarch *gdbarch = frame_unwind_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int size = register_size (gdbarch, regnum);
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (size);

   frame_unwind_register (frame, regnum, buf);
   return extract_signed_integer (buf, size, byte_order);
@@ -1270,7 +1270,7 @@  frame_unwind_register_unsigned (struct frame_info *frame, int regnum)
   struct gdbarch *gdbarch = frame_unwind_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int size = register_size (gdbarch, regnum);
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (size);

   frame_unwind_register (frame, regnum, buf);
   return extract_unsigned_integer (buf, size, byte_order);
@@ -1410,7 +1410,8 @@  get_frame_register_bytes (struct frame_info *frame, int regnum,
 	}
       else
 	{
-	  gdb_byte buf[MAX_REGISTER_SIZE];
+	  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch,
+							      regnum));
 	  enum lval_type lval;
 	  CORE_ADDR addr;
 	  int realnum;
@@ -1460,8 +1461,8 @@  put_frame_register_bytes (struct frame_info *frame, int regnum,
 	}
       else
 	{
-	  gdb_byte buf[MAX_REGISTER_SIZE];
-
+	  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch,
+							      regnum));
 	  deprecated_frame_register_read (frame, regnum, buf);
 	  memcpy (buf + offset, myaddr, curr_len);
 	  put_frame_register (frame, regnum, buf);
diff --git a/gdb/frv-linux-tdep.c b/gdb/frv-linux-tdep.c
index eb87f93058b0287e8f05c585d1b6aa1ff2bffb78..06f8cbb8cc4cd257a626bafac3307a68a1d04855 100644
--- a/gdb/frv-linux-tdep.c
+++ b/gdb/frv-linux-tdep.c
@@ -413,9 +413,10 @@  frv_linux_supply_gregset (const struct regset *regset,
 			  int regnum, const void *gregs, size_t len)
 {
   int regi;
-  char zerobuf[MAX_REGISTER_SIZE];
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  char *zerobuf = (char *) alloca (max_register_size (gdbarch));

-  memset (zerobuf, 0, MAX_REGISTER_SIZE);
+  memset (zerobuf, 0, max_register_size (gdbarch));

   /* gr0 always contains 0.  Also, the kernel passes the TBR value in
      this slot.  */
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8a4d59f6fdae8ec785462d0ceedcd6501b955cf0..6191593174f605cb0425a735ec02ca4d38969bc8 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3250,7 +3250,7 @@  i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 				      int regnum,
 				      struct value *result_value)
 {
-  gdb_byte raw_buf[MAX_REGISTER_SIZE];
+  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
   enum register_status status;
   gdb_byte *buf = value_contents_raw (result_value);

@@ -3455,7 +3455,7 @@  void
 i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int regnum, const gdb_byte *buf)
 {
-  gdb_byte raw_buf[MAX_REGISTER_SIZE];
+  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   if (i386_mmx_regnum_p (gdbarch, regnum))
     {
@@ -5037,7 +5037,7 @@  i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   uint32_t opcode;
   uint8_t opcode8;
   ULONGEST addr;
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (max_register_size (gdbarch));
   struct i386_record_s ir;
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   uint8_t rex_w = -1;
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index adbe72133089bc371108d5dd79bf8d8e61ba259c..acc43d7e98ac317824f4755ec150794f63af71e4 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -899,7 +899,8 @@  i387_supply_xsave (struct regcache *regcache, int regnum,
   const gdb_byte *regs = (const gdb_byte *) xsave;
   int i;
   unsigned int clear_bv;
-  static const gdb_byte zero[MAX_REGISTER_SIZE] = { 0 };
+  gdb_byte *zero = (gdb_byte *) alloca (max_register_size (gdbarch));
+  memset (zero, 0, max_register_size (gdbarch));
   enum
     {
       none = 0x0,
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index 4c53bc6b05a011e4995c94b669b4f11108a12a38..14e924d9d07ffd83d8bd9b41a9a725c78dce3375 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -1227,7 +1227,7 @@  ia64_register_to_value (struct frame_info *frame, int regnum,
 			int *optimizedp, int *unavailablep)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  gdb_byte in[MAX_REGISTER_SIZE];
+  gdb_byte *in = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   /* Convert to TYPE.  */
   if (!get_frame_register_bytes (frame, regnum, 0,
@@ -1245,7 +1245,7 @@  ia64_value_to_register (struct frame_info *frame, int regnum,
                          struct type *valtype, const gdb_byte *in)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  gdb_byte out[MAX_REGISTER_SIZE];
+  gdb_byte *out = (gdb_byte *) alloca (register_size (gdbarch, regnum));
   convert_typed_floating (in, valtype, out, ia64_ext_type (gdbarch));
   put_frame_register (frame, regnum, out);
 }
@@ -1516,7 +1516,9 @@  examine_prologue (CORE_ADDR pc, CORE_ADDR lim_pc,
 	  else if (qp == 0 && rN == 2
 	        && ((rM == fp_reg && fp_reg != 0) || rM == 12))
 	    {
-	      gdb_byte buf[MAX_REGISTER_SIZE];
+	      struct gdbarch *gdbarch = get_frame_arch (this_frame);
+	      gdb_byte *buf
+		= (gdb_byte *) alloca (register_size (gdbarch, sp_regnum));
 	      CORE_ADDR saved_sp = 0;
 	      /* adds r2, spilloffset, rFramePointer
 	           or
@@ -1532,7 +1534,6 @@  examine_prologue (CORE_ADDR pc, CORE_ADDR lim_pc,
 		 this'll be wrong.  FIXME */
 	      if (this_frame)
 		{
-		  struct gdbarch *gdbarch = get_frame_arch (this_frame);
 		  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 		  get_frame_register (this_frame, sp_regnum, buf);
 		  saved_sp = extract_unsigned_integer (buf, 8, byte_order);
@@ -2289,8 +2290,6 @@  static struct value *
 ia64_sigtramp_frame_prev_register (struct frame_info *this_frame,
 				   void **this_cache, int regnum)
 {
-  gdb_byte buf[MAX_REGISTER_SIZE];
-
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct ia64_frame_cache *cache =
@@ -2305,6 +2304,7 @@  ia64_sigtramp_frame_prev_register (struct frame_info *this_frame,
     {
       CORE_ADDR pc = 0;
       CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM];
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));

       if (addr != 0)
 	{
@@ -2495,8 +2495,8 @@  ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   long new_sof, old_sof;
-  gdb_byte buf[MAX_REGISTER_SIZE];
-
+  gdb_byte *buf = (gdb_byte *) alloca (max_register_size (gdbarch));
+
   /* We never call any libunwind routines that need to write registers.  */
   gdb_assert (!write);

@@ -2575,8 +2575,8 @@  ia64_access_rse_reg (unw_addr_space_t as, unw_regnum_t uw_regnum,
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   long new_sof, old_sof;
-  gdb_byte buf[MAX_REGISTER_SIZE];
-
+  gdb_byte *buf = (gdb_byte *) alloca (max_register_size (gdbarch));
+
   /* We never call any libunwind routines that need to write registers.  */
   gdb_assert (!write);

@@ -2982,7 +2982,8 @@  ia64_libunwind_frame_prev_register (struct frame_info *this_frame,
 	{
 	  int rrb_pr = 0;
 	  ULONGEST cfm;
-	  gdb_byte buf[MAX_REGISTER_SIZE];
+	  gdb_byte *buf
+	    = (gdb_byte *) alloca (register_size (gdbarch, IA64_CFM_REGNUM));

 	  /* Fetch predicate register rename base from current frame
 	     marker for this frame.  */
@@ -3229,9 +3230,9 @@  ia64_extract_return_value (struct type *type, struct regcache *regcache,
   float_elt_type = is_float_or_hfa_type (type);
   if (float_elt_type != NULL)
     {
-      gdb_byte from[MAX_REGISTER_SIZE];
       int offset = 0;
       int regnum = IA64_FR8_REGNUM;
+      gdb_byte *from = (gdb_byte *) alloca (register_size (gdbarch, regnum));
       int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type);

       while (n-- > 0)
@@ -3294,9 +3295,9 @@  ia64_store_return_value (struct type *type, struct regcache *regcache,
   float_elt_type = is_float_or_hfa_type (type);
   if (float_elt_type != NULL)
     {
-      gdb_byte to[MAX_REGISTER_SIZE];
       int offset = 0;
       int regnum = IA64_FR8_REGNUM;
+      gdb_byte *to = (gdb_byte *) alloca (register_size (gdbarch, regnum));
       int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type);

       while (n-- > 0)
@@ -3854,9 +3855,9 @@  ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 	{
 	  argoffset = 0;
 	  len = TYPE_LENGTH (type);
+	  gdb_byte *to = (gdb_byte *) alloca (max_register_size (gdbarch));
 	  while (len > 0 && floatreg < IA64_FR16_REGNUM)
 	    {
-	      gdb_byte to[MAX_REGISTER_SIZE];
 	      convert_typed_floating (value_contents (arg) + argoffset,
 				      float_elt_type, to,
 				      ia64_ext_type (gdbarch));
diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c
index 40f29d343b91f254cce2dd783553795c9c990eff..108d67ddfae0b445e41c6e0ae0a143da8f3b15ac 100644
--- a/gdb/m32r-tdep.c
+++ b/gdb/m32r-tdep.c
@@ -677,7 +677,7 @@  m32r_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   enum type_code typecode;
   CORE_ADDR regval;
   gdb_byte *val;
-  gdb_byte valbuf[MAX_REGISTER_SIZE];
+  gdb_byte *valbuf = (gdb_byte *) alloca (max_register_size (gdbarch));
   int len;

   /* First force sp to a 4-byte alignment.  */
@@ -707,7 +707,7 @@  m32r_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
       typecode = TYPE_CODE (type);
       len = TYPE_LENGTH (type);

-      memset (valbuf, 0, sizeof (valbuf));
+      memset (valbuf, 0, max_register_size (gdbarch));

       /* Passes structures that do not fit in 2 registers by reference.  */
       if (len > 8
diff --git a/gdb/m68k-linux-nat.c b/gdb/m68k-linux-nat.c
index 6944c74eb198381135fda3ddf01b9da3a63e62d5..09bfaaa9972054b9982eed20235c21467709b25d 100644
--- a/gdb/m68k-linux-nat.c
+++ b/gdb/m68k-linux-nat.c
@@ -105,7 +105,7 @@  fetch_register (struct regcache *regcache, int regno)
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   long regaddr, val;
   int i;
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regno));
   int tid;

   /* Overload thread id onto process id.  */
@@ -160,7 +160,7 @@  store_register (const struct regcache *regcache, int regno)
   long regaddr, val;
   int i;
   int tid;
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regno));

   /* Overload thread id onto process id.  */
   tid = ptid_get_lwp (inferior_ptid);
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 22803cb55694a835f59368d69bd0c8a389d778db..e4a5030d446d705f1da82ed451bbecc71b966cf2 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1129,8 +1129,8 @@  register_changed_p (int regnum, struct regcache *prev_regs,
 		    struct regcache *this_regs)
 {
   struct gdbarch *gdbarch = get_regcache_arch (this_regs);
-  gdb_byte prev_buffer[MAX_REGISTER_SIZE];
-  gdb_byte this_buffer[MAX_REGISTER_SIZE];
+  gdb_byte *prev_buffer = (gdb_byte *) alloca (max_register_size (gdbarch));
+  gdb_byte *this_buffer = (gdb_byte *) alloca (max_register_size (gdbarch));
   enum register_status prev_status;
   enum register_status this_status;

diff --git a/gdb/mips-fbsd-tdep.c b/gdb/mips-fbsd-tdep.c
index 00fae0ec60ddc9e645d3236efe29f2f9e9ceab5c..3ec9a503aa52d4aa3546cd32af3913eadc62d919 100644
--- a/gdb/mips-fbsd-tdep.c
+++ b/gdb/mips-fbsd-tdep.c
@@ -63,7 +63,7 @@  mips_fbsd_supply_reg (struct regcache *regcache, int regnum, const void *addr,
   else
     {
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-      gdb_byte buf[MAX_REGISTER_SIZE];
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
       LONGEST val;

       val = extract_signed_integer ((const gdb_byte *) addr, len, byte_order);
@@ -90,7 +90,7 @@  mips_fbsd_collect_reg (const struct regcache *regcache, int regnum, void *addr,
   else
     {
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-      gdb_byte buf[MAX_REGISTER_SIZE];
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
       LONGEST val;

       regcache_raw_collect (regcache, regnum, buf);
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index 57e75b5343e1b927e9fe28dea16759f769cf4506..07da374193bf7c83d1e72a0f9e8ebdf025dc0a2e 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -118,7 +118,8 @@  supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
+
   store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
 			extract_signed_integer ((const gdb_byte *) addr, 4,
 						byte_order));
@@ -131,12 +132,12 @@  void
 mips_supply_gregset (struct regcache *regcache,
 		     const mips_elf_gregset_t *gregsetp)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   int regi;
   const mips_elf_greg_t *regp = *gregsetp;
-  char zerobuf[MAX_REGISTER_SIZE];
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  char *zerobuf = (char *) alloca (max_register_size (gdbarch));

-  memset (zerobuf, 0, MAX_REGISTER_SIZE);
+  memset (zerobuf, 0, max_register_size (gdbarch));

   for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
     supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
@@ -245,9 +246,9 @@  mips_supply_fpregset (struct regcache *regcache,
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   int regi;
-  char zerobuf[MAX_REGISTER_SIZE];
+  char *zerobuf = (char *) alloca (max_register_size (gdbarch));

-  memset (zerobuf, 0, MAX_REGISTER_SIZE);
+  memset (zerobuf, 0, max_register_size (gdbarch));

   for (regi = 0; regi < 32; regi++)
     regcache_raw_supply (regcache,
@@ -377,12 +378,12 @@  void
 mips64_supply_gregset (struct regcache *regcache,
 		       const mips64_elf_gregset_t *gregsetp)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   int regi;
   const mips64_elf_greg_t *regp = *gregsetp;
-  gdb_byte zerobuf[MAX_REGISTER_SIZE];
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  gdb_byte *zerobuf = (gdb_byte *) alloca (max_register_size (gdbarch));

-  memset (zerobuf, 0, MAX_REGISTER_SIZE);
+  memset (zerobuf, 0, max_register_size (gdbarch));

   for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
     supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
@@ -470,7 +471,7 @@  mips64_fill_gregset (const struct regcache *regcache,

   if (regaddr != -1)
     {
-      gdb_byte buf[MAX_REGISTER_SIZE];
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regno));
       LONGEST val;

       regcache_raw_collect (regcache, regno, buf);
@@ -574,7 +575,7 @@  mips64_fill_fpregset (const struct regcache *regcache,
     }
   else if (regno == mips_regnum (gdbarch)->fp_control_status)
     {
-      gdb_byte buf[MAX_REGISTER_SIZE];
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regno));
       LONGEST val;

       regcache_raw_collect (regcache, regno, buf);
@@ -585,7 +586,7 @@  mips64_fill_fpregset (const struct regcache *regcache,
     }
   else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
     {
-      gdb_byte buf[MAX_REGISTER_SIZE];
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regno));
       LONGEST val;

       regcache_raw_collect (regcache, regno, buf);
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 637b34edd7c2cf5676b5c359ca1acfe59f0ad6c8..1a427449e053bd9f5a61960bb0eed1b183ca3a2a 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -4523,10 +4523,10 @@  mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* Now load as many as possible of the first arguments into
      registers, and push the rest onto the stack.  Loop thru args
      from first to last.  */
+  gdb_byte *valbuf = (gdb_byte *) alloca (max_register_size (gdbarch));
   for (argnum = 0; argnum < nargs; argnum++)
     {
       const gdb_byte *val;
-      gdb_byte valbuf[MAX_REGISTER_SIZE];
       struct value *arg = args[argnum];
       struct type *arg_type = check_typedef (value_type (arg));
       int len = TYPE_LENGTH (arg_type);
@@ -5757,7 +5757,7 @@  mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
       /* A struct that contains one or two floats.  Each value is part
          in the least significant part of their floating point
          register..  */
-      gdb_byte reg[MAX_REGISTER_SIZE];
+      gdb_byte *reg = (gdb_byte *) alloca (max_register_size (gdbarch));
       int regnum;
       int field;
       for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
@@ -6472,7 +6472,7 @@  print_gp_register_row (struct ui_file *file, struct frame_info *frame,
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   /* Do values for GP (int) regs.  */
-  gdb_byte raw_buffer[MAX_REGISTER_SIZE];
+  gdb_byte *raw_buffer = (gdb_byte *) alloca (max_register_size (gdbarch));
   int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8);    /* display cols
 							       per row.  */
   int col, byte;
diff --git a/gdb/mn10300-linux-tdep.c b/gdb/mn10300-linux-tdep.c
index 8c23f02b2b58b29b10a65df5ae0b4bcdce2925cd..4d36285bc77bcfe75d09682531bdc961f0e215e3 100644
--- a/gdb/mn10300-linux-tdep.c
+++ b/gdb/mn10300-linux-tdep.c
@@ -86,7 +86,9 @@  am33_supply_gregset_method (const struct regset *regset,
 			    struct regcache *regcache,
 			    int regnum, const void *gregs, size_t len)
 {
-  char zerobuf[MAX_REGISTER_SIZE];
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  int regsize = register_size (gdbarch, regnum);
+  char zerobuf[regsize];
   const mn10300_elf_greg_t *regp = (const mn10300_elf_greg_t *) gregs;
   int i;

@@ -188,15 +190,15 @@  am33_supply_gregset_method (const struct regset *regset,

     /* ssp, msp, and usp are inaccessible.  */
   case E_E8_REGNUM:
-    memset (zerobuf, 0, MAX_REGISTER_SIZE);
+    memset (zerobuf, 0, regsize);
     regcache_raw_supply (regcache, E_E8_REGNUM, zerobuf);
     break;
   case E_E9_REGNUM:
-    memset (zerobuf, 0, MAX_REGISTER_SIZE);
+    memset (zerobuf, 0, regsize);
     regcache_raw_supply (regcache, E_E9_REGNUM, zerobuf);
     break;
   case E_E10_REGNUM:
-    memset (zerobuf, 0, MAX_REGISTER_SIZE);
+    memset (zerobuf, 0, regsize);
     regcache_raw_supply (regcache, E_E10_REGNUM, zerobuf);

     break;
@@ -218,11 +220,11 @@  am33_supply_gregset_method (const struct regset *regset,
     break;
   case E_FPCR_REGNUM + 1:
     /* The two unused registers beyond fpcr are inaccessible.  */
-    memset (zerobuf, 0, MAX_REGISTER_SIZE);
+    memset (zerobuf, 0, regsize);
     regcache_raw_supply (regcache, E_FPCR_REGNUM + 1, zerobuf);
     break;
   case E_FPCR_REGNUM + 2:
-    memset (zerobuf, 0, MAX_REGISTER_SIZE);
+    memset (zerobuf, 0, regsize);
     regcache_raw_supply (regcache, E_FPCR_REGNUM + 2, zerobuf);
     break;
   default:	/* An error, obviously, but should we error out?  */
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 5f5d5ca87b811d66da272036a515210cf2f17134..bce8d839f100b0fe851a8f526e521c3b2dda95f3 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -195,7 +195,7 @@  static void
 mn10300_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			      struct regcache *regcache, void *valbuf)
 {
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (max_register_size (gdbarch));
   int len = TYPE_LENGTH (type);
   int reg, regsz;

@@ -1223,7 +1223,7 @@  mn10300_push_dummy_call (struct gdbarch *gdbarch,
   int stack_offset = 0;
   int argnum;
   const gdb_byte *val;
-  gdb_byte valbuf[MAX_REGISTER_SIZE];
+  gdb_byte *valbuf = (gdb_byte *) alloca (max_register_size (gdbarch));

   /* This should be a nop, but align the stack just in case something
      went wrong.  Stacks are four byte aligned on the mn10300.  */
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index a56d154d3126c69431eff0717d6b4bcbe15f9d96..d9d0ad561f1b6b49324c9f516af1b732efad10b7 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -496,7 +496,7 @@  fetch_register (struct regcache *regcache, int tid, int regno)
   CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
   int bytes_transferred;
   unsigned int offset;         /* Offset of registers within the u area.  */
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regno));

   if (altivec_register_p (gdbarch, regno))
     {
@@ -983,7 +983,7 @@  store_register (const struct regcache *regcache, int tid, int regno)
   CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
   int i;
   size_t bytes_to_transfer;
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, regno));

   if (altivec_register_p (gdbarch, regno))
     {
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index ecae6363e3ae0a388bc5294aade5590c4b432d18..15350e19b4acaaf8f92b86db7aa65f9d89c06dec 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -134,13 +134,14 @@  ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		    {
 		      /* Always store the floating point value using
 		         the register's floating-point format.  */
-		      gdb_byte regval[MAX_REGISTER_SIZE];
+		      int regnum = tdep->ppc_fp0_regnum + freg;
+		      gdb_byte *regval
+			= (gdb_byte *) alloca (register_size (gdbarch,
+							      regnum));
 		      struct type *regtype
 			= register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
 		      convert_typed_floating (val, type, regval, regtype);
-		      regcache_cooked_write (regcache,
-                                             tdep->ppc_fp0_regnum + freg,
-					     regval);
+		      regcache_cooked_write (regcache, regnum, regval);
 		    }
 		  freg++;
 		}
@@ -278,7 +279,9 @@  ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		{
 		  if (write_pass)
 		    {
-		      gdb_byte regval[MAX_REGISTER_SIZE];
+		      int regnum = tdep->ppc_fp0_regnum + freg;
+		      gdb_byte *regval
+			= (gdb_byte *) alloca (register_size (gdbarch, regnum));
 		      const gdb_byte *p;

 		      /* 32-bit decimal floats are right aligned in the
@@ -291,8 +294,7 @@  ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      else
 			p = val;

-		      regcache_cooked_write (regcache,
-			  tdep->ppc_fp0_regnum + freg, p);
+		      regcache_cooked_write (regcache, regnum, p);
 		    }

 		  freg++;
@@ -364,7 +366,9 @@  ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			  if (write_pass)
 			    {
 			      int regnum = tdep->ppc_fp0_regnum + freg;
-			      gdb_byte regval[MAX_REGISTER_SIZE];
+			      gdb_byte *regval
+				= (gdb_byte *) alloca (register_size (gdbarch,
+								      regnum));
 			      struct type *regtype
 				= register_type (gdbarch, regnum);
 			      convert_typed_floating (elval, eltype,
@@ -411,16 +415,17 @@  ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		    }
 		  else
 		    {
-		      gdb_byte word[MAX_REGISTER_SIZE];
+		      int regnum = tdep->ppc_gp0_regnum + greg;
+		      gdb_byte *word
+			= (gdb_byte *) alloca (register_size (gdbarch,
+							      regnum));
 		      store_unsigned_integer (word, tdep->wordsize, byte_order,
 					      unpack_long (eltype, elval));

 		      if (greg <= 10)
 			{
 			  if (write_pass)
-			    regcache_cooked_write (regcache,
-						   tdep->ppc_gp0_regnum + greg,
-						   word);
+			    regcache_cooked_write (regcache, regnum, word);
 			  greg++;
 			}
 		      else
@@ -516,8 +521,9 @@  ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 	    {
 	      /* Reduce the parameter down to something that fits in a
 	         "word".  */
-	      gdb_byte word[MAX_REGISTER_SIZE];
-	      memset (word, 0, MAX_REGISTER_SIZE);
+	      gdb_byte *word
+		= (gdb_byte *) alloca (max_register_size (gdbarch));
+	      memset (word, 0, max_register_size (gdbarch));
 	      if (len > tdep->wordsize
 		  || TYPE_CODE (type) == TYPE_CODE_STRUCT
 		  || TYPE_CODE (type) == TYPE_CODE_UNION)
@@ -621,9 +627,11 @@  get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
   /* 32-bit and 64-bit decimal floats in f1.  */
   if (TYPE_LENGTH (valtype) <= 8)
     {
+      int regnum = tdep->ppc_fp0_regnum + 1;
       if (writebuf != NULL)
 	{
-	  gdb_byte regval[MAX_REGISTER_SIZE];
+	  gdb_byte *regval = (gdb_byte *) alloca (register_size (gdbarch,
+								 regnum));
 	  const gdb_byte *p;

 	  /* 32-bit decimal float is right aligned in the doubleword.  */
@@ -635,11 +643,11 @@  get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
 	  else
 	    p = writebuf;

-	  regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, p);
+	  regcache_cooked_write (regcache, regnum, p);
 	}
       if (readbuf != NULL)
 	{
-	  regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf);
+	  regcache_cooked_read (regcache, regnum, readbuf);

 	  /* Left align 32-bit decimal float.  */
 	  if (TYPE_LENGTH (valtype) == 4)
@@ -702,24 +710,26 @@  do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
       && TYPE_LENGTH (type) <= 8
       && !tdep->soft_float)
     {
+      int regnum = tdep->ppc_fp0_regnum + 1;
       if (readbuf)
 	{
 	  /* Floats and doubles stored in "f1".  Convert the value to
 	     the required type.  */
-	  gdb_byte regval[MAX_REGISTER_SIZE];
-	  struct type *regtype = register_type (gdbarch,
-                                                tdep->ppc_fp0_regnum + 1);
-	  regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
+	  gdb_byte *regval = (gdb_byte *) alloca (register_size (gdbarch,
+								 regnum));
+	  struct type *regtype = register_type (gdbarch, regnum);
+	  regcache_cooked_read (regcache, regnum, regval);
 	  convert_typed_floating (regval, regtype, readbuf, type);
 	}
       if (writebuf)
 	{
 	  /* Floats and doubles stored in "f1".  Convert the value to
 	     the register's "double" type.  */
-	  gdb_byte regval[MAX_REGISTER_SIZE];
+	  gdb_byte *regval = (gdb_byte *) alloca (register_size (gdbarch,
+								 regnum));
 	  struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
 	  convert_typed_floating (writebuf, type, regval, regtype);
-	  regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
+	  regcache_cooked_write (regcache, regnum, regval);
 	}
       return RETURN_VALUE_REGISTER_CONVENTION;
     }
@@ -847,7 +857,8 @@  do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 	  if (TYPE_CODE (eltype) == TYPE_CODE_FLT)
 	    {
 	      int regnum = tdep->ppc_fp0_regnum + 1 + i;
-	      gdb_byte regval[MAX_REGISTER_SIZE];
+	      gdb_byte *regval = (gdb_byte *) alloca (register_size (gdbarch,
+								     regnum));
 	      struct type *regtype = register_type (gdbarch, regnum);

 	      if (writebuf != NULL)
@@ -977,7 +988,8 @@  do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
       /* GCC screwed up for structures or unions whose size is less
 	 than or equal to 8 bytes..  Instead of left-aligning, it
 	 right-aligns the data into the buffer formed by r3, r4.  */
-      gdb_byte regvals[MAX_REGISTER_SIZE * 2];
+      gdb_byte *regvals
+	= (gdb_byte *) alloca (max_register_size (gdbarch) * 2);
       int len = TYPE_LENGTH (type);
       int offset = (2 * tdep->wordsize - len) % tdep->wordsize;

@@ -992,7 +1004,7 @@  do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 	}
       if (writebuf)
 	{
-	  memset (regvals, 0, sizeof regvals);
+	  memset (regvals, 0, max_register_size (gdbarch) * 2);
 	  memcpy (regvals + offset, writebuf, len);
 	  regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
 				 regvals + 0 * tdep->wordsize);
@@ -1010,7 +1022,8 @@  do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 	  /* This matches SVr4 PPC, it does not match GCC.  */
 	  /* The value is right-padded to 8 bytes and then loaded, as
 	     two "words", into r3/r4.  */
-	  gdb_byte regvals[MAX_REGISTER_SIZE * 2];
+	  gdb_byte *regvals
+	    = (gdb_byte *) alloca (max_register_size (gdbarch) * 2);
 	  regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3,
 				regvals + 0 * tdep->wordsize);
 	  if (TYPE_LENGTH (type) > tdep->wordsize)
@@ -1023,8 +1036,9 @@  do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 	  /* This matches SVr4 PPC, it does not match GCC.  */
 	  /* The value is padded out to 8 bytes and then loaded, as
 	     two "words" into r3/r4.  */
-	  gdb_byte regvals[MAX_REGISTER_SIZE * 2];
-	  memset (regvals, 0, sizeof regvals);
+	  gdb_byte *regvals
+	    = (gdb_byte *) alloca (max_register_size (gdbarch) * 2);
+	  memset (regvals, 0, max_register_size (gdbarch) * 2);
 	  memcpy (regvals, writebuf, TYPE_LENGTH (type));
 	  regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3,
 				 regvals + 0 * tdep->wordsize);
@@ -1340,7 +1354,7 @@  ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte *buf = (gdb_byte *) alloca (max_register_size (gdbarch));

   if (argpos->regcache)
     store_unsigned_integer (buf, tdep->wordsize, byte_order, val);
@@ -1369,7 +1383,8 @@  ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
 	{
 	  int regnum = tdep->ppc_fp0_regnum + argpos->freg;
 	  struct type *regtype = register_type (gdbarch, regnum);
-	  gdb_byte regval[MAX_REGISTER_SIZE];
+	  gdb_byte *regval = (gdb_byte *) alloca (register_size (gdbarch,
+								 regnum));

 	  convert_typed_floating (val, type, regval, regtype);
 	  regcache_cooked_write (argpos->regcache, regnum, regval);
@@ -1814,7 +1829,7 @@  ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
     {
       int regnum = tdep->ppc_fp0_regnum + 1 + index;
       struct type *regtype = register_type (gdbarch, regnum);
-      gdb_byte regval[MAX_REGISTER_SIZE];
+      gdb_byte *regval = (gdb_byte *) alloca (register_size (gdbarch, regnum));

       if (writebuf != NULL)
 	{
@@ -2072,8 +2087,9 @@  ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,

       for (i = 0; i < n_regs; i++)
 	{
-	  gdb_byte regval[MAX_REGISTER_SIZE];
 	  int regnum = tdep->ppc_gp0_regnum + 3 + i;
+	  gdb_byte *regval = (gdb_byte *) alloca (register_size (gdbarch,
+								 regnum));
 	  int offset = i * tdep->wordsize;
 	  int len = TYPE_LENGTH (valtype) - offset;

@@ -2082,7 +2098,7 @@  ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,

 	  if (writebuf != NULL)
 	    {
-	      memset (regval, 0, sizeof regval);
+	      memset (regval, 0, register_size (gdbarch, regnum));
 	      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
 		  && offset == 0)
 		memcpy (regval + tdep->wordsize - len, writebuf, len);
diff --git a/gdb/record-full.c b/gdb/record-full.c
index fdd613b6e41bbfcd8644b02ccfeb98b53b518bff..c634de5edc73572aee52517c13e205039e1f9dd0 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -698,7 +698,8 @@  record_full_exec_insn (struct regcache *regcache,
     {
     case record_full_reg: /* reg */
       {
-        gdb_byte reg[MAX_REGISTER_SIZE];
+	gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch,
+							    entry->u.reg.num));

         if (record_debug > 1)
           fprintf_unfiltered (gdb_stdlog,
@@ -792,15 +793,17 @@  static void
 record_full_core_open_1 (const char *name, int from_tty)
 {
   struct regcache *regcache = get_current_regcache ();
-  int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  int regnum = gdbarch_num_regs (gdbarch);
+  int regmaxsize = max_register_size (gdbarch);
   int i;

   /* Get record_full_core_regbuf.  */
   target_fetch_registers (regcache, -1);
-  record_full_core_regbuf = (gdb_byte *) xmalloc (MAX_REGISTER_SIZE * regnum);
+  record_full_core_regbuf = (gdb_byte *) xmalloc (regmaxsize * regnum);
   for (i = 0; i < regnum; i ++)
     regcache_raw_collect (regcache, i,
-			  record_full_core_regbuf + MAX_REGISTER_SIZE * i);
+			  record_full_core_regbuf + regmaxsize * i);

   /* Get record_full_core_start and record_full_core_end.  */
   if (build_section_table (core_bfd, &record_full_core_start,
@@ -2038,6 +2041,9 @@  record_full_core_fetch_registers (struct target_ops *ops,
 				  struct regcache *regcache,
 				  int regno)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  int regmaxsize = max_register_size (gdbarch);
+
   if (regno < 0)
     {
       int num = gdbarch_num_regs (get_regcache_arch (regcache));
@@ -2045,11 +2051,11 @@  record_full_core_fetch_registers (struct target_ops *ops,

       for (i = 0; i < num; i ++)
         regcache_raw_supply (regcache, i,
-                             record_full_core_regbuf + MAX_REGISTER_SIZE * i);
+			     record_full_core_regbuf + regmaxsize * i);
     }
   else
     regcache_raw_supply (regcache, regno,
-                         record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
+			 record_full_core_regbuf + regmaxsize * regno);
 }

 /* "to_prepare_to_store" method for prec over corefile.  */
@@ -2067,9 +2073,12 @@  record_full_core_store_registers (struct target_ops *ops,
                              struct regcache *regcache,
                              int regno)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  int regmaxsize = max_register_size (gdbarch);
+
   if (record_full_gdb_operation_disable)
     regcache_raw_collect (regcache, regno,
-                          record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
+			  record_full_core_regbuf + regmaxsize * regno);
   else
     error (_("You can't do that without a process to debug."));
 }
@@ -2265,7 +2274,7 @@  init_record_full_core_ops (void)
      record_full_reg:
        1 byte:  record type (record_full_reg, see enum record_full_type).
        8 bytes: register id (network byte order).
-       MAX_REGISTER_SIZE bytes: register value.
+       max_register_size bytes: register value.
      record_full_mem:
        1 byte:  record type (record_full_mem, see enum record_full_type).
        8 bytes: memory length (network byte order).
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index b0c68c617e365c0ea18ac2eca525598b688ffbb5..b9051269beafbe833126150e1cee2960ec726c0e 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -447,29 +447,31 @@  gdbsim_fetch_register (struct target_ops *ops,
       {
 	/* For moment treat a `does not exist' register the same way
 	   as an ``unavailable'' register.  */
-	gdb_byte buf[MAX_REGISTER_SIZE];
+	int regsize = register_size (gdbarch, regno);
+      	gdb_byte *buf = (gdb_byte *) alloca (regsize);
 	int nr_bytes;

-	memset (buf, 0, MAX_REGISTER_SIZE);
+	memset (buf, 0, regsize);
 	regcache_raw_supply (regcache, regno, buf);
 	break;
       }

     default:
       {
+	int regsize = register_size (gdbarch, regno);
 	static int warn_user = 1;
-	gdb_byte buf[MAX_REGISTER_SIZE];
+	gdb_byte buf[regsize];
 	int nr_bytes;

 	gdb_assert (regno >= 0 && regno < gdbarch_num_regs (gdbarch));
-	memset (buf, 0, MAX_REGISTER_SIZE);
+	memset (buf, 0, regsize);
 	nr_bytes = sim_fetch_register (sim_data->gdbsim_desc,
 				       gdbarch_register_sim_regno
 					 (gdbarch, regno),
 				       buf,
-				       register_size (gdbarch, regno));
+				       regsize);
 	if (nr_bytes > 0
-	    && nr_bytes != register_size (gdbarch, regno) && warn_user)
+	    && nr_bytes != regsize && warn_user)
 	  {
 	    fprintf_unfiltered (gdb_stderr,
 				"Size of register %s (%d/%d) "
@@ -478,7 +480,7 @@  gdbsim_fetch_register (struct target_ops *ops,
 				regno,
 				gdbarch_register_sim_regno
 				  (gdbarch, regno),
-				nr_bytes, register_size (gdbarch, regno));
+				nr_bytes, regsize);
 	    warn_user = 0;
 	  }
 	/* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0'
@@ -492,7 +494,7 @@  gdbsim_fetch_register (struct target_ops *ops,
 	    fprintf_unfiltered (gdb_stdlog,
 				"gdbsim_fetch_register: %d", regno);
 	    /* FIXME: We could print something more intelligible.  */
-	    dump_mem (buf, register_size (gdbarch, regno));
+	    dump_mem (buf, regsize);
 	  }
 	break;
       }
@@ -516,15 +518,16 @@  gdbsim_store_register (struct target_ops *ops,
     }
   else if (gdbarch_register_sim_regno (gdbarch, regno) >= 0)
     {
-      gdb_byte tmp[MAX_REGISTER_SIZE];
+      int regsize = register_size (gdbarch, regno);
+      gdb_byte tmp[regsize];
       int nr_bytes;

       regcache_cooked_read (regcache, regno, tmp);
       nr_bytes = sim_store_register (sim_data->gdbsim_desc,
 				     gdbarch_register_sim_regno
 				       (gdbarch, regno),
-				     tmp, register_size (gdbarch, regno));
-      if (nr_bytes > 0 && nr_bytes != register_size (gdbarch, regno))
+				     tmp, regsize);
+      if (nr_bytes > 0 && nr_bytes != regsize)
 	internal_error (__FILE__, __LINE__,
 			_("Register size different to expected"));
       if (nr_bytes < 0)
@@ -538,7 +541,7 @@  gdbsim_store_register (struct target_ops *ops,
 	{
 	  fprintf_unfiltered (gdb_stdlog, "gdbsim_store_register: %d", regno);
 	  /* FIXME: We could print something more intelligible.  */
-	  dump_mem (tmp, register_size (gdbarch, regno));
+	  dump_mem (tmp, regsize);
 	}
     }
 }
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 9841a60eafb0381cd2343dd3a8d5745571f5460e..eefd0d6a15f7a64eaa4bf10a72bde80a35646ac9 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -236,6 +236,7 @@  rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
    User may have to cast\args to handle promotion correctly
    since gdb won't know if prototype supplied or not.  */

+  gdb_byte *word = (gdb_byte *) alloca (max_register_size (gdbarch));
   for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
     {
       int reg_size = register_size (gdbarch, ii + 3);
@@ -253,14 +254,12 @@  rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 	     Always store the floating point value using the register's
 	     floating-point format.  */
 	  const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno;
-	  gdb_byte reg_val[MAX_REGISTER_SIZE];
 	  struct type *reg_type = register_type (gdbarch, fp_regnum);

 	  gdb_assert (len <= 8);

-	  convert_typed_floating (value_contents (arg), type,
-				  reg_val, reg_type);
-	  regcache_cooked_write (regcache, fp_regnum, reg_val);
+	  convert_typed_floating (value_contents (arg), type, word, reg_type);
+	  regcache_cooked_write (regcache, fp_regnum, word);
 	  ++f_argno;
 	}

@@ -270,7 +269,6 @@  rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 	  /* Argument takes more than one register.  */
 	  while (argbytes < len)
 	    {
-	      gdb_byte word[MAX_REGISTER_SIZE];
 	      memset (word, 0, reg_size);
 	      memcpy (word,
 		      ((char *) value_contents (arg)) + argbytes,
@@ -290,8 +288,6 @@  rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
       else
 	{
 	  /* Argument can fit in one register.  No problem.  */
-	  gdb_byte word[MAX_REGISTER_SIZE];
-
 	  memset (word, 0, reg_size);
 	  memcpy (word, value_contents (arg), len);
 	  regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3 +ii, word);
diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
index f2aa1f8448cf487b1522df89ef42a3937799d95f..56f80410770b52a6ea81639c5108bbddd5c164f5 100644
--- a/gdb/rs6000-lynx178-tdep.c
+++ b/gdb/rs6000-lynx178-tdep.c
@@ -87,6 +87,7 @@  rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
      User may have to cast\args to handle promotion correctly
      since gdb won't know if prototype supplied or not.  */

+  gdb_byte *word = (gdb_byte *) alloca (max_register_size (gdbarch));
   for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
     {
       int reg_size = register_size (gdbarch, ii + 3);
@@ -105,24 +106,22 @@  rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
 	     Always store the floating point value using the register's
 	     floating-point format.  */
 	  const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno;
-	  gdb_byte reg_val[MAX_REGISTER_SIZE];
 	  struct type *reg_type = register_type (gdbarch, fp_regnum);

 	  gdb_assert (len <= 8);

-	  convert_typed_floating (value_contents (arg), type,
-				  reg_val, reg_type);
-	  regcache_cooked_write (regcache, fp_regnum, reg_val);
+	  convert_typed_floating (value_contents (arg), type, word, reg_type);
+	  regcache_cooked_write (regcache, fp_regnum, word);
 	  ++f_argno;
 	}

       if (len > reg_size)
 	{
-
 	  /* Argument takes more than one register.  */
 	  while (argbytes < len)
 	    {
-	      gdb_byte word[MAX_REGISTER_SIZE];
+	      gdb_byte *word
+		= (gdb_byte *) alloca (max_register_size (gdbarch));
 	      memset (word, 0, reg_size);
 	      memcpy (word,
 		      ((char *) value_contents (arg)) + argbytes,
@@ -142,8 +141,6 @@  rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
       else
 	{
 	  /* Argument can fit in one register.  No problem.  */
-	  gdb_byte word[MAX_REGISTER_SIZE];
-
 	  memset (word, 0, reg_size);
 	  memcpy (word, value_contents (arg), len);
 	  regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3 +ii, word);
diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c
index f42847bfeab8ad6d03c96a161238283a262f98d1..6f322ed465ee40f06fe35967104fc0c90fb88661 100644
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -162,7 +162,7 @@  static void
 fetch_register (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  int addr[MAX_REGISTER_SIZE];
+  int *addr = (int *) alloca (register_size (gdbarch, regno) * sizeof (int));
   int nr, isfloat;

   /* Retrieved values may be -1, so infer errors from errno.  */
@@ -222,7 +222,7 @@  static void
 store_register (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  int addr[MAX_REGISTER_SIZE];
+  int *addr = (int *) alloca (register_size (gdbarch, regno) * sizeof (int));
   int nr, isfloat;

   /* Fetch the register's value from the register cache.  */
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 527f643b7be833b4bf7a2386940f9764f8b81514..52bf957dd422deb41248dd8bb696dd0aae74c142 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -2590,8 +2590,7 @@  rs6000_register_to_value (struct frame_info *frame,
 			  int *optimizedp, int *unavailablep)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  gdb_byte from[MAX_REGISTER_SIZE];
-
+  gdb_byte *from = (gdb_byte *) alloca (register_size (gdbarch, regnum));
   gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);

   if (!get_frame_register_bytes (frame, regnum, 0,
@@ -2612,7 +2611,7 @@  rs6000_value_to_register (struct frame_info *frame,
                           const gdb_byte *from)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  gdb_byte to[MAX_REGISTER_SIZE];
+  gdb_byte *to = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);

diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 9b3692dc0c32ffcb53d99f0fc095303d2c221fcb..ac59bdc051c5ce524b70af6d5d3b2942dffc2f1c 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1648,7 +1648,6 @@  sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
 			 int reg_nr, gdb_byte *buffer)
 {
   int base_regnum;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
   enum register_status status;

   if (reg_nr == PSEUDO_BANK_REGNUM)
@@ -1656,6 +1655,8 @@  sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
     {
       base_regnum = dr_reg_base_num (gdbarch, reg_nr);
+      gdb_byte *temp_buffer
+	= (gdb_byte *) alloca (register_size (gdbarch, base_regnum));

       /* Build the value in the provided buffer.  */
       /* Read the real regs for which this one is an alias.  */
@@ -1687,7 +1688,6 @@  sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			  int reg_nr, const gdb_byte *buffer)
 {
   int base_regnum, portion;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];

   if (reg_nr == PSEUDO_BANK_REGNUM)
     {
@@ -1704,6 +1704,8 @@  sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
     {
       base_regnum = dr_reg_base_num (gdbarch, reg_nr);
+      gdb_byte *temp_buffer
+	= (gdb_byte *) alloca (register_size (gdbarch, base_regnum));

       /* We must pay attention to the endiannes.  */
       sh_register_convert_to_raw (gdbarch, register_type (gdbarch, reg_nr),
diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c
index 23f5ade3b2e631eeb50cb918a4f36bb8cfbe6131..9e77bb9597354541a7fc5f7c92149074f5dce719 100644
--- a/gdb/sh64-tdep.c
+++ b/gdb/sh64-tdep.c
@@ -1528,7 +1528,8 @@  sh64_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int base_regnum;
   int offset = 0;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
+  gdb_byte *temp_buffer = (gdb_byte *) alloca (max_register_size (gdbarch));
+
   enum register_status status;

   if (reg_nr >= DR0_REGNUM
@@ -1704,7 +1705,7 @@  sh64_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int base_regnum, portion;
   int offset;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
+  gdb_byte *temp_buffer = (gdb_byte *) alloca (max_register_size (gdbarch));

   if (reg_nr >= DR0_REGNUM
       && reg_nr <= DR_LAST_REGNUM)
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index a09a3ab9a8bc56f367e3ba1537f5674f0a7f491f..4ac95ad5f726e57e5d7a9d2696fef33bbc52473d 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -514,6 +514,7 @@  sol_thread_store_registers (struct target_ops *ops,
   td_err_e val;
   prgregset_t gregset;
   prfpregset_t fpregset;
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);

   if (!ptid_tid_p (inferior_ptid))
     {
@@ -535,7 +536,7 @@  sol_thread_store_registers (struct target_ops *ops,
   if (regnum != -1)
     {
       /* Not writing all the registers.  */
-      char old_value[MAX_REGISTER_SIZE];
+      char *old_value = (char *) alloca (register_size (gdbarch, regnum));

       /* Save new register value.  */
       regcache_raw_collect (regcache, regnum, old_value);
diff --git a/gdb/stack.c b/gdb/stack.c
index e00e2972cf20bc63917af19f86bf57f1c6b0b5b0..b76b2f540de3dce23dcb29a56280295790a7a533 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1667,7 +1667,7 @@  frame_info (char *addr_exp, int from_tty)
 	  {
 	    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 	    int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch));
-	    gdb_byte value[MAX_REGISTER_SIZE];
+	    gdb_byte *value = (gdb_byte *) alloca (sp_size);
 	    CORE_ADDR sp;

 	    frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
diff --git a/gdb/target.c b/gdb/target.c
index be7367c4c940e0ee5889cd00193ecb9e9de01b6b..7997615dfa98147fc080482d6781d3abbb324b75 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3565,7 +3565,7 @@  debug_print_register (const char * func,
     {
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
       int i, size = register_size (gdbarch, regno);
-      gdb_byte buf[MAX_REGISTER_SIZE];
+      gdb_byte *buf = (gdb_byte *) alloca (size);

       regcache_raw_collect (regcache, regno, buf);
       fprintf_unfiltered (gdb_stdlog, " = ");
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 978b13abc57a404974fc02dfd868977b3dab0290..d2e97f86705d13975e5db8d981acab1002cfd567 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -370,7 +370,10 @@  static void
 xtensa_register_write_masked (struct regcache *regcache,
 			      xtensa_register_t *reg, const gdb_byte *buffer)
 {
-  unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  unsigned int *value = (unsigned int *) alloca (max_register_size (gdbarch)
+						 + 1);
+
   const xtensa_mask_t *mask = reg->mask;

   int shift = 0;		/* Shift for next mask (mod 32).  */
@@ -454,7 +457,9 @@  static enum register_status
 xtensa_register_read_masked (struct regcache *regcache,
 			     xtensa_register_t *reg, gdb_byte *buffer)
 {
-  unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  unsigned int *value = (unsigned int *) alloca (max_register_size (gdbarch)
+						 + 1);
   const xtensa_mask_t *mask = reg->mask;

   int shift = 0;
@@ -559,12 +564,11 @@  xtensa_pseudo_register_read (struct gdbarch *gdbarch,
       && (regnum >= gdbarch_tdep (gdbarch)->a0_base)
       && (regnum <= gdbarch_tdep (gdbarch)->a0_base + 15))
     {
-      gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
+      int wb_regnum = gdbarch_tdep (gdbarch)->wb_regnum;
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, wb_regnum));
       enum register_status status;

-      status = regcache_raw_read (regcache,
-				  gdbarch_tdep (gdbarch)->wb_regnum,
-				  buf);
+      status = regcache_raw_read (regcache, wb_regnum, buf);
       if (status != REG_VALID)
 	return status;
       regnum = arreg_number (gdbarch, regnum,
@@ -655,10 +659,10 @@  xtensa_pseudo_register_write (struct gdbarch *gdbarch,
       && (regnum >= gdbarch_tdep (gdbarch)->a0_base)
       && (regnum <= gdbarch_tdep (gdbarch)->a0_base + 15))
     {
-      gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
+      int wb_regnum = gdbarch_tdep (gdbarch)->wb_regnum;
+      gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, wb_regnum));

-      regcache_raw_read (regcache,
-			 gdbarch_tdep (gdbarch)->wb_regnum, buf);
+      regcache_raw_read (regcache, wb_regnum, buf);
       regnum = arreg_number (gdbarch, regnum,
 			     extract_unsigned_integer (buf, 4, byte_order));
     }