[Cairo] ELF shared library improvements [0/4]

Richard Henderson rth at twiddle.net
Mon Jul 28 23:40:38 PDT 2003


Inspired by Carl and Keith's nice OLS talk, I'd like to help out
by adding machinery to build better elf shared libraries.  The
patches I've generated for this are somewhat long and tedious,
but that's what transcontinental flights are for, right?

Anyway, part the zeroth concerns a couple of common header files
that I think would be nice to have.  I can't think of what to
name them though.  For my own testing I've just dropped them by
hand into an include directory.  I think ideally they'd live 
alongside other useful headers such as <X11/Xfuncproto.h>, but
what to do for the moment is still an issue.

Parts 1 through 4 will use these headers (plus other minor changes,
usually the addition of "static" or "const") to reduce the number
of dynamic symbols and relocations to what appears to be the bare
minimum.

Later I will add elf symbol versioning, but I havn't yet written
the autoconfigury to make sure that such support exists.  At the
moment I've just edited the makefiles by hand to see that the
versioning itself works.

Anyway, here's the common header files mentioned above, with names
not quite chosen at random.  Perhaps someone can suggest what 
should be done with them, package-wise?


r~
-------------- next part --------------
--- /dev/null	2003-01-30 05:24:37.000000000 -0500
+++ bits/export.h	2003-07-27 21:33:40.000000000 -0400
@@ -0,0 +1,7 @@
+/* This file is included multiple times.  Don't ifdef protect it.  */
+
+#if defined(WIN32) || defined(__CYGWIN__)
+#define __external_linkage	__declspec(dllexport)
+#else
+#define __external_linkage
+#endif
--- /dev/null	2003-01-30 05:24:37.000000000 -0500
+++ bits/import.h	2003-07-27 21:33:14.000000000 -0400
@@ -0,0 +1,7 @@
+/* This file is included multiple times.  Don't ifdef protect it.  */
+
+#if defined(WIN32) || defined(__CYGWIN__)
+#define __external_linkage	__declspec(dllimport)
+#else
+#define __external_linkage
+#endif
--- /dev/null	2003-01-30 05:24:37.000000000 -0500
+++ bits/internal.h	2003-07-27 21:51:34.000000000 -0400
@@ -0,0 +1,49 @@
+#ifndef BITS_INTERNAL_H
+#define BITS_INTERNAL_H 1
+
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)) && defined(__ELF__)
+#define __internal_linkage	__attribute__((__visibility__("hidden")))
+#else
+#define __internal_linkage
+#endif
+
+/* The following macros are used for PLT bypassing.  First of all,
+   you need to have the function prototyped somewhere, say in foo.h:
+
+	int foo (int __bar);
+
+   If calls to foo within libfoo.so should always go to foo defined
+   in libfoo.so, then in fooint.h you add:
+
+	hidden_proto (foo)
+
+   and after the foo function definition:
+
+	int foo (int __bar)
+	{
+	  return __bar;
+	}
+	hidden_def (foo)
+*/
+
+#if __GNUC__ >= 2 && defined(__ELF__)
+# define hidden_proto(name)	hidden_proto1(name, INT_##name)
+# define hidden_proto1(name, internal)		\
+  extern __typeof (name) name			\
+	__asm__ (hidden_asmname (internal))	\
+	__internal_linkage;
+# define hidden_def(name)	hidden_def1(name, INT_##name)
+# define hidden_def1(name, internal)					\
+  extern __typeof (name) EXT_##name __asm__(hidden_asmname(name))	\
+	__attribute__((__alias__(hidden_asmname(internal))));
+# define hidden_ulp		hidden_ulp1(__USER_LABEL_PREFIX__)
+# define hidden_ulp1(x)		hidden_ulp2(x)
+# define hidden_ulp2(x)		#x
+# define hidden_asmname(name)	hidden_asmname1(name)
+# define hidden_asmname1(name)	hidden_ulp #name
+#else
+# define hidden_proto(name)
+# define hidden_def(name)
+#endif
+
+#endif /* BITS_INTERNAL_H */


More information about the cairo mailing list