summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Symbols.cpp
blob: 194d379e04dac9ca5a765c6834812f063de7421c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//===- 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"
#include "Error.h"
#include "InputFiles.h"

using namespace llvm::object;

using namespace lld;
using namespace lld::elf2;

template <class ELFT>
DefinedRegular<ELFT>::DefinedRegular(StringRef Name)
    : Defined(DefinedRegularKind, Name) {}

// Returns 1, 0 or -1 if this symbol should take precedence
// over the Other, tie or lose, respectively.
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)
    return -Other->compare(this);

  // First handle comparisons between two different kinds.
  if (LK != RK) {
    assert(LK == DefinedRegularKind);
    assert(RK == UndefinedKind);
    return 1;
  }

  // Now handle the case where the kinds are the same.
  switch (LK) {
  case DefinedRegularKind:
    return 0;
  case UndefinedKind:
    return 1;
  default:
    llvm_unreachable("unknown symbol kind");
  }
}

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>;
}
}
OpenPOWER on IntegriCloud