blob: 9b3bc30ed398644894cfa1fc17fca1488a8007a4 [file] [log] [blame]
Michael J. Spencer84487f12015-07-24 21:03:07 +00001//===- 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
13using namespace llvm::object;
14
15using namespace lld;
16using namespace lld::elf2;
17
Michael J. Spencer84487f12015-07-24 21:03:07 +000018// Returns 1, 0 or -1 if this symbol should take precedence
19// over the Other, tie or lose, respectively.
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000020int 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. Spencer84487f12015-07-24 21:03:07 +000026 return -Other->compare(this);
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000027
28 // First handle comparisons between two different kinds.
29 if (LK != RK) {
30 assert(LK == DefinedRegularKind);
31 assert(RK == UndefinedKind);
Michael J. Spencer84487f12015-07-24 21:03:07 +000032 return 1;
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000033 }
Michael J. Spencer84487f12015-07-24 21:03:07 +000034
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000035 // Now handle the case where the kinds are the same.
36 switch (LK) {
37 case DefinedRegularKind:
Michael J. Spencer84487f12015-07-24 21:03:07 +000038 return 0;
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000039 case UndefinedKind:
40 return 1;
41 default:
42 llvm_unreachable("unknown symbol kind");
43 }
Michael J. Spencer84487f12015-07-24 21:03:07 +000044}
45
Michael J. Spencer84487f12015-07-24 21:03:07 +000046namespace lld {
47namespace elf2 {
48template class DefinedRegular<llvm::object::ELF32LE>;
49template class DefinedRegular<llvm::object::ELF32BE>;
50template class DefinedRegular<llvm::object::ELF64LE>;
51template class DefinedRegular<llvm::object::ELF64BE>;
52}
53}