]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/commitdiff
Mark hooked functions as visibility(("protected")).
authorSimon Ruderich <simon@ruderich.org>
Sat, 15 Jun 2013 01:36:50 +0000 (03:36 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sat, 15 Jun 2013 01:36:50 +0000 (03:36 +0200)
src/compiler.h
src/hookmacros.h

index 85b58b1d90dc86e9f002c36099d156148cec50f6..d1c12dc05719262b64443366e0fb817138d7da42 100644 (file)
 # define always_inline __attribute__((always_inline))
 /* Unused parameter. */
 # define unused        __attribute__((unused))
 # define always_inline __attribute__((always_inline))
 /* Unused parameter. */
 # define unused        __attribute__((unused))
+/* Mark the function protected, which means it can't be overwritten by other
+ * modules (libraries), e.g. with LD_PRELOAD); otherwise same as the default
+ * visibility. This causes the compiler not use the PLT (and no relocations)
+ * for local calls from inside this module; but the symbols are still
+ * exported. This is faster and in this case prevents useless lookups as we
+ * hook those functions and nobody else should modify them. Not strictly
+ * necessary, but nice to have. */
+# define visibility_protected __attribute__((visibility("protected")))
 #else
 # define noinline
 # define always_inline
 # define unused
 #else
 # define noinline
 # define always_inline
 # define unused
+# define visibility_protected
 #endif
 
 /* Branch prediction information for the compiler. */
 #endif
 
 /* Branch prediction information for the compiler. */
index 8a05811ddf0b1a07b1ce9f03e92f5bb49e90c2bb..539d0d9d93fc241ca360df59cc9e4a9db6ee8033 100644 (file)
 
 #define HOOK_FUNC_DEF1(type, name, type1, arg1) \
     static type (*real_ ## name)(type1); \
 
 #define HOOK_FUNC_DEF1(type, name, type1, arg1) \
     static type (*real_ ## name)(type1); \
+    type name(type1) visibility_protected; \
     type name(type1 arg1)
 #define HOOK_FUNC_DEF2(type, name, type1, arg1, type2, arg2) \
     static type (*real_ ## name)(type1, type2); \
     type name(type1 arg1)
 #define HOOK_FUNC_DEF2(type, name, type1, arg1, type2, arg2) \
     static type (*real_ ## name)(type1, type2); \
+    type name(type1, type2) visibility_protected; \
     type name(type1 arg1, type2 arg2)
 #define HOOK_FUNC_DEF3(type, name, type1, arg1, type2, arg2, type3, arg3) \
     static type (*real_ ## name)(type1, type2, type3); \
     type name(type1 arg1, type2 arg2)
 #define HOOK_FUNC_DEF3(type, name, type1, arg1, type2, arg2, type3, arg3) \
     static type (*real_ ## name)(type1, type2, type3); \
+    type name(type1, type2, type3) visibility_protected; \
     type name(type1 arg1, type2 arg2, type3 arg3)
 #define HOOK_FUNC_DEF4(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \
     static type (*real_ ## name)(type1, type2, type3, type4); \
     type name(type1 arg1, type2 arg2, type3 arg3)
 #define HOOK_FUNC_DEF4(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \
     static type (*real_ ## name)(type1, type2, type3, type4); \
+    type name(type1, type2, type3, type4) visibility_protected; \
     type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4)
 
 #define HOOK_FUNC_VAR_DEF2(type, name, type1, arg1, type2, arg2) \
     static type (*real_ ## name)(type1, type2, ...); \
     type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4)
 
 #define HOOK_FUNC_VAR_DEF2(type, name, type1, arg1, type2, arg2) \
     static type (*real_ ## name)(type1, type2, ...); \
+    type name(type1, type2, ...) visibility_protected; \
     type name(type1 arg1, type2 arg2, ...)
 
 #define HOOK_FUNC_SIMPLE3(type, name, type1, arg1, type2, arg2, type3, arg3) \
     type name(type1 arg1, type2 arg2, ...)
 
 #define HOOK_FUNC_SIMPLE3(type, name, type1, arg1, type2, arg2, type3, arg3) \
+    type name(type1, type2, type3) visibility_protected; \
     type name(type1 arg1, type2 arg2, type3 arg3)
 
 #define HOOK_FUNC_VAR_SIMPLE1(type, name, type1, arg1) \
     type name(type1 arg1, type2 arg2, type3 arg3)
 
 #define HOOK_FUNC_VAR_SIMPLE1(type, name, type1, arg1) \
+    type name(type1, ...) visibility_protected; \
     type name(type1 arg1, ...)
 #define HOOK_FUNC_VAR_SIMPLE2(type, name, type1, arg1, type2, arg2) \
     type name(type1 arg1, ...)
 #define HOOK_FUNC_VAR_SIMPLE2(type, name, type1, arg1, type2, arg2) \
+    type name(type1, type2, ...) visibility_protected; \
     type name(type1 arg1, type2 arg2, ...)
 #define HOOK_FUNC_VAR_SIMPLE3(type, name, type1, arg1, type2, arg2, type3, arg3) \
     type name(type1 arg1, type2 arg2, ...)
 #define HOOK_FUNC_VAR_SIMPLE3(type, name, type1, arg1, type2, arg2, type3, arg3) \
+    type name(type1, type2, type3, ...) visibility_protected; \
     type name(type1 arg1, type2 arg2, type3 arg3, ...)
 
 #define HOOK_VOID1(type, name, fd, type1, arg1) \
     type name(type1 arg1, type2 arg2, type3 arg3, ...)
 
 #define HOOK_VOID1(type, name, fd, type1, arg1) \