Changeset 58655 in vbox
- Timestamp:
- Nov 11, 2015 3:12:14 AM (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
r58652 r58655 65 65 endef 66 66 67 # 67 68 # elf cross compiling 64-bit gcc (mac): sudo port install x86_64-elf-gcc 69 # 68 70 TOOL_Bs3Gcc64Elf64 := AMD64/ELF64 gcc/g++ cross compiler for mac. 69 71 TOOL_Bs3Gcc64Elf64_CC ?= x86_64-elf-gcc$(HOSTSUFF_EXE) -m64 … … 113 115 $(QUIET)$(VBoxBs3ObjConverter_1_TARGET) -v "$(obj)" 114 116 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" "" 117 endef 118 119 # 120 # VCC elf cross compiling 64-bit gcc (mac): sudo port install x86_64-elf-gcc 121 # 122 TOOL_Bs3Vcc64 := Visual C++ 64-bit 123 TOOL_Bs3Vcc64_CC = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CC) 124 TOOL_Bs3Vcc64_CXX = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CXX) 125 TOOL_Bs3Vcc64_COBJSUFF = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COBJSUFF) 126 TOOL_Bs3Vcc64_CFLAGS = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CFLAGS) 127 TOOL_Bs3Vcc64_CFLAGS.debug = 128 TOOL_Bs3Vcc64_CFLAGS.dbgopt = -O1 129 TOOL_Bs3Vcc64_CFLAGS.profile = -O1 130 TOOL_Bs3Vcc64_CFLAGS.release = -O1 131 TOOL_Bs3Vcc64_CINCS = $(PATH_TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_INC) 132 TOOL_Bs3Vcc64_CDEFS = 133 TOOL_Bs3Vcc64_COMPILE_C_DEPEND = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_C_DEPEND) $(VBoxBs3ObjConverter_1_TARGET) 134 TOOL_Bs3Vcc64_COMPILE_C_DEPORD = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_C_DEPORD) 135 TOOL_Bs3Vcc64_COMPILE_C_OUTPUT = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_C_OUTPUT) 136 TOOL_Bs3Vcc64_COMPILE_C_OUTPUT_MAYBE = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_C_OUTPUT_MAYBE) 137 define TOOL_Bs3Vcc64_COMPILE_C_CMDS 138 $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_C_CMDS) 139 -$(VBoxBs3ObjConverter_1_TARGET) -vv "$(obj)" 140 endef 141 142 TOOL_Bs3Vcc64_CXXOBJSUFF = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CXXOBJSUFF) 143 TOOL_Bs3Vcc64_CXXFLAGS = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CXXFLAGS) 144 TOOL_Bs3Vcc64_CXXFLAGS.debug = 145 TOOL_Bs3Vcc64_CXXFLAGS.dbgopt = -O1 146 TOOL_Bs3Vcc64_CXXFLAGS.profile = -O1 147 TOOL_Bs3Vcc64_CXXFLAGS.release = -O1 148 TOOL_Bs3Vcc64_CXXINCS = $(PATH_TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_INC) 149 TOOL_Bs3Vcc64_CXXDEFS = 150 TOOL_Bs3Vcc64_COMPILE_CXX_DEPEND = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_CXX_DEPEND) $(VBoxBs3ObjConverter_1_TARGET) 151 TOOL_Bs3Vcc64_COMPILE_CXX_DEPORD = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_CXX_DEPORD) 152 TOOL_Bs3Vcc64_COMPILE_CXX_OUTPUT = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_CXX_OUTPUT) 153 TOOL_Bs3Vcc64_COMPILE_CXX_OUTPUT_MAYBE = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_CXX_OUTPUT_MAYBE) 154 define TOOL_Bs3Vcc64_COMPILE_CXX_CMDS 155 $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_CXX_CMDS) 156 $(QUIET)$(VBoxBs3ObjConverter_1_TARGET) -v "$(obj)" 115 157 endef 116 158 … … 214 256 TEMPLATE_VBoxBS3KitImg64_INSTTYPE = none 215 257 TEMPLATE_VBoxBS3KitImg64_ASTOOL = NASM 216 TEMPLATE_VBoxBS3KitImg64_ASFLAGS = -f obj -g #--allow-64bit-code-anywhere -w+orphan-labels258 TEMPLATE_VBoxBS3KitImg64_ASFLAGS = -f obj -g --allow-64bit-code-anywhere -w+orphan-labels 217 259 TEMPLATE_VBoxBS3KitImg64_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__ 218 260 TEMPLATE_VBoxBS3KitImg64_DEFS = IN_BS3KIT ARCH_BITS=64 … … 220 262 TEMPLATE_VBoxBS3KitImg64_INCS = $(VBOX_PATH_BS3KIT_SRC) . 221 263 if1of ($(KBUILD_HOST), win) 222 TEMPLATE_VBoxBS3KitImg64_BLD_TYPE := release# Must avoid debug info as it contains fixups not supported by the linker. 223 TEMPLATE_VBoxBS3KitImg64_CTOOL := $(VBOX_VCC_TOOL_STEM)AMD64 224 TEMPLATE_VBoxBS3KitImg64_CXXTOOL := $(VBOX_VCC_TOOL_STEM)AMD64 225 TEMPLATE_VBoxBS3KitImg64_CFLAGS = -O1 -Oi -GF -GS- -Gy -Gs65536 226 TEMPLATE_VBoxBS3KitImg64_CXXFLAGS = -O1 -Oi -GF -GS- -Gy -Gs65536 264 TEMPLATE_VBoxBS3KitImg64_CTOOL := Bs3Vcc64 265 TEMPLATE_VBoxBS3KitImg64_CXXTOOL := Bs3Vcc64 266 TEMPLATE_VBoxBS3KitImg64_CFLAGS = -Zi -O1 -Oi -GF -GS- -Gy -Gs65536 267 TEMPLATE_VBoxBS3KitImg64_CXXFLAGS = -Zi -O1 -Oi -GF -GS- -Gy -Gs65536 227 268 else 228 269 if1of ($(KBUILD_HOST), darwin) -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp
r58652 r58655 38 38 #include <iprt/formats/elf64.h> 39 39 #include <iprt/formats/elf-amd64.h> 40 #include <iprt/formats/pecoff.h> 40 41 41 42 … … 284 285 285 286 287 /** AMD64 relocation type names for (Microsoft) COFF. */ 288 static const char * const g_apszCoffAmd64RelTypes[] = 289 { 290 "ABSOLUTE", 291 "ADDR64", 292 "ADDR32", 293 "ADDR32NB", 294 "REL32", 295 "REL32_1", 296 "REL32_2", 297 "REL32_3", 298 "REL32_4", 299 "REL32_5", 300 "SECTION", 301 "SECREL", 302 "SECREL7", 303 "TOKEN", 304 "SREL32", 305 "PAIR", 306 "SSPAN32" 307 }; 308 309 static bool convertcoff(const char *pszFile, uint8_t *pbFile, size_t cbFile) 310 { 311 /* 312 * Validate the header and our other expectations. 313 */ 314 PIMAGE_FILE_HEADER pHdr = (PIMAGE_FILE_HEADER)pbFile; 315 if (pHdr->Machine != IMAGE_FILE_MACHINE_AMD64) 316 return error(pszFile, "Expected IMAGE_FILE_MACHINE_AMD64 not %#x\n", pHdr->Machine); 317 if (pHdr->SizeOfOptionalHeader != 0) 318 return error(pszFile, "Expected SizeOfOptionalHeader to be zero, not %#x\n", pHdr->SizeOfOptionalHeader); 319 if (pHdr->NumberOfSections == 0) 320 return error(pszFile, "Expected NumberOfSections to be non-zero\n"); 321 uint32_t const cbHeaders = pHdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) + sizeof(*pHdr); 322 if (cbHeaders > cbFile) 323 return error(pszFile, "Section table goes beyond the end of the of the file (cSections=%#x)\n", pHdr->NumberOfSections); 324 if (pHdr->NumberOfSymbols) 325 { 326 if ( pHdr->PointerToSymbolTable >= cbFile 327 || pHdr->NumberOfSymbols * (uint64_t)IMAGE_SIZE_OF_SYMBOL > cbFile) 328 return error(pszFile, "Symbol table goes beyond the end of the of the file (cSyms=%#x, offFile=%#x)\n", 329 pHdr->NumberOfSymbols, pHdr->PointerToSymbolTable); 330 } 331 332 /* Switch it to a x86 machine. */ 333 pHdr->Machine = IMAGE_FILE_MACHINE_I386; 334 335 /* 336 * Work the section table. 337 */ 338 PCIMAGE_SECTION_HEADER paShdrs = (PCIMAGE_SECTION_HEADER)(pHdr + 1); 339 for (uint32_t i = 0; i < pHdr->NumberOfSections; i++) 340 { 341 if (g_cVerbose) 342 printf("shdr[%2u]: rva=%#010x cbVirt=%#010x '%-8.8s'\n" 343 " offFile=%#010x cbFile=%#010x\n" 344 " offRelocs=%#010x cRelocs=%#010x\n" 345 " offLines=%#010x cLines=%#010x Characteristics=%#010x\n", 346 i, paShdrs[i].VirtualAddress, paShdrs[i].Misc.VirtualSize, paShdrs[i].Name, 347 paShdrs[i].PointerToRawData, paShdrs[i].SizeOfRawData, 348 paShdrs[i].PointerToRelocations, paShdrs[i].NumberOfRelocations, 349 paShdrs[i].PointerToLinenumbers, paShdrs[i].NumberOfLinenumbers, paShdrs[i].Characteristics); 350 uint32_t const cRelocs = paShdrs[i].NumberOfRelocations; 351 if (cRelocs > 0) 352 { 353 if ( paShdrs[i].PointerToRelocations < cbHeaders 354 || paShdrs[i].PointerToRelocations >= cbFile 355 || paShdrs[i].PointerToRelocations + cRelocs * sizeof(IMAGE_RELOCATION) > cbFile) 356 return error(pszFile, "Relocation beyond the end of the file or overlapping the headers (section #%u)\n", i); 357 358 /* 359 * Convert from AMD64 fixups to I386 ones, assuming 64-bit addresses 360 * being fixed up doesn't need the high dword and that it's 361 * appropriately initialized already. 362 */ 363 PIMAGE_RELOCATION paRelocs = (PIMAGE_RELOCATION)&pbFile[paShdrs[i].PointerToRelocations]; 364 for (uint32_t j = 0; j < cRelocs; j++) 365 { 366 if (g_cVerbose > 1) 367 printf("%#010x %#010x %s\n", 368 paRelocs[j].u.VirtualAddress, 369 paRelocs[j].SymbolTableIndex, 370 paRelocs[j].Type < RT_ELEMENTS(g_apszCoffAmd64RelTypes) 371 ? g_apszCoffAmd64RelTypes[paRelocs[j].Type] : "unknown"); 372 switch (paRelocs[j].Type) 373 { 374 case IMAGE_REL_AMD64_ABSOLUTE: 375 paRelocs[j].Type = IMAGE_REL_I386_ABSOLUTE; /* same */ 376 break; 377 case IMAGE_REL_AMD64_ADDR64: 378 /** @todo check the high dword. */ 379 paRelocs[j].Type = IMAGE_REL_I386_DIR32; 380 break; 381 case IMAGE_REL_AMD64_ADDR32: 382 paRelocs[j].Type = IMAGE_REL_I386_DIR32; 383 break; 384 case IMAGE_REL_AMD64_ADDR32NB: 385 paRelocs[j].Type = IMAGE_REL_I386_DIR32NB; 386 break; 387 case IMAGE_REL_AMD64_REL32: 388 paRelocs[j].Type = IMAGE_REL_I386_REL32; 389 break; 390 case IMAGE_REL_AMD64_SECTION: 391 /** @todo check the high dword. */ 392 paRelocs[j].Type = IMAGE_REL_I386_SECTION; 393 break; 394 case IMAGE_REL_AMD64_SECREL: 395 /** @todo check the high dword. */ 396 paRelocs[j].Type = IMAGE_REL_I386_SECREL; 397 break; 398 case IMAGE_REL_AMD64_SECREL7: 399 paRelocs[j].Type = IMAGE_REL_I386_SECREL7; 400 break; 401 402 default: 403 return error(pszFile, "Unsupported fixup type %#x (%s) at rva=%#x in section #%u '%-8.8'\n", 404 paRelocs[j].Type, 405 paRelocs[j].Type < RT_ELEMENTS(g_apszCoffAmd64RelTypes) 406 ? g_apszCoffAmd64RelTypes[paRelocs[j].Type] : "unknown", 407 paRelocs[j].u.VirtualAddress, i, paShdrs[i].Name); 408 } 409 } 410 } 411 } 412 return true; 413 } 414 415 416 286 417 /** 287 418 * Does the convertion using convertelf and convertcoff. … … 304 435 && pbFile[3] == ELFMAG3) 305 436 fRc = convertelf(pszFile, pbFile, cbFile); 437 else if ( cbFile > sizeof(IMAGE_FILE_HEADER) 438 && RT_MAKE_U16(pbFile[0], pbFile[1]) == IMAGE_FILE_MACHINE_AMD64 439 && RT_MAKE_U16(pbFile[2], pbFile[3]) * sizeof(IMAGE_SECTION_HEADER) + sizeof(IMAGE_FILE_HEADER) 440 < cbFile 441 && RT_MAKE_U16(pbFile[2], pbFile[3]) > 0) 442 fRc = convertcoff(pszFile, pbFile, cbFile); 306 443 else 307 444 fprintf(stderr, "error: Don't recognize format of '%s' (%#x %#x %#x %#x, cbFile=%lu)\n",
Note:
See TracChangeset
for help on using the changeset viewer.