[lld] r241376 - COFF: Fix the case where an object defines a weak external and its alias.

Peter Collingbourne peter at pcc.me.uk
Fri Jul 3 15:03:36 PDT 2015


Author: pcc
Date: Fri Jul  3 17:03:36 2015
New Revision: 241376

URL: http://llvm.org/viewvc/llvm-project?rev=241376&view=rev
Log:
COFF: Fix the case where an object defines a weak external and its alias.

This worked before, but only by accident, and only with assertions disabled.
We ended up storing a DefinedRegular symbol in the WeakAlias field,
and never using it as an Undefined.

Differential Revision: http://reviews.llvm.org/D10934

Added:
    lld/trunk/test/COFF/weak-external.test
Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/COFF/SymbolTable.cpp
    lld/trunk/COFF/Symbols.h

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=241376&r1=241375&r2=241376&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Fri Jul  3 17:03:36 2015
@@ -199,7 +199,7 @@ Undefined *ObjectFile::createWeakExterna
   COFFObj->getSymbolName(Sym, Name);
   auto *U = new (Alloc) Undefined(Name);
   auto *Aux = (const coff_aux_weak_external *)AuxP;
-  U->WeakAlias = cast<Undefined>(SparseSymbolBodies[Aux->TagIndex]);
+  U->WeakAlias = SparseSymbolBodies[Aux->TagIndex];
   return U;
 }
 

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=241376&r1=241375&r2=241376&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Fri Jul  3 17:03:36 2015
@@ -126,10 +126,11 @@ bool SymbolTable::reportRemainingUndefin
     if (!Undef)
       continue;
     StringRef Name = Undef->getName();
-    // A weak alias may have been resovled, so check for that. A weak alias
-    // may be an weak alias to other symbol, so check recursively.
-    for (Undefined *U = Undef->WeakAlias; U; U = U->WeakAlias) {
-      if (auto *D = dyn_cast<Defined>(U->repl())) {
+    // A weak alias may have been resolved, so check for that. A weak alias
+    // may be a weak alias to another symbol, so check recursively.
+    for (SymbolBody *A = Undef->WeakAlias; A;
+         A = cast<Undefined>(A)->WeakAlias) {
+      if (auto *D = dyn_cast<Defined>(A->repl())) {
         Sym->Body = D;
         goto next;
       }

Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=241376&r1=241375&r2=241376&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Fri Jul  3 17:03:36 2015
@@ -253,7 +253,7 @@ public:
   // undefined symbol a second chance if it would remain undefined.
   // If it remains undefined, it'll be replaced with whatever the
   // Alias pointer points to.
-  Undefined *WeakAlias = nullptr;
+  SymbolBody *WeakAlias = nullptr;
 };
 
 // Windows-specific classes.

Added: lld/trunk/test/COFF/weak-external.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/weak-external.test?rev=241376&view=auto
==============================================================================
--- lld/trunk/test/COFF/weak-external.test (added)
+++ lld/trunk/test/COFF/weak-external.test Fri Jul  3 17:03:36 2015
@@ -0,0 +1,29 @@
+# RUN: yaml2obj %s > %t.obj
+# RUN: lld -flavor link2 /out:%t.exe /entry:g /subsystem:console %t.obj
+
+---
+header:          
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [  ]
+sections:        
+  - Name:            '.text'
+    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+    Alignment:       16
+    SectionData:     00
+symbols:         
+  - Name:            'f'
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            'g'
+    Value:           0
+    SectionNumber:   0
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
+    StorageClass:    IMAGE_SYM_CLASS_WEAK_EXTERNAL
+    WeakExternal:    
+      TagIndex:        0
+      Characteristics: IMAGE_WEAK_EXTERN_SEARCH_LIBRARY
+...





More information about the llvm-commits mailing list