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 "ARMSubtarget.h"
11 #include "ARMTargetMachine.h"
12 #include "ARMTargetObjectFile.h"
13 #include "llvm/MC/MCAsmInfo.h"
14 #include "llvm/MC/MCContext.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCSectionELF.h"
17 #include "llvm/MC/MCTargetOptions.h"
18 #include "llvm/MC/SectionKind.h"
19 #include "llvm/Support/Dwarf.h"
20 #include "llvm/Support/ELF.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);
47 // Make code section unreadable when in execute-only mode
49 unsigned Type = ELF::SHT_PROGBITS;
50 unsigned Flags = ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE;
51 // Since we cannot modify flags for an existing section, we create a new
52 // section with the right flags, and use 0 as the unique ID for
54 TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
58 const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
59 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
60 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
61 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
62 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
63 GV, Encoding, TM, MMI, Streamer);
65 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
67 return MCSymbolRefExpr::create(TM.getSymbol(GV),
68 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
71 const MCExpr *ARMElfTargetObjectFile::
72 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
73 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
78 ARMElfTargetObjectFile::getExplicitSectionGlobal(const GlobalObject *GO,
79 SectionKind SK, const TargetMachine &TM) const {
80 // Set execute-only access for the explicit section
81 if (genExecuteOnly && SK.isText())
82 SK = SectionKind::getExecuteOnly();
84 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
88 ARMElfTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
89 SectionKind SK, const TargetMachine &TM) const {
90 // Place the global in the execute-only text section
91 if (genExecuteOnly && SK.isText())
92 SK = SectionKind::getExecuteOnly();
94 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);