[lld] r218158 - [PECOFF] Set ordinal to alias atoms

Rui Ueyama ruiu at google.com
Fri Sep 19 14:58:54 PDT 2014


Author: ruiu
Date: Fri Sep 19 16:58:54 2014
New Revision: 218158

URL: http://llvm.org/viewvc/llvm-project?rev=218158&view=rev
Log:
[PECOFF] Set ordinal to alias atoms

Atoms are ordered in the output file by ordinal. File has file ordinal,
and atom has atom ordinal which is unique within the file.
No two atoms should have the same combination of ordinals.

However that contract was not satisifed for alias atoms. Alias atom
is defined by /alternatename:sym1=sym2. In this case sym1 is defined
as an alias for sym2. sym1 always got ordinal 0.

As a result LLD failed with an assertion failure.

This patch assigns ordinal to alias atoms.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
    lld/trunk/test/pecoff/alternatename.test

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=218158&r1=218157&r2=218158&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Fri Sep 19 16:58:54 2014
@@ -88,7 +88,8 @@ public:
     return _absoluteAtoms;
   }
 
-  void addDefinedAtom(const DefinedAtom *atom) {
+  void addDefinedAtom(AliasAtom *atom) {
+    atom->setOrdinal(_ordinal++);
     _definedAtoms._atoms.push_back(atom);
   }
 
@@ -1068,13 +1069,13 @@ private:
 
   // Iterates over defined atoms and create alias atoms if needed.
   void createAlternateNameAtoms(FileCOFF &file) const {
-    std::vector<const DefinedAtom *> aliases;
+    std::vector<AliasAtom *> aliases;
     for (const DefinedAtom *atom : file.defined()) {
       auto it = _ctx.alternateNames().find(atom->name());
       if (it != _ctx.alternateNames().end())
         aliases.push_back(createAlias(file, it->second, atom));
     }
-    for (const DefinedAtom *alias : aliases) {
+    for (AliasAtom *alias : aliases) {
       file.addDefinedAtom(alias);
     }
   }

Modified: lld/trunk/test/pecoff/alternatename.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/alternatename.test?rev=218158&r1=218157&r2=218158&view=diff
==============================================================================
--- lld/trunk/test/pecoff/alternatename.test (original)
+++ lld/trunk/test/pecoff/alternatename.test Fri Sep 19 16:58:54 2014
@@ -10,6 +10,10 @@
 #
 # RUN: lld -flavor link /force /out:%t3.exe -- %t3.obj
 # RUN: llvm-objdump -d %t3.exe | FileCheck -check-prefix=CHECK3 %s
+#
+# RUN: lld -flavor link /force /out:%t4.exe /alternatename:_main=_foo \
+# RUN:   /alternatename:_xyz=_foo -- %t1.obj
+# RUN: llvm-objdump -d %t4.exe | FileCheck -check-prefix=CHECK4 %s
 
 CHECK1:      nop
 CHECK1-NEXT: nop
@@ -28,3 +32,9 @@ CHECK3-NEXT: nop
 CHECK3-NEXT: nop
 CHECK3-NEXT: nop
 CHECK3-NOT:  int3
+
+CHECK4:      nop
+CHECK4-NEXT: nop
+CHECK4-NEXT: nop
+CHECK4-NEXT: nop
+CHECK4-NOT:  int3





More information about the llvm-commits mailing list