Revert "[ELF] Order DT_NEEDED entries by command line order."

This reverts commit r204291 because it broke buildbots.

llvm-svn: 204317
This commit is contained in:
Rui Ueyama 2014-03-20 06:57:28 +00:00
parent ccb38c5588
commit 6d500da3cc
4 changed files with 6 additions and 38 deletions

View File

@ -18,7 +18,7 @@
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "lld/ReaderWriter/Writer.h"
#include <unordered_set>
#include "llvm/ADT/StringSet.h"
namespace lld {
namespace elf {
@ -129,6 +129,7 @@ protected:
LLD_UNIQUE_BUMP_PTR(DynamicSymbolTable<ELFT>) _dynamicSymbolTable;
LLD_UNIQUE_BUMP_PTR(StringTable<ELFT>) _dynamicStringTable;
LLD_UNIQUE_BUMP_PTR(HashSection<ELFT>) _hashTable;
llvm::StringSet<> _soNeeded;
/// @}
};
@ -164,12 +165,6 @@ void OutputELFWriter<ELFT>::buildStaticSymbolTable(const File &file) {
_symtab->addSymbol(a, ELF::SHN_UNDEF);
}
struct StringRefFilePairHash {
std::size_t operator()(const std::pair<StringRef, const File *> &v) const {
return llvm::hash_combine(v.first, v.second);
}
};
template <class ELFT>
void OutputELFWriter<ELFT>::buildDynamicSymbolTable(const File &file) {
ScopedTask task(getDefaultDomain(), "buildDynamicSymbolTable");
@ -181,26 +176,14 @@ void OutputELFWriter<ELFT>::buildDynamicSymbolTable(const File &file) {
_dynamicSymbolTable->addSymbol(atom->_atom, section->ordinal(),
atom->_virtualAddr, atom);
}
std::unordered_set<std::pair<StringRef, const File *>, StringRefFilePairHash>
soNeeded;
for (const auto sla : file.sharedLibrary()) {
_dynamicSymbolTable->addSymbol(sla, ELF::SHN_UNDEF);
soNeeded.insert(std::make_pair(sla->loadName(), &sla->file()));
_soNeeded.insert(sla->loadName());
}
// Sort needed entries by command line order. This is needed so the correct
// dynamic symbol is loaded in cases where multiple dynamic libraries define
// the same symbol.
std::vector<std::pair<StringRef, const File *>> sortedSoNeeded(
soNeeded.begin(), soNeeded.end());
std::sort(sortedSoNeeded.begin(), sortedSoNeeded.end(),
[](const std::pair<StringRef, const File *> &a,
const std::pair<StringRef, const File *> &b) {
return a.second->ordinal() < b.second->ordinal();
});
for (auto const &lib : sortedSoNeeded) {
for (const auto &loadName : _soNeeded) {
Elf_Dyn dyn;
dyn.d_tag = DT_NEEDED;
dyn.d_un.d_val = _dynamicStringTable->addString(lib.first);
dyn.d_un.d_val = _dynamicStringTable->addString(loadName.getKey());
_dynamicTable->addEntry(dyn);
}
const auto &rpathList = _context.getRpathList();

View File

@ -1,14 +0,0 @@
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared2.x86-64 \
RUN: %p/Inputs/shared.so-x86-64 %p/Inputs/libundef.so -o %t -e main \
RUN: --noinhibit-exec
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/use-shared2.x86-64 \
RUN: %p/Inputs/libundef.so %p/Inputs/shared.so-x86-64 -o %t2 -e main \
RUN: --noinhibit-exec
RUN: llvm-readobj -dynamic-table %t | FileCheck --check-prefix=ORDER1 %s
RUN: llvm-readobj -dynamic-table %t2 | FileCheck --check-prefix=ORDER2 %s
ORDER1: NEEDED SharedLibrary (shared.so
ORDER1: NEEDED SharedLibrary (libundef.so
ORDER2: NEEDED SharedLibrary (libundef.so
ORDER2: NEEDED SharedLibrary (shared.so

View File

@ -1,8 +1,7 @@
extern int i;
extern long long x __attribute__((weak));
void foo();
int main() {
foo();
return i + x;
return i;
}