diff -upr gcc-4.0.2/gcc/cp/cp-gimplify.c gcc-4.0.2-targetcompiler/gcc/cp/cp-gimplify.c
--- gcc-4.0.2/gcc/cp/cp-gimplify.c	2004-12-22 19:00:38.000000000 +0100
+++ gcc-4.0.2-targetcompiler/gcc/cp/cp-gimplify.c	2006-07-26 15:29:06.000000000 +0200
@@ -283,7 +283,10 @@ cp_genericize_r (tree *stmt_p, int *walk
   tree stmt = *stmt_p;
   struct pointer_set_t *p_set = (struct pointer_set_t*) data;
 
-  if (is_invisiref_parm (stmt))
+  if (is_invisiref_parm (stmt)
+      /* Don't dereference parms in a thunk, pass the references through. */
+      && !(DECL_THUNK_P (current_function_decl)
+           && TREE_CODE (stmt) == PARM_DECL))
     {
       *stmt_p = convert_from_reference (stmt);
       *walk_subtrees = 0;
diff -upr gcc-4.0.2/gcc/cp/method.c gcc-4.0.2-targetcompiler/gcc/cp/method.c
--- gcc-4.0.2/gcc/cp/method.c	2005-07-12 13:27:32.000000000 +0200
+++ gcc-4.0.2-targetcompiler/gcc/cp/method.c	2006-07-26 15:29:08.000000000 +0200
@@ -491,7 +491,8 @@ use_thunk (tree thunk_fndecl, bool emit_
 		t = build3 (COND_EXPR, TREE_TYPE (t), cond, t,
 			    cp_convert (TREE_TYPE (t), integer_zero_node));
 	    }
-	  t = force_target_expr (TREE_TYPE (t), t);
+	  if (IS_AGGR_TYPE (TREE_TYPE (t)))
+		  t = build_cplus_new (TREE_TYPE (t), t);
 	  finish_return_stmt (t);
 	}
 
diff -upr gcc-4.0.2/gcc/tree.h gcc-4.0.2-targetcompiler/gcc/tree.h
--- gcc-4.0.2/gcc/tree.h	2005-08-23 09:39:41.000000000 +0200
+++ gcc-4.0.2-targetcompiler/gcc/tree.h	2006-07-26 15:39:56.000000000 +0200
@@ -1001,7 +1001,7 @@ extern void tree_operand_check_failed (i
 
 /* In a CALL_EXPR, means that the call is the jump from a thunk to the
    thunked-to function.  */
-#define CALL_FROM_THUNK_P(NODE) ((NODE)->common.protected_flag)
+#define CALL_FROM_THUNK_P(NODE) (CALL_EXPR_CHECK (NODE)->common.protected_flag)
 
 /* In a type, nonzero means that all objects of the type are guaranteed by the
    language or front-end to be properly aligned, so we can indicate that a MEM
diff -upr gcc-4.0.2/libstdc++-v3/config/locale/generic/c_locale.h gcc-4.0.2-targetcompiler/libstdc++-v3/config/locale/generic/c_locale.h
--- gcc-4.0.2/libstdc++-v3/config/locale/generic/c_locale.h	2005-01-30 15:09:58.000000000 +0100
+++ gcc-4.0.2-targetcompiler/libstdc++-v3/config/locale/generic/c_locale.h	2006-07-26 14:55:30.000000000 +0200
@@ -41,12 +41,18 @@
 #include <clocale>
 #include <cstring>   // get std::strlen
 #include <cstdio>    // get std::snprintf or std::sprintf
+#include <features.h>
+#include <ctype.h>
 
 #define _GLIBCXX_NUM_CATEGORIES 0
 
 namespace std
 {
-  typedef int*			__c_locale;
+#ifdef __UCLIBC__
+   typedef __ctype_touplow_t*	__c_locale;
+#else
+   typedef int*			__c_locale;
+#endif
 
   // Convert numeric value of type _Tv to string and return length of
   // string.  If snprintf is available use it, otherwise fall back to
diff -upr gcc-4.0.2/libstdc++-v3/config/os/gnu-linux/ctype_base.h gcc-4.0.2-targetcompiler/libstdc++-v3/config/os/gnu-linux/ctype_base.h
--- gcc-4.0.2/libstdc++-v3/config/os/gnu-linux/ctype_base.h	2004-11-23 10:18:38.000000000 +0100
+++ gcc-4.0.2-targetcompiler/libstdc++-v3/config/os/gnu-linux/ctype_base.h	2006-07-26 14:56:20.000000000 +0200
@@ -31,6 +31,8 @@
 //
 // ISO C++ 14882: 22.1  Locales
 //
+#include <features.h>
+#include <ctype.h>
   
 /** @file ctype_base.h
  *  This is an internal header file, included by other library headers.
@@ -43,7 +45,11 @@
   struct ctype_base
   {
     // Non-standard typedefs.
-    typedef const int* 		__to_type;
+#ifdef __UCLIBC__
+    typedef const __ctype_touplow_t*	__to_type;
+#else
+    typedef const int*			__to_type;
+#endif
 
     // NB: Offsets into ctype<char>::_M_table force a particular size
     // on the mask type. Because of this, we don't use an enum.
