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/MCExpr.h" 12 #include "llvm/MC/MCFragment.h" 13 #include "llvm/MC/MCSymbol.h" 14 namespace llvm { 15 class MCSection; 16 } 17 18 using namespace llvm; 19 20 MCObjectWriter::~MCObjectWriter() = default; 21 22 void MCObjectWriter::reset() { FileNames.clear(); } 23 24 bool MCObjectWriter::isSymbolRefDifferenceFullyResolved( 25 const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B, 26 bool InSet) const { 27 // Modified symbol references cannot be resolved. 28 if (A->getKind() != MCSymbolRefExpr::VK_None || 29 B->getKind() != MCSymbolRefExpr::VK_None) 30 return false; 31 32 const MCSymbol &SA = A->getSymbol(); 33 const MCSymbol &SB = B->getSymbol(); 34 assert(!SA.isUndefined() && !SB.isUndefined()); 35 MCFragment *FB = SB.getFragment(); 36 if (!FB || !SA.getFragment()) 37 return false; 38 39 return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *FB, InSet, /*IsPCRel=*/false); 40 } 41 42 bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( 43 const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, 44 bool InSet, bool IsPCRel) const { 45 const MCSection &SecA = SymA.getSection(); 46 const MCSection &SecB = *FB.getParent(); 47 // On ELF and COFF A - B is absolute if A and B are in the same section. 48 return &SecA == &SecB; 49 } 50 51 void MCObjectWriter::addFileName(MCAssembler &Asm, StringRef FileName) { 52 FileNames.emplace_back(std::string(FileName), Asm.Symbols.size()); 53 } 54