Daniel Dunbar | 79e0e5a | 2010-03-19 10:43:15 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===// |
Daniel Dunbar | f027abf | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Daniel Dunbar | f027abf | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/MC/MCObjectWriter.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCAssembler.h" |
| 11 | #include "llvm/MC/MCExpr.h" |
| 12 | #include "llvm/MC/MCFragment.h" |
Rafael Espindola | b403e09 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | f027abf | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace llvm; |
| 16 | |
Eugene Zelenko | 3d8b0eb | 2017-02-08 22:23:19 +0000 | [diff] [blame] | 17 | MCObjectWriter::~MCObjectWriter() = default; |
Kevin Enderby | e46564a | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 18 | |
Jim Grosbach | 36e60e9 | 2015-06-04 22:24:41 +0000 | [diff] [blame] | 19 | bool MCObjectWriter::isSymbolRefDifferenceFullyResolved( |
Rafael Espindola | 59f90b2 | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 20 | const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B, |
| 21 | bool InSet) const { |
Rafael Espindola | b403e09 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 22 | // Modified symbol references cannot be resolved. |
| 23 | if (A->getKind() != MCSymbolRefExpr::VK_None || |
| 24 | B->getKind() != MCSymbolRefExpr::VK_None) |
| 25 | return false; |
| 26 | |
| 27 | const MCSymbol &SA = A->getSymbol(); |
| 28 | const MCSymbol &SB = B->getSymbol(); |
Rafael Espindola | 972756b | 2015-04-06 16:10:05 +0000 | [diff] [blame] | 29 | if (SA.isUndefined() || SB.isUndefined()) |
Rafael Espindola | b403e09 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 30 | return false; |
| 31 | |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 32 | if (!SA.getFragment() || !SB.getFragment()) |
Kevin Enderby | e1a12cf | 2012-01-31 23:02:57 +0000 | [diff] [blame] | 33 | return false; |
Rafael Espindola | 0f8abeb | 2010-12-24 21:22:02 +0000 | [diff] [blame] | 34 | |
Rafael Espindola | e3a20f5 | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 35 | return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, SB, InSet); |
| 36 | } |
| 37 | |
| 38 | bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( |
| 39 | const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, |
| 40 | bool InSet) const { |
| 41 | return isSymbolRefDifferenceFullyResolvedImpl(Asm, A, *B.getFragment(), InSet, |
| 42 | false); |
Rafael Espindola | b403e09 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 43 | } |
Rafael Espindola | 490d02a | 2011-02-16 03:25:55 +0000 | [diff] [blame] | 44 | |
Jim Grosbach | 36e60e9 | 2015-06-04 22:24:41 +0000 | [diff] [blame] | 45 | bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( |
Duncan P. N. Exon Smith | d81ba53 | 2015-05-16 01:01:55 +0000 | [diff] [blame] | 46 | const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, |
Rafael Espindola | 35d6189 | 2015-04-17 21:15:17 +0000 | [diff] [blame] | 47 | bool InSet, bool IsPCRel) const { |
Duncan P. N. Exon Smith | d81ba53 | 2015-05-16 01:01:55 +0000 | [diff] [blame] | 48 | const MCSection &SecA = SymA.getSection(); |
Rafael Espindola | 7549f87 | 2015-05-26 00:36:57 +0000 | [diff] [blame] | 49 | const MCSection &SecB = *FB.getParent(); |
Rafael Espindola | 490d02a | 2011-02-16 03:25:55 +0000 | [diff] [blame] | 50 | // On ELF and COFF A - B is absolute if A and B are in the same section. |
| 51 | return &SecA == &SecB; |
| 52 | } |