Fixing tools to support code sourcery ELF GCC variant for ARM. Had to add some noops...
authorandrewfish <andrewfish@c2973edb-eda0-4c78-bc6a-9341b269661f>
Thu, 11 Mar 2010 19:34:47 +0000 (19:34 +0000)
committerandrewfish <andrewfish@c2973edb-eda0-4c78-bc6a-9341b269661f>
Thu, 11 Mar 2010 19:34:47 +0000 (19:34 +0000)
git-svn-id: https://edk2-buildtools.svn.sourceforge.net/svnroot/edk2-buildtools/trunk/BaseTools@1927 c2973edb-eda0-4c78-bc6a-9341b269661f

Source/C/GenFw/GenFw.c
Source/C/GenFw/elf_common.h

index 414851a..4d60814 100644 (file)
@@ -1036,14 +1036,20 @@ WriteSections(
               - (SecOffset - SecShdr->sh_addr);\r
             break;\r
           default:\r
-            Error (NULL, 0, 3000, "Invalid", "%s unhandled section type %x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r
+            Error (NULL, 0, 3000, "Invalid", "%s unsupported ELF EM_386 relocation 0x%x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r
           }\r
         } else if (Ehdr->e_machine == EM_ARM) {\r
           switch (ELF32_R_TYPE(Rel->r_info)) {\r
           case R_ARM_RBASE:   // No relocation - no action required\r
-          case R_ARM_PC24:    // PC-relative relocations don't require modification\r
-          case R_ARM_XPC25:   // PC-relative relocations don't require modification\r
+          \r
+          // Thease are all PC-relative relocations and don't require modification\r
+          case R_ARM_PC24:    \r
+          case R_ARM_XPC25:   \r
+          case R_ARM_THM_PC22:\r
+          case R_ARM_THM_JUMP19:\r
+          case R_ARM_CALL:\r
             break;\r
+\r
           case R_ARM_ABS32:\r
           case R_ARM_RABS32:\r
             //\r
@@ -1052,7 +1058,7 @@ WriteSections(
             *(UINT32 *)Targ = *(UINT32 *)Targ - SymShdr->sh_addr + CoffSectionsOffset[Sym->st_shndx];\r
             break;\r
           default:\r
-            Error (NULL, 0, 3000, "Invalid", "%s unhandled section type %x.", mInImageName, (unsigned) ELF32_R_TYPE(Rel->r_info));\r
+            Error (NULL, 0, 3000, "Invalid", "WriteSections (): %s unsupported ELF EM_ARM relocation 0x%x.", mInImageName, (unsigned) ELF32_R_TYPE(Rel->r_info));\r
           }\r
         }\r
       }\r
@@ -1126,7 +1132,7 @@ GetPhdrByIndex (
 \r
 \r
 VOID\r
-WriteRelocations(\r
+WriteRelocations (\r
   VOID\r
   )\r
 {\r
@@ -1143,7 +1149,6 @@ WriteRelocations(
   UINT8                            *Targ;\r
   Elf32_Phdr                       *DynamicSegment;\r
   Elf32_Phdr                       *TargetSegment;\r
-  static int                       ErrorCount = 0;\r
 \r
   for (Index = 0, FoundRelocations = FALSE; Index < Ehdr->e_shnum; Index++) {\r
     Elf_Shdr *RelShdr = GetShdrByIndex(Index);\r
@@ -1167,13 +1172,18 @@ WriteRelocations(
               EFI_IMAGE_REL_BASED_HIGHLOW);\r
               break;\r
             default:\r
-              Error (NULL, 0, 3000, "Invalid", "%s unkown relocation %x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r
+              Error (NULL, 0, 3000, "Invalid", "%s unsupported ELF EM_386 relocation 0x%x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r
             }\r
           } else if (Ehdr->e_machine == EM_ARM) {\r
             switch (ELF32_R_TYPE(Rel->r_info)) {\r
-            case R_ARM_RBASE:\r
+            case R_ARM_RBASE: // No relocation - no action required\r
+          \r
+            // Thease are all PC-relative relocations and don't require modification\r
             case R_ARM_PC24:\r
             case R_ARM_XPC25:\r
+            case R_ARM_THM_PC22:\r
+            case R_ARM_THM_JUMP19:\r
+            case R_ARM_CALL:\r
               break;\r
             case R_ARM_ABS32:\r
             case R_ARM_RABS32:\r
@@ -1183,17 +1193,9 @@ WriteRelocations(
                 EFI_IMAGE_REL_BASED_HIGHLOW\r
                 );\r
               break;\r
-              \r
-            case R_ARM_CALL:\r
-            case R_ARM_THM_MOVW_ABS_NC:\r
-            case R_ARM_THM_MOVT_ABS:\r
-              if (ErrorCount++ == 0) {\r
-                Error (NULL, 0, 3000, "Invalid", "www.codesourcery.com ELF relocations not yet implemented!!!! Bad Image", mInImageName);\r
-              }\r
-              break;\r
 \r
-            default:\r
-              Error (NULL, 0, 3000, "Invalid", "%s unkown relocation %x.", mInImageName, (unsigned) ELF32_R_TYPE(Rel->r_info));\r
+           default:\r
+              Error (NULL, 0, 3000, "Invalid", "WriteRelocations(): %s unsupported ELF EM_ARM relocation 0x%x.", mInImageName, (unsigned) ELF32_R_TYPE(Rel->r_info));\r
             }\r
           } else {\r
             Error (NULL, 0, 3000, "Not Supported", "This tool does not support relocations for ELF with e_machine %u (processor type).", (unsigned) Ehdr->e_machine);\r
@@ -1229,6 +1231,9 @@ WriteRelocations(
             case  DT_RELENT:\r
               RelElementSize = Dyn->d_un.d_val;\r
               break;\r
+\r
+            default:\r
+              break;\r
           }\r
           Dyn++;\r
         }\r
@@ -1238,7 +1243,13 @@ WriteRelocations(
 \r
         for (K = 0; K < RelSize; K += RelElementSize) {\r
 \r
-          Rel = (Elf32_Rel *) ((UINT8 *) Ehdr + DynamicSegment->p_offset + RelOffset + K);\r
+          if (DynamicSegment->p_paddr == 0) {\r
+            // This seems to be how it works on armcc???? Have the email in to find out?\r
+            Rel = (Elf32_Rel *) ((UINT8 *) Ehdr + DynamicSegment->p_offset + RelOffset + K);\r
+          } else {\r
+            // This is how it reads in the ELF specification\r
+            Rel = (Elf32_Rel *) ((UINT8 *) Ehdr + RelOffset + K);\r
+          }\r
 \r
           switch (ELF32_R_TYPE (Rel->r_info)) {\r
           case  R_ARM_RBASE:\r
@@ -1254,7 +1265,8 @@ WriteRelocations(
             CoffAddFixup (CoffSectionsOffset[ELF32_R_SYM (Rel->r_info)] + (Rel->r_offset - TargetSegment->p_vaddr), EFI_IMAGE_REL_BASED_HIGHLOW);\r
             break;\r
           default:\r
-            Error (NULL, 0, 3000, "Invalid", "%s bad ARM dynamic relocations, unkown type.", mInImageName);\r
+            Error (NULL, 0, 3000, "Invalid", "%s bad ARM dynamic relocations, unkown type %d.", mInImageName, ELF32_R_TYPE (Rel->r_info));\r
+            break;\r
           }\r
         }\r
         break;\r
index ed99bbc..3798c95 100644 (file)
@@ -597,11 +597,8 @@ typedef struct {
 #define        R_ARM_GOTPC             25      /* Add PC-relative GOT table address. */
 #define        R_ARM_GOT32             26      /* Add PC-relative GOT offset. */
 #define        R_ARM_PLT32             27      /* Add PC-relative PLT offset. */
-
-#define R_ARM_CALL              28  // New block for ARM Thumb2
-#define R_ARM_THM_MOVW_ABS_NC   47
-#define R_ARM_THM_MOVT_ABS      48
-
+#define R_ARM_CALL          28
+#define R_ARM_THM_JUMP19    51
 #define        R_ARM_GNU_VTENTRY       100
 #define        R_ARM_GNU_VTINHERIT     101
 #define        R_ARM_RSBREL32          250