LCOV - code coverage report
Current view: top level - lib/Target/AMDGPU/MCTargetDesc - AMDGPUELFObjectWriter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 22 26 84.6 %
Date: 2018-10-20 13:21:21 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- AMDGPUELFObjectWriter.cpp - AMDGPU ELF Writer ----------------------===//
       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 "AMDGPUMCTargetDesc.h"
      11             : #include "llvm/BinaryFormat/ELF.h"
      12             : #include "llvm/MC/MCELFObjectWriter.h"
      13             : #include "llvm/MC/MCExpr.h"
      14             : #include "llvm/MC/MCFixup.h"
      15             : #include "llvm/MC/MCObjectWriter.h"
      16             : #include "llvm/MC/MCSymbol.h"
      17             : #include "llvm/MC/MCValue.h"
      18             : #include "llvm/Support/ErrorHandling.h"
      19             : 
      20             : using namespace llvm;
      21             : 
      22             : namespace {
      23             : 
      24           0 : class AMDGPUELFObjectWriter : public MCELFObjectTargetWriter {
      25             : public:
      26             :   AMDGPUELFObjectWriter(bool Is64Bit, uint8_t OSABI, bool HasRelocationAddend);
      27             : 
      28             : protected:
      29             :   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
      30             :                         const MCFixup &Fixup, bool IsPCRel) const override;
      31             : };
      32             : 
      33             : 
      34             : } // end anonymous namespace
      35             : 
      36             : AMDGPUELFObjectWriter::AMDGPUELFObjectWriter(bool Is64Bit,
      37             :                                              uint8_t OSABI,
      38           0 :                                              bool HasRelocationAddend)
      39             :   : MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_AMDGPU,
      40           0 :                             HasRelocationAddend) {}
      41             : 
      42         212 : unsigned AMDGPUELFObjectWriter::getRelocType(MCContext &Ctx,
      43             :                                              const MCValue &Target,
      44             :                                              const MCFixup &Fixup,
      45             :                                              bool IsPCRel) const {
      46         212 :   if (const auto *SymA = Target.getSymA()) {
      47             :     // SCRATCH_RSRC_DWORD[01] is a special global variable that represents
      48             :     // the scratch buffer.
      49         212 :     if (SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD0")
      50             :       return ELF::R_AMDGPU_ABS32_LO;
      51             : 
      52             :     if (SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD1")
      53             :       return ELF::R_AMDGPU_ABS32_HI;
      54             :   }
      55             : 
      56         208 :   switch (Target.getAccessVariant()) {
      57             :   default:
      58             :     break;
      59             :   case MCSymbolRefExpr::VK_GOTPCREL:
      60             :     return ELF::R_AMDGPU_GOTPCREL;
      61          11 :   case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_LO:
      62          11 :     return ELF::R_AMDGPU_GOTPCREL32_LO;
      63          11 :   case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_HI:
      64          11 :     return ELF::R_AMDGPU_GOTPCREL32_HI;
      65           5 :   case MCSymbolRefExpr::VK_AMDGPU_REL32_LO:
      66           5 :     return ELF::R_AMDGPU_REL32_LO;
      67           5 :   case MCSymbolRefExpr::VK_AMDGPU_REL32_HI:
      68           5 :     return ELF::R_AMDGPU_REL32_HI;
      69           8 :   case MCSymbolRefExpr::VK_AMDGPU_REL64:
      70           8 :     return ELF::R_AMDGPU_REL64;
      71             :   }
      72             : 
      73         161 :   switch (Fixup.getKind()) {
      74             :   default: break;
      75             :   case FK_PCRel_4:
      76             :     return ELF::R_AMDGPU_REL32;
      77         109 :   case FK_Data_4:
      78             :   case FK_SecRel_4:
      79         109 :     return ELF::R_AMDGPU_ABS32;
      80          49 :   case FK_Data_8:
      81          49 :     return ELF::R_AMDGPU_ABS64;
      82             :   }
      83             : 
      84           0 :   llvm_unreachable("unhandled relocation type");
      85             : }
      86             : 
      87             : std::unique_ptr<MCObjectTargetWriter>
      88        2643 : llvm::createAMDGPUELFObjectWriter(bool Is64Bit, uint8_t OSABI,
      89             :                                   bool HasRelocationAddend) {
      90        2643 :   return llvm::make_unique<AMDGPUELFObjectWriter>(Is64Bit, OSABI,
      91        2643 :                                                   HasRelocationAddend);
      92             : }

Generated by: LCOV version 1.13