[PATCH] [ELF][X86_64][Hexagon] order plt/got entries properly and fix test

Shankar Kalpathi Easwaran shankarke at gmail.com
Tue Mar 12 22:55:17 PDT 2013


Hi Bigcheese,

The atoms in the map are not ordered in the same way as we create plt / got entries. This is to make the result consistent across continuous runs so that the ordinals are properly assigned.

http://llvm-reviews.chandlerc.com/D533

Files:
  test/elf/x86-64-dynamic.test
  lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
  lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp

Index: test/elf/x86-64-dynamic.test
===================================================================
--- test/elf/x86-64-dynamic.test
+++ test/elf/x86-64-dynamic.test
@@ -26,16 +26,6 @@
 CHECK:    section-choice:  custom-required
 CHECK:    section-name:    .got.plt
 CHECK:    permissions:     rw-
-        - name:            __got_i
-CHECK:    type:            got
-CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
-CHECK:    section-choice:  custom-required
-CHECK:    section-name:    .got.dyn
-CHECK:    permissions:     rw-
-CHECK:    references:
-CHECK:      - kind:            R_X86_64_GLOB_DAT
-CHECK:        offset:          0
-CHECK:        target:          i
         - name:            __got_foo
 CHECK:    type:            got
 CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
@@ -51,6 +41,16 @@
 CHECK:        offset:          0
               target:          __plt_foo
 CHECK:        addend:          6
+        - name:            __got_i
+CHECK:    type:            got
+CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
+CHECK:    section-choice:  custom-required
+CHECK:    section-name:    .got.dyn
+CHECK:    permissions:     rw-
+CHECK:    references:
+CHECK:      - kind:            R_X86_64_GLOB_DAT
+CHECK:        offset:          0
+CHECK:        target:          i
 
 CHECK:  - name:            main
 CHECK:    scope:           global
Index: lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
===================================================================
--- lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
+++ lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
@@ -79,21 +79,21 @@
       _PLT0->setOrdinal(ordinal++);
       mf.addAtom(*_PLT0);
     }
-    for (const auto &plt : _pltMap) {
-      plt.second->setOrdinal(ordinal++);
-      mf.addAtom(*plt.second);
+    for (auto &plt : _pltVector) {
+      plt->setOrdinal(ordinal++);
+      mf.addAtom(*plt);
     }
     if (_null) {
       _null->setOrdinal(ordinal++);
       mf.addAtom(*_null);
     }
-    if (_PLT0) {
+    if (_got0) {
       _got0->setOrdinal(ordinal++);
       mf.addAtom(*_got0);
     }
-    for (const auto &got : _gotMap) {
-      got.second->setOrdinal(ordinal++);
-      mf.addAtom(*got.second);
+    for (auto &got : _gotVector) {
+      got->setOrdinal(ordinal++);
+      mf.addAtom(*got);
     }
   }
 
@@ -107,6 +107,10 @@
   /// \brief Map Atoms to their PLT entries.
   llvm::DenseMap<const Atom *, PLTAtom *> _pltMap;
 
+  /// \brief the list of GOT/PLT atoms
+  std::vector<GOTAtom *> _gotVector;
+  std::vector<PLTAtom *> _pltVector;
+
   /// \brief GOT entry that is always 0. Used for undefined weaks.
   GOTAtom *_null;
 
@@ -134,6 +138,8 @@
 #ifndef NDEBUG
     _got0->_name = "__got0";
 #endif
+    DEBUG_WITH_TYPE("PLT", llvm::dbgs() << "[ PLT0/GOT0 ] "
+                                        << "Adding plt0/got0 \n");
     return _PLT0;
   }
 
@@ -154,9 +160,14 @@
     ga->_name += a->name();
     pa->_name = "__plt_";
     pa->_name += a->name();
+    DEBUG_WITH_TYPE("PLT", llvm::dbgs() << "[" << a->name() << "] "
+                                        << "Adding plt/got: " << pa->_name
+                                        << "/" << ga->_name << "\n");
 #endif
     _gotMap[a] = ga;
     _pltMap[a] = pa;
+    _gotVector.push_back(ga);
+    _pltVector.push_back(pa);
     return pa;
   }
 
Index: lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
===================================================================
--- lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
+++ lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
@@ -128,6 +128,8 @@
 #endif
     _gotMap[da] = ga;
     _pltMap[da] = pa;
+    _gotVector.push_back(ga);
+    _pltVector.push_back(pa);
     return pa;
   }
 
@@ -153,6 +155,7 @@
       g->_name += atom->name();
 #endif
       _gotMap[atom] = g;
+      _gotVector.push_back(g);
       return g;
     }
     return got->second;
@@ -187,6 +190,7 @@
       g->_name += da->name();
 #endif
       _gotMap[da] = g;
+      _gotVector.push_back(g);
       return g;
     }
     return got->second;
@@ -227,9 +231,9 @@
       _PLT0->setOrdinal(ordinal++);
       mf.addAtom(*_PLT0);
     }
-    for (const auto &plt : _pltMap) {
-      plt.second->setOrdinal(ordinal++);
-      mf.addAtom(*plt.second);
+    for (auto &plt : _pltVector) {
+      plt->setOrdinal(ordinal++);
+      mf.addAtom(*plt);
     }
     if (_null) {
       _null->setOrdinal(ordinal++);
@@ -241,9 +245,9 @@
       mf.addAtom(*_got0);
       mf.addAtom(*_got1);
     }
-    for (const auto &got : _gotMap) {
-      got.second->setOrdinal(ordinal++);
-      mf.addAtom(*got.second);
+    for (auto &got : _gotVector) {
+      got->setOrdinal(ordinal++);
+      mf.addAtom(*got);
     }
   }
 
@@ -257,6 +261,10 @@
   /// \brief Map Atoms to their PLT entries.
   llvm::DenseMap<const Atom *, PLTAtom *> _pltMap;
 
+  /// \brief the list of GOT/PLT atoms
+  std::vector<GOTAtom *> _gotVector;
+  std::vector<PLTAtom *> _pltVector;
+
   /// \brief GOT entry that is always 0. Used for undefined weaks.
   GOTAtom *_null;
 
@@ -339,6 +347,8 @@
 #endif
     _gotMap[a] = ga;
     _pltMap[a] = pa;
+    _gotVector.push_back(ga);
+    _pltVector.push_back(pa);
     return pa;
   }
 
@@ -370,6 +380,7 @@
       g->_name += sla->name();
 #endif
       _gotMap[sla] = g;
+      _gotVector.push_back(g);
       return g;
     }
     return got->second;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D533.1.patch
Type: text/x-patch
Size: 5429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130312/4db14ad2/attachment.bin>


More information about the llvm-commits mailing list