[patch] Avoiding PLT indirect calls for internal functions



Hi,

the patch below adds a G_GNUC_INTERNAL define to glib2. This define
translates to an alias that causes gcc to avoid doing indirect PLT calls for
functions marked with this define (and it makes them library private as
well). PLT calls are *expensive*, and for the library internal functions
there is normally no need for such functions to use PLT calls. (The only
common exceptions are malloc-like functions)

With the patch below, glib2 goes from 20 PLT entries for "_g*" function to
only 5, all of which are caused by libcharset/ which isn't really internal
after all.

Comments?

Greetings,
    Arjan van de Ven

diff -purN glib-org/glib/gconvert.c glib-2.4.2/glib/gconvert.c
--- glib-org/glib/gconvert.c	2004-06-04 15:40:37.000000000 +0200
+++ glib-2.4.2/glib/gconvert.c	2004-07-05 17:25:14.443264448 +0200
@@ -90,7 +90,7 @@ try_to_aliases (const char **to_aliases,
   return FALSE;
 }
 
-extern const char **_g_charset_get_aliases (const char *canonical_name);
+extern const char **_g_charset_get_aliases (const char *canonical_name) G_GNUC_INTERNAL;
 
 /**
  * g_iconv_open:
diff -purN glib-org/glib/gdebug.h glib-2.4.2/glib/gdebug.h
--- glib-org/glib/gdebug.h	2002-02-26 04:47:47.000000000 +0100
+++ glib-2.4.2/glib/gdebug.h	2004-07-05 17:25:58.054634512 +0200
@@ -50,10 +50,10 @@ typedef enum {
       
 #endif /* G_ENABLE_DEBUG */
 
-GLIB_VAR gboolean _g_debug_initialized;
-GLIB_VAR guint _g_debug_flags;
+GLIB_VAR gboolean _g_debug_initialized G_GNUC_INTERNAL;
+GLIB_VAR guint _g_debug_flags G_GNUC_INTERNAL;
 
-void _g_debug_init ();
+void _g_debug_init () G_GNUC_INTERNAL;
 
 #ifdef __cplusplus
 }
diff -purN glib-org/glib/gmacros.h glib-2.4.2/glib/gmacros.h
--- glib-org/glib/gmacros.h	2004-07-05 16:38:37.883406000 +0200
+++ glib-2.4.2/glib/gmacros.h	2004-07-05 16:40:35.605509688 +0200
@@ -54,6 +54,16 @@
 #define G_GNUC_PURE
 #endif
 
+/*
+ * Provide G_GNUC_INTERNAL that is used for marking library functions
+ * as being used internally to the lib only, to not create inefficient PLT entries
+ */
+#if defined (__GNUC__) 
+#define G_GNUC_INTERNAL __attribute((visibility("hidden")))
+#else
+#define G_GNUC_INTERNAL
+#endif
+
 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
   __attribute__((__format__ (__printf__, format_idx, arg_idx)))
diff -purN glib-org/glib/gmessages.h glib-2.4.2/glib/gmessages.h
--- glib-org/glib/gmessages.h	2003-02-06 20:57:14.000000000 +0100
+++ glib-2.4.2/glib/gmessages.h	2004-07-05 17:20:00.114049752 +0200
@@ -104,7 +104,7 @@ GLogLevelFlags  g_log_set_always_fatal  
 void	_g_log_fallback_handler	(const gchar   *log_domain,
 				 GLogLevelFlags log_level,
 				 const gchar   *message,
-				 gpointer       unused_data);
+				 gpointer       unused_data) G_GNUC_INTERNAL;
 
 
 #ifndef G_LOG_DOMAIN
diff -purN glib-org/glib/gthreadinit.h glib-2.4.2/glib/gthreadinit.h
--- glib-org/glib/gthreadinit.h	2004-03-05 22:10:45.000000000 +0100
+++ glib-2.4.2/glib/gthreadinit.h	2004-07-05 17:22:41.799469832 +0200
@@ -27,16 +27,16 @@ G_BEGIN_DECLS
 void g_thread_init_glib (void);
 
 /* Are called from glib/gthread.c. May not contain g_private_new calls */
-void _g_mem_thread_init (void);
-void _g_messages_thread_init (void);
-void _g_convert_thread_init (void);
-void _g_rand_thread_init (void);
-void _g_main_thread_init (void);
-void _g_atomic_thread_init (void);
+void _g_mem_thread_init (void) G_GNUC_INTERNAL;
+void _g_messages_thread_init (void) G_GNUC_INTERNAL;
+void _g_convert_thread_init (void) G_GNUC_INTERNAL;
+void _g_rand_thread_init (void) G_GNUC_INTERNAL;
+void _g_main_thread_init (void) G_GNUC_INTERNAL;
+void _g_atomic_thread_init (void) G_GNUC_INTERNAL;
 
 /* Are called from glib/gthread.c. Must only contain g_private_new calls */
-void _g_mem_thread_private_init (void);
-void _g_messages_thread_private_init (void);
+void _g_mem_thread_private_init (void) G_GNUC_INTERNAL;
+void _g_messages_thread_private_init (void) G_GNUC_INTERNAL;
 
 G_END_DECLS
  
diff -purN glib-org/glib/gatomic.c glib-2.4.2/glib/gatomic.c
--- glib-org/glib/gatomic.c	2004-03-13 00:22:46.000000000 +0100
+++ glib-2.4.2/glib/gatomic.c	2004-07-05 17:23:51.815825728 +0200
@@ -23,7 +23,7 @@
 #include "config.h"
 
 #include "glib.h"
-
+#include "gthreadinit.h"
 #if defined (__GNUC__)
 # if defined (G_ATOMIC_I486)
 /* Adapted from CVS version 1.10 of glibc's sysdeps/i386/i486/bits/atomic.h 
diff -purN glib-org/glib/gunicodeprivate.h glib-2.4.2/glib/gunicodeprivate.h
--- glib-org/glib/gunicodeprivate.h	2003-09-10 18:55:36.000000000 +0200
+++ glib-2.4.2/glib/gunicodeprivate.h	2004-07-05 17:27:02.221879608 +0200
@@ -27,8 +27,8 @@ G_BEGIN_DECLS
 
 gunichar *_g_utf8_normalize_wc       (const gchar    *str,
                                       gssize          max_len,
-                                      GNormalizeMode  mode);
-gint      _g_unichar_combining_class (gunichar uc);
+                                      GNormalizeMode  mode) G_GNUC_INTERNAL;
+gint      _g_unichar_combining_class (gunichar uc) G_GNUC_INTERNAL;
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]