Browse Source

[build] Add {PROVIDE,REQUIRE}_SYMBOL macros and tidy up compiler.h

tags/v0.9.8
Michael Brown 15 years ago
parent
commit
7c47ebd65c
1 changed files with 68 additions and 41 deletions
  1. 68
    41
      src/include/compiler.h

+ 68
- 41
src/include/compiler.h View File

@@ -24,6 +24,50 @@
24 24
  *
25 25
  */
26 26
 
27
+/* Force visibility of all symbols to "hidden", i.e. inform gcc that
28
+ * all symbol references resolve strictly within our final binary.
29
+ * This avoids unnecessary PLT/GOT entries on x86_64.
30
+ *
31
+ * This is a stronger claim than specifying "-fvisibility=hidden",
32
+ * since it also affects symbols marked with "extern".
33
+ */
34
+#ifndef ASSEMBLY
35
+#if __GNUC__ >= 4
36
+#pragma GCC visibility push(hidden)
37
+#endif
38
+#endif /* ASSEMBLY */
39
+
40
+/**
41
+ * @defgroup symmacros Macros to provide or require explicit symbols
42
+ * @{
43
+ */
44
+
45
+/** Provide a symbol within this object file */
46
+#ifdef ASSEMBLY
47
+#define PROVIDE_SYMBOL( _sym )				\
48
+	.globl	_sym ;					\
49
+	.comm	_sym, 0
50
+#else /* ASSEMBLY */
51
+#define PROVIDE_SYMBOL( _sym )				\
52
+	char _sym[0]
53
+#endif /* ASSEMBLY */
54
+
55
+/** Require a symbol within this object file */
56
+#ifdef ASSEMBLY
57
+#define REQUIRE_SYMBOL( _sym )				\
58
+	.equ	__need_ # _sym, _sym
59
+#else /* ASSEMBLY */
60
+#define REQUIRE_SYMBOL( _sym )				\
61
+	__asm__ ( ".equ\t__need_" #_sym ", " #_sym )
62
+#endif /* ASSEMBLY */
63
+
64
+/** @} */
65
+
66
+/**
67
+ * @defgroup objmacros Macros to provide or require explicit objects
68
+ * @{
69
+ */
70
+
27 71
 /* Not quite sure why cpp requires two levels of macro call in order
28 72
  * to actually expand OBJECT...
29 73
  */
@@ -31,44 +75,24 @@
31 75
 #define _H1( x, y ) x ## y
32 76
 #undef _H2
33 77
 #define _H2( x, y ) _H1 ( x, y )
34
-#define PREFIX_OBJECT(prefix) _H2 ( prefix, OBJECT )
35
-#define OBJECT_SYMBOL PREFIX_OBJECT(obj_)
36
-#undef _STR
37
-#define _STR(s) #s
38
-#undef _XSTR
39
-#define _XSTR(s) _STR(s)
40
-#define OBJECT_SYMBOL_STR _XSTR ( OBJECT_SYMBOL )
41
-
42
-#ifdef ASSEMBLY
78
+#define PREFIX_OBJECT( _prefix ) _H2 ( _prefix, OBJECT )
79
+#define OBJECT_SYMBOL PREFIX_OBJECT ( obj_ )
43 80
 
44
-	.globl	OBJECT_SYMBOL
45
-	.equ	OBJECT_SYMBOL, 0
81
+/** Always provide the symbol for the current object (defined by -DOBJECT) */
82
+PROVIDE_SYMBOL ( OBJECT_SYMBOL );
46 83
 
47
-#else /* ASSEMBLY */
84
+/** Explicitly require another object */
85
+#define REQUIRE_OBJECT( _obj ) REQUIRE_SYMBOL ( obj_ ## _obj )
48 86
 
49
-__asm__ ( ".globl\t" OBJECT_SYMBOL_STR );
50
-__asm__ ( ".equ\t" OBJECT_SYMBOL_STR ", 0" );
87
+/** @} */
51 88
 
52
-/**
53
- * Drag in an object by object name.
54
- *
55
- * Macro to allow objects to explicitly drag in other objects by
56
- * object name.  Used by config.c.
57
- *
58
- */
59
-#define REQUIRE_OBJECT(object) \
60
-	__asm__ ( ".equ\tneed_" #object ", obj_" #object );
89
+/** Select file identifier for errno.h (if used) */
90
+#define ERRFILE PREFIX_OBJECT ( ERRFILE_ )
61 91
 
62
-/* Force visibility of all symbols to "hidden", i.e. inform gcc that
63
- * all symbol references resolve strictly within our final binary.
64
- * This avoids unnecessary PLT/GOT entries on x86_64.
65
- *
66
- * This is a stronger claim than specifying "-fvisibility=hidden",
67
- * since it also affects symbols marked with "extern".
92
+/** @defgroup dbg Debugging infrastructure
93
+ * @{
68 94
  */
69
-#if __GNUC__ >= 4
70
-#pragma GCC visibility push(hidden)
71
-#endif
95
+#ifndef ASSEMBLY
72 96
 
73 97
 /** @def DBG
74 98
  *
@@ -117,12 +141,7 @@ __asm__ ( ".equ\t" OBJECT_SYMBOL_STR ", 0" );
117 141
  * DEBUG_LEVEL will be inserted into the object file.
118 142
  *
119 143
  */
120
-#define DEBUG_SYMBOL PREFIX_OBJECT(debug_)
121
-
122
-#if DEBUG_SYMBOL
123
-#define DEBUG_SYMBOL_STR _XSTR ( DEBUG_SYMBOL )
124
-__asm__ ( ".equ\tDBGLVL, " DEBUG_SYMBOL_STR );
125
-#endif
144
+#define DEBUG_SYMBOL PREFIX_OBJECT ( debug_ )
126 145
 
127 146
 /** printf() for debugging
128 147
  *
@@ -305,8 +324,13 @@ int __debug_disable;
305 324
 #define NDEBUG
306 325
 #endif
307 326
 
308
-/** Select file identifier for errno.h (if used) */
309
-#define ERRFILE PREFIX_OBJECT ( ERRFILE_ )
327
+#endif /* ASSEMBLY */
328
+/** @} */
329
+
330
+/** @defgroup attrs Miscellaneous attributes
331
+ * @{
332
+ */
333
+#ifndef ASSEMBLY
310 334
 
311 335
 /** Declare a data structure as packed. */
312 336
 #define PACKED __attribute__ (( packed ))
@@ -374,11 +398,14 @@ int __debug_disable;
374 398
  */
375 399
 #define __shared __asm__ ( "_shared_bss" ) __aligned
376 400
 
401
+#endif /* ASSEMBLY */
402
+/** @} */
403
+
377 404
 /**
378 405
  * Optimisation barrier
379 406
  */
407
+#ifndef ASSEMBLY
380 408
 #define barrier() __asm__ __volatile__ ( "" : : : "memory" )
381
-
382 409
 #endif /* ASSEMBLY */
383 410
 
384 411
 #include <bits/compiler.h>

Loading…
Cancel
Save