blob: a058bbe0ba0b8b475446d783a8a46997be8c61ec [file] [log] [blame]
Daniel Dunbar79e0e5a2010-03-19 10:43:15 +00001//===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
Daniel Dunbarf027abf2010-03-19 09:28:59 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Dunbarf027abf2010-03-19 09:28:59 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/MC/MCObjectWriter.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000010#include "llvm/MC/MCAssembler.h"
11#include "llvm/MC/MCExpr.h"
12#include "llvm/MC/MCFragment.h"
Rafael Espindolab403e092010-12-18 06:27:54 +000013#include "llvm/MC/MCSymbol.h"
Daniel Dunbarf027abf2010-03-19 09:28:59 +000014
15using namespace llvm;
16
Eugene Zelenko3d8b0eb2017-02-08 22:23:19 +000017MCObjectWriter::~MCObjectWriter() = default;
Kevin Enderbye46564a2010-09-30 16:52:03 +000018
Jim Grosbach36e60e92015-06-04 22:24:41 +000019bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
Rafael Espindola59f90b22015-03-25 19:24:39 +000020 const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
21 bool InSet) const {
Rafael Espindolab403e092010-12-18 06:27:54 +000022 // 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 Espindola972756b2015-04-06 16:10:05 +000029 if (SA.isUndefined() || SB.isUndefined())
Rafael Espindolab403e092010-12-18 06:27:54 +000030 return false;
31
Rafael Espindola4d37b2a2015-05-29 21:45:01 +000032 if (!SA.getFragment() || !SB.getFragment())
Kevin Enderbye1a12cf2012-01-31 23:02:57 +000033 return false;
Rafael Espindola0f8abeb2010-12-24 21:22:02 +000034
Rafael Espindolae3a20f52015-10-05 12:07:05 +000035 return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, SB, InSet);
36}
37
38bool 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 Espindolab403e092010-12-18 06:27:54 +000043}
Rafael Espindola490d02a2011-02-16 03:25:55 +000044
Jim Grosbach36e60e92015-06-04 22:24:41 +000045bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
Duncan P. N. Exon Smithd81ba532015-05-16 01:01:55 +000046 const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
Rafael Espindola35d61892015-04-17 21:15:17 +000047 bool InSet, bool IsPCRel) const {
Duncan P. N. Exon Smithd81ba532015-05-16 01:01:55 +000048 const MCSection &SecA = SymA.getSection();
Rafael Espindola7549f872015-05-26 00:36:57 +000049 const MCSection &SecB = *FB.getParent();
Rafael Espindola490d02a2011-02-16 03:25:55 +000050 // On ELF and COFF A - B is absolute if A and B are in the same section.
51 return &SecA == &SecB;
52}