18
18
#include " llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
19
19
#include " llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h"
20
20
#include " llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
21
+ #include " llvm/DebugInfo/CodeView/SymbolSerializer.h"
21
22
#include " llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
22
23
#include " llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
23
24
#include " llvm/DebugInfo/CodeView/TypeStreamMerger.h"
24
25
#include " llvm/DebugInfo/CodeView/TypeTableBuilder.h"
25
26
#include " llvm/DebugInfo/MSF/MSFBuilder.h"
26
27
#include " llvm/DebugInfo/MSF/MSFCommon.h"
28
+ #include " llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
27
29
#include " llvm/DebugInfo/PDB/Native/DbiStream.h"
28
30
#include " llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
29
31
#include " llvm/DebugInfo/PDB/Native/InfoStream.h"
30
32
#include " llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
31
33
#include " llvm/DebugInfo/PDB/Native/PDBFile.h"
32
34
#include " llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
33
- #include " llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
34
35
#include " llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
35
36
#include " llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h"
36
37
#include " llvm/DebugInfo/PDB/Native/TpiStream.h"
@@ -396,9 +397,54 @@ static void addObjectsToPDB(BumpPtrAllocator &Alloc, SymbolTable *Symtab,
396
397
addTypeInfo (Builder.getIpiBuilder (), IDTable);
397
398
}
398
399
400
+ static void addLinkerModuleSymbols (StringRef Path,
401
+ pdb::DbiModuleDescriptorBuilder &Mod,
402
+ BumpPtrAllocator &Allocator) {
403
+ codeview::SymbolSerializer Serializer (Allocator, CodeViewContainer::Pdb);
404
+ codeview::ObjNameSym ONS (SymbolRecordKind::ObjNameSym);
405
+ codeview::Compile3Sym CS (SymbolRecordKind::Compile3Sym);
406
+ codeview::EnvBlockSym EBS (SymbolRecordKind::EnvBlockSym);
407
+
408
+ ONS.Name = " * Linker *" ;
409
+ ONS.Signature = 0 ;
410
+
411
+ CS.Machine = Config->is64 () ? CPUType::X64 : CPUType::Intel80386;
412
+ CS.Flags = CompileSym3Flags::None;
413
+ CS.VersionBackendBuild = 0 ;
414
+ CS.VersionBackendMajor = 0 ;
415
+ CS.VersionBackendMinor = 0 ;
416
+ CS.VersionBackendQFE = 0 ;
417
+ CS.VersionFrontendBuild = 0 ;
418
+ CS.VersionFrontendMajor = 0 ;
419
+ CS.VersionFrontendMinor = 0 ;
420
+ CS.VersionFrontendQFE = 0 ;
421
+ CS.Version = " LLVM Linker" ;
422
+ CS.setLanguage (SourceLanguage::Link);
423
+
424
+ ArrayRef<StringRef> Args = makeArrayRef (Config->Argv ).drop_front ();
425
+ std::string ArgStr = llvm::join (Args, " " );
426
+ EBS.Fields .push_back (" cwd" );
427
+ SmallString<64 > cwd;
428
+ llvm::sys::fs::current_path (cwd);
429
+ EBS.Fields .push_back (cwd);
430
+ EBS.Fields .push_back (" exe" );
431
+ std::string Exe =
432
+ llvm::sys::fs::getMainExecutable (Config->Argv [0 ].data (), nullptr );
433
+ EBS.Fields .push_back (Exe);
434
+ EBS.Fields .push_back (" pdb" );
435
+ EBS.Fields .push_back (Path);
436
+ EBS.Fields .push_back (" cmd" );
437
+ EBS.Fields .push_back (ArgStr);
438
+ Mod.addSymbol (codeview::SymbolSerializer::writeOneSymbol (
439
+ ONS, Allocator, CodeViewContainer::Pdb));
440
+ Mod.addSymbol (codeview::SymbolSerializer::writeOneSymbol (
441
+ CS, Allocator, CodeViewContainer::Pdb));
442
+ Mod.addSymbol (codeview::SymbolSerializer::writeOneSymbol (
443
+ EBS, Allocator, CodeViewContainer::Pdb));
444
+ }
445
+
399
446
// Creates a PDB file.
400
- void coff::createPDB (StringRef Path, SymbolTable *Symtab,
401
- ArrayRef<uint8_t > SectionTable,
447
+ void coff::createPDB (SymbolTable *Symtab, ArrayRef<uint8_t > SectionTable,
402
448
const llvm::codeview::DebugInfo *DI) {
403
449
BumpPtrAllocator Alloc;
404
450
pdb::PDBFileBuilder Builder (Alloc);
@@ -413,7 +459,8 @@ void coff::createPDB(StringRef Path, SymbolTable *Symtab,
413
459
auto &InfoBuilder = Builder.getInfoBuilder ();
414
460
InfoBuilder.setAge (DI ? DI->PDB70 .Age : 0 );
415
461
416
- llvm::SmallString<128 > NativePath (Path.begin (), Path.end ());
462
+ llvm::SmallString<128 > NativePath (Config->PDBPath .begin (),
463
+ Config->PDBPath .end ());
417
464
llvm::sys::fs::make_absolute (NativePath);
418
465
llvm::sys::path::native (NativePath, llvm::sys::path::Style ::windows);
419
466
@@ -449,11 +496,12 @@ void coff::createPDB(StringRef Path, SymbolTable *Symtab,
449
496
450
497
auto &LinkerModule = ExitOnErr (DbiBuilder.addModuleInfo (" * Linker *" ));
451
498
LinkerModule.setPdbFilePathNI (PdbFilePathNI);
499
+ addLinkerModuleSymbols (NativePath, LinkerModule, Alloc);
452
500
453
501
// Add COFF section header stream.
454
502
ExitOnErr (
455
503
DbiBuilder.addDbgStream (pdb::DbgHeaderType::SectionHdr, SectionTable));
456
504
457
505
// Write to a file.
458
- ExitOnErr (Builder.commit (Path ));
506
+ ExitOnErr (Builder.commit (Config-> PDBPath ));
459
507
}
0 commit comments