[uim-commit] r1819 - branches/r5rs/uim

yamaken at freedesktop.org yamaken at freedesktop.org
Wed Oct 5 21:13:46 PDT 2005


Author: yamaken
Date: 2005-10-05 21:13:41 -0700 (Wed, 05 Oct 2005)
New Revision: 1819

Modified:
   branches/r5rs/uim/uim-scm.c
   branches/r5rs/uim/uim-scm.h
Log:
* uim/uim-scm.c
* uim/uim-scm.h
  - Port r1777 from trunk


Modified: branches/r5rs/uim/uim-scm.c
===================================================================
--- branches/r5rs/uim/uim-scm.c	2005-10-06 03:43:22 UTC (rev 1818)
+++ branches/r5rs/uim/uim-scm.c	2005-10-06 04:13:41 UTC (rev 1819)
@@ -78,19 +78,10 @@
 static FILE *uim_output = NULL;
 
 #if UIM_SCM_GCC4_READY_GC
-/*
- * For ensuring that these function calls be uninlined. Don't access these
- * variables directly.
- *
- * Exporting the variables ensures that a expression (*f)() is certainly real
- * function call since the variables can be updated from outside of
- * libuim. Therefore, be avoid making the variables static by combining libuim
- * into other codes which enables function inlining for them.
- */
-uim_lisp *(*uim_scm_gc_protect_stack_ptr)(void)
-     = &uim_scm_gc_protect_stack_internal;
-uim_func_ptr (*uim_scm_gc_ensure_uninlined_func_ptr)(uim_func_ptr)
-     = &uim_scm_gc_ensure_uninlined_func_internal;
+/* See also the comment about these variables in uim-scm.h */
+uim_lisp *(*volatile uim_scm_gc_protect_stack_ptr)(void)
+   = &uim_scm_gc_protect_stack_internal;
+volatile uim_func_ptr uim_scm_uninlined_func_ptr = NULL;
 #endif /* UIM_SCM_GCC4_READY_GC */
 
 
@@ -315,12 +306,6 @@
   /* intentionally returns invalidated local address */
   return (uim_lisp *)SigScm_GC_ProtectStack(&stack_start);
 }
-
-uim_func_ptr
-uim_scm_gc_ensure_uninlined_func_internal(uim_func_ptr func)
-{
-  return func;
-}
 #else /* UIM_SCM_GCC4_READY_GC */
 void
 uim_scm_gc_protect_stack(uim_lisp *stack_start)

Modified: branches/r5rs/uim/uim-scm.h
===================================================================
--- branches/r5rs/uim/uim-scm.h	2005-10-06 03:43:22 UTC (rev 1818)
+++ branches/r5rs/uim/uim-scm.h	2005-10-06 04:13:41 UTC (rev 1819)
@@ -87,16 +87,27 @@
 
 #if UIM_SCM_GCC4_READY_GC
 /*
- * For ensuring that these function calls be uninlined. Don't access these
- * variables directly.
+ * Variables for ensuring that some function calls be uninlined, to against
+ * variable reordering on a stack frame performed in some compilers as
+ * anti-stack smashing or optimization. Don't access these variables directly.
  *
- * Exporting the variables ensures that a expression (*f)() is certainly real
- * function call since the variables can be updated from outside of
- * libuim. Therefore, be avoid making the variables static by combining libuim
- * into other codes which enables function inlining for them.
+ * Exporting the variables as global symbol ensures that a expression (*f)() is
+ * certainly real function call since the variables can be updated from outside
+ * of libuim. Therefore, be avoid making the variables static by combining
+ * libuim into other codes which enables function inlining for them.
+ *
+ * Although the volatile qualifier is sufficient to prohibit inlining in
+ * ordinary situation, some aggressive (or buggy) compiler may optimize the
+ * constraint out when producing self-completed single executable. So I decided
+ * that performs both following method as double-insurance.
+ *
+ *   1. export the variables as global symbol
+ *   2. qualify the variables volatile
+ *
+ *   -- YamaKen 2005-10-04
  */
-extern uim_lisp *(*uim_scm_gc_protect_stack_ptr)(void);
-extern uim_func_ptr (*uim_scm_gc_ensure_uninlined_func_ptr)(uim_func_ptr);
+extern uim_lisp *(*volatile uim_scm_gc_protect_stack_ptr)(void);
+extern volatile uim_func_ptr uim_scm_uninlined_func_ptr;
 #endif /* UIM_SCM_GCC4_READY_GC */
 
 
@@ -134,14 +145,20 @@
 #define UIM_SCM_GC_CALL_PROTECTED_VOID_FUNC(func, args)                      \
     UIM_SCM_GC_CALL_PROTECTED_FUNC_INTERNAL((void), func, args)
 
+/*
+ * Although the volatile qualifier of the 'fp' can remove
+ * uim_scm_uninlined_func_ptr, I do it as triple insurance for anti aggressive
+ * optimization (including optimizer bugs) -- YamaKen 2005-10-04
+ */
 #define UIM_SCM_GC_CALL_PROTECTED_FUNC_INTERNAL(exp_ret, func, args)         \
     do {                                                                     \
-        UIM_SCM_GC_PROTECTED_FUNC_T(func) fp;                                \
+        volatile UIM_SCM_GC_PROTECTED_FUNC_T(func) fp;                       \
         uim_lisp *stack_start;                                               \
                                                                              \
         stack_start = uim_scm_gc_protect_stack();                            \
-        fp = (UIM_SCM_GC_PROTECTED_FUNC_T(func))                             \
-                  uim_scm_gc_ensure_uninlined_func((uim_func_ptr)&func);     \
+        /* ensure that func is uninlined */                                  \
+        uim_scm_uninlined_func_ptr = (uim_func_ptr)&func;                    \
+        fp = (UIM_SCM_GC_PROTECTED_FUNC_T(func))uim_scm_uninlined_func_ptr;  \
         exp_ret (*fp)args;                                                   \
         uim_scm_gc_unprotect_stack(stack_start);                             \
     } while (/* CONSTCOND */ 0)
@@ -152,10 +169,8 @@
  */
 #ifdef __GNUC__
 #define uim_scm_gc_protect_stack uim_scm_gc_protect_stack_internal
-#define uim_scm_gc_ensure_uninlined_func uim_scm_gc_ensure_uninlined_func_internal
 #else /* __GNUC__ */
 #define uim_scm_gc_protect_stack (*uim_scm_gc_protect_stack_ptr)
-#define uim_scm_gc_ensure_uninlined_func (*uim_scm_gc_ensure_uninlined_func_ptr)
 #endif /* __GNUC__ */
 void
 uim_scm_gc_protect(uim_lisp *location);
@@ -164,8 +179,6 @@
 
 uim_lisp *
 uim_scm_gc_protect_stack_internal(void) UIM_SCM_NOINLINE;
-uim_func_ptr
-uim_scm_gc_ensure_uninlined_func_internal(uim_func_ptr func) UIM_SCM_NOINLINE;
 #else /* UIM_SCM_GCC4_READY_GC */
 void
 uim_scm_gc_protect(uim_lisp *location);



More information about the uim-commit mailing list