[lld] r240756 - COFF: Fix local absolute symbols.

Rui Ueyama ruiu at google.com
Thu Jun 25 20:09:23 PDT 2015


Author: ruiu
Date: Thu Jun 25 22:09:23 2015
New Revision: 240756

URL: http://llvm.org/viewvc/llvm-project?rev=240756&view=rev
Log:
COFF: Fix local absolute symbols.

Absolute symbols were always handled as external symbols, so if two
or more object files define the same absolute symbol, they would
conflict even if the symbol is private to each file.
This patch fixes that bug.

Added:
    lld/trunk/test/COFF/internal.test
Modified:
    lld/trunk/COFF/InputFiles.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=240756&r1=240755&r2=240756&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Thu Jun 25 22:09:23 2015
@@ -198,7 +198,7 @@ SymbolBody *ObjectFile::createSymbolBody
     // Skip special symbols.
     if (Name == "@comp.id" || Name == "@feat.00")
       return nullptr;
-    return new (Alloc) DefinedAbsolute(Name, Sym.getValue());
+    return new (Alloc) DefinedAbsolute(Name, Sym);
   }
   if (Sym.getSectionNumber() == llvm::COFF::IMAGE_SYM_DEBUG)
     return nullptr;

Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=240756&r1=240755&r2=240756&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Thu Jun 25 22:09:23 2015
@@ -173,20 +173,26 @@ private:
 // Absolute symbols.
 class DefinedAbsolute : public Defined {
 public:
-  DefinedAbsolute(StringRef N, uint64_t VA)
-      : Defined(DefinedAbsoluteKind), Name(N), RVA(VA - Config->ImageBase) {}
+  DefinedAbsolute(StringRef N, COFFSymbolRef S)
+      : Defined(DefinedAbsoluteKind), Name(N), VA(S.getValue()),
+        External(S.isExternal()) {}
+
+  DefinedAbsolute(StringRef N, uint64_t V)
+      : Defined(DefinedAbsoluteKind), Name(N), VA(V) {}
 
   static bool classof(const SymbolBody *S) {
     return S->kind() == DefinedAbsoluteKind;
   }
 
   StringRef getName() override { return Name; }
-  uint64_t getRVA() override { return RVA; }
+  uint64_t getRVA() override { return VA - Config->ImageBase; }
   uint64_t getFileOff() override { llvm_unreachable("internal error"); }
+  bool isExternal() override { return External; }
 
 private:
   StringRef Name;
-  uint64_t RVA;
+  uint64_t VA;
+  bool External = true;
 };
 
 // This class represents a symbol defined in an archive file. It is

Added: lld/trunk/test/COFF/internal.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/internal.test?rev=240756&view=auto
==============================================================================
--- lld/trunk/test/COFF/internal.test (added)
+++ lld/trunk/test/COFF/internal.test Thu Jun 25 22:09:23 2015
@@ -0,0 +1,42 @@
+# Test that non-external symbols don't conflict
+
+# RUN: yaml2obj < %s > %t1.obj
+# RUN: yaml2obj < %s > %t2.obj
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t3.obj
+# RUN: lld -flavor link2 /out:%t.exe %t1.obj %t2.obj %t3.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:       4
+    SectionData:     000000000000
+symbols:
+  - Name:            .text
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          6
+      NumberOfRelocations: 0
+      NumberOfLinenumbers: 0
+      CheckSum:        0
+      Number:          0
+  - Name:            defined
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+  - Name:            absolute
+    Value:           0xdeadbeef
+    SectionNumber:   -1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+...





More information about the llvm-commits mailing list