[gPXE-devel] [PATCH 3/3] [efi] Fix *.efi linking

Piotr Jaroszyński p.jaroszynski at gmail.com
Tue Mar 30 13:09:11 EDT 2010


Linker chooses to look for _start first and always picks efidrvprefix.o
to satisfy it (probably because it's earlier in the archive) which
causes a multiple definition error when linker later has to pick
efiprefix.o for other symbols.
Custom prefix LD_FLAGS with --defsym magic works around that.
---
 src/Makefile.housekeeping          |    3 ++-
 src/arch/x86/Makefile.efi          |    4 ++++
 src/arch/x86/prefix/efidrvprefix.c |    2 +-
 src/arch/x86/prefix/efiprefix.c    |    2 +-
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index a573356..7f38df4 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -612,7 +612,8 @@ TGT_LD_IDS	= pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
 #
 TGT_LD_FLAGS	= $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
 		    -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
-		  $(patsubst %,--defsym %,$(TGT_LD_IDS))
+		  $(patsubst %,--defsym %,$(TGT_LD_IDS)) \
+		  $($(TGT_PREFIX)_LD_FLAGS)
 
 # Calculate makerom flags for the specific target
 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
diff --git a/src/arch/x86/Makefile.efi b/src/arch/x86/Makefile.efi
index bef8d59..0a8b658 100644
--- a/src/arch/x86/Makefile.efi
+++ b/src/arch/x86/Makefile.efi
@@ -13,6 +13,10 @@ LDFLAGS		+= -q -S
 NON_AUTO_MEDIA	+= efi
 NON_AUTO_MEDIA	+= efidrv
 
+# Extra LD FLAGS
+efidrv_LD_FLAGS = --defsym _start=_efidrv_start
+efi_LD_FLAGS = --defsym _start=_efi_start
+
 # Rules for building EFI files
 #
 $(BIN)/%.efi : $(BIN)/%.efi.tmp $(ELF2EFI)
diff --git a/src/arch/x86/prefix/efidrvprefix.c b/src/arch/x86/prefix/efidrvprefix.c
index 36d5650..6a34367 100644
--- a/src/arch/x86/prefix/efidrvprefix.c
+++ b/src/arch/x86/prefix/efidrvprefix.c
@@ -29,7 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
  * @v systab		System table
  * @ret efirc		EFI return status code
  */
-EFI_STATUS EFIAPI _start ( EFI_HANDLE image_handle,
+EFI_STATUS EFIAPI _efidrv_start ( EFI_HANDLE image_handle,
 			   EFI_SYSTEM_TABLE *systab ) {
 	EFI_STATUS efirc;
 
diff --git a/src/arch/x86/prefix/efiprefix.c b/src/arch/x86/prefix/efiprefix.c
index 4cc9e04..548c858 100644
--- a/src/arch/x86/prefix/efiprefix.c
+++ b/src/arch/x86/prefix/efiprefix.c
@@ -28,7 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
  * @v systab		System table
  * @ret efirc		EFI return status code
  */
-EFI_STATUS EFIAPI _start ( EFI_HANDLE image_handle,
+EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
 			   EFI_SYSTEM_TABLE *systab ) {
 	EFI_STATUS efirc;
 
-- 
1.7.0.3



More information about the gPXE-devel mailing list