VirtualBox

Changeset 58814 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
Nov 22, 2015 6:50:50 AM (9 years ago)
Author:
vboxsync
Message:

bs3kit: Solved the FLAT fixup issue for OMF files, while for COFF/ELF (64-bit only) we cannot do absolute fixups in places we care about (like just won't do what we want it to). Made the object converter check for COFF relocation we don't want, found 4 in one file and convinced the compiler to use RIP relative addressing instead of image relative addressing. (There's an alternative I've been avoiding, which is linking LX and using RTLdr to do the final linking.)

Location:
trunk/src/VBox/ValidationKit/bootsectors/bs3kit
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk

    r58812 r58814  
    123123TOOL_Bs3Vcc64_CXX = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CXX)
    124124TOOL_Bs3Vcc64_COBJSUFF                 = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COBJSUFF)
    125 TOOL_Bs3Vcc64_CFLAGS                   = $(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CFLAGS)
     125TOOL_Bs3Vcc64_CFLAGS                   = $(filter-out -TC,$(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_CFLAGS)) -TP # compile as C++
    126126TOOL_Bs3Vcc64_CFLAGS.debug             =
    127127TOOL_Bs3Vcc64_CFLAGS.dbgopt            = -O1
     
    327327        output raw offset=0x10000 \
    328328        order \
     329         clname BS3FLAT segaddr=0x0000 \
     330           segment BS3FLAT segaddr=0x0000 \
    329331         clname BS3CODE16 segaddr=0x1000 \
    330332          segment BS3TEXT16 \
     
    354356          segment BS3DATA64 \
    355357          segment DATA64 \
    356           segment .data
     358          segment .data \
     359          segment .pdata \
     360          segment .xdata \
     361
    357362TEMPLATE_VBoxBS3KitImg_DEPS = \
    358363        $(bs3-bootsector_1_TARGET) \
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp

    r58809 r58814  
    348348     * Work the section table.
    349349     */
     350    bool fRet = true;
    350351    PCIMAGE_SECTION_HEADER paShdrs   = (PCIMAGE_SECTION_HEADER)(pHdr + 1);
    351352    for (uint32_t i = 0; i < pHdr->NumberOfSections; i++)
     
    374375                return error(pszFile, "Raw data beyond the end of the file or overlapping the headers (section #%u)\n", i);
    375376            uint8_t *pbRawData = &pbFile[paShdrs[i].PointerToRawData];
     377
     378            /* Is this a section which ends up in the binary? */
     379            bool const fInBinary = !(paShdrs[i].Characteristics & (IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_LNK_INFO));
     380            bool const fIsPData  = fInBinary
     381                                && memcmp(paShdrs[i].Name, RT_STR_TUPLE(".pdata\0")) == 0;
    376382
    377383            /*
     
    425431
    426432                /* Convert it. */
     433                uint8_t uDir = IMAGE_REL_AMD64_ABSOLUTE;
    427434                switch (paRelocs[j].Type)
    428435                {
     
    441448                                         uAddend, paRelocs[j].u.VirtualAddress, i, paShdrs[i].Name);
    442449                        paRelocs[j].Type = IMAGE_REL_I386_DIR32;
     450                        uDir = IMAGE_REL_AMD64_ADDR64;
    443451                        break;
    444452                    }
     
    462470                    case IMAGE_REL_AMD64_ADDR32:
    463471                        paRelocs[j].Type = IMAGE_REL_I386_DIR32;
     472                        uDir = IMAGE_REL_AMD64_ADDR32;
    464473                        break;
    465474                    case IMAGE_REL_AMD64_ADDR32NB:
    466475                        paRelocs[j].Type = IMAGE_REL_I386_DIR32NB;
     476                        uDir = IMAGE_REL_AMD64_ADDR32NB;
    467477                        break;
    468478                    case IMAGE_REL_AMD64_REL32:
     
    489499                                     paRelocs[j].u.VirtualAddress, i, paShdrs[i].Name);
    490500                }
     501
     502                /*
     503                 * Error no absolute fixup that we care about. We continue so
     504                 * the developer can get the full story before failing.
     505                 */
     506                if (   fInBinary
     507                    && !fIsPData
     508                    && uDir != IMAGE_REL_AMD64_ABSOLUTE)
     509                {
     510                    error(pszFile, "%s at %#x in section %u '%-8.8s': wlink won't get this right\n",
     511                          g_apszCoffAmd64RelTypes[uDir], paRelocs[j].u.VirtualAddress, i, paShdrs[i].Name);
     512                    fRet = false;
     513                }
    491514            }
    492515        }
    493516    }
    494     return true;
     517    return fRet;
    495518}
    496519
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemAlloc.c

    r58789 r58814  
    4343         */
    4444        PBS3SLABHEAD pHead = enmKind == BS3MEMKIND_REAL
    45                            ? &BS3_DATA_NM(g_aBs3LowSlabLists)[idxSlabList]
    46                            : &BS3_DATA_NM(g_aBs3UpperTiledSlabLists)[idxSlabList];
     45                           ? &BS3_MSC64_FIXUP_HACK(BS3SLABHEAD, BS3_DATA_NM(g_aBs3LowSlabLists))[idxSlabList]
     46                           : &BS3_MSC64_FIXUP_HACK(BS3SLABHEAD, BS3_DATA_NM(g_aBs3UpperTiledSlabLists))[idxSlabList];
    4747
    48         BS3_ASSERT(BS3_DATA_NM(g_aBs3LowSlabLists)[idxSlabList].cbChunk >= cb);
     48        BS3_ASSERT(BS3_MSC64_FIXUP_HACK(BS3SLABHEAD, BS3_DATA_NM(g_aBs3LowSlabLists))[idxSlabList].cbChunk >= cb);
    4949        pvRet = Bs3SlabListAlloc(pHead);
    5050        if (pvRet)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-memory.h

    r58789 r58814  
    7070{
    7171    if (cbRequest <= BS3_DATA_NM(g_acbBs3SlabLists)[BS3_MEM_SLAB_LIST_COUNT - 1])
    72         return BS3_DATA_NM(g_aiBs3SlabListsByPowerOfTwo)[cbRequest ? ASMBitLastSetU16((uint16_t)(cbRequest - 1)) : 0];
     72    {
     73        unsigned idx = cbRequest ? ASMBitLastSetU16((uint16_t)(cbRequest - 1)) : 0;
     74        return BS3_MSC64_FIXUP_HACK(uint8_t const, BS3_DATA_NM(g_aiBs3SlabListsByPowerOfTwo))[idx];
     75    }
    7376    return UINT8_MAX;
    7477}
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-common.mac

    r58812 r58814  
    120120    db      10,13,'eye-catcher: BS3TEXT64',10,13
    121121
     122%ifdef ASM_FORMAT_OMF
     123section TEXT64 align=4 CLASS=CODE PUBLIC USE32
     124;section .text  align=4 CLASS=CODE PUBLIC USE32 - nasm doesn't do '.' at the start of segments in OMF mode. Not that this helps anyways...
     125;section .rdata align=4 CLASS=CODE PUBLIC USE32
     126;GROUP CODE64 TEXT64 _text _rdata
     127%endif
     128
    122129%ifdef ASM_FORMAT_ELF
    123130section BS3TEXT64_END   align=1 progbits alloc exec nowrite
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-pe16.asm

    r58812 r58814  
    5454
    5555extern _Bs3Printf_c32
     56extern Bs3Printf_c64
    5657
    5758BS3_BEGIN_TEXT16
     
    6566    call    NAME(Bs3SwitchToPE32_rm)
    6667    BS3_SET_BITS 32
     68.halt: hlt
     69jmp .halt
    6770    call    NAME(Bs3SwitchToRM_pe32)
    6871    BS3_SET_BITS 16
    69 
    70 .halt: hlt
    71 jmp .halt
    7272
    7373
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32.asm

    r58812 r58814  
    8585        mov     cr0, eax
    8686        jmp     BS3_SEL_R0_CS32:dword .thirty_two_bit wrt FLAT
    87 extern TODO_CONVINCE_WATCOM_TO_DO_FLAT_RELOCS
    8887BS3_BEGIN_TEXT32
    8988.thirty_two_bit:
     
    104103        mov     [esp + 8], eax          ; Store it in the place right for 32-bit returns.
    105104 %endif
    106         pop     esp
    107105        popfd
     106        pop     eax
    108107        ret
    109108
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r58812 r58814  
    372372#else
    373373# define BS3_DATA_NM(a_Name)  a_Name
     374#endif
     375
     376/** @def BS3_MSC64_FIXUP_HACK
     377 * Used to avoid IMAGE_REL_AMD64_ADDR32NB fixups where the compiler tries to
     378 * make use of __ImageBase as a base pointer instead of emitting rip relative
     379 * accesses.  Happens when there are a bunch of global data accesses in the same
     380 * function, probably to save space.
     381 *
     382 * The volatile variable in the lambda fixes it.
     383 */
     384#if _MSC_VER && ARCH_BITS == 64
     385# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) \
     386    ([]() -> a_BaseType * \
     387     { \
     388        a_BaseType * volatile x = a_Data; \
     389        return x; \
     390     }())
     391
     392#else
     393# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) (a_Data)
    374394#endif
    375395
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac

    r58812 r58814  
    126126;; @name Segment definitions.
    127127;; @{
     128
     129%ifdef ASM_FORMAT_OMF
     130; !!HACK ALERT!!
     131;
     132;   To make FLAT actually be flat, i.e. have a base of 0 rather than the same as
     133;   the target (?) segment, we tweak it a little bit here.  We associate a segment
     134;   with it so that we can get at it in the class/segment ordering directives
     135;   we pass to the linker.  The segment does not contain any data or anything, it
     136;   is just an empty one which we assign the address of zero.
     137;
     138;   Look for 'clname BS3FLAT segaddr=0x0000' and 'segment BS3FLAT segaddr=0x0000'
     139;   in the makefile.
     140;
     141; !!HACK ALERT!!
     142segment BS3FLAT use32 class=BS3FLAT
     143GROUP FLAT BS3FLAT
     144%endif
     145
    128146%macro BS3_BEGIN_TEXT16 0
    129147 %ifndef  BS3_BEGIN_TEXT16_NOT_FIRST
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette