LLVM 19.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"
14#include "llvm/MC/MCAsmInfo.h"
15#include "llvm/MC/MCContext.h"
16#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
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
54 Ctx.getELFSection(".text", Type, Flags, 0, "", false, 0U, nullptr);
55 }
56}
57
59
61 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
62 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
63 int64_t FinalOffset = Offset + MV.getConstant();
66 const MCExpr *Off = MCConstantExpr::create(FinalOffset, getContext());
67 return MCBinaryExpr::createAdd(Res, Off, getContext());
68}
69
73 getContext());
74}
75
77 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
78 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
81 GV, Encoding, TM, MMI, Streamer);
82
83 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
84
87}
88
92 getContext());
93}
94
96 const TargetMachine &TM) {
97 if (const Function *F = dyn_cast<Function>(GO))
98 if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
99 return true;
100 return false;
101}
102
104 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
105 // Set execute-only access for the explicit section
106 if (isExecuteOnlyFunction(GO, SK, TM))
108
110}
111
113 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
114 // Place the global in the execute-only text section
115 if (isExecuteOnlyFunction(GO, SK, TM))
117
119}
static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK, const TargetMachine &TM)
This file contains constants used for implementing Dwarf debug support.
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define F(x, y, z)
Definition: MD5.cpp:55
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
enum llvm::ARMBaseTargetMachine::ARMABI TargetABI
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 type info global variable from exception han...
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:780
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:536
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
Context object for machine code objects.
Definition: MCContext.h:82
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:543
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
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:35
Streaming machine code generation interface.
Definition: MCStreamer.h:212
bool hasFeature(unsigned Feature) const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:397
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
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
Definition: SectionKind.h:127
static SectionKind getExecuteOnly()
Definition: SectionKind.h:191
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.
Definition: TargetMachine.h:76
const MCSubtargetInfo * getMCSubtargetInfo() const
MCSymbol * getSymbol(const GlobalValue *GV) const
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
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:1067
@ SHF_ALLOC
Definition: ELF.h:1161
@ SHF_ARM_PURECODE
Definition: ELF.h:1256
@ SHF_EXECINSTR
Definition: ELF.h:1164
@ DW_EH_PE_absptr
Definition: Dwarf.h:840
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456