[Cbe-oss-dev] [PATCH] libspe: fix misalignment in PPE assited library calls

Kazunori Asayama asayama at sm.sony.co.jp
Mon Apr 24 20:02:18 EST 2006


This is a patch to fix a problem of libspe about SPE C99 handler.
va_lists allocated in order to process
`PPE assisted library calls with variable arguments'
are misaligned in some cases, and it causes incorrect access to
the arguments of the function calls.
This patch should be applied to development version of libspe 1.0.1.

You can reproduce this problem as following:

1. build libspe with AltiVec ABI (-mabi=altivec)
  (it's default for cross compiling)

2. run a simple SPU program such as:

  ---
  #include <stdio.h>
  int main()
  {
     printf("%f,%f,%f,%f\n", 1.0f, 2.0f, 3.0f, 4.0f);
     return 0;
  }
  ---

  and you will get wrong output as:

  ---
  4.000000,-320039143797039123542117658189456796681509412 ...
  ---

  Of course, you need to use `CELL SDK library and sample' as SPU libc,
  but newlib (newlib does not call `PPE assisted printf').

Thanks,
-- 
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t
--
Index: libspe-1.0.1/default_c99_handler.c
===================================================================
RCS file: /cvsroot/misc/libspe/default_c99_handler.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 default_c99_handler.c
--- libspe-1.0.1/default_c99_handler.c	9 Dec 2005 10:38:50 -0000	1.1.1.2
+++ libspe-1.0.1/default_c99_handler.c	21 Apr 2006 08:12:20 -0000
@@ -157,8 +157,11 @@ typedef unsigned long long __va_elem;
     }

 /* Allocate stack space for vargs array. */
+#define __VA_LIST_ALIGN 16UL
+
 #define __VA_LIST_ALLOCA(_nr)    \
-	(__va_elem *) alloca((_nr+1) * sizeof(__va_elem) + 1)
+	(__va_elem *)(((unsigned long)alloca((_nr+1) * sizeof(__va_elem) + __VA_LIST_ALIGN) \
+		       + __VA_LIST_ALIGN - 1) & ~(__VA_LIST_ALIGN - 1))

 #define __OFFSET(_type)	(sizeof(_type)-1)
 #define __MASK(_type)	~(__OFFSET(_type))



More information about the cbe-oss-dev mailing list