]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
Update llvm to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / ARM / ARMTargetObjectFile.cpp
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 "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"
21 using namespace llvm;
22 using namespace dwarf;
23
24 //===----------------------------------------------------------------------===//
25 //                               ELF Target
26 //===----------------------------------------------------------------------===//
27
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();
33
34   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
35   InitializeELF(isAAPCS_ABI);
36
37   if (isAAPCS_ABI) {
38     LSDASection = nullptr;
39   }
40
41   AttributesSection =
42       getContext().getELFSection(".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0);
43
44   // Make code section unreadable when in execute-only mode
45   if (genExecuteOnly) {
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
50     // execute-only text
51     TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
52   }
53 }
54
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);
61
62   assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
63
64   return MCSymbolRefExpr::create(TM.getSymbol(GV),
65                                  MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
66 }
67
68 const MCExpr *ARMElfTargetObjectFile::
69 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
70   return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
71                                  getContext());
72 }
73
74 MCSection *
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();
80
81   return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
82 }
83
84 MCSection *
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();
90
91   return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
92 }