Changeset 59953 in vbox
- Timestamp:
- Mar 8, 2016 12:11:02 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp
r59932 r59953 799 799 }; 800 800 801 802 static bool convertelf(const char *pszFile, uint8_t *pbFile, size_t cbFile) 801 static bool validateElf(const char *pszFile, uint8_t const *pbFile, size_t cbFile) 803 802 { 804 803 /* … … 837 836 * Work the section table. 838 837 */ 838 bool fRet = true; 839 839 for (uint32_t i = 1; i < pEhdr->e_shnum; i++) 840 840 { … … 859 859 return error(pszFile, "The content of section #%u '%s' is outside the file (%#" ELF_FMT_X64 " LB %#" ELF_FMT_X64 ", cbFile=%#lx)\n", 860 860 i, &pszStrTab[paShdrs[i].sh_name], paShdrs[i].sh_offset, paShdrs[i].sh_size, (unsigned long)cbFile); 861 Elf64_Rela *paRels = (Elf64_Rela *)&pbFile[paShdrs[i].sh_offset]; 861 862 Elf64_Rela const *paRelocs = (Elf64_Rela *)&pbFile[paShdrs[i].sh_offset]; 862 863 for (uint32_t j = 0; j < cRelocs; j++) 863 864 { 864 uint8_t const bType = ELF64_R_TYPE(paRels[j].r_info); 865 uint8_t const bType = ELF64_R_TYPE(paRelocs[j].r_info); 866 if (RT_UNLIKELY(bType >= R_X86_64_COUNT)) 867 fRet = error(pszFile, 868 "%#018" ELF_FMT_X64 " %#018" ELF_FMT_X64 " unknown fix up %#x (%+" ELF_FMT_D64 ")\n", 869 paRelocs[j].r_offset, paRelocs[j].r_info, bType, paRelocs[j].r_addend); 870 } 871 } 872 else if (paShdrs[i].sh_type == SHT_REL) 873 fRet = error(pszFile, "Did not expect SHT_REL sections (#%u '%s')\n", i, &pszStrTab[paShdrs[i].sh_name]); 874 } 875 return fRet; 876 } 877 878 879 880 static bool convertelf(const char *pszFile, uint8_t *pbFile, size_t cbFile) 881 { 882 /* 883 * Validate the header and our other expectations. 884 */ 885 if (!validateElf(pszFile, pbFile, cbFile)) 886 return false; 887 888 /* 889 * Locate the section name string table. 890 * We assume it's okay as we only reference it in verbose mode. 891 */ 892 Elf64_Ehdr const *pEhdr = (Elf64_Ehdr const *)pbFile; 893 Elf64_Shdr const *paShdrs = (Elf64_Shdr const *)&pbFile[pEhdr->e_shoff]; 894 const char * pszStrTab = (const char *)&pbFile[paShdrs[pEhdr->e_shstrndx].sh_offset]; 895 896 /* 897 * Work the section table. 898 */ 899 for (uint32_t i = 1; i < pEhdr->e_shnum; i++) 900 { 901 if (g_cVerbose) 902 printf("shdr[%u]: name=%#x '%s' type=%#x flags=%#" ELF_FMT_X64 " addr=%#" ELF_FMT_X64 " off=%#" ELF_FMT_X64 " size=%#" ELF_FMT_X64 "\n" 903 " link=%u info=%#x align=%#" ELF_FMT_X64 " entsize=%#" ELF_FMT_X64 "\n", 904 i, paShdrs[i].sh_name, &pszStrTab[paShdrs[i].sh_name], paShdrs[i].sh_type, paShdrs[i].sh_flags, 905 paShdrs[i].sh_addr, paShdrs[i].sh_offset, paShdrs[i].sh_size, 906 paShdrs[i].sh_link, paShdrs[i].sh_info, paShdrs[i].sh_addralign, paShdrs[i].sh_entsize); 907 if (paShdrs[i].sh_type == SHT_RELA) 908 { 909 Elf64_Rela *paRelocs = (Elf64_Rela *)&pbFile[paShdrs[i].sh_offset]; 910 uint32_t const cRelocs = paShdrs[i].sh_size / sizeof(Elf64_Rela); 911 for (uint32_t j = 0; j < cRelocs; j++) 912 { 913 uint8_t const bType = ELF64_R_TYPE(paRelocs[j].r_info); 865 914 if (g_cVerbose > 1) 866 printf("%#018" ELF_FMT_X64 " %#018" ELF_FMT_X64 " %s %+" ELF_FMT_D64 "\n", paRel s[j].r_offset, paRels[j].r_info,867 bType < RT_ELEMENTS(g_apszElfAmd64RelTypes) ? g_apszElfAmd64RelTypes[bType] : "unknown", paRel s[j].r_addend);915 printf("%#018" ELF_FMT_X64 " %#018" ELF_FMT_X64 " %s %+" ELF_FMT_D64 "\n", paRelocs[j].r_offset, paRelocs[j].r_info, 916 bType < RT_ELEMENTS(g_apszElfAmd64RelTypes) ? g_apszElfAmd64RelTypes[bType] : "unknown", paRelocs[j].r_addend); 868 917 869 918 /* Truncate 64-bit wide absolute relocations, ASSUMING that the high bits … … 871 920 if (bType == R_X86_64_64) 872 921 { 873 paRel s[j].r_info &= ~(uint64_t)0xff;874 paRel s[j].r_info |= R_X86_64_32;922 paRelocs[j].r_info &= ~(uint64_t)0xff; 923 paRelocs[j].r_info |= R_X86_64_32; 875 924 } 876 925 }
Note:
See TracChangeset
for help on using the changeset viewer.