This is an archive of the discontinued LLVM Phabricator instance.

Reland r319090, "COFF: Do not create SectionChunks for discarded comdat sections." with a fix for debug sections.
ClosedPublic

Authored by pcc on Nov 27 2017, 5:21 PM.

Details

Summary

If /debug was not specified, readSection will return a null
pointer for debug sections. If the debug section is associative with
another section, we need to make sure that the section returned from
readSection is not a null pointer before adding it as an associative
section.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Nov 27 2017, 5:21 PM
pcc added a comment.Nov 27 2017, 5:22 PM

Diff against previous patch:

diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 0ecfbdaf7373..d0c7bcaefe06 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -208,7 +208,8 @@ void ObjFile::readAssociativeDefinition(
   int32_t SectionNumber = Sym.getSectionNumber();
   if (Parent) {
     SparseChunks[SectionNumber] = readSection(SectionNumber, Def);
-    Parent->addAssociative(SparseChunks[SectionNumber]);
+    if (SparseChunks[SectionNumber])
+      Parent->addAssociative(SparseChunks[SectionNumber]);
   } else {
     SparseChunks[SectionNumber] = nullptr;
   }
diff --git a/lld/test/COFF/pdb-comdat.test b/lld/test/COFF/pdb-comdat.test
index a3283d206ab8..655f215e0199 100644
--- a/lld/test/COFF/pdb-comdat.test
+++ b/lld/test/COFF/pdb-comdat.test
@@ -107,3 +107,6 @@ REORDER-LABEL:   Mod 0001 | `{{.*}}pdb_comdat_main.obj`:
 REORDER:       c:\src\llvm-project\build\pdb_comdat_main.c
 REORDER-NOT:       c:\src\llvm-project\build\foo.h
 REORDER-LABEL:   Mod 0002 | `* Linker *`:
+
+Make sure that we don't crash on non-prevailing debug sections if -debug is not enabled.
+RUN: lld-link pdb_comdat_main.obj pdb_comdat_bar.obj -out:%t.exe -nodefaultlib -entry:main
ruiu accepted this revision.Nov 27 2017, 5:24 PM

LGTM

This revision is now accepted and ready to land.Nov 27 2017, 5:24 PM
This revision was automatically updated to reflect the committed changes.