blob: 33f9a7e198e5589995bfa756b453e92956b39db7 [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"
Rafael Espindola49a2ca62015-08-06 15:33:19 +000012#include "Error.h"
Michael J. Spencercdae0a42015-07-28 22:58:25 +000013#include "InputFiles.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000014
15using namespace llvm::object;
16
17using namespace lld;
18using namespace lld::elf2;
19
Michael J. Spencer84487f12015-07-24 21:03:07 +000020// Returns 1, 0 or -1 if this symbol should take precedence
21// over the Other, tie or lose, respectively.
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000022int SymbolBody::compare(SymbolBody *Other) {
Rafael Espindola3a63f3f2015-08-28 20:19:34 +000023 std::pair<bool, bool> L(isDefined(), isWeak());
24 std::pair<bool, bool> R(Other->isDefined(), Other->isWeak());
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000025
Rafael Espindola3a63f3f2015-08-28 20:19:34 +000026 // Normalize
27 if (L > R)
Michael J. Spencer84487f12015-07-24 21:03:07 +000028 return -Other->compare(this);
Rui Ueyamaa7ccb292015-07-27 20:39:01 +000029
Rafael Espindola3a63f3f2015-08-28 20:19:34 +000030 if (L != R)
31 return -1;
Michael J. Spencer84487f12015-07-24 21:03:07 +000032
Rafael Espindola3a63f3f2015-08-28 20:19:34 +000033 if (L.first && !L.second)
Michael J. Spencer84487f12015-07-24 21:03:07 +000034 return 0;
Rafael Espindola3a63f3f2015-08-28 20:19:34 +000035 return 1;
Michael J. Spencer84487f12015-07-24 21:03:07 +000036}