Back to index

lightning-sunbird  0.9+nobinonly
slim_internal.h
Go to the documentation of this file.
00001 /* slim - Shared Library Interface Macros
00002  *
00003  * Copyright © 2003 Richard Henderson
00004  *
00005  * Permission to use, copy, modify, distribute, and sell this software
00006  * and its documentation for any purpose is hereby granted without
00007  * fee, provided that the above copyright notice appear in all copies
00008  * and that both that copyright notice and this permission notice
00009  * appear in supporting documentation, and that the name of Richard Henderson
00010  * not be used in advertising or publicity pertaining to distribution
00011  * of the software without specific, written prior permission.
00012  * Richard Henderson makes no representations about the suitability of this
00013  * software for any purpose.  It is provided "as is" without express
00014  * or implied warranty.
00015  * 
00016  * RICHARD HENDERSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00017  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
00018  * NO EVENT SHALL RICHARD HENDERSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00019  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00020  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00021  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00022  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00023  *
00024  * Author: Richard Henderson <rth@twiddle.net>
00025  */
00026 
00027 #ifndef _SLIM_INTERNAL_H_
00028 #define _SLIM_INTERNAL_H_ 1
00029 
00030 /* This macro marks a symbol as STV_HIDDEN, which prevents it from being
00031    added to the dynamic symbol table of the shared library.  This prevents
00032    users of the library from knowingly or unknowingly accessing library
00033    internals that may change in future releases.  It also allows the 
00034    compiler to generate slightly more efficient code in some cases.
00035 
00036    The macro should be placed either immediately before the return type in
00037    a function declaration:
00038 
00039        pixman_private int
00040        somefunction(void);
00041 
00042    or after a data name,
00043 
00044        extern int somedata pixman_private;
00045 
00046    The ELF visibility attribute did not exist before gcc 3.3.  */
00047 /* ??? Not marked with "slim" because that makes it look too much
00048    like the function name instead of just an attribute.  */
00049 
00050 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__)
00051 #define pixman_private      __attribute__((__visibility__("hidden")))
00052 #else
00053 #define pixman_private
00054 #endif
00055 
00056 /* The following macros are used for PLT bypassing.  First of all,
00057    you need to have the function prototyped somewhere, say in foo.h:
00058 
00059        int foo (int __bar);
00060 
00061    If calls to foo within libfoo.so should always go to foo defined
00062    in libfoo.so, then in fooint.h you add:
00063 
00064        slim_hidden_proto (foo)
00065 
00066    and after the foo function definition:
00067 
00068        int foo (int __bar)
00069        {
00070          return __bar;
00071        }
00072        slim_hidden_def (foo);
00073 
00074    This works by arranging for the C symbol "foo" to be renamed to
00075    "INT_foo" at the assembly level, which is marked pixman_private.
00076    We then create another symbol at the same address (an alias) with
00077    the C symbol "EXT_foo", which is renamed to "foo" at the assembly
00078    level.  */
00079 
00080 #if __GNUC__ >= 3 && defined(__ELF__)
00081 # define slim_hidden_proto(name)   slim_hidden_proto1(name, INT_##name)
00082 # define slim_hidden_def(name)            slim_hidden_def1(name, INT_##name)
00083 # define slim_hidden_proto1(name, internal)                           \
00084   extern __typeof (name) name                                         \
00085        __asm__ (slim_hidden_asmname (internal))                \
00086        pixman_private;
00087 # define slim_hidden_def1(name, internal)                      \
00088   extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name))       \
00089        __attribute__((__alias__(slim_hidden_asmname(internal))))
00090 # define slim_hidden_ulp           slim_hidden_ulp1(__USER_LABEL_PREFIX__)
00091 # define slim_hidden_ulp1(x)              slim_hidden_ulp2(x)
00092 # define slim_hidden_ulp2(x)              #x
00093 # define slim_hidden_asmname(name) slim_hidden_asmname1(name)
00094 # define slim_hidden_asmname1(name)       slim_hidden_ulp #name
00095 #else
00096 # define slim_hidden_proto(name)
00097 # define slim_hidden_def(name)
00098 #endif
00099 
00100 #endif /* _SLIM_INTERNAL_H_ */