Changeset 58652 in vbox for trunk/src/VBox/ValidationKit/bootsectors
- Timestamp:
- Nov 10, 2015 9:13:21 PM (9 years ago)
- Location:
- trunk/src/VBox/ValidationKit/bootsectors/bs3kit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
r58648 r58652 80 80 TOOL_Bs3Gcc64Elf64_CINCS ?= 81 81 TOOL_Bs3Gcc64Elf64_CDEFS ?= 82 TOOL_Bs3Gcc64Elf64_COMPILE_C_DEPEND = 82 TOOL_Bs3Gcc64Elf64_COMPILE_C_DEPEND = $(VBoxBs3ObjConverter_1_TARGET) 83 83 TOOL_Bs3Gcc64Elf64_COMPILE_C_DEPORD = 84 84 TOOL_Bs3Gcc64Elf64_COMPILE_C_OUTPUT = … … 89 89 -o $(obj)\ 90 90 $(abspath $(source)) 91 ls -la $(obj) 92 -$(VBoxBs3ObjConverter_1_TARGET) -vv "$(obj)" 91 93 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" "" 92 94 endef … … 100 102 TOOL_Bs3Gcc64Elf64_CXXINCS ?= 101 103 TOOL_Bs3Gcc64Elf64_CXXDEFS ?= 102 TOOL_Bs3Gcc64Elf64_COMPILE_CXX_DEPEND = 104 TOOL_Bs3Gcc64Elf64_COMPILE_CXX_DEPEND = $(VBoxBs3ObjConverter_1_TARGET) 103 105 TOOL_Bs3Gcc64Elf64_COMPILE_CXX_DEPORD = 104 106 TOOL_Bs3Gcc64Elf64_COMPILE_CXX_OUTPUT = … … 109 111 -o $(obj)\ 110 112 $(abspath $(source)) 113 $(QUIET)$(VBoxBs3ObjConverter_1_TARGET) -v "$(obj)" 111 114 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" "" 112 115 endef 116 117 # Debug info format depends on what we use for 64-bit. 118 if1of ($(KBUILD_HOST), win) 119 BS3_OW_DBG_OPT = -hc 120 BS3_OW_DBG_LDOPT = codeview 121 else 122 BS3_OW_DBG_OPT = -hd 123 BS3_OW_DBG_LDOPT = dwarf 124 endif 113 125 114 126 # BS3Kit template for assembly and 16-bit code. … … 126 138 TEMPLATE_VBoxBS3KitImg_CTOOL = OPENWATCOM-16 127 139 TEMPLATE_VBoxBS3KitImg_CXXTOOL = OPENWATCOM-16 128 TEMPLATE_VBoxBS3KitImg_CFLAGS = -nt=BS3TEXT16 -nd=BS3DATA16 -nc=BS3CODE16 -ecc -q -3 -wx -zl -zu -s -oafs -mc -hc-d1+129 TEMPLATE_VBoxBS3KitImg_CXXFLAGS = -nt=BS3TEXT16 -nd=BS3DATA16 -nc=BS3CODE16 -ecc -q -3 -wx -zl -zu -s -oafs -mc -hc-d1+140 TEMPLATE_VBoxBS3KitImg_CFLAGS = -nt=BS3TEXT16 -nd=BS3DATA16 -nc=BS3CODE16 -ecc -q -3 -wx -zl -zu -s -oafs -mc $(BS3_OW_DBG_OPT) -d1+ 141 TEMPLATE_VBoxBS3KitImg_CXXFLAGS = -nt=BS3TEXT16 -nd=BS3DATA16 -nc=BS3CODE16 -ecc -q -3 -wx -zl -zu -s -oafs -mc $(BS3_OW_DBG_OPT) -d1+ 130 142 TEMPLATE_VBoxBS3KitImg_INCS = $(VBOX_PATH_BS3KIT_SRC) . 131 143 TEMPLATE_VBoxBS3KitImg_LDTOOL = OPENWATCOM-WL … … 134 146 135 147 TEMPLATE_VBoxBS3KitImg_LDFLAGS = system dos \ 136 debug codeviewall \148 debug $(BS3_OW_DBG_LDOPT) all \ 137 149 option quiet, map, statics, verbose, symfile, start=_start \ 138 150 disable 1014, 1080, 1150 \ … … 191 203 TEMPLATE_VBoxBS3KitImg32_CTOOL = OPENWATCOM 192 204 TEMPLATE_VBoxBS3KitImg32_CXXTOOL = OPENWATCOM 193 TEMPLATE_VBoxBS3KitImg32_CFLAGS = -nt=BS3TEXT32 -nd=BS3DATA32 -nc=BS3CODE32 -ecc -q -wx -zu -zl -s -oas -mf -hc-d1194 TEMPLATE_VBoxBS3KitImg32_CXXFLAGS = -nt=BS3TEXT32 -nd=BS3DATA32 -nc=BS3CODE32 -ecc -q -wx -zu -zl -s -oas -mf -hc-d1205 TEMPLATE_VBoxBS3KitImg32_CFLAGS = -nt=BS3TEXT32 -nd=BS3DATA32 -nc=BS3CODE32 -ecc -q -wx -zu -zl -s -oas -mf $(BS3_OW_DBG_OPT) -d1 206 TEMPLATE_VBoxBS3KitImg32_CXXFLAGS = -nt=BS3TEXT32 -nd=BS3DATA32 -nc=BS3CODE32 -ecc -q -wx -zu -zl -s -oas -mf $(BS3_OW_DBG_OPT) -d1 195 207 TEMPLATE_VBoxBS3KitImg32_INCS = $(VBOX_PATH_BS3KIT_SRC) . 196 208 TEMPLATE_VBoxBS3KitImg32_LDTOOL = VBoxBsUnusedLd … … 202 214 TEMPLATE_VBoxBS3KitImg64_INSTTYPE = none 203 215 TEMPLATE_VBoxBS3KitImg64_ASTOOL = NASM 204 TEMPLATE_VBoxBS3KitImg64_ASFLAGS = -f obj -g --allow-64bit-code-anywhere -w+orphan-labels216 TEMPLATE_VBoxBS3KitImg64_ASFLAGS = -f obj -g #--allow-64bit-code-anywhere -w+orphan-labels 205 217 TEMPLATE_VBoxBS3KitImg64_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__ 206 218 TEMPLATE_VBoxBS3KitImg64_DEFS = IN_BS3KIT ARCH_BITS=64 … … 221 233 TEMPLATE_VBoxBS3KitImg64_CXXTOOL := $(VBOX_GCC_TOOL) 222 234 endif 223 TEMPLATE_VBoxBS3KitImg64_CFLAGS = -m64 -maccumulate-outgoing-args -g 0-Os -fno-omit-frame-pointer $(VBOX_GCC_WARN_PEDANTIC_C)224 TEMPLATE_VBoxBS3KitImg64_CXXFLAGS = -m64 -maccumulate-outgoing-args -g 0-Os -fno-omit-frame-pointer $(VBOX_GCC_WARN_PEDANTIC_CXX)235 TEMPLATE_VBoxBS3KitImg64_CFLAGS = -m64 -maccumulate-outgoing-args -g -Os -fno-omit-frame-pointer $(VBOX_GCC_WARN_PEDANTIC_C) 236 TEMPLATE_VBoxBS3KitImg64_CXXFLAGS = -m64 -maccumulate-outgoing-args -g -Os -fno-omit-frame-pointer $(VBOX_GCC_WARN_PEDANTIC_CXX) 225 237 endif 226 238 TEMPLATE_VBoxBS3KitImg64_LDTOOL = VBoxBsUnusedLd -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp
r58648 r58652 37 37 38 38 #include <iprt/formats/elf64.h> 39 #include <iprt/formats/elf-amd64.h> 39 40 40 41 … … 83 84 * Figure the size. 84 85 */ 85 if (fseek(pFile, SEEK_END, 0) == 0)86 if (fseek(pFile, 0, SEEK_END) == 0) 86 87 { 87 88 long cbFile = ftell(pFile); … … 170 171 171 172 173 /** AMD64 relocation type names for ELF. */ 174 static const char * const g_apszElfAmd64RelTypes[] = 175 { 176 "R_X86_64_NONE", 177 "R_X86_64_64", 178 "R_X86_64_PC32", 179 "R_X86_64_GOT32", 180 "R_X86_64_PLT32", 181 "R_X86_64_COPY", 182 "R_X86_64_GLOB_DAT", 183 "R_X86_64_JMP_SLOT", 184 "R_X86_64_RELATIVE", 185 "R_X86_64_GOTPCREL", 186 "R_X86_64_32", 187 "R_X86_64_32S", 188 "R_X86_64_16", 189 "R_X86_64_PC16", 190 "R_X86_64_8", 191 "R_X86_64_PC8", 192 "R_X86_64_DTPMOD64", 193 "R_X86_64_DTPOFF64", 194 "R_X86_64_TPOFF64", 195 "R_X86_64_TLSGD", 196 "R_X86_64_TLSLD", 197 "R_X86_64_DTPOFF32", 198 "R_X86_64_GOTTPOFF", 199 "R_X86_64_TPOFF32", 200 }; 201 202 172 203 static bool convertelf(const char *pszFile, uint8_t *pbFile, size_t cbFile) 173 204 { 174 205 /* 175 * Validate the header .206 * Validate the header and our other expectations. 176 207 */ 177 208 Elf64_Ehdr const *pEhdr = (Elf64_Ehdr const *)pbFile; … … 186 217 if (pEhdr->e_machine != EM_X86_64) 187 218 return error(pszFile, "Expected relocatable ELF file (e_type=%d)\n", pEhdr->e_machine); 188 189 #if 0 190 if ( pEhdr->e_phoff < pEhdr->e_ehsize 191 && !(pEhdr->e_phoff && pEhdr->e_phnum) 192 && pEhdr->e_phnum) 193 { 194 Log(("RTLdrELF: %s: The program headers overlap with the ELF header! e_phoff=" FMT_ELF_OFF "\n", 195 pszLogName, pEhdr->e_phoff)); 196 return VERR_BAD_EXE_FORMAT; 197 } 198 if ( pEhdr->e_phoff + pEhdr->e_phnum * pEhdr->e_phentsize > cbRawImage 199 || pEhdr->e_phoff + pEhdr->e_phnum * pEhdr->e_phentsize < pEhdr->e_phoff) 200 { 201 Log(("RTLdrELF: %s: The program headers extends beyond the file! e_phoff=" FMT_ELF_OFF " e_phnum=" FMT_ELF_HALF "\n", 202 pszLogName, pEhdr->e_phoff, pEhdr->e_phnum)); 203 return VERR_BAD_EXE_FORMAT; 204 } 205 206 207 if ( pEhdr->e_shoff < pEhdr->e_ehsize 208 && !(pEhdr->e_shoff && pEhdr->e_shnum)) 209 { 210 Log(("RTLdrELF: %s: The section headers overlap with the ELF header! e_shoff=" FMT_ELF_OFF "\n", 211 pszLogName, pEhdr->e_shoff)); 212 return VERR_BAD_EXE_FORMAT; 213 } 214 if ( pEhdr->e_shoff + pEhdr->e_shnum * pEhdr->e_shentsize > cbRawImage 215 || pEhdr->e_shoff + pEhdr->e_shnum * pEhdr->e_shentsize < pEhdr->e_shoff) 216 { 217 Log(("RTLdrELF: %s: The section headers extends beyond the file! e_shoff=" FMT_ELF_OFF " e_shnum=" FMT_ELF_HALF "\n", 218 pszLogName, pEhdr->e_shoff, pEhdr->e_shnum)); 219 return VERR_BAD_EXE_FORMAT; 220 } 221 222 if (pEhdr->e_shstrndx == 0 || pEhdr->e_shstrndx > pEhdr->e_shnum) 223 { 224 Log(("RTLdrELF: %s: The section headers string table is out of bounds! e_shstrndx=" FMT_ELF_HALF " e_shnum=" FMT_ELF_HALF "\n", 225 pszLogName, pEhdr->e_shstrndx, pEhdr->e_shnum)); 226 return VERR_BAD_EXE_FORMAT; 227 } 228 #endif 229 219 if (pEhdr->e_phnum != 0) 220 return error(pszFile, "Expected e_phnum to be zero not %u\n", pEhdr->e_phnum); 221 if (pEhdr->e_shnum < 2) 222 return error(pszFile, "Expected e_shnum to be two or higher\n"); 223 if (pEhdr->e_shstrndx >= pEhdr->e_shnum || pEhdr->e_shstrndx == 0) 224 return error(pszFile, "Bad e_shstrndx=%u (e_shnum=%u)\n", pEhdr->e_shstrndx, pEhdr->e_shnum); 225 if ( pEhdr->e_shoff >= cbFile 226 || pEhdr->e_shoff + pEhdr->e_shnum * sizeof(Elf64_Shdr) > cbFile) 227 return error(pszFile, "Section table is outside the file (e_shoff=%#llx, e_shnum=%u, cbFile=%#llx)\n", 228 pEhdr->e_shstrndx, pEhdr->e_shnum, (uint64_t)cbFile); 229 230 /* 231 * Locate the section name string table. 232 * We assume it's okay as we only reference it in verbose mode. 233 */ 234 Elf64_Shdr const *paShdrs = (Elf64_Shdr const *)&pbFile[pEhdr->e_shoff]; 235 const char * pszStrTab = (const char *)&pbFile[paShdrs[pEhdr->e_shstrndx].sh_offset]; 236 237 /* 238 * Work the section table. 239 */ 240 for (uint32_t i = 1; i < pEhdr->e_shnum; i++) 241 { 242 if (g_cVerbose) 243 printf("shdr[%u]: name=%#x '%s' type=%#x flags=%#llx addr=%#llx off=%#llx size=%#llx\n" 244 " link=%u info=%#x align=%#llx entsize=%#llx\n", 245 i, paShdrs[i].sh_name, &pszStrTab[paShdrs[i].sh_name], paShdrs[i].sh_type, paShdrs[i].sh_flags, 246 paShdrs[i].sh_addr, paShdrs[i].sh_offset, paShdrs[i].sh_size, 247 paShdrs[i].sh_link, paShdrs[i].sh_info, paShdrs[i].sh_addralign, paShdrs[i].sh_entsize); 248 if (paShdrs[i].sh_type == SHT_RELA) 249 { 250 if (paShdrs[i].sh_entsize != sizeof(Elf64_Rela)) 251 return error(pszFile, "Expected sh_entsize to be %u not %u for section #%u (%s)\n", (unsigned)sizeof(Elf64_Rela), 252 paShdrs[i].sh_entsize, i, &pszStrTab[paShdrs[i].sh_name]); 253 uint32_t const cRelocs = paShdrs[i].sh_size / sizeof(Elf64_Rela); 254 if (cRelocs * sizeof(Elf64_Rela) != paShdrs[i].sh_size) 255 return error(pszFile, "Uneven relocation entry count in #%u (%s): sh_size=%#llx\n", (unsigned)sizeof(Elf64_Rela), 256 paShdrs[i].sh_entsize, i, &pszStrTab[paShdrs[i].sh_name], paShdrs[i].sh_size); 257 if ( paShdrs[i].sh_offset > cbFile 258 || paShdrs[i].sh_size >= cbFile 259 || paShdrs[i].sh_offset + paShdrs[i].sh_size > cbFile) 260 return error(pszFile, "The content of section #%u '%s' is outside the file (%#llx LB %#llx, cbFile=%#lx)\n", 261 i, &pszStrTab[paShdrs[i].sh_name], paShdrs[i].sh_offset, paShdrs[i].sh_size, (unsigned long)cbFile); 262 Elf64_Rela *paRels = (Elf64_Rela *)&pbFile[paShdrs[i].sh_offset]; 263 for (uint32_t j = 0; j < cRelocs; j++) 264 { 265 uint8_t const bType = ELF64_R_TYPE(paRels[j].r_info); 266 if (g_cVerbose > 1) 267 printf("%#018llx %#018llx %s %+lld\n", paRels[j].r_offset, paRels[j].r_info, 268 bType < RT_ELEMENTS(g_apszElfAmd64RelTypes) ? g_apszElfAmd64RelTypes[bType] : "unknown", paRels[j].r_addend); 269 270 /* Truncate 64-bit wide absolute relocations, ASSUMING that the high bits 271 are already zero and won't be non-zero after calculating the fixup value. */ 272 if (bType == R_X86_64_64) 273 { 274 paRels[j].r_info &= ~(uint64_t)0xff; 275 paRels[j].r_info |= R_X86_64_32; 276 } 277 } 278 } 279 else if (paShdrs[i].sh_type == SHT_REL) 280 return error(pszFile, "Did not expect SHT_REL sections (#%u '%s')\n", i, &pszStrTab[paShdrs[i].sh_name]); 281 } 230 282 return true; 231 283 } … … 253 305 fRc = convertelf(pszFile, pbFile, cbFile); 254 306 else 255 fprintf(stderr, "error: Don't recognize format of '%s'\n", pszFile); 307 fprintf(stderr, "error: Don't recognize format of '%s' (%#x %#x %#x %#x, cbFile=%lu)\n", 308 pszFile, pbFile[0], pbFile[1], pbFile[2], pbFile[3], (unsigned long)cbFile); 256 309 if (fRc) 257 310 fRc = writefile(pszFile, pvFile, cbFile);
Note:
See TracChangeset
for help on using the changeset viewer.