<div dir="ltr">(Ignore the fact that my hashes are 8 byte in the "good" file, this is due to some local changes I've been experimenting with)</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jan 26, 2018 at 9:48 AM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I did this:<div><br></div><div>// a.cpp</div><div><div>static int x = 0;</div><div>void b(int);<br></div><div>void a(int) {<br></div><div>  if (x)</div><div>    b(x);</div><div>}</div><div>int main(int argc, char **argv) {<br></div><div>  a(argc);</div><div>  return x;</div><div>}</div></div><div><br></div><div><br></div><div>clang-cl /Z7 /c a.cpp /Foa.noghash.obj</div><div>clang-cl /Z7 /c a.cpp -mllvm -emit-codeview-ghash-section /Foa.ghash.good.obj</div><div>llvm-objcopy a.noghash.obj a.ghash.bad.obj</div><div>obj2yaml a.ghash.good.obj > a.ghash.good.yaml</div><div>obj2yaml a.ghash.bad.obj > a.ghash.bad.yaml</div><div><br></div><div>Then open these 2 yaml files up in a diff viewer.  It looks like the hashes aren't getting emitted at all.  For example, in the good yaml file I see this:</div><div><br></div><div><div>  - Name:            '.debug$H'</div><div>    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]</div><div>    Alignment:       4</div><div>    SectionData:     C5C93301000001005549419E78044E3896D45CD7009428758BE4A1E2B3E022BA267DEE221F5C42B17BCA182AF84584814A8B5E7E3FB17B397A9E3DEA75CD5627</div><div>    GlobalHashes:    </div><div>      Version:         0</div><div>      HashAlgorithm:   1</div><div>      HashValues:      </div><div>        - 5549419E78044E38</div><div>        - 96D45CD700942875</div><div>        - 8BE4A1E2B3E022BA</div><div>        - 267DEE221F5C42B1</div><div>        - 7BCA182AF8458481</div><div>        - 4A8B5E7E3FB17B39</div><div>        - 7A9E3DEA75CD5627</div></div><div>  - Name:            .pdata  <br></div><div><br></div><div>And in the bad yaml file I see this:</div><div><div>  - Name:            '.debug$H'</div><div>    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]</div><div>    Alignment:       4</div><div>    SectionData:     C5C9330100000000</div><div>    GlobalHashes:    </div><div>      Version:         0</div><div>      HashAlgorithm:   0</div><div>  - Name:            .pdata</div></div><div><br></div><div>Don't focus too much on trying to figure out weird linker errors.  Just get the output of obj2yaml to be identical when run under a diff utility, then everything should work fine.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jan 26, 2018 at 7:27 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I'm so close I can almost smell it :)</div><div><br></div><div>I know how bad the code looks, I don't intend to submit this, but if you want to try it out its at: <a href="https://gist.github.com/santagada/544136b1ee143bf31653b1158ac6829e" target="_blank">https://gist.github.com/santagada/544136b1ee143bf31653b1158ac6829e</a><br></div><div><br></div><div>I'm seeing: lld-link.exe: error: duplicate symbol: "<redacted_unmangled>" (<redacted>) in <internal> and in <redacted_filename>.obj, looking at the .yaml dump the symbols are all similar to this:<br></div><div><br></div><div><div><div><span style="color:rgb(0,0,0)">  - </span><span style="color:rgb(128,0,0)">Name</span><span style="color:rgb(0,0,0)">:            </span><redacted></div><div><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(128,0,0)">Value</span><span style="color:rgb(0,0,0)">:           </span><span style="color:rgb(9,136,90)">0</span></div><div><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(128,0,0)">SectionNumber</span><span style="color:rgb(0,0,0)">:   </span><span style="color:rgb(9,136,90)">0</span></div><div><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(128,0,0)">SimpleType</span><span style="color:rgb(0,0,0)">:      </span><span style="color:rgb(0,0,255)">IMAGE_SYM_TYPE_NULL</span></div><div><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(128,0,0)">ComplexType</span><span style="color:rgb(0,0,0)">:     </span><span style="color:rgb(0,0,255)">IMAGE_SYM_DTYPE_FUNCTION</span></div><div><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(128,0,0)">StorageClass</span><span style="color:rgb(0,0,0)">:    </span><span style="color:rgb(0,0,255)">IMAGE_SYM_CLASS_WEAK_EXTERNAL</span></div><div><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(128,0,0)">WeakExternal</span><span style="color:rgb(0,0,0)">:    </span></div><div><span style="color:rgb(0,0,0)">      </span><span style="color:rgb(128,0,0)">TagIndex</span><span style="color:rgb(0,0,0)">:        </span><span style="color:rgb(9,136,90)">134</span></div><div><span style="color:rgb(0,0,0)">      </span><span style="color:rgb(128,0,0)">Characteristics</span><span style="color:rgb(0,0,0)">: </span><span style="color:rgb(0,0,255)">IMAGE_WEAK_EXTERN_SEARCH_LIBRARY</span></div></div></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 8:01 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I haven't really dabbled in this part of the COFF format personally, so hopefully I'm not leading you astray :)<div><br></div><div>But I checked the code for coff2yaml, and I see this:</div><div><br></div><div><div>      } else if (Symbol.isSectionDefinition()) {</div><div>        // This symbol represents a section definition.</div><div>        assert(Symbol.getNumberOfAuxSymbols() == 1 &&</div><div>               "Expected a single aux symbol to describe this section!");</div></div><div><div>        const object::coff_aux_section_definition *ObjSD =<br></div><div>            reinterpret_cast<const object::coff_aux_section_definition *>(</div><div>                AuxData.data());</div></div><div><br></div><div>So it looks like you need exactly 1 aux symbol for each section symbol.</div><div><br></div><div>I then scrolled up in this function to figure out where AuxData comes from, and it comes from COFFObjectFile::getSymbolAuxData.  I think that function holds the clue to what you need to do.  It looks like you need to set coff::symbol::NumberOfAuxSymbols to 1, and then there is a comment in getSymbolAuxData which says:</div><div><br></div><div><div>    // AUX data comes immediately after the symbol in COFF</div><div>    Aux = reinterpret_cast<const uint8_t *>(Symbol.getRawPtr()) + SymbolSize;</div></div><div><br></div><div>So I think you just need to write the bytes immediately after the coff::symbol.  The thing you need to write looks like a coff::coff_aux_section_definition structure.</div><div><br></div><div>For the CheckSum, look at WinCOFFObjectWriter::writeSection.  It looks like its a CRC32 of the actual section contents, which you can generate with a couple of lines of code:</div><div><br></div><div><div>  JamCRC JC(/*Init=*/0);</div><div>  JC.update(DebugHContents);</div><div>  AuxSymbol.CheckSum = JC.getCRC();</div></div><div><br></div><div>Hope this helps</div></div><div class="m_-5288612815025643675m_1332462045029486301HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 25, 2018 at 10:46 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div>I see that there is an auxsymbol per section symbol, and also on the yaml representation there is a checksum, selection and unused all of them I have no idea how to fill in, also this aux symbol might have some important information for me to patch on the other symbols. Can you find the part in llvm that it writes those? because at least for auxsymbol the yaml part of the code threats as a binary blob so there is no info on what they should be.<br></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 7:15 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">If you run obj2yaml against a very simple object file, you'll see something like this at the end:<div>```</div><div><div>symbols:</div><div>  - Name:            '@<a href="http://comp.id" target="_blank">comp.id</a>'</div><div>    Value:           17130443</div><div>    SectionNumber:   -1</div><div>    SimpleType:      IMAGE_SYM_TYPE_NULL</div><div>    ComplexType:     IMAGE_SYM_DTYPE_NULL</div><div>    StorageClass:    IMAGE_SYM_CLASS_STATIC</div><div>  - Name:            '@feat.00'</div><div>    Value:           <a href="tel:(21)%204748-4048" value="+552147484048" target="_blank">2147484048</a></div><div>    SectionNumber:   -1</div><div>    SimpleType:      IMAGE_SYM_TYPE_NULL</div><div>    ComplexType:     IMAGE_SYM_DTYPE_NULL</div><div>    StorageClass:    IMAGE_SYM_CLASS_STATIC</div><div>  - Name:            .drectve</div><div>    Value:           0</div><div>    SectionNumber:   1</div><div>    SimpleType:      IMAGE_SYM_TYPE_NULL</div><div>    ComplexType:     IMAGE_SYM_DTYPE_NULL</div><div>    StorageClass:    IMAGE_SYM_CLASS_STATIC</div><div>    SectionDefinition:</div><div>      Length:          47</div><div>      NumberOfRelocations: 0</div><div>      NumberOfLinenumbers: 0</div><div>      CheckSum:        0</div><div>      Number:          0</div><div>...</div><div>```<br></div></div><div><br></div><div>There's a structure called coff::symbol which basically represents each one of these records.  It looks like this:</div><div><br></div><div>```</div><div><div>struct symbol {</div><div>  char Name[NameSize];</div><div>  uint32_t Value;</div><div>  int32_t SectionNumber;</div><div>  uint16_t Type;</div><div>  uint8_t StorageClass;</div><div>  uint8_t NumberOfAuxSymbols;</div><div>};</div></div><div>```</div><div><br></div><div>So you'll need to create one for the debug$H section and stick it into the list.  This particular list doesn't have to be in any special order, so you can just put it at the end (although it's probably not that much harder to insert into the middle, and it will make for a good test that you've done it right.  The output can be diffed against clang-cl object file and be identical this way).  So write all the normal symbols as you probably already are, then write one for the .debug$H section.  Initialize the fields to the same thing that you see when you run obj2yaml against an object file generated by clang-cl for the .debug$H section.</div><div><br></div><div>This structure doesn't contain any kind of file pointers or offsets, so all you really need to fix up are the "SectionNumber" fields.  Basically as you are writing the existing symbols, you would do somethign like:</div><div><br></div><div>for (const auto &Sym : ObjFile.symbols()) {</div><div>  if (Symbol->SectionNumber >= DebugHInsertionIndex)</div><div>    ++Symbol->SectionNumber;</div><div>  writeSymbol(Sym);</div><div>}</div><div>writeSymbol(DebugHSym);</div><div><br></div></div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 25, 2018 at 9:57 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Any idea on how to create this new symbol there? I saw that there is a symbol pointing to each section, but didn't understand the format, and yaml2obj doesn't check it or do anything with the list.<br></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 6:56 PM, Leonardo Santagada <span dir="ltr"><<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>YES, THANK YOU... I WAS THINKING THIS BUT COMPLETELY FORGOT.<br><br></div>sorry for the caps... long day of working on this, and using vs 2017, which adds a new section type .chks64 that I couldn't find documentation anywhere was difficult. I highly recommend everyone to just not using vs 2017 until 15.8 or something, our internal bug list is gigantic.<br></div><div class="gmail_extra"><div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513h5"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 6:52 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Actually I already have a theory that even though you are adding the section to the section table, you might not be adding a *symbol* for the section to the symbol table.  So the existing symbols (which reference sections by index) will all be wrong because you've inserted a new section.  Still though, obj2yaml would expose that.</div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 25, 2018 at 9:50 AM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yea as long as you compare clang-cl object file with automatically generated .debug$H section against clang-cl object file without .debug$H but added after the fact with llvm-objcopy, that should expose the problem I think when you run obj2yaml on them.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 25, 2018 at 9:49 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>I did reorder my sections, so that .debug$H is in the correct place, but now I get some errors on dubplicate symbols, I created a folder with examples:<br><br><a href="https://www.dropbox.com/sh/nmvzi44pi0boe76/AAA0f47O5PCJ9JiUc6wVuwBra?dl=0" target="_blank">https://www.dropbox.com/sh/nmvzi44pi0boe76/AAA0f47O5PCJ9JiUc6wVuwBra?dl=0</a><br><br></div>t.obj is generated by vs 2015 and it links fine with lld-link.exe, but tout.obj gives this errors:<br><br>lld-link.exe /DEBUG:GHASH tout.obj<br>LLD-LINK.EXE: error: duplicate symbol: __local_stdio_printf_options in tout.obj and in LIBCMT.lib(default_local_stdio_options.obj)<br>LLD-LINK.EXE: error: duplicate symbol: __local_stdio_printf_options in tout.obj and in libvcruntime.lib(undname.obj)<br><br></div>I'm using PEView from <a href="http://wjradburn.com/software/" target="_blank">http://wjradburn.com/software/</a> to look at the files and can't see anything wrong, except some valid differences in the offsets being used for the data (so pointer to data is different between them).<br><br></div>I will look into yaml2obj now to see if I see anything else weird going on.<br><br></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 6:41 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm pretty confident that cl is not putting anything strange in the .debug$T sections.  We've done a lot of testing and never seen anything except CodeView type records in a .debug$T.  My hunch is that your objcopy patch is probably not doing the right thing in one or more of the section headers, and this is confusing the linker.<div><br></div><div>One idea might be to build a simple object file with clang-cl but without the magic -mllvm -emit-codeview-ghash-section, then run your llvm-objcopy on it.  Then build the same object file passing -mllvm -emit-codeview-ghash-section.  Then run obj2yaml on both and diff the results.  They should be byte-for-byte identical.  That should give you a clue about if objcopy is doing something wrong.</div></div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 25, 2018 at 2:21 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Don't worry, I definetly want to perfect this to generate legal obj files, this is just to speed up testing.<br><br></div>Now after patching all the obj files I get this errors when linking a small part of our code base (msvc 2017 15.5.3, lld and llvm-objcopy 7.0.0):<br>lld-link.exe : error : relocation against symbol in discarded section: $LN8<br>lld-link.exe : error : relocation against symbol in discarded section: $LN43<br>lld-link.exe : error : relocation against symbol in discarded section: $LN37<br><br></div>I'm starting to guess that cl.exe might be putting some random comdat or other discardable symbols in the .debug$T and clang doesn't? I will try to debug this and see what more I can uncover.<br><br></div>Linking works perfectly without my llvm-objcopy pass to add .debug$H?<br><div><div><br></div></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 1:53 AM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It might not influence LLD, but at the same time we don't want to upstream something that is producing technically illegal COFF files.  Also good to hear about the planned changes to your header files.  Looking forward to hearing about your experiences with clang-cl.</div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509h5"><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 24, 2018 at 10:41 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi,<br><br></div>I finally got my first .obj file patched with .debug$H to look somewhat right. I added the new section at the end of the file so I don't have to recalculate all sections (although now I probably could position it in the middle, knowing that each section is: SizeOfRawData + (last.Header.NumberOfRelocations * (4+4+2)) and the $H needs to come right after $T in the file). That although illegal based on the coff specs doesn't seem its going to influence lld.<br><br></div><div>Also we talked and we are probably going to do something similar to a bunch of windows defines and a check for our own define (to guarantee that no one imported windows.h before win32.h) and drop the namespace and the conflicting names.<br><br></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 23, 2018 at 12:46 AM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">That's very possible that a 3rd party indirect header include is involved.  One idea might be like I suggested where you #define _WINDOWS_ in win32.h and guarantee that it's always included first.  Then those other headers won't be able to #include <windows.h>.  but it will probably greatly expand the amount of stuff you have to add to win32.h, as you will probably find some callers of functions that aren't yet in your win32.h that you'd have to add.<div><br></div><div><br></div></div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212h5"><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 22, 2018 at 3:28 PM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Ok some information was lost on getting this example to you, I'm sorry for not being clear. <div dir="auto"><br></div><div dir="auto">We have a huge code base, let's say 90% of it doesn't include either header, 9% include win32.h and 1% includes both, I will try to discover why, but my guess is they include both a third party that includes windows.h and some of our libs that use win32.h. </div><div dir="auto"><br></div><div dir="auto">I will try to fully understand this tomorrow.</div><div dir="auto"><br></div><div dir="auto">I guess clang will not implement this ever so finishing the object copier is the best solution until all code is ported to clang. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 Jan 2018 00:02, "Zachary Turner" <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>You said win32.h doesn't include windows.h, but main.cpp does.  So what's the disadvantage of just including it in win32.h anyway, since it's already going to be in every translation unit?  (Unless you didn't mean to #include it in main.cpp)</div><div><br></div><div><br></div>I guess all I can do is warn you how bad of an idea this is.  For starters, I already found a bug in your code ;-)<div><br></div><div>// stdint.h<br></div><div><div>typedef int                int32_t;</div></div><div><br></div><div>// winnt.h</div><div><div>typedef long LONG;</div></div><div><br></div><div>// windef.h</div><div><div>typedef struct tagPOINT<br></div><div>{</div><div>    LONG  x;   // long x</div><div>    LONG  y;   // long y</div><div>} POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;</div></div><div><br></div><div>// win32.h</div><div><div>typedef int32_t LONG;<br></div><div><br></div><div>struct POINT</div><div>{</div><div><span style="white-space:pre-wrap">  </span>LONG x;   // int x</div><div><span style="white-space:pre-wrap">     </span>LONG y;   // int y</div><div>};</div></div><div><br></div><div>So POINT is defined two different ways.  In your minimal interface, it's declared as 2 int32's, which are int.  In the actual Windows header files, it's declared as 2 longs.</div><div><br></div><div>This might seem like a unimportant bug since int and long are the same size, but int and long also mangle differently and affect overload resolution, so you could have weird linker errors or call the wrong function overload.</div><div><br></div><div>Plus, it illustrates the fact that this struct *actually is* a different type from the one in the windows header.</div><div><br></div><div>You said at the end that you never intentionally import win32.h and windows.h from the same translation unit.  But then in this example you did.  I wonder if you could enforce that by doing this:</div><div><br></div><div>// win32.h</div><div>#pragma once</div><div><br></div><div>// Error if windows.h was included before us.</div><div>#if defined(_WINDOWS_)<br></div><div>#error "You're including win32.h after having already included windows.h.  Don't do this!"</div><div>#endif</div><div><br></div><div>// And also make sure windows.h can't get included after us</div><div>#define _WINDOWS_</div><div><br></div><div>For the record, I tried the test case you linked when windows.h is not included in main.cpp and it works (but still has the bug about int and long).</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 22, 2018 at 2:23 PM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>It is super gross, but we copy parts of windows.h because having all of it if both gigantic and very very messy. So our win32.h has a couple thousands of lines and not 30k+ for windows.h and we try to have zero macros. Win32.h doesn't include windows.h so using ::BOOL wouldn't work. We don't want to create a namespace, we just want a cleaner interface to windows api. The namespace with c linkage is the way to trick cl into allowing us to in some files have both windows.h and Win32.h. I really don't see any way for us to have this Win32.h without this cl support, so maybe we should either put windows.h in a compiled header somewhere and not care that it is infecting everything or just have one place we can call to clean up after including windows.h (a massive set of undefs).<br><br></div><div>So using can't work, because we never intentionally import windows.h and win32.h on the same translation unit.<br></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 22, 2018 at 7:08 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This is pretty gross, honestly :)<div><br></div><div>Can't you just use using declarations?</div><div><br></div><div><div>namespace Win32 {</div><div>extern "C" { </div><div><br></div><div>using ::BOOL;</div><div>using ::LONG;</div><div>using ::POINT;</div><div>using ::LPPOINT;</div><div><br></div><div>using ::GetCursorPos;</div><div>}</div><div>}</div></div><div><br></div><div>This works with clang-cl.</div></div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141h5"><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 22, 2018 at 5:39 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Here it is a minimal example, we do this so we don't have to import the whole windows api everywhere.<br><div><br><a href="https://gist.github.com/santagada/7977e929d31c629c4bf18ebb987f6be3" target="_blank">https://gist.github.com/santagada/7977e929d31c629c4bf18ebb987f6be3</a><br></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 21, 2018 at 2:31 AM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Clang-cl maintains compatibility with msvc even in cases where it’s non standards compliant (eg 2 phase name lookup), but we try to keep these cases few and far between.<br><br>To help me understand your case, do you mean you copy windows.h and modify it?  How does this lead to the same struct being defined twice?  If i were to write this:<br><br>struct Foo {};<br>struct Foo {};<br><br>Is this a small repro of the issue you’re talking about?<div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084h5"><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 20, 2018 at 3:44 PM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I can totally see something like incremental linking with a simple padding between obj and a mapping file (which can also help with edit and continue, something we also would love to have). <br><br>We have another developer doing the port to support clang-cl, but although most of our code also goes trough a version of clang, migrating the rest to clang-cl has been a fight. From what I heard the main problem is that we have a copy of parts of windows.h (so not to bring the awful parts of it like lower case macros) and that totally works on cl, but clang (at least 6.0) complains about two struct/vars with the same name, even though they are exactly the same. Making clang-cl as broken as cl.exe is not an option I suppose? I would love to turn on a flag --accept-that-cl-made-bad-decisions-and-live-with-it and have this at least until this is completely fixed in our code base.<br><br></div>the biggest win with moving to cl would be a better more standards compliant compiler, no 1 minute compiles on heavily templated files and maybe the holy grail of ThinLTO.<br></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 20, 2018 at 10:56 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">10-15s will be hard without true incremental linking.<div><br></div><div>At some point that's going to be the only way to get any faster, but incremental linking is hard (putting it lightly), and since our full links are already really fast we think we can get reasonably close to link.exe incremental speeds with full links.  But it's never enough and I will always want it to be faster, so you may see incremental linking in the future after we hit a performance wall with full link speed :)</div><div><br></div><div>In any case, I'm definitely interested in seeing what kind of numbers you get with /debug:ghash after you get this llvm-objcopy feature implemented.  So keep me updated :)</div><div><br></div><div>As an aside, have you tried building with clang instead of cl?  If you build with clang you wouldn't even have to do this llvm-objcopy work, because it would "just work".  If you've tried but ran into issues I'm interested in hearing about those too.  On the other hand, it's also reasonable to only switch one thing at a time.</div></div><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285h5"><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 20, 2018 at 1:34 PM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">if we get to < 30s I think most users would prefer it to link.exe, just hopping there is still some more optimizations to get closer to ELF linking times (around 10-15s here).<br></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 20, 2018 at 9:50 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Generally speaking a good rule of thumb is that /debug:ghash will be close to or faster than /debug:fastlink, but with none of the penalties like slow debug time <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285m_4290125905266486172m_-4983865677775689192HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285m_4290125905266486172m_-4983865677775689192h5"><div class="gmail_quote"><div dir="ltr">On Sat, Jan 20, 2018 at 12:44 PM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Chrome is actually one of my exact benchmark cases.  When building blink_core.dll and browser_tests.exe, i get anywhere from a 20-40% reduction in link time.  We have some other optimizations in the pipeline but not upstream yet.<br><br>My best time so far (including other optimizations not yet upstream) is 28s on blink_core.dll, compared to 110s with /debug<br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 20, 2018 at 12:28 PM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">On Sat, Jan 20, 2018 at 9:05 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You probably don't want to go down the same route that clang goes through to write the object file.  If you think yaml2coff is convoluted, the way clang does it will just give you a headache.  There are multiple abstractions involved to account for different object file formats (ELF, COFF, MachO) and output formats (Assembly, binary file).  At least with yaml2coff <br></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I think your phrase got cut there, but yeah I just found AsmPrinter.cpp and it is convoluted.<br><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>It's true that yaml2coff is using the COFFParser structure, but if you look at the <span style="color:rgb(33,33,33)">writeCOFF function in yaml2coff it's pretty bare-metal.  The logic you need will be almost identical, except that instead of checking the COFFParser for the various fields, you'll check the existing COFFObjectFile, which should have similar fields.</span></div><div><span style="color:rgb(33,33,33)"><br></span></div><div><span style="color:rgb(33,33,33)">The only thing you need to different is when writing the section table and section contents, to insert a new entry.  </span><span style="color:rgb(33,33,33)">Since you're injecting a section into the middle, you'll also probably need to push back the file pointer of all subsequent sections so that they don't overlap.  (e.g. if the original sections are 1, 2, 3, 4, 5 and you insert between 2 and 3, then the original sections 3, 4, and 5 would need to have their FilePointerToRawData offset by the size of the new section).</span></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I have the PE/COFF spec open here and I'm happy that I read a bit of it so I actually know what you are talking about... yeah it doesn't seem too complicated. <br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="color:rgb(33,33,33)"></span></div><div><span style="color:rgb(33,33,33)">If you need to know what values to put for the other fields in a section header, run `dumpbin /headers foo.obj` on a clang-generated object file that has a .debug$H section already (e.g. run clang with -emit-codeview-ghash-section, and look at the properties of the .debug$H section and use the same values).</span></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Thanks I will do that and then also look at how the CodeView part of the code does it if I can't understand some of it. <br><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="color:rgb(33,33,33)"><br></span></div><div><span style="color:rgb(33,33,33)">The only invariant that needs to be maintained is that Section[N]->FilePointerOfRawData == Section[N-1]->FilePointerOfRawData + Section[N-1]->SizeOfRawData</span></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Well, that and all the sections need to be on the final file... But I'm hopeful.<br><br><br></div><div>Anyone has times on linking a big project like chrome with this so that at least I know what kind of performance to expect?<br><br></div><div>My numbers are something like:<br><br></div><div>1 pdb per obj file: link.exe takes ~15 minutes and 16GB of ram, lld-link.exe takes 2:30 minutes and ~8GB of ram<br></div><div>around 10 pdbs per folder: link.exe takes 1 minute and 2-3GB of ram, lld-link.exe takes 1:30 minutes and ~6GB of ram<br></div><div>faslink: link.exe takes 40 seconds, but then 20 seconds of loading at the first break point in the debugger and we lost DIA support for listing symbols.<br></div><div>incremental: link.exe takes 8 seconds, but it only happens when very minor changes happen.<br></div><div><br></div><div>We have an non negligible number of symbols used on some runtime systems.<br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285m_4290125905266486172m_-4983865677775689192m_1330076587365671697m_3129290989285100139m_8012910641178389879HOEnZb"><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285m_4290125905266486172m_-4983865677775689192m_1330076587365671697m_3129290989285100139m_8012910641178389879h5"><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 20, 2018 at 11:52 AM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thanks for the tips, I now have something that reads the obj file, finds .debug$T sections and global hashes it (proof of concept kind of code). What I can't find is: how does clang itself writes the coff files with global hashes, as that might help me understand how to create the .debug$H section, how to update the file section count and how to properly write this back.<br><br></div>The code on yaml2coff is expecting to be working on the yaml COFFParser struct and I'm having quite a bit of a headache turning the COFFObjectFile into a COFFParser object or compatible... Tomorrow I might try the very non efficient path of coff2yaml and then yaml2coff with the hashes header... but it seems way too inefficient and convoluted.<br></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 19, 2018 at 10:38 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span><div dir="ltr">On Fri, Jan 19, 2018 at 1:02 PM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">On Fri, Jan 19, 2018 at 9:44 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span><div dir="ltr">On Fri, Jan 19, 2018 at 12:29 PM Leonardo Santagada <<a href="mailto:santagada@gmail.com" target="_blank">santagada@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>No I didn't, I used cl.exe from the visual studio toolchain. What I'm proposing is a tool for processing .obj files in COFF format, reading them and generating the GHASH part.</div><div><br></div><div>To make our build faster we use hundreds of unity build files (.cpp's with a lot of other .cpp's in them aka munch files) but still have a lot of single .cpp's as well (in total something like 3.4k .obj files).</div><div><br></div><div>ps: sorry for sending to the wrong list, I was reading about llvm mailing lists and jumped when I saw what I thought was a lld exclusive list.<br></div></div></blockquote><div><br></div></span><div>A tool like this would be useful, yes.  We've talked about it internally as well and agreed it would be useful, we just haven't prioritized it.  If you're interested in submitting a patch along those lines though, I think it would be a good addition.</div><div><br></div><div>I'm not sure what the best place for it would be.  llvm-readobj and llvm-objdump seem like obvious choices, but they are intended to be read-only, so perhaps they wouldn't be a good fit.</div><div><br></div><div>llvm-pdbutil is kind of a hodgepodge of everything else related to PDBs and symbols, so I wouldn't be opposed to making a new subcommand there called "ghash" or something that could process an object file and output a new object file with a .debug$H section.</div><div><br></div><div>A third option would be to make a new tool for it.</div><div><br></div><div>I don't htink it would be that hard to write.  If you're interested in trying to make a patch for this, I can offer some guidance on where to look in the code.  Otherwise it's something that we'll probably get to, I'm just not sure when.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra">
</div></blockquote></div></div>
</blockquote></div></div><div class="gmail_extra"><br></div></div><div dir="ltr"><div class="gmail_extra">I would love to write it and contribute it back, please do tell, I did find some of the code of ghash in lld, but in fuzzy on the llvm codeview part of it and never seen llvm-readobj/objdump or llvm-pdbutil, but I'm not afraid to look :)<br></div></div><div dir="ltr"><div class="gmail_extra"><br></div></div></blockquote><div><br></div></span><div> Luckily all of the important code is hidden behind library calls, and it should already just do the right thing, so I suspect you won't need to know much about CodeView to do this.</div><div><br></div><div>I think Peter has the right idea about putting this in llvm-objcopy.</div><div><br></div><div>You can look at one of the existing CopyBinary functions there, which currently only work for ELF, but you can just make a new overload that accepts a COFFObjectFile.</div><div><br></div><div>I would probably start by iterating over each of the sections (getNumberOfSections / getSectionName) looking for .debug$T and .debug$H sections.  </div><div><br></div><div>If you find a .debug$H section then you can just skip that object file.  </div><div><br></div><div>If you find a .debug$T but not a .debug$H, then basically do the same thing that LLD does in PDBLinker::mergeDebugT  (create a CVTypeArray, and pass it to GloballyHashedType::hashTypes.  That will return an array of hash values.  (the format of .debug$H is the header, followed by the hash values).  Then when you're writing the list of sections, just add in the .debug$H section right after the .debug$T section.</div><div><br></div><div>Currently llvm-objcopy only writes ELF files, so it would need to be taught to write COFF files.  We have code to do this in the yaml2obj utility (specifically, in yaml2coff.cpp in the function writeCOFF).  There may be a way to move this code to somewhere else (llvm/Object/COFF.h?) so that it can be re-used by both yaml2coff and llvm-objcopy, but in the worst case scenario you could copy the code and re-write it to work with these new structures.</div><div><br></div><div>Lastly, you'll probably want to put all of this behind an option in llvm-objcopy such as -add-codeview-ghash-section</div><div><br></div></div></div>
</blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285m_4290125905266486172m_-4983865677775689192m_1330076587365671697m_3129290989285100139m_8012910641178389879m_8441690070965861958m_6919085447883523515gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><br><br clear="all"><br>-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285m_4290125905266486172m_-4983865677775689192m_1330076587365671697m_3129290989285100139m_8012910641178389879gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></div></blockquote></div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285m_4290125905266486172m_-4983865677775689192gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084m_6328300659575866201m_3251013050043970285gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141m_8303529303722936371m_4449077111515507084gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212m_-208965418331623548m_-8573953329845491371m_-2709266468793015360m_6098347775258118141gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</blockquote></div></div>
</blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509m_-5305452228246432736m_6488132418004115212gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033m_4446702591307542288m_8583369498253859509gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329m_-5655083758196447727m_1801649823140256066m_1932301727518110033gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div></div><span class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513HOEnZb"><font color="#888888">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513m_-8875478527294765329gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</font></span></div>
</blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028m_-4350989755979064182m_2071976144951359513gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301m_8962849001622190948m_122654845606253028gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br></div><div class="gmail_extra">-- <br><div class="m_-5288612815025643675m_1332462045029486301gmail_signature" data-smartmail="gmail_signature"><br>Leonardo Santagada</div>
</div></blockquote></div></blockquote></div>