Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCObjectWriter.cpp
35233 views
//===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/MC/MCObjectWriter.h"9#include "llvm/MC/MCAssembler.h"10#include "llvm/MC/MCExpr.h"11#include "llvm/MC/MCFragment.h"12#include "llvm/MC/MCSymbol.h"13namespace llvm {14class MCSection;15}1617using namespace llvm;1819MCObjectWriter::~MCObjectWriter() = default;2021void MCObjectWriter::reset() {22FileNames.clear();23AddrsigSyms.clear();24EmitAddrsigSection = false;25SubsectionsViaSymbols = false;26CGProfile.clear();27}2829bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(30const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,31bool InSet) const {32// Modified symbol references cannot be resolved.33if (A->getKind() != MCSymbolRefExpr::VK_None ||34B->getKind() != MCSymbolRefExpr::VK_None)35return false;3637const MCSymbol &SA = A->getSymbol();38const MCSymbol &SB = B->getSymbol();39assert(!SA.isUndefined() && !SB.isUndefined());40MCFragment *FB = SB.getFragment();41if (!FB || !SA.getFragment())42return false;4344return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *FB, InSet, /*IsPCRel=*/false);45}4647bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(48const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,49bool InSet, bool IsPCRel) const {50const MCSection &SecA = SymA.getSection();51const MCSection &SecB = *FB.getParent();52// On ELF and COFF A - B is absolute if A and B are in the same section.53return &SecA == &SecB;54}5556void MCObjectWriter::addFileName(MCAssembler &Asm, StringRef FileName) {57FileNames.emplace_back(std::string(FileName), Asm.Symbols.size());58}596061