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"
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"
22 #include <cassert>
23 
24 using namespace llvm;
25 using namespace dwarf;
26 
27 //===----------------------------------------------------------------------===//
28 //                               ELF Target
29 //===----------------------------------------------------------------------===//
30 
Initialize(MCContext & Ctx,const TargetMachine & TM)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();
36 
37   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
38   InitializeELF(isAAPCS_ABI);
39 
40   if (isAAPCS_ABI) {
41     LSDASection = nullptr;
42   }
43 }
44 
getTTypeGlobalReference(const GlobalValue * GV,unsigned Encoding,const TargetMachine & TM,MachineModuleInfo * MMI,MCStreamer & Streamer) const45 const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
46     const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
47     MachineModuleInfo *MMI, MCStreamer &Streamer) const {
48   if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
49     return TargetLoweringObjectFileELF::getTTypeGlobalReference(
50         GV, Encoding, TM, MMI, Streamer);
51 
52   assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
53 
54   return MCSymbolRefExpr::create(TM.getSymbol(GV),
55                                  MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
56 }
57 
58 const MCExpr *ARMElfTargetObjectFile::
getDebugThreadLocalSymbol(const MCSymbol * Sym) const59 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
60   return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
61                                  getContext());
62 }
63 
isExecuteOnlyFunction(const GlobalObject * GO,SectionKind SK,const TargetMachine & TM)64 static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK,
65                                   const TargetMachine &TM) {
66   if (const Function *F = dyn_cast<Function>(GO))
67     if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
68       return true;
69   return false;
70 }
71 
getExplicitSectionGlobal(const GlobalObject * GO,SectionKind SK,const TargetMachine & TM) const72 MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal(
73     const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
74   // Set execute-only access for the explicit section
75   if (isExecuteOnlyFunction(GO, SK, TM))
76     SK = SectionKind::getExecuteOnly();
77 
78   return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
79 }
80 
SelectSectionForGlobal(const GlobalObject * GO,SectionKind SK,const TargetMachine & TM) const81 MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal(
82     const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
83   // Place the global in the execute-only text section
84   if (isExecuteOnlyFunction(GO, SK, TM))
85     SK = SectionKind::getExecuteOnly();
86 
87   return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
88 }
89