Coverage Report

Created: 2019-07-24 05:18

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