Menu

Support for COFF COMDATs - CheckSum?

japheth
2011-10-02
2013-04-20
  • japheth

    japheth - 2011-10-02

    Hello,

    I'm considering to add support for the COFF COMDAT section attribute (IMAGE_SCN_LNK_COMDAT).

    However, I didn't find any documentation about how the contents of field IMAGE_AUX_SYMBOL.Section.CheckSum is supposed to be calculated. This info is required for COMDATs.

    Perhaps anybody has an idea - I already checked FASM/NASM/YASM docs with no luck.

     
  • mineiro

    mineiro - 2011-10-11

    Hello Sr japheth, I have found some info in this book:
    Common Language Infrastructure Annotated Standard, The
    By Jim Miller, Susann Ragsdale

     
  • filofel

    filofel - 2011-10-11

    Hi Japheth,

    I just sent some source code to your (site) email address.
    If this is what you're looking for, a more detailed explanation is available at
    http://www.codeproject.com/KB/cpp/PEChecksum.aspx

    Hope this helps, /Ph.

     
  • Greenhorn

    Greenhorn - 2011-10-13

    I've also searched the web but google just spits out nothing relevant.

    The only thing I've found is a thread in the flat asm forums.
    If you've also ment with "docs" the forums of FASM/NASM/YASM then you'll know this thread.
    At the end he (the poster) sticked at the same point as you are now.

    http://board.flatassembler.net/topic.php?t=4706

    But maybe Thomas has implemented it in FASM and you can ask him ?

    Regards
    Greenhorn

     
  • japheth

    japheth - 2011-10-14

    I'm aware of the discussion in the FASM forum. AFAICS the feature isn't implemented yet in FASM.

    There's also a request to support COFF COMDAT for YASM, but there's also no implementation yet.

    I'm about to  test if the PE checksum algorithm can be used for COMDAT checksums as well, but I'm not too optimistic.

     
  • Greenhorn

    Greenhorn - 2011-10-14

    What's up with GCC or Open Watcom ? Do they support COMDAT ? Maybe the sources can offer the algorithm …

    Very strange that there is no such information/documentation in the web, is it such a secret ?!
    That makes it very hard to help you. Pitiful, because I wish to be able to give something back to you for that what you are giving us …

     
  • japheth

    japheth - 2011-10-15

    OW's compiler's support OMF only. The OW linker WLINK ( and JWLINK! ) don't support COFF COMDATs currently. In fact, their incapability triggered my interest in this subject - there are a few MS libraries ( i.e. DXGUID.LIB ) that contain COMDATs and currently you have to avoid (J)WLINK if such libraries are to be used.

    GCC might be better - but I won't use GNU code in JWasm.

     
  • drizz

    drizz - 2011-10-19

    Hello,

    I did some "investigating"… to help of course…
    MS C++ compiler calls MSPDBxxx!SigForPbCb for every instruction in the COMDAT section.
    SigForPbCb is nothing more than a CRC32 function with omitted bit inversion.
    You don't need to call CRC32 for every instruction just call CRC32(section,len,0)

    Here is code:
    .data
    align 16
    CRC32Table label dword
    i = 0
    crc = i
    WHILE i LT 256
    crc = i
    REPT 8
        crc = (crc shr 1) xor (0EDB88320h * (crc and 1))
    ENDM
    DD crc
    i = i + 1
    ENDM

    .code
    ; MSPDBxx!SigForPbCb
    CRC32COMDAT proc lpBuffer:DWORD, dwBufLen:DWORD, dwCRC:DWORD
    mov edx,lpBuffer
    mov ecx,dwBufLen
    mov eax,dwCRC
    add edx,ecx
    push esi
    neg ecx
    mov esi,edx
    jz @F; Len = 0
    .repeat
    xor edx,edx
    mov dl,
    xor dl,al
    shr eax,8
    xor eax,
    inc ecx
    .until zero?
    @@: pop esi
    ret
    CRC32COMDAT endp

     
  • japheth

    japheth - 2011-10-19

    Great, drizzz! I'll check this out ASAP.

     
  • japheth

    japheth - 2012-07-03

    Support for COMDAT won't be included in v2.07. I'm going to implement this support in jwlink first.

     
  • japheth

    japheth - 2013-03-05

    Support for COMDAT is added in jwasm v2.10.

    >. I'm going to implement this support in jwlink first.

    jwlink currently does NOT support COMDAT sections as of yet.

     

Log in to post a comment.