LCOV - code coverage report
Current view: top level - lib/Target/AMDGPU/MCTargetDesc - AMDGPUELFObjectWriter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 24 25 96.0 %
Date: 2017-09-14 15:23:50 Functions: 3 4 75.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/MCSymbol.h"
      16             : #include "llvm/MC/MCValue.h"
      17             : #include "llvm/Support/ErrorHandling.h"
      18             : 
      19             : using namespace llvm;
      20             : 
      21             : namespace {
      22             : 
      23          61 : class AMDGPUELFObjectWriter : public MCELFObjectTargetWriter {
      24             : public:
      25             :   AMDGPUELFObjectWriter(bool Is64Bit, bool HasRelocationAddend);
      26             : 
      27             : protected:
      28             :   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
      29             :                         const MCFixup &Fixup, bool IsPCRel) const override;
      30             : };
      31             : 
      32             : 
      33             : } // end anonymous namespace
      34             : 
      35             : AMDGPUELFObjectWriter::AMDGPUELFObjectWriter(bool Is64Bit,
      36          61 :                                              bool HasRelocationAddend)
      37             :   : MCELFObjectTargetWriter(Is64Bit,
      38             :                             ELF::ELFOSABI_AMDGPU_HSA,
      39             :                             ELF::EM_AMDGPU,
      40          61 :                             HasRelocationAddend) {}
      41             : 
      42         188 : unsigned AMDGPUELFObjectWriter::getRelocType(MCContext &Ctx,
      43             :                                              const MCValue &Target,
      44             :                                              const MCFixup &Fixup,
      45             :                                              bool IsPCRel) const {
      46         188 :   if (const auto *SymA = Target.getSymA()) {
      47             :     // SCRATCH_RSRC_DWORD[01] is a special global variable that represents
      48             :     // the scratch buffer.
      49         376 :     if (SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD0")
      50             :       return ELF::R_AMDGPU_ABS32_LO;
      51             : 
      52         374 :     if (SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD1")
      53             :       return ELF::R_AMDGPU_ABS32_HI;
      54             :   }
      55             : 
      56         186 :   switch (Target.getAccessVariant()) {
      57             :   default:
      58             :     break;
      59             :   case MCSymbolRefExpr::VK_GOTPCREL:
      60             :     return ELF::R_AMDGPU_GOTPCREL;
      61           6 :   case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_LO:
      62           6 :     return ELF::R_AMDGPU_GOTPCREL32_LO;
      63           6 :   case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_HI:
      64           6 :     return ELF::R_AMDGPU_GOTPCREL32_HI;
      65           4 :   case MCSymbolRefExpr::VK_AMDGPU_REL32_LO:
      66           4 :     return ELF::R_AMDGPU_REL32_LO;
      67           4 :   case MCSymbolRefExpr::VK_AMDGPU_REL32_HI:
      68           4 :     return ELF::R_AMDGPU_REL32_HI;
      69             :   }
      70             : 
      71         160 :   switch (Fixup.getKind()) {
      72             :   default: break;
      73             :   case FK_PCRel_4:
      74             :     return ELF::R_AMDGPU_REL32;
      75         109 :   case FK_Data_4:
      76             :   case FK_SecRel_4:
      77         109 :     return ELF::R_AMDGPU_ABS32;
      78          48 :   case FK_Data_8:
      79          48 :     return ELF::R_AMDGPU_ABS64;
      80             :   }
      81             : 
      82           0 :   llvm_unreachable("unhandled relocation type");
      83             : }
      84             : 
      85          61 : MCObjectWriter *llvm::createAMDGPUELFObjectWriter(bool Is64Bit,
      86             :                                                   bool HasRelocationAddend,
      87             :                                                   raw_pwrite_stream &OS) {
      88             :   MCELFObjectTargetWriter *MOTW =
      89         122 :       new AMDGPUELFObjectWriter(Is64Bit, HasRelocationAddend);
      90          61 :   return createELFObjectWriter(MOTW, OS, true);
      91             : }

Generated by: LCOV version 1.13