Browse Source

[build] Use weak definitions instead of weak declarations

This removes the need for inline safety wrappers, marginally reducing
the size penalty of weak functions, and works around an apparent
binutils bug that causes undefined weak symbols to not actually be
NULL when compiling with -fPIE (as EFI builds do).

A bug in versions of binutils prior to 2.16 (released in 2005) will
cause same-file weak definitions to not work with those
toolchains. Update the README to reflect our new dependency on
binutils >= 2.16.

Signed-off-by: Joshua Oreman <oremanj@rwcr.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Joshua Oreman 14 years ago
parent
commit
2aad3fab23

+ 0
- 8
README View File

1
-iPXE README File
2
-
3
-Quick start guide:
4
-
5
-   cd src
6
-   make
7
-
8
-For any more detailed instructions, see http://ipxe.org

+ 1
- 19
src/arch/i386/include/pxe_call.h View File

38
 extern int pxe_deactivate ( void );
38
 extern int pxe_deactivate ( void );
39
 extern int pxe_start_nbp ( void );
39
 extern int pxe_start_nbp ( void );
40
 extern __asmcall void pxe_api_call ( struct i386_all_regs *ix86 );
40
 extern __asmcall void pxe_api_call ( struct i386_all_regs *ix86 );
41
-extern int _pxe_api_call_weak ( struct i386_all_regs *ix86 )
42
-	__attribute__ (( weak ));
43
-
44
-/**
45
- * Dispatch PXE API call weakly
46
- *
47
- * @v ix86		Registers for PXE call
48
- * @ret present		Zero if the PXE stack is present, nonzero if not
49
- *
50
- * A successful return only indicates that the PXE stack was available
51
- * for dispatching the call; it says nothing about the success of
52
- * whatever the call asked for.
53
- */
54
-static inline int pxe_api_call_weak ( struct i386_all_regs *ix86 )
55
-{
56
-	if ( _pxe_api_call_weak != NULL )
57
-		return _pxe_api_call_weak ( ix86 );
58
-	return -1;
59
-}
41
+extern int pxe_api_call_weak ( struct i386_all_regs *ix86 );
60
 
42
 
61
 #endif /* _PXE_CALL_H */
43
 #endif /* _PXE_CALL_H */

+ 1
- 1
src/arch/i386/interface/pxe/pxe_call.c View File

351
  * @v ix86		Registers for PXE call
351
  * @v ix86		Registers for PXE call
352
  * @ret present		Zero (PXE stack present)
352
  * @ret present		Zero (PXE stack present)
353
  */
353
  */
354
-int _pxe_api_call_weak ( struct i386_all_regs *ix86 )
354
+int pxe_api_call_weak ( struct i386_all_regs *ix86 )
355
 {
355
 {
356
 	pxe_api_call ( ix86 );
356
 	pxe_api_call ( ix86 );
357
 	return 0;
357
 	return 0;

+ 1
- 1
src/arch/i386/interface/pxeparent/pxeparent_dhcp.c View File

29
 /**
29
 /**
30
  * Present cached DHCP packet if it exists
30
  * Present cached DHCP packet if it exists
31
  */
31
  */
32
-void __weak_impl ( get_cached_dhcpack ) ( void ) {
32
+void get_cached_dhcpack ( void ) {
33
 	struct undi_device *undi;
33
 	struct undi_device *undi;
34
 	struct s_PXENV_GET_CACHED_INFO get_cached_info;
34
 	struct s_PXENV_GET_CACHED_INFO get_cached_info;
35
 	int rc;
35
 	int rc;

+ 14
- 0
src/arch/i386/interface/syslinux/comboot_call.c View File

318
 }
318
 }
319
 
319
 
320
 
320
 
321
+/**
322
+ * Dispatch PXE API call weakly
323
+ *
324
+ * @v ix86		Registers for PXE call
325
+ * @ret present		Zero if the PXE stack is present, nonzero if not
326
+ *
327
+ * A successful return only indicates that the PXE stack was available
328
+ * for dispatching the call; it says nothing about the success of
329
+ * whatever the call asked for.
330
+ */
331
+__weak int pxe_api_call_weak ( struct i386_all_regs *ix86 __unused ) {
332
+	return -1;
333
+}
334
+
321
 /**
335
 /**
322
  * SYSLINUX API
336
  * SYSLINUX API
323
  */
337
  */

+ 2
- 31
src/include/compiler.h View File

179
 /** Select file identifier for errno.h (if used) */
179
 /** Select file identifier for errno.h (if used) */
180
 #define ERRFILE PREFIX_OBJECT ( ERRFILE_ )
180
 #define ERRFILE PREFIX_OBJECT ( ERRFILE_ )
181
 
181
 
182
-/**
183
- * @defgroup weakmacros Macros to manage weak symbol definitions
184
- *
185
- * Weak symbols allow one to reference a function in another file
186
- * without necessarily requiring that file to be linked in. In their
187
- * native form, the function will be @c NULL if its file is not linked
188
- * in; these macros provide an inline wrapper that returns an
189
- * appropriate error indication or default value.
190
- *
191
- * @{
192
- */
193
 #ifndef ASSEMBLY
182
 #ifndef ASSEMBLY
194
 
183
 
195
-/** Mangle @a name into its weakly-referenced implementation */
196
-#define __weak_impl( name )   _w_ ## name
197
-
198
-/**
199
- * Declare a weak function with inline safety wrapper
200
- *
201
- * @v ret	Return type of weak function
202
- * @v name	Name of function to expose
203
- * @v proto	Parenthesized list of arguments with types
204
- * @v args	Parenthesized list of argument names
205
- * @v dfl	Value to return if weak function is not available
206
- */
207
-#define __weak_decl( ret, name, proto, args, dfl )		\
208
-        ret __weak_impl( name ) proto __attribute__ (( weak ));	\
209
-        static inline ret name proto {				\
210
-                if ( __weak_impl( name ) )			\
211
-                        return __weak_impl( name ) args;	\
212
-                return dfl;					\
213
-        }
184
+/** Declare a function as weak (use *before* the definition) */
185
+#define __weak		__attribute__ (( weak ))
214
 
186
 
215
 #endif
187
 #endif
216
-/** @} */
217
 
188
 
218
 /** @defgroup dbg Debugging infrastructure
189
 /** @defgroup dbg Debugging infrastructure
219
  * @{
190
  * @{

+ 1
- 1
src/include/ipxe/dhcp.h View File

630
  * should look for such a packet and call store_cached_dhcpack() with
630
  * should look for such a packet and call store_cached_dhcpack() with
631
  * it if it exists.
631
  * it if it exists.
632
  */
632
  */
633
-__weak_decl ( void, get_cached_dhcpack, ( void ), (), );
633
+extern void get_cached_dhcpack ( void );
634
 
634
 
635
 extern void store_cached_dhcpack ( userptr_t data, size_t len );
635
 extern void store_cached_dhcpack ( userptr_t data, size_t len );
636
 
636
 

+ 3
- 34
src/include/ipxe/sec80211.h View File

27
 /** @file
27
 /** @file
28
  *
28
  *
29
  * Definitions for general secured-network routines.
29
  * Definitions for general secured-network routines.
30
- *
31
- * Any function in this file which may be referenced by code which is
32
- * not exclusive to encryption-enabled builds (e.g. sec80211_detect(),
33
- * which is called by net80211_probe_step() to fill the net80211_wlan
34
- * structure's security fields) must be declared as a weak symbol,
35
- * using an inline interface similar to that used for
36
- * sec80211_detect() below. This prevents secure network support from
37
- * bloating general builds by any more than a few tiny hooks to call
38
- * crypto functions when crypto structures are non-NULL.
39
  */
30
  */
40
 
31
 
41
-int _sec80211_detect ( struct io_buffer *iob,
42
-		       enum net80211_security_proto *secprot,
43
-		       enum net80211_crypto_alg *crypt )
44
-	__attribute__ (( weak ));
45
-
46
-
47
-/**
48
- * Inline safety wrapper for _sec80211_detect()
49
- *
50
- * @v iob	I/O buffer containing beacon frame
51
- * @ret secprot	Security handshaking protocol used by network
52
- * @ret crypt	Cryptosystem used by network
53
- * @ret rc	Return status code
54
- *
55
- * This function transparently calls _sec80211_detect() if the file
56
- * containing it was compiled in, or returns an error indication of
57
- * @c -ENOTSUP if not.
58
- */
59
-static inline int sec80211_detect ( struct io_buffer *iob,
60
-				    enum net80211_security_proto *secprot,
61
-				    enum net80211_crypto_alg *crypt ) {
62
-	if ( _sec80211_detect )
63
-		return _sec80211_detect ( iob, secprot, crypt );
64
-	return -ENOTSUP;
65
-}
32
+int sec80211_detect ( struct io_buffer *iob,
33
+		      enum net80211_security_proto *secprot,
34
+		      enum net80211_crypto_alg *crypt );
66
 
35
 
67
 int sec80211_detect_ie ( int is_rsn, u8 *start, u8 *end,
36
 int sec80211_detect_ie ( int is_rsn, u8 *start, u8 *end,
68
 			 enum net80211_security_proto *secprot,
37
 			 enum net80211_security_proto *secprot,

+ 1
- 2
src/include/usr/autoboot.h View File

19
 					   const char *filename );
19
 					   const char *filename );
20
 extern int boot_root_path ( const char *root_path );
20
 extern int boot_root_path ( const char *root_path );
21
 
21
 
22
-extern int pxe_menu_boot ( struct net_device *netdev )
23
-	__attribute__ (( weak ));
22
+extern int pxe_menu_boot ( struct net_device *netdev );
24
 
23
 
25
 #endif /* _USR_AUTOBOOT_H */
24
 #endif /* _USR_AUTOBOOT_H */

+ 11
- 0
src/net/80211/net80211.c View File

139
 	int times_tried;
139
 	int times_tried;
140
 };
140
 };
141
 
141
 
142
+/**
143
+ * Detect secure 802.11 network when security support is not available
144
+ *
145
+ * @return -ENOTSUP, always.
146
+ */
147
+__weak int sec80211_detect ( struct io_buffer *iob __unused,
148
+			     enum net80211_security_proto *secprot __unused,
149
+			     enum net80211_crypto_alg *crypt __unused ) {
150
+	return -ENOTSUP;
151
+}
152
+
142
 /**
153
 /**
143
  * @defgroup net80211_netdev Network device interface functions
154
  * @defgroup net80211_netdev Network device interface functions
144
  * @{
155
  * @{

+ 5
- 0
src/net/udp/dhcp.c View File

1406
 	.sa_family = AF_INET,
1406
 	.sa_family = AF_INET,
1407
 };
1407
 };
1408
 
1408
 
1409
+/**
1410
+ * Get cached DHCPACK where none exists
1411
+ */
1412
+__weak void get_cached_dhcpack ( void ) {}
1413
+
1409
 /**
1414
 /**
1410
  * Start DHCP state machine on a network device
1415
  * Start DHCP state machine on a network device
1411
  *
1416
  *

+ 8
- 1
src/usr/autoboot.c View File

42
 /** Shutdown flags for exit */
42
 /** Shutdown flags for exit */
43
 int shutdown_exit_flags = 0;
43
 int shutdown_exit_flags = 0;
44
 
44
 
45
+/**
46
+ * Perform PXE menu boot when PXE stack is not available
47
+ */
48
+__weak int pxe_menu_boot ( struct net_device *netdev __unused ) {
49
+	return -ENOTSUP;
50
+}
51
+
45
 /**
52
 /**
46
  * Identify the boot network device
53
  * Identify the boot network device
47
  *
54
  *
155
 			       buf, sizeof ( buf ) );
162
 			       buf, sizeof ( buf ) );
156
 	pxe_discovery_control =
163
 	pxe_discovery_control =
157
 		fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
164
 		fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
158
-	if ( ( strcmp ( buf, "PXEClient" ) == 0 ) && pxe_menu_boot != NULL &&
165
+	if ( ( strcmp ( buf, "PXEClient" ) == 0 ) &&
159
 	     setting_exists ( NULL, &pxe_boot_menu_setting ) &&
166
 	     setting_exists ( NULL, &pxe_boot_menu_setting ) &&
160
 	     ( ! ( ( pxe_discovery_control & PXEBS_SKIP ) &&
167
 	     ( ! ( ( pxe_discovery_control & PXEBS_SKIP ) &&
161
 		   setting_exists ( NULL, &filename_setting ) ) ) ) {
168
 		   setting_exists ( NULL, &filename_setting ) ) ) ) {

Loading…
Cancel
Save