[lld] r239287 - COFF: Check for auxiliary symbol's type.

Rui Ueyama ruiu at google.com
Sun Jun 7 22:00:42 PDT 2015


Author: ruiu
Date: Mon Jun  8 00:00:42 2015
New Revision: 239287

URL: http://llvm.org/viewvc/llvm-project?rev=239287&view=rev
Log:
COFF: Check for auxiliary symbol's type.

We forgot to check for auxiliary symbol's type. So we sometimes read
garbage as associative section definitions.

Associative sections are considered as not live themselves by the
garbage collector because they are live only when associaited sections
are live.

By reading more data (or garbage) as associative section definitions,
we treated more sections as non-GC-roots, that caused the linker to
discard too many sections by mistake. That caused another mysterious
bug (such as some global constructors don't run at all for some reason.)

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/test/COFF/lto.ll

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=239287&r1=239286&r2=239287&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Mon Jun  8 00:00:42 2015
@@ -22,6 +22,7 @@
 using namespace llvm::object;
 using namespace llvm::support::endian;
 using llvm::COFF::ImportHeader;
+using llvm::COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE;
 using llvm::RoundUpToAlignment;
 using llvm::sys::fs::identify_magic;
 using llvm::sys::fs::file_magic;
@@ -200,13 +201,16 @@ SymbolBody *ObjectFile::createSymbolBody
     auto *Aux = (const coff_aux_weak_external *)AuxP;
     return new (Alloc) Undefined(Name, &SparseSymbolBodies[Aux->TagIndex]);
   }
+  // Handle associative sections
   if (IsFirst && AuxP) {
     if (Chunk *C = SparseChunks[Sym.getSectionNumber()]) {
       auto *Aux = reinterpret_cast<const coff_aux_section_definition *>(AuxP);
-      auto *Parent =
+      if (Aux->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
+        auto *Parent =
           (SectionChunk *)(SparseChunks[Aux->getNumber(Sym.isBigObj())]);
-      if (Parent)
-        Parent->addAssociative((SectionChunk *)C);
+        if (Parent)
+          Parent->addAssociative((SectionChunk *)C);
+      }
     }
   }
   if (Chunk *C = SparseChunks[Sym.getSectionNumber()])

Modified: lld/trunk/test/COFF/lto.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lto.ll?rev=239287&r1=239286&r2=239287&view=diff
==============================================================================
--- lld/trunk/test/COFF/lto.ll (original)
+++ lld/trunk/test/COFF/lto.ll Mon Jun  8 00:00:42 2015
@@ -50,7 +50,7 @@
 ; TEXT-11-NEXT: movl	$2, %eax
 ; TEXT-11-NEXT: retq
 
-; HEADERS-01: AddressOfEntryPoint: 0x1000
+; HEADERS-01: AddressOfEntryPoint: 0x2000
 ; TEXT-01: Disassembly of section .text:
 ; TEXT-01-NEXT: .text:
 ; TEXT-01-NEXT: subq	$40, %rsp
@@ -60,7 +60,7 @@
 ; TEXT-01-NEXT: retq
 ; TEXT-01-NEXT: retq
 
-; HEADERS-10: AddressOfEntryPoint: 0x1010
+; HEADERS-10: AddressOfEntryPoint: 0x2010
 ; TEXT-10: Disassembly of section .text:
 ; TEXT-10-NEXT: .text:
 ; TEXT-10-NEXT: retq





More information about the llvm-commits mailing list