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 "ARMTargetMachine.h"
12 #include "llvm/ADT/StringExtras.h"
13 #include "llvm/IR/Mangler.h"
14 #include "llvm/MC/MCAsmInfo.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCSectionELF.h"
18 #include "llvm/Support/Dwarf.h"
19 #include "llvm/Support/ELF.h"
20 #include "llvm/Target/TargetLowering.h"
22 using namespace dwarf;
24 //===----------------------------------------------------------------------===//
26 //===----------------------------------------------------------------------===//
28 void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
29 const TargetMachine &TM) {
30 const ARMTargetMachine &ARM_TM = static_cast<const ARMTargetMachine &>(TM);
31 bool isAAPCS_ABI = ARM_TM.TargetABI == ARMTargetMachine::ARMABI::ARM_ABI_AAPCS;
32 genExecuteOnly = ARM_TM.getSubtargetImpl()->genExecuteOnly();
34 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
35 InitializeELF(isAAPCS_ABI);
38 LSDASection = nullptr;
42 getContext().getELFSection(".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0);
44 // Make code section unreadable when in execute-only mode
46 unsigned Type = ELF::SHT_PROGBITS;
47 unsigned Flags = ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE;
48 // Since we cannot modify flags for an existing section, we create a new
49 // section with the right flags, and use 0 as the unique ID for
51 TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
55 const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
56 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
57 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
58 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
59 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
60 GV, Encoding, TM, MMI, Streamer);
62 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
64 return MCSymbolRefExpr::create(TM.getSymbol(GV),
65 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
68 const MCExpr *ARMElfTargetObjectFile::
69 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
70 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
75 ARMElfTargetObjectFile::getExplicitSectionGlobal(const GlobalObject *GO,
76 SectionKind SK, const TargetMachine &TM) const {
77 // Set execute-only access for the explicit section
78 if (genExecuteOnly && SK.isText())
79 SK = SectionKind::getExecuteOnly();
81 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
85 ARMElfTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
86 SectionKind SK, const TargetMachine &TM) const {
87 // Place the global in the execute-only text section
88 if (genExecuteOnly && SK.isText())
89 SK = SectionKind::getExecuteOnly();
91 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);