Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 1 | //===- Symbols.cpp --------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Symbols.h" |
| 11 | #include "Chunks.h" |
| 12 | |
| 13 | using namespace llvm::object; |
| 14 | |
| 15 | using namespace lld; |
| 16 | using namespace lld::elf2; |
| 17 | |
| 18 | template <class ELFT> |
| 19 | DefinedRegular<ELFT>::DefinedRegular(StringRef Name) |
| 20 | : Defined(DefinedRegularKind), Name(Name) {} |
| 21 | |
| 22 | // Returns 1, 0 or -1 if this symbol should take precedence |
| 23 | // over the Other, tie or lose, respectively. |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame^] | 24 | int SymbolBody::compare(SymbolBody *Other) { |
| 25 | Kind LK = kind(); |
| 26 | Kind RK = Other->kind(); |
| 27 | |
| 28 | // Normalize so that the smaller kind is on the left. |
| 29 | if (LK > RK) |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 30 | return -Other->compare(this); |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame^] | 31 | |
| 32 | // First handle comparisons between two different kinds. |
| 33 | if (LK != RK) { |
| 34 | assert(LK == DefinedRegularKind); |
| 35 | assert(RK == UndefinedKind); |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 36 | return 1; |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame^] | 37 | } |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 38 | |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame^] | 39 | // Now handle the case where the kinds are the same. |
| 40 | switch (LK) { |
| 41 | case DefinedRegularKind: |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 42 | return 0; |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame^] | 43 | case UndefinedKind: |
| 44 | return 1; |
| 45 | default: |
| 46 | llvm_unreachable("unknown symbol kind"); |
| 47 | } |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | template <class ELFT> StringRef DefinedRegular<ELFT>::getName() { return Name; } |
| 51 | |
| 52 | namespace lld { |
| 53 | namespace elf2 { |
| 54 | template class DefinedRegular<llvm::object::ELF32LE>; |
| 55 | template class DefinedRegular<llvm::object::ELF32BE>; |
| 56 | template class DefinedRegular<llvm::object::ELF64LE>; |
| 57 | template class DefinedRegular<llvm::object::ELF64BE>; |
| 58 | } |
| 59 | } |