LLVM  9.0.0svn
ARMTargetObjectFile.cpp
Go to the documentation of this file.
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"
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"
19 #include "llvm/MC/SectionKind.h"
21 #include <cassert>
22 
23 using namespace llvm;
24 using namespace dwarf;
25 
26 //===----------------------------------------------------------------------===//
27 // ELF Target
28 //===----------------------------------------------------------------------===//
29 
31  const TargetMachine &TM) {
32  const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM);
33  bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS;
34  bool genExecuteOnly =
35  ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly);
36 
38  InitializeELF(isAAPCS_ABI);
39 
40  if (isAAPCS_ABI) {
41  LSDASection = nullptr;
42  }
43 
44  // Make code section unreadable when in execute-only mode
45  if (genExecuteOnly) {
46  unsigned Type = ELF::SHT_PROGBITS;
47  unsigned Flags =
49  // Since we cannot modify flags for an existing section, we create a new
50  // section with the right flags, and use 0 as the unique ID for
51  // execute-only text
52  TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
53  }
54 }
55 
57  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
58  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
61  GV, Encoding, TM, MMI, Streamer);
62 
63  assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
64 
65  return MCSymbolRefExpr::create(TM.getSymbol(GV),
66  MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
67 }
68 
72  getContext());
73 }
74 
76  const TargetMachine &TM) {
77  if (const Function *F = dyn_cast<Function>(GO))
78  if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
79  return true;
80  return false;
81 }
82 
84  const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
85  // Set execute-only access for the explicit section
86  if (isExecuteOnlyFunction(GO, SK, TM))
88 
90 }
91 
93  const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
94  // Place the global in the execute-only text section
95  if (isExecuteOnlyFunction(GO, SK, TM))
97 
99 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:322
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
F(f)
setjmp/longjmp based exceptions
enum llvm::ARMBaseTargetMachine::ARMABI TargetABI
bool genExecuteOnly() const
Definition: ARMSubtarget.h:637
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Context object for machine code objects.
Definition: MCContext.h:62
bool isText() const
Definition: SectionKind.h:118
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Streaming machine code generation interface.
Definition: MCStreamer.h:188
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Return an MCExpr to use for a reference to the specified type info global variable from exception han...
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
MCSymbol * getSymbol(const GlobalValue *GV) const
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const override
Describe a TLS variable address within debug info.
const MCSubtargetInfo * getMCSubtargetInfo() const
This file contains constants used for implementing Dwarf debug support.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK, const TargetMachine &TM)
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Return an MCExpr to use for a reference to the specified type info global variable from exception han...
bool hasFeature(unsigned Feature) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:388
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:569
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:58
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
This class contains meta information specific to a module.
static SectionKind getExecuteOnly()
Definition: SectionKind.h:180