1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "llvm/MC/MCObjectWriter.h" 10 #include "llvm/MC/MCAssembler.h" 11 #include "llvm/MC/MCContext.h" 12 #include "llvm/MC/MCExpr.h" 13 #include "llvm/MC/MCSymbol.h" 14 #include "llvm/MC/MCValue.h" 15 namespace llvm { 16 class MCSection; 17 } 18 19 using namespace llvm; 20 21 MCObjectWriter::~MCObjectWriter() = default; 22 23 MCContext &MCObjectWriter::getContext() const { return Asm->getContext(); } 24 25 void MCObjectWriter::reset() { 26 FileNames.clear(); 27 AddrsigSyms.clear(); 28 EmitAddrsigSection = false; 29 SubsectionsViaSymbols = false; 30 CGProfile.clear(); 31 } 32 33 void MCObjectWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup, 34 MCValue Target, uint64_t &FixedValue) {} 35 36 bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(const MCSymbol &SA, 37 const MCSymbol &SB, 38 bool InSet) const { 39 assert(!SA.isUndefined() && !SB.isUndefined()); 40 return isSymbolRefDifferenceFullyResolvedImpl(SA, *SB.getFragment(), InSet, 41 /*IsPCRel=*/false); 42 } 43 44 bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( 45 const MCSymbol &SymA, const MCFragment &FB, bool InSet, 46 bool IsPCRel) const { 47 const MCSection &SecA = SymA.getSection(); 48 const MCSection &SecB = *FB.getParent(); 49 // On ELF and COFF A - B is absolute if A and B are in the same section. 50 return &SecA == &SecB; 51 } 52 53 void MCObjectWriter::addFileName(StringRef FileName) { 54 FileNames.emplace_back(std::string(FileName), Asm->Symbols.size()); 55 } 56 57 MCContext &MCObjectTargetWriter::getContext() const { 58 return Asm->getContext(); 59 } 60 61 void MCObjectTargetWriter::reportError(SMLoc L, const Twine &Msg) const { 62 return Asm->getContext().reportError(L, Msg); 63 } 64