<div dir="ltr">Apologies, I thought <a href="https://reviews.llvm.org/D26974">https://reviews.llvm.org/D26974</a> was already submitted to fix this issue. I just submitted that.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 23, 2016 at 3:02 PM, Jan Vesely <span dir="ltr"><<a href="mailto:jan.vesely@rutgers.edu" target="_blank">jan.vesely@rutgers.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">this commit broke build. I have attached fix, please review.<br>
<br>
thanks,<br>
Jan<br>
<div class="HOEnZb"><div class="h5"><br>
On Mon, 2016-11-21 at 17:22 +0000, Rui Ueyama via llvm-commits wrote:<br>
> Author: ruiu<br>
> Date: Mon Nov 21 11:22:35 2016<br>
> New Revision: 287555<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=287555&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=287555&view=rev</a><br>
> Log:<br>
> Do plumbing work for CodeView debug info.<br>
><br>
> Previously, we discarded .debug$ sections. This patch adds them to<br>
> files so that PDB.cpp can access them.<br>
><br>
> This patch also adds a debug option, /dumppdb, to dump debug info<br>
> fed to createPDB so that we can verify that valid data has been passed.<br>
><br>
> Added:<br>
>     lld/trunk/test/COFF/dumppdb.<wbr>test<br>
> Modified:<br>
>     lld/trunk/COFF/Config.h<br>
>     lld/trunk/COFF/Driver.cpp<br>
>     lld/trunk/COFF/InputFiles.cpp<br>
>     lld/trunk/COFF/InputFiles.h<br>
>     lld/trunk/COFF/Options.td<br>
>     lld/trunk/COFF/PDB.cpp<br>
>     lld/trunk/COFF/SymbolTable.h<br>
><br>
> Modified: lld/trunk/COFF/Config.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=287555&r1=287554&r2=287555&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Config.<wbr>h?rev=287555&r1=287554&r2=<wbr>287555&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/COFF/Config.h (original)<br>
> +++ lld/trunk/COFF/Config.h Mon Nov 21 11:22:35 2016<br>
> @@ -150,6 +150,9 @@ struct Configuration {<br>
>    bool TerminalServerAware = true;<br>
>    bool LargeAddressAware = false;<br>
>    bool HighEntropyVA = false;<br>
> +<br>
> +  // This is for debugging.<br>
> +  bool DumpPdb = false;<br>
>  };<br>
><br>
>  extern Configuration *Config;<br>
><br>
> Modified: lld/trunk/COFF/Driver.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=287555&r1=287554&r2=287555&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/Driver.<wbr>cpp?rev=287555&r1=287554&r2=<wbr>287555&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/COFF/Driver.cpp (original)<br>
> +++ lld/trunk/COFF/Driver.cpp Mon Nov 21 11:22:35 2016<br>
> @@ -528,6 +528,7 @@ void LinkerDriver::link(llvm::<wbr>ArrayRef<c<br>
>      Config->TerminalServerAware = false;<br>
>    if (Args.hasArg(OPT_nosymtab))<br>
>      Config->WriteSymtab = false;<br>
> +  Config->DumpPdb = Args.hasArg(OPT_dumppdb);<br>
><br>
>    // Create a list of input files. Files can be given as arguments<br>
>    // for /defaultlib option.<br>
><br>
> Modified: lld/trunk/COFF/InputFiles.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=287555&r1=287554&r2=287555&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>InputFiles.cpp?rev=287555&r1=<wbr>287554&r2=287555&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/COFF/InputFiles.cpp (original)<br>
> +++ lld/trunk/COFF/InputFiles.cpp Mon Nov 21 11:22:35 2016<br>
> @@ -150,13 +150,28 @@ void ObjectFile::initializeChunks() {<br>
>        Directives = std::string((const char *)Data.data(), Data.size());<br>
>        continue;<br>
>      }<br>
> -    // Skip non-DWARF debug info. MSVC linker converts the sections into<br>
> -    // a PDB file, but we don't support that.<br>
> -    if (Name == ".debug" || Name.startswith(".debug$"))<br>
> -      continue;<br>
> -    // We want to preserve DWARF debug sections only when /debug is on.<br>
> +<br>
> +    // Object files may have DWARF debug info or MS CodeView debug info<br>
> +    // (or both).<br>
> +    //<br>
> +    // DWARF sections don't need any special handling from the perspective<br>
> +    // of the linker; they are just a data section containing relocations.<br>
> +    // We can just link them to complete debug info.<br>
> +    //<br>
> +    // CodeView needs a linker support. We need to interpret and debug<br>
> +    // info, and then write it to a separate .pdb file.<br>
> +<br>
> +    // Ignore debug info unless /debug is given.<br>
>      if (!Config->Debug && Name.startswith(".debug"))<br>
>        continue;<br>
> +<br>
> +    // CodeView sections are stored to a different vector because they are<br>
> +    // not linked in the regular manner.<br>
> +    if (Name == ".debug" || Name.startswith(".debug$")) {<br>
> +      DebugChunks.push_back(new (Alloc) SectionChunk(this, Sec));<br>
> +      continue;<br>
> +    }<br>
> +<br>
>      if (Sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_<wbr>REMOVE)<br>
>        continue;<br>
>      auto *C = new (Alloc) SectionChunk(this, Sec);<br>
><br>
> Modified: lld/trunk/COFF/InputFiles.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=287555&r1=287554&r2=287555&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>InputFiles.h?rev=287555&r1=<wbr>287554&r2=287555&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/COFF/InputFiles.h (original)<br>
> +++ lld/trunk/COFF/InputFiles.h Mon Nov 21 11:22:35 2016<br>
> @@ -38,6 +38,7 @@ class Defined;<br>
>  class DefinedImportData;<br>
>  class DefinedImportThunk;<br>
>  class Lazy;<br>
> +class SectionChunk;<br>
>  class SymbolBody;<br>
>  class Undefined;<br>
><br>
> @@ -122,6 +123,7 @@ public:<br>
>    void parse() override;<br>
>    MachineTypes getMachineType() override;<br>
>    std::vector<Chunk *> &getChunks() { return Chunks; }<br>
> +  std::vector<SectionChunk *> &getDebugChunks() { return DebugChunks; }<br>
>    std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }<br>
><br>
>    // Returns a SymbolBody object for the SymbolIndex'th symbol in the<br>
> @@ -157,6 +159,9 @@ private:<br>
>    // chunks and non-section chunks for common symbols.<br>
>    std::vector<Chunk *> Chunks;<br>
><br>
> +  // CodeView debug info sections.<br>
> +  std::vector<SectionChunk *> DebugChunks;<br>
> +<br>
>    // This vector contains the same chunks as Chunks, but they are<br>
>    // indexed such that you can get a SectionChunk by section index.<br>
>    // Nonexistent section indices are filled with null pointers.<br>
><br>
> Modified: lld/trunk/COFF/Options.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=287555&r1=287554&r2=287555&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>Options.td?rev=287555&r1=<wbr>287554&r2=287555&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/COFF/Options.td (original)<br>
> +++ lld/trunk/COFF/Options.td Mon Nov 21 11:22:35 2016<br>
> @@ -94,6 +94,7 @@ def help_q : Flag<["/?", "-?"], "">, Ali<br>
>  def nosymtab : F<"nosymtab">;<br>
><br>
>  // Flags for debugging<br>
> +def dumppdb : Joined<["/", "-"], "dumppdb">;<br>
>  def lldmap : Joined<["/", "-"], "lldmap:">;<br>
><br>
>  //============================<wbr>==============================<wbr>====================<br>
><br>
> Modified: lld/trunk/COFF/PDB.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=287555&r1=287554&r2=287555&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/PDB.<wbr>cpp?rev=287555&r1=287554&r2=<wbr>287555&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/COFF/PDB.cpp (original)<br>
> +++ lld/trunk/COFF/PDB.cpp Mon Nov 21 11:22:35 2016<br>
> @@ -9,9 +9,11 @@<br>
><br>
>  #include "PDB.h"<br>
>  #include "Chunks.h"<br>
> +#include "Config.h"<br>
>  #include "Error.h"<br>
>  #include "SymbolTable.h"<br>
>  #include "Symbols.h"<br>
> +#include "llvm/DebugInfo/CodeView/<wbr>TypeDumper.h"<br>
>  #include "llvm/DebugInfo/MSF/<wbr>MSFBuilder.h"<br>
>  #include "llvm/DebugInfo/MSF/MSFCommon.<wbr>h"<br>
>  #include "llvm/DebugInfo/PDB/Raw/<wbr>DbiStream.h"<br>
> @@ -25,11 +27,13 @@<br>
>  #include "llvm/Object/COFF.h"<br>
>  #include "llvm/Support/Endian.h"<br>
>  #include "llvm/Support/<wbr>FileOutputBuffer.h"<br>
> +#include "llvm/Support/ScopedPrinter.h"<br>
>  #include <memory><br>
><br>
>  using namespace lld;<br>
>  using namespace lld::coff;<br>
>  using namespace llvm;<br>
> +using namespace llvm::codeview;<br>
>  using namespace llvm::support;<br>
>  using namespace llvm::support::endian;<br>
><br>
> @@ -46,9 +50,35 @@ static std::vector<coff_section> getInpu<br>
>    return V;<br>
>  }<br>
><br>
> +static SectionChunk *findByName(std::vector<<wbr>SectionChunk *> &Sections,<br>
> +                                StringRef Name) {<br>
> +  for (SectionChunk *C : Sections)<br>
> +    if (C->getSectionName() == Name)<br>
> +      return C;<br>
> +  return nullptr;<br>
> +}<br>
> +<br>
> +// Dump CodeView debug info. This is for debugging.<br>
> +static void dumpCodeView(SymbolTable *Symtab) {<br>
> +  ScopedPrinter W(outs());<br>
> +<br>
> +  for (ObjectFile *File : Symtab->ObjectFiles) {<br>
> +    SectionChunk *C = findByName(File-><wbr>getDebugChunks(), ".debug$T");<br>
> +    if (!C)<br>
> +      continue;<br>
> +<br>
> +    CVTypeDumper TypeDumper(&W, false);<br>
> +    if (auto EC = TypeDumper.dump(C-><wbr>getContents()))<br>
> +      fatal(EC, "CVTypeDumper::dump failed");<br>
> +  }<br>
> +}<br>
> +<br>
>  // Creates a PDB file.<br>
>  void coff::createPDB(StringRef Path, SymbolTable *Symtab,<br>
>                       ArrayRef<uint8_t> SectionTable) {<br>
> +  if (Config->DumpPdb)<br>
> +    dumpCodeView(Symtab);<br>
> +<br>
>    BumpPtrAllocator Alloc;<br>
>    pdb::PDBFileBuilder Builder(Alloc);<br>
>    ExitOnErr(Builder.initialize(<wbr>4096)); // 4096 is blocksize<br>
><br>
> Modified: lld/trunk/COFF/SymbolTable.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=287555&r1=287554&r2=287555&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/<wbr>SymbolTable.h?rev=287555&r1=<wbr>287554&r2=287555&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/COFF/SymbolTable.h (original)<br>
> +++ lld/trunk/COFF/SymbolTable.h Mon Nov 21 11:22:35 2016<br>
> @@ -33,6 +33,7 @@ namespace coff {<br>
>  class Chunk;<br>
>  class Defined;<br>
>  class Lazy;<br>
> +class SectionChunk;<br>
>  class SymbolBody;<br>
>  struct Symbol;<br>
><br>
><br>
> Added: lld/trunk/test/COFF/dumppdb.<wbr>test<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/dumppdb.test?rev=287555&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/COFF/<wbr>dumppdb.test?rev=287555&view=<wbr>auto</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/test/COFF/dumppdb.<wbr>test (added)<br>
> +++ lld/trunk/test/COFF/dumppdb.<wbr>test Mon Nov 21 11:22:35 2016<br>
> @@ -0,0 +1,113 @@<br>
> +# RUN: yaml2obj %s > %t.obj<br>
> +# RUN: lld-link /debug /pdb:%t.pdb /dumppdb /dll /out:%t.dll /entry:main \<br>
> +# RUN:   /nodefaultlib %t.obj | FileCheck %s<br>
> +<br>
> +# CHECK:      UnknownLeaf (0x1000) {<br>
> +# CHECK-NEXT:   TypeLeafKind: 0x0<br>
> +# CHECK-NEXT:   Kind: 0x0<br>
> +# CHECK-NEXT:   Length: 2<br>
> +# CHECK-NEXT: }<br>
> +<br>
> +<br>
> +--- !COFF<br>
> +header:<br>
> +  Machine:         IMAGE_FILE_MACHINE_AMD64<br>
> +  Characteristics: [  ]<br>
> +sections:<br>
> +  - Name:            .drectve<br>
> +    Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]<br>
> +    Alignment:       1<br>
> +    SectionData:     2020202F44454641554C544C49423A<wbr>224C4942434D5422202F4445464155<wbr>4C544C49423A224F4C444E414D4553<wbr>2220<br>
> +  - Name:            '.debug$S'<br>
> +    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_<wbr>DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
> +    Alignment:       1<br>
> +    SectionData:     04000000F100000053000000150001<wbr>1100000000443A5C625C7265743432<wbr>2E6F626A003A003C1100600000D000<wbr>13000000F259000013000000F25900<wbr>004D6963726F736F66742028522920<wbr>4F7074696D697A696E6720436F6D70<wbr>696C65720000F10000004E0000002A<wbr>004711000000000000000000000000<wbr>060000000000000005000000021000<wbr>00000000000000006D61696E001C00<wbr>121000000000000000000000000000<wbr>000000000000000000004211000200<wbr>4F110000F200000020000000000000<wbr>000000000006000000000000000100<wbr>0000140000000000000001000080F4<wbr>000000180000000100000010010BFC<wbr>79AA614B536E3D64B110330D1E5800<wbr>00F30000000E00000000643A5C625C<wbr>72657434322E63000000F100000008<wbr>00000006004C110A100000<br>
> +    Relocations:<br>
> +      - VirtualAddress:  136<br>
> +        SymbolName:      main<br>
> +        Type:            IMAGE_REL_AMD64_SECREL<br>
> +      - VirtualAddress:  140<br>
> +        SymbolName:      main<br>
> +        Type:            IMAGE_REL_AMD64_SECTION<br>
> +      - VirtualAddress:  192<br>
> +        SymbolName:      main<br>
> +        Type:            IMAGE_REL_AMD64_SECREL<br>
> +      - VirtualAddress:  196<br>
> +        SymbolName:      main<br>
> +        Type:            IMAGE_REL_AMD64_SECTION<br>
> +  - Name:            '.debug$T'<br>
> +    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_<wbr>DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
> +    Alignment:       1<br>
> +    SectionData:     040000000A00011201000000000000<wbr>000E00081074000000000000000010<wbr>00001200011600000000011000006D<wbr>61696E00F3F2F10E00051600000000<wbr>443A5C6200F3F2F122000516000000<wbr>00433A5C767331345C56435C42494E<wbr>5C616D6436345C636C2E6578650002<wbr>010516000000002D5A37202D63202D<wbr>4D54202D49433A5C767331345C5643<wbr>5C494E434C554445202D49433A5C76<wbr>7331345C56435C41544C4D46435C49<wbr>4E434C554445202D4922433A5C5072<wbr>6F6772616D2046696C657320287838<wbr>36295C57696E646F7773204B697473<wbr>5C31305C696E636C7564655C31302E<wbr>302E31303135302E305C7563727422<wbr>202D4922433A5C50726F6772616D20<wbr>46696C65732028783836295C57696E<wbr>646F7773204B6974735C4E45544658<wbr>53444B5C342E365C696E636C756465<wbr>5C756D22202D4922433A5C50726F67<wbr>72616D2046696C6573202878383629<wbr>5C57696E646F7773204B6974735C38<wbr>2E315C696E636C7564655C73686172<wbr>656422000A00041601000000051000<wbr>008200051606100000202D4922433A<wbr>5C50726F6772616D2046696C657320<wbr>28783836295C57696E646F7773204B<wbr>6974735C382E315C696E636C756465<wbr>5C756D22202D4922433A5C50726F67<wbr>72616D2046696C6573202878383629<wbr>5C57696E646F7773204B6974735C38<wbr>2E315C696E636C75<br>
>  64655C77696E727422202D5443202D<wbr>5800F3F2F10E000516000000007265<wbr>7434322E6300160005160000000044<wbr>3A5C625C76633134302E70646200F1<wbr>1A0003160500031000000410000008<wbr>1000000910000007100000F2F1<br>
> +  - Name:            '.text$mn'<br>
> +    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]<br>
> +    Alignment:       16<br>
> +    SectionData:     B82A000000C3<br>
> +symbols:<br>
> +  - Name:            '@<a href="http://comp.id" rel="noreferrer" target="_blank">comp.id</a>'<br>
> +    Value:           17062386<br>
> +    SectionNumber:   -1<br>
> +    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
> +    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
> +    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
> +  - Name:            '@feat.00'<br>
> +    Value:           <a href="tel:2147484048" value="+12147484048">2147484048</a><br>
> +    SectionNumber:   -1<br>
> +    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
> +    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
> +    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
> +  - Name:            .drectve<br>
> +    Value:           0<br>
> +    SectionNumber:   1<br>
> +    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
> +    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
> +    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
> +    SectionDefinition:<br>
> +      Length:          47<br>
> +      NumberOfRelocations: 0<br>
> +      NumberOfLinenumbers: 0<br>
> +      CheckSum:        0<br>
> +      Number:          0<br>
> +  - Name:            '.debug$S'<br>
> +    Value:           0<br>
> +    SectionNumber:   2<br>
> +    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
> +    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
> +    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
> +    SectionDefinition:<br>
> +      Length:          296<br>
> +      NumberOfRelocations: 4<br>
> +      NumberOfLinenumbers: 0<br>
> +      CheckSum:        0<br>
> +      Number:          0<br>
> +  - Name:            '.debug$T'<br>
> +    Value:           0<br>
> +    SectionNumber:   3<br>
> +    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
> +    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
> +    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
> +    SectionDefinition:<br>
> +      Length:          576<br>
> +      NumberOfRelocations: 0<br>
> +      NumberOfLinenumbers: 0<br>
> +      CheckSum:        0<br>
> +      Number:          0<br>
> +  - Name:            '.text$mn'<br>
> +    Value:           0<br>
> +    SectionNumber:   4<br>
> +    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
> +    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
> +    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
> +    SectionDefinition:<br>
> +      Length:          6<br>
> +      NumberOfRelocations: 0<br>
> +      NumberOfLinenumbers: 0<br>
> +      CheckSum:        2139436471<br>
> +      Number:          0<br>
> +  - Name:            main<br>
> +    Value:           0<br>
> +    SectionNumber:   4<br>
> +    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
> +    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION<br>
> +    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL<br>
> +...<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>