LLVM 22.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
10#include "ARMSubtarget.h"
11#include "ARMTargetMachine.h"
15#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCValue.h"
20#include "llvm/MC/SectionKind.h"
22#include <cassert>
23
24using namespace llvm;
25using namespace dwarf;
26
27//===----------------------------------------------------------------------===//
28// ELF Target
29//===----------------------------------------------------------------------===//
30
35
37 const TargetMachine &TM) {
38 const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM);
39 bool isAAPCS_ABI = ARM_TM.TargetABI == ARM::ARMABI::ARM_ABI_AAPCS;
40 bool genExecuteOnly =
41 ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly);
42
44 InitializeELF(isAAPCS_ABI);
45
46 if (isAAPCS_ABI) {
47 LSDASection = nullptr;
48 }
49
50 // Make code section unreadable when in execute-only mode
51 if (genExecuteOnly) {
52 unsigned Type = ELF::SHT_PROGBITS;
53 unsigned Flags =
55 // Since we cannot modify flags for an existing section, we create a new
56 // section with the right flags, and use 0 as the unique ID for
57 // execute-only text
59 Ctx.getELFSection(".text", Type, Flags, 0, "", false, 0U, nullptr);
60 }
61}
62
64
66 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
67 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
68 int64_t FinalOffset = Offset + MV.getConstant();
69 const MCExpr *Res =
71 const MCExpr *Off = MCConstantExpr::create(FinalOffset, getContext());
72 return MCBinaryExpr::createAdd(Res, Off, getContext());
73}
74
79
81 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
82 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
83 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
85 GV, Encoding, TM, MMI, Streamer);
86
87 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
88
89 return MCSymbolRefExpr::create(TM.getSymbol(GV), ARM::S_TARGET2,
90 getContext());
91}
92
97
99 const TargetMachine &TM) {
100 if (const Function *F = dyn_cast<Function>(GO))
101 if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
102 return true;
103 return false;
104}
105
107 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
108 // Set execute-only access for the explicit section
109 if (isExecuteOnlyFunction(GO, SK, TM))
111
113}
114
116 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
117 // Place the global in the execute-only text section
118 if (isExecuteOnlyFunction(GO, SK, TM))
120
122}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM)
This file contains constants used for implementing Dwarf debug support.
#define F(x, y, z)
Definition MD5.cpp:55
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const override
Describe a TLS variable address within debug info.
MCRegister getStaticBase() const override
Returns the register used as static base in RWPI variants.
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...
const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get the target specific PC relative GOT entry relocation.
const MCExpr * getIndirectSymViaRWPI(const MCSymbol *Sym) const override
Get the target specific RWPI relocation.
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 global variable from exception handling info...
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:343
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
MCSection * TextSection
Section directive for standard text.
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
MCContext & getContext() const
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:496
Streaming machine code generation interface.
Definition MCStreamer.h:220
bool hasFeature(unsigned Feature) const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
int64_t getConstant() const
Definition MCValue.h:44
This class contains meta information specific to a module.
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition SectionKind.h:22
bool isText() const
static SectionKind getExecuteOnly()
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
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...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
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...
Primary interface to the complete machine description for the target machine.
const MCSubtargetInfo * getMCSubtargetInfo() const
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
@ SHT_PROGBITS
Definition ELF.h:1140
@ SHF_ALLOC
Definition ELF.h:1240
@ SHF_ARM_PURECODE
Definition ELF.h:1335
@ SHF_EXECINSTR
Definition ELF.h:1243
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:34
@ DW_EH_PE_absptr
Definition Dwarf.h:854
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649