1 //===-- llvm/Target/ARMTargetObjectFile.cpp - ARM Object Info Impl --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "ARMTargetObjectFile.h"
11 #include "ARMSubtarget.h"
12 #include "ARMTargetMachine.h"
13 #include "llvm/BinaryFormat/Dwarf.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"
19 #include "llvm/MC/MCTargetOptions.h"
20 #include "llvm/MC/SectionKind.h"
21 #include "llvm/Target/TargetMachine.h"
25 using namespace dwarf;
27 //===----------------------------------------------------------------------===//
29 //===----------------------------------------------------------------------===//
31 void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
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 // genExecuteOnly = ARM_TM.getSubtargetImpl()->genExecuteOnly();
37 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
38 InitializeELF(isAAPCS_ABI);
41 LSDASection = nullptr;
45 getContext().getELFSection(".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0);
48 const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
49 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
50 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
51 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
52 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
53 GV, Encoding, TM, MMI, Streamer);
55 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
57 return MCSymbolRefExpr::create(TM.getSymbol(GV),
58 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
61 const MCExpr *ARMElfTargetObjectFile::
62 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
63 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
67 static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK,
68 const TargetMachine &TM) {
69 if (const Function *F = dyn_cast<Function>(GO))
70 if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
75 MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal(
76 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
77 // Set execute-only access for the explicit section
78 if (isExecuteOnlyFunction(GO, SK, TM))
79 SK = SectionKind::getExecuteOnly();
81 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
84 MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal(
85 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
86 // Place the global in the execute-only text section
87 if (isExecuteOnlyFunction(GO, SK, TM))
88 SK = SectionKind::getExecuteOnly();
90 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);