LLVM  14.0.0git
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 =
53  Ctx.getELFSection(".text", Type, Flags, 0, "", false, 0U, nullptr);
54  }
55 }
56 
58  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
59  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
60  if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
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 }
llvm::SectionKind::isText
bool isText() const
Definition: SectionKind.h:121
ARMSubtarget.h
llvm::ARMBaseTargetMachine
Definition: ARMTargetMachine.h:27
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::SectionKind::getExecuteOnly
static SectionKind getExecuteOnly()
Definition: SectionKind.h:184
llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:874
MCTargetOptions.h
llvm::ARMSubtarget
Definition: ARMSubtarget.h:46
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::Function
Definition: Function.h:62
isExecuteOnlyFunction
static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK, const TargetMachine &TM)
Definition: ARMTargetObjectFile.cpp:76
llvm::TargetLoweringObjectFileELF::getExplicitSectionGlobal
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...
Definition: TargetLoweringObjectFileImpl.cpp:806
MCSectionELF.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::MCSymbolRefExpr::VK_ARM_TARGET2
@ VK_ARM_TARGET2
Definition: MCExpr.h:232
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
llvm::ELF::SHF_ARM_PURECODE
@ SHF_ARM_PURECODE
Definition: ELF.h:1086
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition: ELF.h:997
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::ARMElfTargetObjectFile::getExplicitSectionGlobal
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...
Definition: ARMTargetObjectFile.cpp:84
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
ELF.h
TargetMachine.h
llvm::MCSubtargetInfo::hasFeature
bool hasFeature(unsigned Feature) const
Definition: MCSubtargetInfo.h:118
llvm::GlobalObject
Definition: GlobalObject.h:28
MCContext.h
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:540
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::ARMElfTargetObjectFile::getTTypeGlobalReference
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...
Definition: ARMTargetObjectFile.cpp:57
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:916
llvm::TargetMachine::getMCSubtargetInfo
const MCSubtargetInfo * getMCSubtargetInfo() const
Definition: TargetMachine.h:211
ARMTargetObjectFile.h
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:994
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
llvm::MCSymbolRefExpr::VK_ARM_TLSLDO
@ VK_ARM_TLSLDO
Definition: MCExpr.h:235
MCAsmInfo.h
Dwarf.h
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::ARMElfTargetObjectFile::getDebugThreadLocalSymbol
const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const override
Describe a TLS variable address within debug info.
Definition: ARMTargetObjectFile.cpp:71
llvm::dwarf::DW_EH_PE_absptr
@ DW_EH_PE_absptr
Definition: Dwarf.h:432
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::ARMElfTargetObjectFile::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: ARMTargetObjectFile.cpp:93
llvm::TargetLoweringObjectFileELF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:116
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
SectionKind.h
llvm::ARMBaseTargetMachine::TargetABI
enum llvm::ARMBaseTargetMachine::ARMABI TargetABI
llvm::TargetLoweringObjectFileELF::getTTypeGlobalReference
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...
Definition: TargetLoweringObjectFileImpl.cpp:413
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::ARMElfTargetObjectFile::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: ARMTargetObjectFile.cpp:30
ARMTargetMachine.h
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::ARMSubtarget::genExecuteOnly
bool genExecuteOnly() const
Definition: ARMSubtarget.h:733