From: Simon Ruderich Date: Sat, 15 Jun 2013 01:36:50 +0000 (+0200) Subject: Mark hooked functions as visibility(("protected")). X-Git-Tag: 0.1~37 X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=a58d1a9017a1a15a237f5b516fe2c44a0f01482e;p=coloredstderr%2Fcoloredstderr.git Mark hooked functions as visibility(("protected")). --- diff --git a/src/compiler.h b/src/compiler.h index 85b58b1..d1c12dc 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -26,10 +26,19 @@ # 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 +# define visibility_protected #endif /* Branch prediction information for the compiler. */ diff --git a/src/hookmacros.h b/src/hookmacros.h index 8a05811..539d0d9 100644 --- a/src/hookmacros.h +++ b/src/hookmacros.h @@ -103,29 +103,38 @@ #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, 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, 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, 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, type2, ...) visibility_protected; \ 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, ...) visibility_protected; \ 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, type2, type3, ...) visibility_protected; \ type name(type1 arg1, type2 arg2, type3 arg3, ...) #define HOOK_VOID1(type, name, fd, type1, arg1) \