LCOV - code coverage report
Current view: top level - lib/Target/AArch64/MCTargetDesc - AArch64WinCOFFObjectWriter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 25 30 83.3 %
Date: 2018-02-18 16:14:26 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //= AArch64WinCOFFObjectWriter.cpp - AArch64 Windows COFF Object Writer C++ =//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===---------------------------------------------------------------------===//
       9             : 
      10             : #include "MCTargetDesc/AArch64FixupKinds.h"
      11             : #include "llvm/ADT/Twine.h"
      12             : #include "llvm/BinaryFormat/COFF.h"
      13             : #include "llvm/MC/MCAsmBackend.h"
      14             : #include "llvm/MC/MCExpr.h"
      15             : #include "llvm/MC/MCFixup.h"
      16             : #include "llvm/MC/MCFixupKindInfo.h"
      17             : #include "llvm/MC/MCObjectWriter.h"
      18             : #include "llvm/MC/MCValue.h"
      19             : #include "llvm/MC/MCWinCOFFObjectWriter.h"
      20             : #include "llvm/Support/ErrorHandling.h"
      21             : #include "llvm/Support/raw_ostream.h"
      22             : #include <cassert>
      23             : 
      24             : using namespace llvm;
      25             : 
      26             : namespace {
      27             : 
      28             : class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
      29             : public:
      30             :   AArch64WinCOFFObjectWriter()
      31           6 :       : MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_ARM64) {}
      32             : 
      33           6 :   ~AArch64WinCOFFObjectWriter() override = default;
      34             : 
      35             :   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
      36             :                         const MCFixup &Fixup, bool IsCrossSection,
      37             :                         const MCAsmBackend &MAB) const override;
      38             : 
      39             :   bool recordRelocation(const MCFixup &) const override;
      40             : };
      41             : 
      42             : } // end anonymous namespace
      43             : 
      44          18 : unsigned AArch64WinCOFFObjectWriter::getRelocType(
      45             :     MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
      46             :     bool IsCrossSection, const MCAsmBackend &MAB) const {
      47             :   auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
      48             :                                       : Target.getSymA()->getKind();
      49             : 
      50          18 :   switch (static_cast<unsigned>(Fixup.getKind())) {
      51           0 :   default: {
      52           0 :     const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
      53           0 :     report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
      54             :   }
      55             : 
      56           2 :   case FK_Data_4:
      57           2 :     switch (Modifier) {
      58             :     default:
      59             :       return COFF::IMAGE_REL_ARM64_ADDR32;
      60           1 :     case MCSymbolRefExpr::VK_COFF_IMGREL32:
      61           1 :       return COFF::IMAGE_REL_ARM64_ADDR32NB;
      62           0 :     case MCSymbolRefExpr::VK_SECREL:
      63           0 :       return COFF::IMAGE_REL_ARM64_SECREL;
      64             :     }
      65             : 
      66             :   case FK_Data_8:
      67             :     return COFF::IMAGE_REL_ARM64_ADDR64;
      68             : 
      69           3 :   case FK_SecRel_2:
      70           3 :     return COFF::IMAGE_REL_ARM64_SECTION;
      71             : 
      72           3 :   case FK_SecRel_4:
      73           3 :     return COFF::IMAGE_REL_ARM64_SECREL;
      74             : 
      75           2 :   case AArch64::fixup_aarch64_add_imm12:
      76           2 :     return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12A;
      77             : 
      78           3 :   case AArch64::fixup_aarch64_ldst_imm12_scale1:
      79             :   case AArch64::fixup_aarch64_ldst_imm12_scale2:
      80             :   case AArch64::fixup_aarch64_ldst_imm12_scale4:
      81             :   case AArch64::fixup_aarch64_ldst_imm12_scale8:
      82             :   case AArch64::fixup_aarch64_ldst_imm12_scale16:
      83           3 :     return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L;
      84             : 
      85           3 :   case AArch64::fixup_aarch64_pcrel_adrp_imm21:
      86           3 :     return COFF::IMAGE_REL_ARM64_PAGEBASE_REL21;
      87             : 
      88           1 :   case AArch64::fixup_aarch64_pcrel_branch26:
      89             :   case AArch64::fixup_aarch64_pcrel_call26:
      90           1 :     return COFF::IMAGE_REL_ARM64_BRANCH26;
      91             :   }
      92             : }
      93             : 
      94          18 : bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
      95          18 :   return true;
      96             : }
      97             : 
      98             : namespace llvm {
      99             : 
     100             : std::unique_ptr<MCObjectWriter>
     101           6 : createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS) {
     102           6 :   auto MOTW = llvm::make_unique<AArch64WinCOFFObjectWriter>();
     103          18 :   return createWinCOFFObjectWriter(std::move(MOTW), OS);
     104             : }
     105             : 
     106             : } // end namespace llvm

Generated by: LCOV version 1.13