]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[compiler] Prevent empty weak function stubs from being removed
authorJoshua Oreman <oremanj@rwcr.net>
Wed, 18 Aug 2010 23:37:22 +0000 (16:37 -0700)
committerMichael Brown <mcb30@ipxe.org>
Thu, 19 Aug 2010 12:37:52 +0000 (13:37 +0100)
Even with the noinline specifier added by commit 1a260f8, gcc may skip
calls to non-inlinable functions that it knows have no side
effects. This caused the get_cached_dhcpack() call in start_dhcp(),
the weak stub of which has no code in its body, to be removed,
preventing cached DHCP from working.

Fix by adding a __keepme macro to compiler.h expanding to asm(""), as
recommended by gcc's info page, and using it in the weak stub for
get_cached_dhcpack().

Reported-by: Aaron Brooks <aaron@brooks1.net>
Tested-by: Aaron Brooks <aaron@brooks1.net>
Signed-off-by: Joshua Oreman <oremanj@rwcr.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/compiler.h
src/net/udp/dhcp.c

index 16165b369ac2c0f4dbd3baa1b6d1b824ac810b24..738655afa9767ebafccf94602bcf72c8695d5cd7 100644 (file)
@@ -191,6 +191,14 @@ REQUEST_EXPANDED ( CONFIG_SYMBOL );
  */
 #define __weak         __attribute__ (( weak, noinline ))
 
+/** Prevent a function from being optimized away without inlining
+ *
+ * Calls to functions with void return type that contain no code in their body
+ * may be removed by gcc's optimizer even when inlining is inhibited. Placing
+ * this macro in the body of the function prevents that from occurring.
+ */
+#define __keepme       asm("");
+
 #endif
 
 /** @defgroup dbg Debugging infrastructure
index fb62bef53de3a1fdeeae358af44bd71006a9c7b7..77d4654537faf47b6035229e9cad32dd31880b8d 100644 (file)
@@ -1389,7 +1389,7 @@ static struct sockaddr dhcp_peer = {
 /**
  * Get cached DHCPACK where none exists
  */
-__weak void get_cached_dhcpack ( void ) {}
+__weak void get_cached_dhcpack ( void ) { __keepme }
 
 /**
  * Start DHCP state machine on a network device