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 _pltMap; + /// \brief the list of GOT/PLT atoms + std::vector _gotVector; + std::vector _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 _pltMap; + /// \brief the list of GOT/PLT atoms + std::vector _gotVector; + std::vector _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; 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