objcopy in binutil 2.50.0.18 contains a bug that will set a EFI PE image to "RELOC_ST...
authorklu2 <klu2@c2973edb-eda0-4c78-bc6a-9341b269661f>
Fri, 5 Mar 2010 10:23:53 +0000 (10:23 +0000)
committerklu2 <klu2@c2973edb-eda0-4c78-bc6a-9341b269661f>
Fri, 5 Mar 2010 10:23:53 +0000 (10:23 +0000)
This patch is to correct EFI image as relocable after image corrupted by objcopy in UNIXGCC/CYGGCC tool chain.

git-svn-id: https://edk2-buildtools.svn.sourceforge.net/svnroot/edk2-buildtools/trunk/BaseTools@1917 c2973edb-eda0-4c78-bc6a-9341b269661f

Conf/tools_def.template
Source/C/GenFw/GenFw.c

index 68c617a..b25eab4 100644 (file)
@@ -1589,8 +1589,8 @@ DEFINE GCC44_ASM_FLAGS               = DEF(GCC_ASM_FLAGS)
 *_UNIXGCC_*_MAKE_PATH                    = make\r
 *_UNIXGCC_*_ASL_PATH                     = DEF(UNIX_IASL_BIN)\r
 \r
-*_UNIXGCC_IA32_DLINK_FLAGS               = DEF(GCC_IA32_X64_DLINK_FLAGS)\r
-*_UNIXGCC_X64_DLINK_FLAGS                = DEF(GCC_IA32_X64_DLINK_FLAGS)\r
+*_UNIXGCC_IA32_DLINK_FLAGS               = DEF(GCC_IA32_X64_DLINK_FLAGS) --image-base=0\r
+*_UNIXGCC_X64_DLINK_FLAGS                = DEF(GCC_IA32_X64_DLINK_FLAGS) --image-base=0\r
 *_UNIXGCC_IA32_ASLDLINK_FLAGS            = DEF(GCC_IA32_X64_ASLDLINK_FLAGS)\r
 *_UNIXGCC_X64_ASLDLINK_FLAGS             = DEF(GCC_IA32_X64_ASLDLINK_FLAGS)\r
 *_UNIXGCC_*_ASM_FLAGS                    = DEF(GCC_ASM_FLAGS)\r
@@ -1717,8 +1717,8 @@ DEFINE GCC44_ASM_FLAGS               = DEF(GCC_ASM_FLAGS)
 *_CYGGCC_*_MAKE_PATH             = DEF(MS_VS_BIN)\nmake.exe\r
 *_CYGGCC_*_ASL_PATH              = DEF(DEFAULT_WIN_ASL_BIN)\r
 \r
-*_CYGGCC_IA32_DLINK_FLAGS               = DEF(GCC_IA32_X64_DLINK_FLAGS)\r
-*_CYGGCC_X64_DLINK_FLAGS                = DEF(GCC_IA32_X64_DLINK_FLAGS)\r
+*_CYGGCC_IA32_DLINK_FLAGS               = DEF(GCC_IA32_X64_DLINK_FLAGS) --image-base=0\r
+*_CYGGCC_X64_DLINK_FLAGS                = DEF(GCC_IA32_X64_DLINK_FLAGS) --image-base=0\r
 *_CYGGCC_IA32_ASLDLINK_FLAGS            = DEF(GCC_IA32_X64_ASLDLINK_FLAGS)\r
 *_CYGGCC_X64_ASLDLINK_FLAGS             = DEF(GCC_IA32_X64_ASLDLINK_FLAGS)\r
 *_CYGGCC_*_MAKE_FLAGS                   = /nologo\r
index d42c88e..e4d7f84 100644 (file)
@@ -3467,6 +3467,27 @@ Returns:
     FileLength = FileLength + sizeof (EFI_TE_IMAGE_HEADER);\r
     memcpy (FileBuffer, &TEImageHeader, sizeof (EFI_TE_IMAGE_HEADER));\r
     VerboseMsg ("the size of output file is %u bytes", (unsigned) (FileLength));\r
+  } else {\r
+\r
+    //\r
+    // Following codes are to fix the objcopy's issue:\r
+    // objcopy in binutil 2.50.18 will set PE image's charactices to "RELOC_STRIPPED" if image has no ".reloc" section\r
+    // It cause issue for EFI image which has no ".reloc" sections.\r
+    // Following codes will be removed when objcopy in binutil fix this problem for PE image.\r
+    //\r
+    if ((PeHdr->Pe32.FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0) {\r
+      if (PeHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+        Optional32 = (EFI_IMAGE_OPTIONAL_HEADER32 *)&PeHdr->Pe32.OptionalHeader;\r
+        if (Optional32->ImageBase == 0) {\r
+          PeHdr->Pe32.FileHeader.Characteristics &= ~EFI_IMAGE_FILE_RELOCS_STRIPPED;\r
+        }\r
+      } else if (PeHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+        Optional64 = (EFI_IMAGE_OPTIONAL_HEADER64 *)&PeHdr->Pe32.OptionalHeader;\r
+        if (Optional64->ImageBase == 0) {\r
+          PeHdr->Pe32.FileHeader.Characteristics &= ~EFI_IMAGE_FILE_RELOCS_STRIPPED;\r
+        }\r
+      }\r
+    }\r
   }\r
 \r
 WriteFile:\r