MCObjectWriter.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #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"
  13. using namespace llvm;
  14. MCObjectWriter::~MCObjectWriter() = default;
  15. bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
  16. const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
  17. bool InSet) const {
  18. // Modified symbol references cannot be resolved.
  19. if (A->getKind() != MCSymbolRefExpr::VK_None ||
  20. B->getKind() != MCSymbolRefExpr::VK_None)
  21. return false;
  22. const MCSymbol &SA = A->getSymbol();
  23. const MCSymbol &SB = B->getSymbol();
  24. if (SA.isUndefined() || SB.isUndefined())
  25. return false;
  26. if (!SA.getFragment() || !SB.getFragment())
  27. return false;
  28. return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, SB, InSet);
  29. }
  30. bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
  31. const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B,
  32. bool InSet) const {
  33. return isSymbolRefDifferenceFullyResolvedImpl(Asm, A, *B.getFragment(), InSet,
  34. false);
  35. }
  36. bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
  37. const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
  38. bool InSet, bool IsPCRel) const {
  39. const MCSection &SecA = SymA.getSection();
  40. const MCSection &SecB = *FB.getParent();
  41. // On ELF and COFF A - B is absolute if A and B are in the same section.
  42. return &SecA == &SecB;
  43. }