[lld] r255039 - COFF: Create an empty but valid PDF file.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 11:05:10 PST 2015


On Tue, Dec 8, 2015 at 11:00 AM, David Blaikie <dblaikie at gmail.com> wrote:

>
>
> On Tue, Dec 8, 2015 at 10:39 AM, Rui Ueyama via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: ruiu
>> Date: Tue Dec  8 12:39:55 2015
>> New Revision: 255039
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=255039&view=rev
>> Log:
>> COFF: Create an empty but valid PDF file.
>>
>
> ^ had me wondering for a second there (PDF files? from the compiler?)
>

Sorry I didn't notice until now. :|


>
>
>>
>> MSVC linker considers PDB files created with this patch valid.
>> So you don't have to remove PDB files created by lld before
>> running MSVC linker.
>>
>> This patch has no test since llvm-pdbdump dislikes PDB files
>> with no metadata streams.
>>
>
> Could we fix the dumper so we can test this please?
>

I'm going to add metadata in the next patch so that it can be dumped using
llvm-pdbdump. There's no official spec of the PDB file, and a PDB file
without metadata is very artificial, I cannot say that that's a bug of
llvm-pdbdump even if it cannot dump such file.


>
>>
>> Modified:
>>     lld/trunk/COFF/PDB.cpp
>>
>> Modified: lld/trunk/COFF/PDB.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=255039&r1=255038&r2=255039&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/COFF/PDB.cpp (original)
>> +++ lld/trunk/COFF/PDB.cpp Tue Dec  8 12:39:55 2015
>> @@ -10,23 +10,51 @@
>>  #include "Driver.h"
>>  #include "Error.h"
>>  #include "Symbols.h"
>> +#include "llvm/Support/Endian.h"
>>  #include "llvm/Support/FileOutputBuffer.h"
>>  #include <memory>
>>
>>  using namespace llvm;
>> +using namespace llvm::support;
>> +using namespace llvm::support::endian;
>>
>>  const int PageSize = 4096;
>>  const uint8_t Magic[32] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0";
>>
>> +namespace {
>> +struct PDBHeader {
>> +  uint8_t Magic[32];
>> +  ulittle32_t PageSize;
>> +  ulittle32_t FpmPage;
>> +  ulittle32_t PageCount;
>> +  ulittle32_t RootSize;
>> +  ulittle32_t Reserved;
>> +  ulittle32_t RootPointer;
>> +};
>> +}
>> +
>>  void lld::coff::createPDB(StringRef Path) {
>>    // Create a file.
>>    size_t FileSize = PageSize * 3;
>> -  ErrorOr<std::unique_ptr<FileOutputBuffer>> BufOrErr =
>> +  ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
>>        FileOutputBuffer::create(Path, FileSize);
>> -  error(BufOrErr, Twine("failed to open ") + Path);
>> -  std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufOrErr);
>> +  error(BufferOrErr, Twine("failed to open ") + Path);
>> +  std::unique_ptr<FileOutputBuffer> Buffer = std::move(*BufferOrErr);
>> +
>> +  // Write the file header.
>> +  uint8_t *Buf = Buffer->getBufferStart();
>> +  auto *Hdr = reinterpret_cast<PDBHeader *>(Buf);
>> +  memcpy(Hdr->Magic, Magic, sizeof(Magic));
>> +  Hdr->PageSize = PageSize;
>> +  // I don't know what FpmPage field means, but it must not be 0.
>> +  Hdr->FpmPage = 1;
>> +  Hdr->PageCount = FileSize / PageSize;
>> +  // Root directory is empty, containing only the length field.
>> +  Hdr->RootSize = 4;
>> +  // Root directory is on page 1.
>> +  Hdr->RootPointer = 1;
>>
>> -  // Write the file magic.
>> -  uint8_t *P = Buf->getBufferStart();
>> -  memcpy(P, Magic, sizeof(Magic));
>> +  // Write the root directory. Root stream is on page 2.
>> +  write32le(Buf + PageSize, 2);
>> +  Buffer->commit();
>>  }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151208/444d6f6b/attachment.html>


More information about the llvm-commits mailing list