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" |
Rafael Espindola | 49a2ca6 | 2015-08-06 15:33:19 +0000 | [diff] [blame] | 12 | #include "Error.h" |
Michael J. Spencer | cdae0a4 | 2015-07-28 22:58:25 +0000 | [diff] [blame] | 13 | #include "InputFiles.h" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace llvm::object; |
| 16 | |
| 17 | using namespace lld; |
| 18 | using namespace lld::elf2; |
| 19 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 20 | // Returns 1, 0 or -1 if this symbol should take precedence |
| 21 | // over the Other, tie or lose, respectively. |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 22 | int SymbolBody::compare(SymbolBody *Other) { |
Rafael Espindola | 30e1797 | 2015-08-30 23:17:30 +0000 | [diff] [blame] | 23 | std::pair<bool, bool> L(isDefined(), !isWeak()); |
| 24 | std::pair<bool, bool> R(Other->isDefined(), !Other->isWeak()); |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 25 | |
Rafael Espindola | 3a63f3f | 2015-08-28 20:19:34 +0000 | [diff] [blame] | 26 | // Normalize |
| 27 | if (L > R) |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 28 | return -Other->compare(this); |
Rui Ueyama | a7ccb29 | 2015-07-27 20:39:01 +0000 | [diff] [blame] | 29 | |
Rafael Espindola | 3a63f3f | 2015-08-28 20:19:34 +0000 | [diff] [blame] | 30 | if (L != R) |
| 31 | return -1; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 32 | |
Rafael Espindola | 30e1797 | 2015-08-30 23:17:30 +0000 | [diff] [blame] | 33 | if (L.first && L.second) { |
| 34 | // FIXME: In the case where both are common we need to pick the largest |
| 35 | // and remember the alignment restriction. |
| 36 | if (isCommon()) |
| 37 | return -1; |
| 38 | if (Other->isCommon()) |
| 39 | return 1; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 40 | return 0; |
Rafael Espindola | 30e1797 | 2015-08-30 23:17:30 +0000 | [diff] [blame] | 41 | } |
Rafael Espindola | 3a63f3f | 2015-08-28 20:19:34 +0000 | [diff] [blame] | 42 | return 1; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 43 | } |