LCOV - code coverage report
Current view: top level - lib/Target/AArch64/MCTargetDesc - AArch64WinCOFFObjectWriter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 27 32 84.4 %
Date: 2017-09-14 15:23:50 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/MCValue.h"
      18             : #include "llvm/MC/MCWinCOFFObjectWriter.h"
      19             : #include "llvm/Support/ErrorHandling.h"
      20             : #include "llvm/Support/raw_ostream.h"
      21             : #include <cassert>
      22             : 
      23             : using namespace llvm;
      24             : 
      25             : namespace {
      26             : 
      27             : class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
      28             : public:
      29             :   AArch64WinCOFFObjectWriter()
      30           5 :       : MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_ARM64) {}
      31             : 
      32           5 :   ~AArch64WinCOFFObjectWriter() override = default;
      33             : 
      34             :   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
      35             :                         const MCFixup &Fixup, bool IsCrossSection,
      36             :                         const MCAsmBackend &MAB) const override;
      37             : 
      38             :   bool recordRelocation(const MCFixup &) const override;
      39             : };
      40             : 
      41             : } // end anonymous namespace
      42             : 
      43          18 : unsigned AArch64WinCOFFObjectWriter::getRelocType(
      44             :     MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
      45             :     bool IsCrossSection, const MCAsmBackend &MAB) const {
      46          18 :   auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
      47          18 :                                       : Target.getSymA()->getKind();
      48             : 
      49          18 :   switch (static_cast<unsigned>(Fixup.getKind())) {
      50           0 :   default: {
      51           0 :     const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
      52           0 :     report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
      53             :   }
      54             : 
      55           2 :   case FK_Data_4:
      56           2 :     switch (Modifier) {
      57             :     default:
      58             :       return COFF::IMAGE_REL_ARM64_ADDR32;
      59           1 :     case MCSymbolRefExpr::VK_COFF_IMGREL32:
      60           1 :       return COFF::IMAGE_REL_ARM64_ADDR32NB;
      61           0 :     case MCSymbolRefExpr::VK_SECREL:
      62           0 :       return COFF::IMAGE_REL_ARM64_SECREL;
      63             :     }
      64             : 
      65             :   case FK_Data_8:
      66             :     return COFF::IMAGE_REL_ARM64_ADDR64;
      67             : 
      68           3 :   case FK_SecRel_2:
      69           3 :     return COFF::IMAGE_REL_ARM64_SECTION;
      70             : 
      71           3 :   case FK_SecRel_4:
      72           3 :     return COFF::IMAGE_REL_ARM64_SECREL;
      73             : 
      74           2 :   case AArch64::fixup_aarch64_add_imm12:
      75           2 :     return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12A;
      76             : 
      77           3 :   case AArch64::fixup_aarch64_ldst_imm12_scale1:
      78             :   case AArch64::fixup_aarch64_ldst_imm12_scale2:
      79             :   case AArch64::fixup_aarch64_ldst_imm12_scale4:
      80             :   case AArch64::fixup_aarch64_ldst_imm12_scale8:
      81             :   case AArch64::fixup_aarch64_ldst_imm12_scale16:
      82           3 :     return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L;
      83             : 
      84           3 :   case AArch64::fixup_aarch64_pcrel_adrp_imm21:
      85           3 :     return COFF::IMAGE_REL_ARM64_PAGEBASE_REL21;
      86             : 
      87           1 :   case AArch64::fixup_aarch64_pcrel_branch26:
      88             :   case AArch64::fixup_aarch64_pcrel_call26:
      89           1 :     return COFF::IMAGE_REL_ARM64_BRANCH26;
      90             :   }
      91             : }
      92             : 
      93          18 : bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
      94          18 :   return true;
      95             : }
      96             : 
      97             : namespace llvm {
      98             : 
      99           5 : MCObjectWriter *createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS) {
     100          10 :   MCWinCOFFObjectTargetWriter *MOTW = new AArch64WinCOFFObjectWriter();
     101           5 :   return createWinCOFFObjectWriter(MOTW, OS);
     102             : }
     103             : 
     104             : } // end namespace llvm

Generated by: LCOV version 1.13