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 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 18 | // Returns 1, 0 or -1 if this symbol should take precedence |
| 19 | // over the Other, tie or lose, respectively. |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 20 | int SymbolBody::compare(SymbolBody *Other) { |
| 21 | Kind LK = kind(); |
| 22 | Kind RK = Other->kind(); |
| 23 | |
| 24 | // Normalize so that the smaller kind is on the left. |
| 25 | if (LK > RK) |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 26 | return -Other->compare(this); |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 27 | |
| 28 | // First handle comparisons between two different kinds. |
| 29 | if (LK != RK) { |
| 30 | assert(LK == DefinedRegularKind); |
| 31 | assert(RK == UndefinedKind); |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 32 | return 1; |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 33 | } |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 34 | |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 35 | // Now handle the case where the kinds are the same. |
| 36 | switch (LK) { |
| 37 | case DefinedRegularKind: |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 38 | return 0; |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 39 | case UndefinedKind: |
| 40 | return 1; |
| 41 | default: |
| 42 | llvm_unreachable("unknown symbol kind"); |
| 43 | } |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 46 | namespace lld { |
| 47 | namespace elf2 { |
| 48 | template class DefinedRegular<llvm::object::ELF32LE>; |
| 49 | template class DefinedRegular<llvm::object::ELF32BE>; |
| 50 | template class DefinedRegular<llvm::object::ELF64LE>; |
| 51 | template class DefinedRegular<llvm::object::ELF64BE>; |
| 52 | } |
| 53 | } |