From 075538abb9af8a31fa8239ecfda592b968cd53d8 Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Wed, 23 Nov 2011 14:09:01 +0000
Subject: [PATCH] Use the proper "-Wl,--undefined=BootloaderAPI_JumpTable"
 linker command line parameter in the bootloaders to ensure that the API jump
 tables are not discarded, rather than the previous C volatile pointer hack
 (thanks to Opendous Inc.).

---
 Bootloaders/CDC/BootloaderAPI.h | 3 ---
 Bootloaders/CDC/BootloaderCDC.c | 4 ----
 Bootloaders/CDC/makefile        | 2 +-
 Bootloaders/DFU/BootloaderAPI.h | 3 ---
 Bootloaders/DFU/BootloaderDFU.c | 4 ----
 Bootloaders/DFU/makefile        | 2 +-
 6 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/Bootloaders/CDC/BootloaderAPI.h b/Bootloaders/CDC/BootloaderAPI.h
index 9c9d5a4ce..e9709125d 100644
--- a/Bootloaders/CDC/BootloaderAPI.h
+++ b/Bootloaders/CDC/BootloaderAPI.h
@@ -43,9 +43,6 @@
 		
 		#include <LUFA/Common/Common.h>
 	
-	/* External Variables: */
-		extern uint8_t* BootloaderAPI_JumpTable;
-	
 	/* Function Prototypes: */
 		void    BootloaderAPI_ErasePage(uint32_t Address);
 		void    BootloaderAPI_WritePage(uint32_t Address);
diff --git a/Bootloaders/CDC/BootloaderCDC.c b/Bootloaders/CDC/BootloaderCDC.c
index f336a1368..7695e33d8 100644
--- a/Bootloaders/CDC/BootloaderCDC.c
+++ b/Bootloaders/CDC/BootloaderCDC.c
@@ -63,10 +63,6 @@ static bool RunBootloader = true;
  */
 int main(void)
 {
-	/* Force a reference to the API jump table to prevent the linker from discarding it */
-	uint8_t* volatile Dummy = BootloaderAPI_JumpTable;
-	(void)Dummy;
-
 	/* Setup hardware required for the bootloader */
 	SetupHardware();
 
diff --git a/Bootloaders/CDC/makefile b/Bootloaders/CDC/makefile
index 65982263e..f98372dfb 100644
--- a/Bootloaders/CDC/makefile
+++ b/Bootloaders/CDC/makefile
@@ -340,7 +340,7 @@ EXTMEMOPTS =
 #    -Map:      create map file
 #    --cref:    add cross reference to  map file
 LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref
-LDFLAGS += -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART)
+LDFLAGS += -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART) -Wl,--undefined=BootloaderAPI_JumpTable
 LDFLAGS += -Wl,--relax
 LDFLAGS += -Wl,--gc-sections
 LDFLAGS += $(EXTMEMOPTS)
diff --git a/Bootloaders/DFU/BootloaderAPI.h b/Bootloaders/DFU/BootloaderAPI.h
index 9c9d5a4ce..e9709125d 100644
--- a/Bootloaders/DFU/BootloaderAPI.h
+++ b/Bootloaders/DFU/BootloaderAPI.h
@@ -43,9 +43,6 @@
 		
 		#include <LUFA/Common/Common.h>
 	
-	/* External Variables: */
-		extern uint8_t* BootloaderAPI_JumpTable;
-	
 	/* Function Prototypes: */
 		void    BootloaderAPI_ErasePage(uint32_t Address);
 		void    BootloaderAPI_WritePage(uint32_t Address);
diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c
index 078d59deb..6e0c95d06 100644
--- a/Bootloaders/DFU/BootloaderDFU.c
+++ b/Bootloaders/DFU/BootloaderDFU.c
@@ -99,10 +99,6 @@ static uint16_t EndAddr = 0x0000;
  */
 int main(void)
 {
-	/* Force a reference to the API jump table to prevent the linker from discarding it */
-	uint8_t* volatile Dummy = BootloaderAPI_JumpTable;
-	(void)Dummy;
-
 	/* Configure hardware required by the bootloader */
 	SetupHardware();
 
diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile
index bd7120d8f..87cfd072e 100644
--- a/Bootloaders/DFU/makefile
+++ b/Bootloaders/DFU/makefile
@@ -335,7 +335,7 @@ EXTMEMOPTS =
 #    -Map:      create map file
 #    --cref:    add cross reference to  map file
 LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref
-LDFLAGS += -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART)
+LDFLAGS += -Wl,--section-start=.text=$(BOOT_START) -Wl,--section-start=.apitable=$(BOOT_API_TABLESTART) -Wl,--undefined=BootloaderAPI_JumpTable
 LDFLAGS += -Wl,--relax
 LDFLAGS += -Wl,--gc-sections
 LDFLAGS += $(EXTMEMOPTS)
-- 
GitLab