MCObjectWriter.cpp 1.8 KB

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