[lld] r356395 - [DebugInfo][PDB] Don't write empty debug streams

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 18 12:13:24 PDT 2019


Author: aganea
Date: Mon Mar 18 12:13:23 2019
New Revision: 356395

URL: http://llvm.org/viewvc/llvm-project?rev=356395&view=rev
Log:
[DebugInfo][PDB] Don't write empty debug streams

Before, empty debug streams were written as 8 bytes (4 bytes signature + 4 bytes for the GlobalRefs count).

With this patch, unused empty streams aren't emitted anymore. Modules now encode 65535 as an 'unused stream' value, by convention.
Also fix the * Linker * contrib section which wasn't correctly emitted previously.

Differential Revision: https://reviews.llvm.org/D59502

Modified:
    lld/trunk/COFF/PDB.cpp
    lld/trunk/test/COFF/pdb-global-gc.yaml
    lld/trunk/test/COFF/pdb-lib.s
    lld/trunk/test/COFF/pdb.test

Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=356395&r1=356394&r2=356395&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Mon Mar 18 12:13:23 2019
@@ -1088,13 +1088,13 @@ static ArrayRef<uint8_t> relocateDebugCh
 }
 
 static pdb::SectionContrib createSectionContrib(const Chunk *C, uint32_t Modi) {
-  OutputSection *OS = C->getOutputSection();
+  OutputSection *OS = C ? C->getOutputSection() : nullptr;
   pdb::SectionContrib SC;
   memset(&SC, 0, sizeof(SC));
-  SC.ISect = OS->SectionIndex;
-  SC.Off = C->getRVA() - OS->getRVA();
-  SC.Size = C->getSize();
-  if (auto *SecChunk = dyn_cast<SectionChunk>(C)) {
+  SC.ISect = OS ? OS->SectionIndex : llvm::pdb::kInvalidStreamIndex;
+  SC.Off = C && OS ? C->getRVA() - OS->getRVA() : 0;
+  SC.Size = C ? C->getSize() : -1;
+  if (auto *SecChunk = dyn_cast_or_null<SectionChunk>(C)) {
     SC.Characteristics = SecChunk->Header->Characteristics;
     SC.Imod = SecChunk->File->ModuleDBI->getModuleIndex();
     ArrayRef<uint8_t> Contents = SecChunk->getContents();
@@ -1104,7 +1104,7 @@ static pdb::SectionContrib createSection
     CRC.update(CharContents);
     SC.DataCrc = CRC.getCRC();
   } else {
-    SC.Characteristics = OS->Header.Characteristics;
+    SC.Characteristics = OS ? OS->Header.Characteristics : 0;
     // FIXME: When we start creating DBI for import libraries, use those here.
     SC.Imod = Modi;
   }
@@ -1589,6 +1589,13 @@ void PDBLinker::addSections(ArrayRef<Out
     }
   }
 
+  // The * Linker * first section contrib is only used along with /INCREMENTAL,
+  // to provide trampolines thunks for incremental function patching. Set this
+  // as "unused" because LLD doesn't support /INCREMENTAL link.
+  pdb::SectionContrib SC =
+      createSectionContrib(nullptr, llvm::pdb::kInvalidStreamIndex);
+  LinkerModule.setFirstSectionContrib(SC);
+
   // Add Section Map stream.
   ArrayRef<object::coff_section> Sections = {
       (const object::coff_section *)SectionTable.data(),

Modified: lld/trunk/test/COFF/pdb-global-gc.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-global-gc.yaml?rev=356395&r1=356394&r2=356395&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-global-gc.yaml (original)
+++ lld/trunk/test/COFF/pdb-global-gc.yaml Mon Mar 18 12:13:23 2019
@@ -23,6 +23,7 @@
 # CHECK:      ============================================================
 # CHECK-NEXT:   Mod 0000 | `{{.*}}pdb-global-gc.yaml.tmp.obj`:
 # CHECK-NEXT:   Mod 0001 | `{{.*}}pdb-global-gc.yaml.tmp2.obj`:
+# CHECK-NEXT:   Error loading module stream 1.  The specified stream could not be loaded. Module stream not present
 # CHECK-NEXT:   Mod 0002 | `* Linker *`:
 
 --- !COFF

Modified: lld/trunk/test/COFF/pdb-lib.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-lib.s?rev=356395&r1=356394&r2=356395&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-lib.s (original)
+++ lld/trunk/test/COFF/pdb-lib.s Mon Mar 18 12:13:23 2019
@@ -13,15 +13,15 @@
 # CHECK-NEXT: ============================================================
 # CHECK-NEXT:   Mod 0000 | `{{.*pdb-lib.s.tmp[/\\]foo.obj}}`:
 # CHECK-NEXT:              Obj: `{{.*pdb-lib.s.tmp[/\\]foo.obj}}`:
-# CHECK-NEXT:              debug stream: 10, # files: 0, has ec info: false
+# CHECK-NEXT:              debug stream: 65535, # files: 0, has ec info: false
 # CHECK-NEXT:              pdb file ni: 0 ``, src file ni: 0 ``
 # CHECK-NEXT:   Mod 0001 | `bar.obj`:
 # CHECK-NEXT:              Obj: `{{.*pdb-lib.s.tmp[/\\]bar.lib}}`:
-# CHECK-NEXT:              debug stream: 11, # files: 0, has ec info: false
+# CHECK-NEXT:              debug stream: 65535, # files: 0, has ec info: false
 # CHECK-NEXT:              pdb file ni: 0 ``, src file ni: 0 ``
 # CHECK-NEXT:   Mod 0002 | `* Linker *`:
 # CHECK-NEXT:              Obj: ``:
-# CHECK-NEXT:              debug stream: 12, # files: 0, has ec info: false
+# CHECK-NEXT:              debug stream: 10, # files: 0, has ec info: false
 # CHECK-NEXT:              pdb file ni: 1 `{{.*foo.pdb}}`, src file ni: 0 ``
 
         .def     _main;

Modified: lld/trunk/test/COFF/pdb.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb.test?rev=356395&r1=356394&r2=356395&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb.test (original)
+++ lld/trunk/test/COFF/pdb.test Mon Mar 18 12:13:23 2019
@@ -134,7 +134,7 @@ RAW-NEXT:              Obj: `{{.*}}pdb.t
 RAW-NEXT:              debug stream: 12, # files: 1, has ec info: false
 RAW-NEXT:              pdb file ni: 0 ``, src file ni: 0 ``
 RAW-NEXT:   Mod 0002 | `* Linker *`:
-RAW-NEXT:              SC[???]  | mod = 2, 0000:0000, size = 0, data crc = 0, reloc crc = 0
+RAW-NEXT:              SC[???]  | mod = 65535, 65535:0000, size = -1, data crc = 0, reloc crc = 0
 RAW-NEXT:                         none
 RAW-NEXT:              Obj: ``:
 RAW-NEXT:              debug stream: 13, # files: 0, has ec info: false




More information about the llvm-commits mailing list