LLVM  8.0.1
ARMTargetObjectFile.cpp
Go to the documentation of this file.
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"
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"
20 #include "llvm/MC/SectionKind.h"
22 #include <cassert>
23 
24 using namespace llvm;
25 using namespace dwarf;
26 
27 //===----------------------------------------------------------------------===//
28 // ELF Target
29 //===----------------------------------------------------------------------===//
30 
32  const TargetMachine &TM) {
33  const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM);
34  bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS;
35  bool genExecuteOnly =
36  ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly);
37 
39  InitializeELF(isAAPCS_ABI);
40 
41  if (isAAPCS_ABI) {
42  LSDASection = nullptr;
43  }
44 
45  // Make code section unreadable when in execute-only mode
46  if (genExecuteOnly) {
47  unsigned Type = ELF::SHT_PROGBITS;
48  unsigned Flags =
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  TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
54  }
55 }
56 
58  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
59  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
62  GV, Encoding, TM, MMI, Streamer);
63 
64  assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
65 
66  return MCSymbolRefExpr::create(TM.getSymbol(GV),
67  MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
68 }
69 
73  getContext());
74 }
75 
77  const TargetMachine &TM) {
78  if (const Function *F = dyn_cast<Function>(GO))
79  if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
80  return true;
81  return false;
82 }
83 
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))
89 
91 }
92 
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))
98 
100 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
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:323
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
F(f)
setjmp/longjmp based exceptions
enum llvm::ARMBaseTargetMachine::ARMABI TargetABI
bool genExecuteOnly() const
Definition: ARMSubtarget.h:633
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Context object for machine code objects.
Definition: MCContext.h:63
bool isText() const
Definition: SectionKind.h:119
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:189
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
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:23
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:389
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:570
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
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:181