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

Richard Henderson rth at twiddle.net
Mon Jul 28 23:51:46 PDT 2003


The patch to libpixregion is the simplest, mostly because
the library is a single object file, and was already marked
static as necessary.

The first trick here that most folks are not aware of is the
avoidance of PLT entries for calls within a single library.
This is yet another side effect of the occasionally usefull,
occasionally annoying name binding rules that ELF has.

The mechanism to work around this is a pair of symbols at the 
same address, one private, one public.  The somewhat automatic
generation of these symbols is somewhat of a black art, and 
only works with gcc; see the previous patch for gory details.
Other compilers just suffer with the unnecessary indirection.


r~
-------------- next part --------------
Index: src/pixregion.c
===================================================================
RCS file: /local/src/CVS/libpixregion/src/pixregion.c,v
retrieving revision 1.2
diff -c -p -d -u -p -r1.2 pixregion.c
--- src/pixregion.c	25 Feb 2003 18:28:05 -0000	1.2
+++ src/pixregion.c	29 Jul 2003 06:41:46 -0000
@@ -51,6 +51,7 @@ SOFTWARE.
 #include <string.h>
 
 #include "pixregionint.h"
+#include <bits/internal.h>
 
 #if defined (__GNUC__) && !defined (NO_INLINES)
 #define INLINE	__inline
@@ -87,6 +88,10 @@ PixRegionInit (PixRegion *region, PixReg
 static void
 PixRegionUninit (PixRegion *region);
 
+hidden_proto(PixRegionCreateSimple)
+hidden_proto(PixRegionCopy)
+hidden_proto(PixRegionUnion)
+
 /*
  * The functions in this file implement the Region abstraction used extensively
  * throughout the X11 sample server. A Region is simply a set of disjoint
@@ -325,6 +330,7 @@ PixRegionCreateSimple (PixRegionBox *ext
 
     return region;
 }
+hidden_def(PixRegionCreateSimple)
 
 /*****************************************************************
  *   RegionInit(pReg, rect, size)
@@ -449,6 +455,7 @@ PixRegionCopy(PixRegion *dst, PixRegion 
 	  dst->data->numRects * sizeof(PixRegionBox));
     return PixRegionStatusSuccess;
 }
+hidden_def(PixRegionCopy)
 
 
 /*======================================================================
@@ -1232,6 +1239,7 @@ PixRegionUnion(PixRegion *newReg, PixReg
     good(newReg);
     return PixRegionStatusSuccess;
 }
+hidden_def(PixRegionUnion)
 
 
 /*======================================================================
Index: src/pixregion.h
===================================================================
RCS file: /local/src/CVS/libpixregion/src/pixregion.h,v
retrieving revision 1.3
diff -c -p -d -u -p -r1.3 pixregion.h
--- src/pixregion.h	25 Apr 2003 20:21:42 -0000	1.3
+++ src/pixregion.h	29 Jul 2003 06:41:46 -0000
@@ -46,8 +46,18 @@ SOFTWARE.
 ******************************************************************/
 /* $Id: pixregion.h,v 1.3 2003/04/25 20:21:42 cworth Exp $ */
 
-#ifndef PIXREGION_H
-#define PIXREGION_H
+#ifndef _PIXREGION_H_
+#define _PIXREGION_H_
+
+#include <X11/Xfuncproto.h>
+
+#ifdef _PIXREGIONINT_H_
+#include <bits/export.h>
+#else
+#include <bits/import.h>
+#endif
+
+_XFUNCPROTOBEGIN
 
 typedef struct _PixRegion PixRegion;
 
@@ -62,51 +72,51 @@ typedef enum {
 
 /* creation/destruction */
 
-PixRegion *
+extern PixRegion * __external_linkage
 PixRegionCreate (void);
 
-PixRegion *
+extern PixRegion * __external_linkage
 PixRegionCreateSimple (PixRegionBox *extents);
 
-void
+extern void __external_linkage
 PixRegionDestroy (PixRegion *region);
 
 /* manipulation */
 
-void
+extern void __external_linkage
 PixRegionTranslate (PixRegion *region, int x, int y);
 
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionCopy (PixRegion *dest, PixRegion *source);
 
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionIntersect (PixRegion *newReg, PixRegion *reg1, PixRegion *reg2);
 
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionUnion (PixRegion *newReg, PixRegion *reg1, PixRegion *reg2);
 
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionUnionRect(PixRegion *dest, PixRegion *source,
 		   int x, int y, unsigned int width, unsigned int height);
 
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionSubtract (PixRegion *regD, PixRegion *regM, PixRegion *regS);
 
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionInverse (PixRegion *newReg, PixRegion *reg1, PixRegionBox *invRect);
 
 /* XXX: Need to fix this so it doesn't depend on an X data structure
-PixRegion *
+extern PixRegion * __external_linkage
 RectsToPixRegion (int nrects, xRectanglePtr prect, int ctype);
 */
 
 /* querying */
 
 /* XXX: These should proably be combined: PixRegionGetRects? */
-int
+extern int __external_linkage
 PixRegionNumRects (PixRegion *region);
 
-PixRegionBox *
+extern PixRegionBox * __external_linkage
 PixRegionRects (PixRegion *region);
 
 /* XXX: Change to an enum */
@@ -114,36 +124,39 @@ PixRegionRects (PixRegion *region);
 #define rgnIN  1
 #define rgnPART 2
 
-int
+extern int __external_linkage
 PixRegionPointInRegion (PixRegion *region, int x, int y, PixRegionBox *box);
 
-int
+extern int __external_linkage
 PixRegionRectIn (PixRegion *PixRegion, PixRegionBox *prect);
 
-int
+extern int __external_linkage
 PixRegionNotEmpty (PixRegion *region);
 
-PixRegionBox *
+extern PixRegionBox * __external_linkage
 PixRegionExtents (PixRegion *region);
 
 /* mucking around */
 
 /* WARNING: calling PixRegionAppend may leave dest as an invalid
    region. Follow-up with PixRegionValidate to fix it up. */
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionAppend (PixRegion *dest, PixRegion *region);
 
-PixRegionStatus
+extern PixRegionStatus __external_linkage
 PixRegionValidate (PixRegion *badreg, int *pOverlap);
 
 /* Unclassified functionality
  * XXX: Do all of these need to be exported?
  */
 
-void
+extern void __external_linkage
 PixRegionReset (PixRegion *region, PixRegionBox *pBox);
 
-void
+extern void __external_linkage
 PixRegionEmpty (PixRegion *region);
 
-#endif /* PIXREGION_H */
+_XFUNCPROTOEND
+#undef __external_linkage
+
+#endif /* _PIXREGION_H_ */
Index: src/pixregionint.h
===================================================================
RCS file: /local/src/CVS/libpixregion/src/pixregionint.h,v
retrieving revision 1.2
diff -c -p -d -u -p -r1.2 pixregionint.h
--- src/pixregionint.h	25 Apr 2003 20:21:42 -0000	1.2
+++ src/pixregionint.h	29 Jul 2003 06:41:46 -0000
@@ -46,8 +46,8 @@ SOFTWARE.
 ******************************************************************/
 /* $Id: pixregionint.h,v 1.2 2003/04/25 20:21:42 cworth Exp $ */
 
-#ifndef PIXREGIONINT_H
-#define PIXREGIONINT_H
+#ifndef _PIXREGIONINT_H_
+#define _PIXREGIONINT_H_
 
 #include "pixregion.h"
 
@@ -80,4 +80,4 @@ typedef struct _PixRegionPoint {
 #define PIXREGION_END(reg) PIXREGION_BOX(reg, (reg)->data->numRects - 1)
 #define PIXREGION_SZOF(n) (sizeof(PixRegionData) + ((n) * sizeof(PixRegionBox)))
 
-#endif
+#endif /* _PIXREGIONINT_H_ */


More information about the cairo mailing list