2015-07-25 05:03:07 +08:00
|
|
|
//===- Symbols.cpp --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Symbols.h"
|
|
|
|
#include "Chunks.h"
|
2015-08-06 23:33:19 +08:00
|
|
|
#include "Error.h"
|
2015-07-29 06:58:25 +08:00
|
|
|
#include "InputFiles.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
using namespace llvm::object;
|
|
|
|
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::elf2;
|
|
|
|
|
2015-07-29 06:58:25 +08:00
|
|
|
template <class ELFT>
|
2015-08-06 23:33:21 +08:00
|
|
|
DefinedRegular<ELFT>::DefinedRegular(StringRef Name)
|
|
|
|
: Defined(DefinedRegularKind, Name) {}
|
2015-07-29 06:58:25 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// Returns 1, 0 or -1 if this symbol should take precedence
|
|
|
|
// over the Other, tie or lose, respectively.
|
2015-07-28 04:39:01 +08:00
|
|
|
int SymbolBody::compare(SymbolBody *Other) {
|
|
|
|
Kind LK = kind();
|
|
|
|
Kind RK = Other->kind();
|
|
|
|
|
|
|
|
// Normalize so that the smaller kind is on the left.
|
|
|
|
if (LK > RK)
|
2015-07-25 05:03:07 +08:00
|
|
|
return -Other->compare(this);
|
|
|
|
|
2015-07-28 04:39:01 +08:00
|
|
|
// First handle comparisons between two different kinds.
|
|
|
|
if (LK != RK) {
|
|
|
|
assert(LK == DefinedRegularKind);
|
|
|
|
assert(RK == UndefinedKind);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-07-28 04:39:01 +08:00
|
|
|
// Now handle the case where the kinds are the same.
|
|
|
|
switch (LK) {
|
|
|
|
case DefinedRegularKind:
|
2015-07-25 05:03:07 +08:00
|
|
|
return 0;
|
2015-07-28 04:39:01 +08:00
|
|
|
case UndefinedKind:
|
|
|
|
return 1;
|
|
|
|
}
|
2015-08-12 01:10:02 +08:00
|
|
|
llvm_unreachable("unknown symbol kind");
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf2 {
|
|
|
|
template class DefinedRegular<llvm::object::ELF32LE>;
|
|
|
|
template class DefinedRegular<llvm::object::ELF32BE>;
|
|
|
|
template class DefinedRegular<llvm::object::ELF64LE>;
|
|
|
|
template class DefinedRegular<llvm::object::ELF64BE>;
|
|
|
|
}
|
|
|
|
}
|