On ELF, put PIC jump tables in a non executable section.
[oota-llvm.git] / include / llvm / CodeGen / TargetLoweringObjectFileImpl.h
1 //==-- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info -*- C++ -*-==//
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 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
17
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
21
22 namespace llvm {
23   class MachineModuleInfo;
24   class Mangler;
25   class MCAsmInfo;
26   class MCExpr;
27   class MCSection;
28   class MCSectionMachO;
29   class MCSymbol;
30   class MCContext;
31   class GlobalValue;
32   class TargetMachine;
33
34
35 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
36   bool UseInitArray;
37
38 public:
39   TargetLoweringObjectFileELF() : UseInitArray(false) {}
40
41   virtual ~TargetLoweringObjectFileELF() {}
42
43   void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM,
44                             const MCSymbol *Sym) const override;
45
46   /// Given a constant with the SectionKind, return a section that it should be
47   /// placed in.
48   const MCSection *getSectionForConstant(SectionKind Kind,
49                                          const Constant *C) const override;
50
51   const MCSection *getExplicitSectionGlobal(const GlobalValue *GV,
52                                         SectionKind Kind, Mangler &Mang,
53                                         const TargetMachine &TM) const override;
54
55   const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
56                                         SectionKind Kind, Mangler &Mang,
57                                         const TargetMachine &TM) const override;
58
59   const MCSection *
60   getSectionForJumpTable(const Function &F, Mangler &Mang,
61                          const TargetMachine &TM) const override;
62
63   bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
64                                            const Function &F) const override;
65
66   /// Return an MCExpr to use for a reference to the specified type info global
67   /// variable from exception handling information.
68   const MCExpr *
69   getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
70                           Mangler &Mang, const TargetMachine &TM,
71                           MachineModuleInfo *MMI,
72                           MCStreamer &Streamer) const override;
73
74   // The symbol that gets passed to .cfi_personality.
75   MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
76                                     const TargetMachine &TM,
77                                     MachineModuleInfo *MMI) const override;
78
79   void InitializeELF(bool UseInitArray_);
80   const MCSection *getStaticCtorSection(unsigned Priority,
81                                         const MCSymbol *KeySym) const override;
82   const MCSection *getStaticDtorSection(unsigned Priority,
83                                         const MCSymbol *KeySym) const override;
84 };
85
86
87
88 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
89 public:
90   virtual ~TargetLoweringObjectFileMachO() {}
91
92   /// Extract the dependent library name from a linker option string. Returns
93   /// StringRef() if the option does not specify a library.
94   StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
95
96   /// Emit the module flags that specify the garbage collection information.
97   void emitModuleFlags(MCStreamer &Streamer,
98                        ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
99                        Mangler &Mang, const TargetMachine &TM) const override;
100
101   const MCSection *
102     SelectSectionForGlobal(const GlobalValue *GV,
103                            SectionKind Kind, Mangler &Mang,
104                            const TargetMachine &TM) const override;
105
106   const MCSection *
107     getExplicitSectionGlobal(const GlobalValue *GV,
108                              SectionKind Kind, Mangler &Mang,
109                              const TargetMachine &TM) const override;
110
111   const MCSection *getSectionForConstant(SectionKind Kind,
112                                          const Constant *C) const override;
113
114   /// The mach-o version of this method defaults to returning a stub reference.
115   const MCExpr *
116   getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
117                           Mangler &Mang, const TargetMachine &TM,
118                           MachineModuleInfo *MMI,
119                           MCStreamer &Streamer) const override;
120
121   // The symbol that gets passed to .cfi_personality.
122   MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
123                                     const TargetMachine &TM,
124                                     MachineModuleInfo *MMI) const override;
125 };
126
127
128
129 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
130 public:
131   virtual ~TargetLoweringObjectFileCOFF() {}
132
133   const MCSection *
134     getExplicitSectionGlobal(const GlobalValue *GV,
135                              SectionKind Kind, Mangler &Mang,
136                              const TargetMachine &TM) const override;
137
138   const MCSection *
139     SelectSectionForGlobal(const GlobalValue *GV,
140                            SectionKind Kind, Mangler &Mang,
141                            const TargetMachine &TM) const override;
142
143   /// Extract the dependent library name from a linker option string. Returns
144   /// StringRef() if the option does not specify a library.
145   StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
146
147   /// Emit Obj-C garbage collection and linker options. Only linker option
148   /// emission is implemented for COFF.
149   void emitModuleFlags(MCStreamer &Streamer,
150                        ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
151                        Mangler &Mang, const TargetMachine &TM) const override;
152
153   const MCSection *getStaticCtorSection(unsigned Priority,
154                                         const MCSymbol *KeySym) const override;
155   const MCSection *getStaticDtorSection(unsigned Priority,
156                                         const MCSymbol *KeySym) const override;
157 };
158
159 } // end namespace llvm
160
161 #endif