blob: c711785e5382aee5b627bbe41a96fef3db13b79f [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
18template <class ELFT>
19DefinedRegular<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 Ueyamaa7ccb292015-07-27 20:39:01 +000024int 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. Spencer84487f12015-07-24 21:03:07 +000030 return -Other->compare(this);
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000031
32 // First handle comparisons between two different kinds.
33 if (LK != RK) {
34 assert(LK == DefinedRegularKind);
35 assert(RK == UndefinedKind);
Michael J. Spencer84487f12015-07-24 21:03:07 +000036 return 1;
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000037 }
Michael J. Spencer84487f12015-07-24 21:03:07 +000038
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000039 // Now handle the case where the kinds are the same.
40 switch (LK) {
41 case DefinedRegularKind:
Michael J. Spencer84487f12015-07-24 21:03:07 +000042 return 0;
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000043 case UndefinedKind:
44 return 1;
45 default:
46 llvm_unreachable("unknown symbol kind");
47 }
Michael J. Spencer84487f12015-07-24 21:03:07 +000048}
49
50template <class ELFT> StringRef DefinedRegular<ELFT>::getName() { return Name; }
51
52namespace lld {
53namespace elf2 {
54template class DefinedRegular<llvm::object::ELF32LE>;
55template class DefinedRegular<llvm::object::ELF32BE>;
56template class DefinedRegular<llvm::object::ELF64LE>;
57template class DefinedRegular<llvm::object::ELF64BE>;
58}
59}