blob: 2b2d52fc6ed753499d0988d69035f396e03309d7 [file] [log] [blame]
Chris Lattnerc4c40a92009-07-28 03:13:23 +00001//===-- llvm/Target/TargetLoweringObjectFile.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_TARGET_TARGETLOWERINGOBJECTFILE_H
16#define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17
Chris Lattnere6ad12f2009-07-31 18:48:30 +000018#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringMap.h"
Chris Lattnerfb299e42009-08-01 21:30:49 +000020#include "llvm/MC/SectionKind.h"
Chris Lattnerc4c40a92009-07-28 03:13:23 +000021
22namespace llvm {
Chris Lattnere6ad12f2009-07-31 18:48:30 +000023 class MCSection;
Chris Lattner01316272009-07-31 17:42:42 +000024 class MCContext;
Chris Lattnere6ad12f2009-07-31 18:48:30 +000025 class GlobalValue;
26 class Mangler;
27 class TargetMachine;
28
Chris Lattnercfd15d82009-08-01 21:46:23 +000029
Chris Lattnerc4c40a92009-07-28 03:13:23 +000030class TargetLoweringObjectFile {
Chris Lattnere6ad12f2009-07-31 18:48:30 +000031 MCContext *Ctx;
Chris Lattnerc4c40a92009-07-28 03:13:23 +000032protected:
33
34 TargetLoweringObjectFile();
35
36 /// TextSection - Section directive for standard text.
37 ///
Chris Lattnere6ad12f2009-07-31 18:48:30 +000038 const MCSection *TextSection; // Defaults to ".text".
Chris Lattnerc4c40a92009-07-28 03:13:23 +000039
40 /// DataSection - Section directive for standard data.
41 ///
Chris Lattnere6ad12f2009-07-31 18:48:30 +000042 const MCSection *DataSection; // Defaults to ".data".
Chris Lattnerc4c40a92009-07-28 03:13:23 +000043
44
45
46 // FIXME: SINK THESE.
Chris Lattnere6ad12f2009-07-31 18:48:30 +000047 const MCSection *BSSSection_;
Chris Lattnerc4c40a92009-07-28 03:13:23 +000048
49 /// ReadOnlySection - This is the directive that is emitted to switch to a
50 /// read-only section for constant data (e.g. data declared const,
51 /// jump tables).
Chris Lattnere6ad12f2009-07-31 18:48:30 +000052 const MCSection *ReadOnlySection; // Defaults to NULL
Chris Lattnerc4c40a92009-07-28 03:13:23 +000053
54 /// TLSDataSection - Section directive for Thread Local data.
55 ///
Chris Lattnere6ad12f2009-07-31 18:48:30 +000056 const MCSection *TLSDataSection; // Defaults to ".tdata".
Chris Lattnerc4c40a92009-07-28 03:13:23 +000057
58 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
59 /// Null if this target doesn't support a BSS section.
60 ///
Chris Lattnere6ad12f2009-07-31 18:48:30 +000061 const MCSection *TLSBSSSection; // Defaults to ".tbss".
Chris Lattnerc4c40a92009-07-28 03:13:23 +000062
Chris Lattnere6ad12f2009-07-31 18:48:30 +000063 const MCSection *CStringSection_;
Chris Lattnerc4c40a92009-07-28 03:13:23 +000064
65public:
66 // FIXME: NONPUB.
Chris Lattnere6ad12f2009-07-31 18:48:30 +000067 const MCSection *getOrCreateSection(const char *Name,
68 bool isDirective,
Chris Lattner9de48762009-08-01 21:11:14 +000069 SectionKind K) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +000070public:
71
72 virtual ~TargetLoweringObjectFile();
73
Chris Lattner01316272009-07-31 17:42:42 +000074 /// Initialize - this method must be called before any actual lowering is
75 /// done. This specifies the current context for codegen, and gives the
76 /// lowering implementations a chance to set up their default sections.
Chris Lattnere6ad12f2009-07-31 18:48:30 +000077 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
78 Ctx = &ctx;
79 }
Chris Lattner01316272009-07-31 17:42:42 +000080
81
Chris Lattnere6ad12f2009-07-31 18:48:30 +000082 const MCSection *getTextSection() const { return TextSection; }
83 const MCSection *getDataSection() const { return DataSection; }
Chris Lattnerc4c40a92009-07-28 03:13:23 +000084
Chris Lattner84362ac2009-07-31 20:52:39 +000085 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
86 /// decide not to emit the UsedDirective for some symbols in llvm.used.
87 /// FIXME: REMOVE this (rdar://7071300)
88 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
89 Mangler *) const {
90 return (GV!=0);
91 }
Chris Lattnerc4c40a92009-07-28 03:13:23 +000092
93 /// getSectionForMergeableConstant - Given a mergeable constant with the
94 /// specified size and relocation information, return a section that it
95 /// should be placed in.
Chris Lattnere6ad12f2009-07-31 18:48:30 +000096 virtual const MCSection *
Chris Lattnerc4c40a92009-07-28 03:13:23 +000097 getSectionForMergeableConstant(SectionKind Kind) const;
98
99 /// getKindForNamedSection - If this target wants to be able to override
100 /// section flags based on the name of the section specified for a global
101 /// variable, it can implement this. This is used on ELF systems so that
102 /// ".tbss" gets the TLS bit set etc.
Chris Lattner9de48762009-08-01 21:11:14 +0000103 virtual SectionKind getKindForNamedSection(const char *Section,
104 SectionKind K) const {
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000105 return K;
106 }
107
108 /// SectionForGlobal - This method computes the appropriate section to emit
109 /// the specified global variable or function definition. This should not
110 /// be passed external (or available externally) globals.
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000111 const MCSection *SectionForGlobal(const GlobalValue *GV,
112 Mangler *Mang,
113 const TargetMachine &TM) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000114
115 /// getSpecialCasedSectionGlobals - Allow the target to completely override
116 /// section assignment of a global.
117 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
118 /// getFlagsForNamedSection.
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000119 virtual const MCSection *
Chris Lattner2931fe42009-07-29 05:09:30 +0000120 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
Chris Lattnercfd15d82009-08-01 21:46:23 +0000121 SectionKind Kind) const {
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000122 return 0;
123 }
124
125 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
126 /// into a string that can be printed to the assembly file after the
127 /// ".section foo" part of a section directive.
128 virtual void getSectionFlagsAsString(SectionKind Kind,
129 SmallVectorImpl<char> &Str) const {
130 }
131
132protected:
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000133 virtual const MCSection *
Chris Lattnercfd15d82009-08-01 21:46:23 +0000134 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Chris Lattner2931fe42009-07-29 05:09:30 +0000135 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000136};
137
138
139
140
141class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
142 bool AtIsCommentChar; // True if @ is the comment character on this target.
Chris Lattner01316272009-07-31 17:42:42 +0000143 bool HasCrazyBSS;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000144public:
145 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
146 /// is "@".
Chris Lattner01316272009-07-31 17:42:42 +0000147 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000148 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
Chris Lattner01316272009-07-31 17:42:42 +0000149 bool hasCrazyBSS = false)
150 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
151
152 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
153
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000154
155 /// getSectionForMergeableConstant - Given a mergeable constant with the
156 /// specified size and relocation information, return a section that it
157 /// should be placed in.
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000158 virtual const MCSection *
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000159 getSectionForMergeableConstant(SectionKind Kind) const;
160
Chris Lattner9de48762009-08-01 21:11:14 +0000161 virtual SectionKind getKindForNamedSection(const char *Section,
162 SectionKind K) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000163 void getSectionFlagsAsString(SectionKind Kind,
164 SmallVectorImpl<char> &Str) const;
165
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000166 virtual const MCSection *
Chris Lattnercfd15d82009-08-01 21:46:23 +0000167 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Chris Lattner2931fe42009-07-29 05:09:30 +0000168 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000169protected:
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000170 const MCSection *DataRelSection;
171 const MCSection *DataRelLocalSection;
172 const MCSection *DataRelROSection;
173 const MCSection *DataRelROLocalSection;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000174
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000175 const MCSection *MergeableConst4Section;
176 const MCSection *MergeableConst8Section;
177 const MCSection *MergeableConst16Section;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000178};
179
Chris Lattner01316272009-07-31 17:42:42 +0000180
181
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000182class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000183 const MCSection *TextCoalSection;
184 const MCSection *ConstTextCoalSection;
185 const MCSection *ConstDataCoalSection;
186 const MCSection *ConstDataSection;
187 const MCSection *DataCoalSection;
188 const MCSection *FourByteConstantSection;
189 const MCSection *EightByteConstantSection;
190 const MCSection *SixteenByteConstantSection;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000191public:
Chris Lattner01316272009-07-31 17:42:42 +0000192
193 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
194
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000195 virtual const MCSection *
Chris Lattnercfd15d82009-08-01 21:46:23 +0000196 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Chris Lattner2931fe42009-07-29 05:09:30 +0000197 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000198
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000199 virtual const MCSection *
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000200 getSectionForMergeableConstant(SectionKind Kind) const;
Chris Lattner84362ac2009-07-31 20:52:39 +0000201
202 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
203 /// decide not to emit the UsedDirective for some symbols in llvm.used.
204 /// FIXME: REMOVE this (rdar://7071300)
205 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
206 Mangler *) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000207};
208
209
210
211class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
212public:
Chris Lattner01316272009-07-31 17:42:42 +0000213 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
214
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000215 virtual void getSectionFlagsAsString(SectionKind Kind,
216 SmallVectorImpl<char> &Str) const;
217
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000218 virtual const MCSection *
Chris Lattnercfd15d82009-08-01 21:46:23 +0000219 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Chris Lattner2931fe42009-07-29 05:09:30 +0000220 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000221};
222
223} // end namespace llvm
224
225#endif