<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 11, 2015, at 2:24 PM, David Majnemer <<a href="mailto:david.majnemer@gmail.com" class="">david.majnemer@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I went ahead and implemented this in r228879.<br class=""></div><div class="gmail_extra"><br class=""></div></div></blockquote><div>Ha, awesome!</div><div><br class=""></div><div>thanks,</div><div>adrian</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 11, 2015 at 1:15 PM, Adrian Prantl <span dir="ltr" class=""><<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><div class=""><div class="h5"><blockquote type="cite" class=""><div class="">On Feb 11, 2015, at 12:57 PM, David Majnemer <<a href="mailto:david.majnemer@gmail.com" target="_blank" class="">david.majnemer@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Feb 11, 2015 at 11:39 AM, Adrian Prantl <span dir="ltr" class=""><<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br class="">
On Jan 30, 2015, at 6:04 PM, Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>> wrote:<br class="">
> The big drawback is that I can no longer influence the order in which the sections are emitted, which turns out to be a problem for COFF.<br class="">
> Although COFF sections are marked with the correct alignment characteristics, they are not actually emitted aligned on disk. This is hopefully just a bug in our COFF backend. Since the DWARF sections are of arbitrary size and come before the serialized AST, this messes up the alignment for OnDiskHashTable. Until I figure out a solution for this problem, I’ve disabled module debug info ouput for COFF.<br class="">
<br class="">
[CC’ing a bunch of people who recently touched the COFF streamer.]<br class="">
<br class="">
I’m creating a new section via a global variable like this:<br class="">
<br class="">
    auto *ASTSym = new llvm::GlobalVariable(<br class="">
        *M, Ty, /*constant*/ true, llvm::GlobalVariable::InternalLinkage,<br class="">
        Data, "__clang_ast");<br class="">
    ASTSym->setAlignment(8);<br class="">
    ASTSym->setSection("clangast”);<br class="">
<br class="">
and llvm-readobj tells me it comes out as:<br class="">
<br class="">
  Section {<br class="">
    Number: 12<br class="">
    Name: clangast (63 6C 61 6E 67 61 73 74)<br class="">
    VirtualSize: 0x0<br class="">
    VirtualAddress: 0x0<br class="">
    RawDataSize: 148992<br class="">
    PointerToRawData: 0x4FB   <-- 1275<br class="">
    PointerToRelocations: 0x0<br class="">
    PointerToLineNumbers: 0x0<br class="">
    RelocationCount: 0<br class="">
    LineNumberCount: 0<br class="">
    Characteristics [ (0x40400040)<br class="">
      IMAGE_SCN_ALIGN_8BYTES (0x400000)<br class="">
      IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)<br class="">
      IMAGE_SCN_MEM_READ (0x40000000)<br class="">
    ]<br class="">
  }<br class="">
<br class="">
or in assembly:<br class="">
<br class="">
  ...<br class="">
  Lsection_debug_loc:<br class="">
        .section        .debug_ranges,"r"<br class="">
  Ldebug_range:<br class="">
        .section        clangast,"dr"<br class="">
        .align  8<br class="">
  ___clang_ast:<br class="">
  ...<br class="">
<br class="">
Even though the section has the IMAGE_SCN_ALIGN_8BYTES characteristic and the symbol is aligned, the ___clang_ast symbol is still emitted to disk immediately following the previous section and thus ends up at a random unaligned address. This breaks OnDiskHashtable when the object file is mmapped from disk later.<br class="">
<br class="">
Am I using it wrong or is this a bug in the coff backend?<br class=""></blockquote><div class=""><br class=""></div><div class="">I don't think this is a bug.  Here is the relevant text from the COFF specification for the PointerToRawData field:</div><div class=""><div class="">For executable images, this must be a multiple of FileAlignment from the optional header.</div><div class="">For object files, the value should be aligned on a 4byte boundary for best performance.</div></div><div class=""><br class=""></div><div class="">We aren't required to align the section contents in object files.</div></div></div></div></div></blockquote><div class=""><br class=""></div></div></div><div class="">I see. In this particular case, however, it is not even aligned on a 4-byte boundary (0x4FB==1275). Technically I think 4-byte alignment is all that OnDiskHashTable is asking for, so if we could get that right, it would be good enough for my use-case.</div><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Any ideas how to fix it?<br class=""></blockquote><div class=""><br class=""></div><div class="">Nothing would stop us from having a little padding before the start of the section contents.</div></div></div></div></div></blockquote><div class=""><br class=""></div></span>Do you have a pointer where to look for?</div><div class=""><br class=""></div><div class="">thanks!</div><span class="HOEnZb"><font color="#888888" class=""><div class="">adrian</div></font></span></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>