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 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 AttributesSection = 45 getContext().getELFSection(".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0); 46 } 47 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); 54 55 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only"); 56 57 return MCSymbolRefExpr::create(TM.getSymbol(GV), 58 MCSymbolRefExpr::VK_ARM_TARGET2, getContext()); 59 } 60 61 const MCExpr *ARMElfTargetObjectFile:: 62 getDebugThreadLocalSymbol(const MCSymbol *Sym) const { 63 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO, 64 getContext()); 65 } 66 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()) 71 return true; 72 return false; 73 } 74 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(); 80 81 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM); 82 } 83 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(); 89 90 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM); 91 } 92