Daniel Dunbar | 2df4ceb | 2010-03-19 10:43:15 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===// |
Daniel Dunbar | 53b2338 | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 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 "llvm/MC/MCObjectWriter.h" |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCAssembler.h" |
| 12 | #include "llvm/MC/MCExpr.h" |
| 13 | #include "llvm/MC/MCFragment.h" |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | 53b2338 | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace llvm; |
| 17 | |
Eugene Zelenko | 498b48e | 2017-02-08 22:23:19 +0000 | [diff] [blame] | 18 | MCObjectWriter::~MCObjectWriter() = default; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 19 | |
Jim Grosbach | bc81286 | 2015-06-04 22:24:41 +0000 | [diff] [blame] | 20 | bool MCObjectWriter::isSymbolRefDifferenceFullyResolved( |
Rafael Espindola | 55f6e3b | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 21 | const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B, |
| 22 | bool InSet) const { |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 23 | // Modified symbol references cannot be resolved. |
| 24 | if (A->getKind() != MCSymbolRefExpr::VK_None || |
| 25 | B->getKind() != MCSymbolRefExpr::VK_None) |
| 26 | return false; |
| 27 | |
| 28 | const MCSymbol &SA = A->getSymbol(); |
| 29 | const MCSymbol &SB = B->getSymbol(); |
Rafael Espindola | e17e7a2 | 2015-04-06 16:10:05 +0000 | [diff] [blame] | 30 | if (SA.isUndefined() || SB.isUndefined()) |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 31 | return false; |
| 32 | |
Rafael Espindola | cfac75a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 33 | if (!SA.getFragment() || !SB.getFragment()) |
Kevin Enderby | d49b2a7 | 2012-01-31 23:02:57 +0000 | [diff] [blame] | 34 | return false; |
Rafael Espindola | fea753b | 2010-12-24 21:22:02 +0000 | [diff] [blame] | 35 | |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 36 | return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, SB, InSet); |
| 37 | } |
| 38 | |
| 39 | bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( |
| 40 | const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, |
| 41 | bool InSet) const { |
| 42 | return isSymbolRefDifferenceFullyResolvedImpl(Asm, A, *B.getFragment(), InSet, |
| 43 | false); |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 44 | } |
Rafael Espindola | 908159b | 2011-02-16 03:25:55 +0000 | [diff] [blame] | 45 | |
Jim Grosbach | bc81286 | 2015-06-04 22:24:41 +0000 | [diff] [blame] | 46 | bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( |
Duncan P. N. Exon Smith | 9e6378d | 2015-05-16 01:01:55 +0000 | [diff] [blame] | 47 | const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, |
Rafael Espindola | fb118bd | 2015-04-17 21:15:17 +0000 | [diff] [blame] | 48 | bool InSet, bool IsPCRel) const { |
Duncan P. N. Exon Smith | 9e6378d | 2015-05-16 01:01:55 +0000 | [diff] [blame] | 49 | const MCSection &SecA = SymA.getSection(); |
Rafael Espindola | f363960 | 2015-05-26 00:36:57 +0000 | [diff] [blame] | 50 | const MCSection &SecB = *FB.getParent(); |
Rafael Espindola | 908159b | 2011-02-16 03:25:55 +0000 | [diff] [blame] | 51 | // On ELF and COFF A - B is absolute if A and B are in the same section. |
| 52 | return &SecA == &SecB; |
| 53 | } |