LCOV - code coverage report
Current view: top level - lib/Target/ARM - ARMTargetObjectFile.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 23 25 92.0 %
Date: 2018-10-20 13:21:21 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- llvm/Target/ARMTargetObjectFile.cpp - ARM Object Info Impl --------===//
       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 "ARMTargetObjectFile.h"
      11             : #include "ARMSubtarget.h"
      12             : #include "ARMTargetMachine.h"
      13             : #include "llvm/BinaryFormat/Dwarf.h"
      14             : #include "llvm/BinaryFormat/ELF.h"
      15             : #include "llvm/MC/MCAsmInfo.h"
      16             : #include "llvm/MC/MCContext.h"
      17             : #include "llvm/MC/MCExpr.h"
      18             : #include "llvm/MC/MCSectionELF.h"
      19             : #include "llvm/MC/MCTargetOptions.h"
      20             : #include "llvm/MC/SectionKind.h"
      21             : #include "llvm/Target/TargetMachine.h"
      22             : #include <cassert>
      23             : 
      24             : using namespace llvm;
      25             : using namespace dwarf;
      26             : 
      27             : //===----------------------------------------------------------------------===//
      28             : //                               ELF Target
      29             : //===----------------------------------------------------------------------===//
      30             : 
      31        1974 : void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
      32             :                                         const TargetMachine &TM) {
      33             :   const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM);
      34        1974 :   bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS;
      35             :   bool genExecuteOnly =
      36             :       ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly);
      37             : 
      38        1974 :   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
      39        1974 :   InitializeELF(isAAPCS_ABI);
      40             : 
      41        1974 :   if (isAAPCS_ABI) {
      42        1963 :     LSDASection = nullptr;
      43             :   }
      44             : 
      45             :   // Make code section unreadable when in execute-only mode
      46        1974 :   if (genExecuteOnly) {
      47             :     unsigned Type = ELF::SHT_PROGBITS;
      48             :     unsigned Flags =
      49             :         ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE;
      50             :     // Since we cannot modify flags for an existing section, we create a new
      51             :     // section with the right flags, and use 0 as the unique ID for
      52             :     // execute-only text
      53          23 :     TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
      54             :   }
      55        1974 : }
      56             : 
      57           7 : const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
      58             :     const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
      59             :     MachineModuleInfo *MMI, MCStreamer &Streamer) const {
      60           7 :   if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
      61           3 :     return TargetLoweringObjectFileELF::getTTypeGlobalReference(
      62           3 :         GV, Encoding, TM, MMI, Streamer);
      63             : 
      64             :   assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
      65             : 
      66           4 :   return MCSymbolRefExpr::create(TM.getSymbol(GV),
      67           4 :                                  MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
      68             : }
      69             : 
      70           1 : const MCExpr *ARMElfTargetObjectFile::
      71             : getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
      72           2 :   return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
      73           1 :                                  getContext());
      74             : }
      75             : 
      76           0 : static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK,
      77             :                                   const TargetMachine &TM) {
      78             :   if (const Function *F = dyn_cast<Function>(GO))
      79       11849 :     if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
      80           0 :       return true;
      81             :   return false;
      82             : }
      83             : 
      84          39 : MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal(
      85             :     const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
      86             :   // Set execute-only access for the explicit section
      87             :   if (isExecuteOnlyFunction(GO, SK, TM))
      88             :     SK = SectionKind::getExecuteOnly();
      89             : 
      90          39 :   return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
      91             : }
      92             : 
      93       12401 : MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal(
      94             :     const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
      95             :   // Place the global in the execute-only text section
      96             :   if (isExecuteOnlyFunction(GO, SK, TM))
      97             :     SK = SectionKind::getExecuteOnly();
      98             : 
      99       12401 :   return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
     100             : }

Generated by: LCOV version 1.13