Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1 | //===-- llvm/Target/TargetLoweringObjectFile.cpp - Object File Info -------===// |
| 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 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/GlobalVariable.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCContext.h" |
| 20 | #include "llvm/MC/MCSection.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
| 22 | #include "llvm/Target/TargetData.h" |
| 23 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Mangler.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
| 26 | using namespace llvm; |
| 27 | |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | // Generic Code |
| 30 | //===----------------------------------------------------------------------===// |
| 31 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 32 | TargetLoweringObjectFile::TargetLoweringObjectFile() : Ctx(0) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 33 | TextSection = 0; |
| 34 | DataSection = 0; |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 35 | BSSSection = 0; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 36 | ReadOnlySection = 0; |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 37 | StaticCtorSection = 0; |
| 38 | StaticDtorSection = 0; |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 39 | LSDASection = 0; |
Chris Lattner | 35039ac | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 40 | EHFrameSection = 0; |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 41 | |
| 42 | DwarfAbbrevSection = 0; |
| 43 | DwarfInfoSection = 0; |
| 44 | DwarfLineSection = 0; |
| 45 | DwarfFrameSection = 0; |
| 46 | DwarfPubNamesSection = 0; |
| 47 | DwarfPubTypesSection = 0; |
| 48 | DwarfDebugInlineSection = 0; |
| 49 | DwarfStrSection = 0; |
| 50 | DwarfLocSection = 0; |
| 51 | DwarfARangesSection = 0; |
| 52 | DwarfRangesSection = 0; |
| 53 | DwarfMacroInfoSection = 0; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | TargetLoweringObjectFile::~TargetLoweringObjectFile() { |
| 57 | } |
| 58 | |
| 59 | static bool isSuitableForBSS(const GlobalVariable *GV) { |
| 60 | Constant *C = GV->getInitializer(); |
| 61 | |
| 62 | // Must have zero initializer. |
| 63 | if (!C->isNullValue()) |
| 64 | return false; |
| 65 | |
| 66 | // Leave constant zeros in readonly constant sections, so they can be shared. |
| 67 | if (GV->isConstant()) |
| 68 | return false; |
| 69 | |
| 70 | // If the global has an explicit section specified, don't put it in BSS. |
| 71 | if (!GV->getSection().empty()) |
| 72 | return false; |
| 73 | |
| 74 | // If -nozero-initialized-in-bss is specified, don't ever use BSS. |
| 75 | if (NoZerosInBSS) |
| 76 | return false; |
| 77 | |
| 78 | // Otherwise, put it in BSS! |
| 79 | return true; |
| 80 | } |
| 81 | |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 82 | /// IsNullTerminatedString - Return true if the specified constant (which is |
| 83 | /// known to have a type that is an array of 1/2/4 byte elements) ends with a |
| 84 | /// nul value and contains no other nuls in it. |
| 85 | static bool IsNullTerminatedString(const Constant *C) { |
| 86 | const ArrayType *ATy = cast<ArrayType>(C->getType()); |
| 87 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 88 | // First check: is we have constant array of i8 terminated with zero |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 89 | if (const ConstantArray *CVA = dyn_cast<ConstantArray>(C)) { |
| 90 | if (ATy->getNumElements() == 0) return false; |
| 91 | |
| 92 | ConstantInt *Null = |
| 93 | dyn_cast<ConstantInt>(CVA->getOperand(ATy->getNumElements()-1)); |
| 94 | if (Null == 0 || Null->getZExtValue() != 0) |
| 95 | return false; // Not null terminated. |
| 96 | |
| 97 | // Verify that the null doesn't occur anywhere else in the string. |
| 98 | for (unsigned i = 0, e = ATy->getNumElements()-1; i != e; ++i) |
| 99 | // Reject constantexpr elements etc. |
| 100 | if (!isa<ConstantInt>(CVA->getOperand(i)) || |
| 101 | CVA->getOperand(i) == Null) |
| 102 | return false; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 103 | return true; |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 104 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 105 | |
| 106 | // Another possibility: [1 x i8] zeroinitializer |
| 107 | if (isa<ConstantAggregateZero>(C)) |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 108 | return ATy->getNumElements() == 1; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 109 | |
| 110 | return false; |
| 111 | } |
| 112 | |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 113 | /// getKindForGlobal - This is a top-level target-independent classifier for |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 114 | /// a global variable. Given an global variable and information from TM, it |
| 115 | /// classifies the global in a variety of ways that make various target |
| 116 | /// implementations simpler. The target implementation is free to ignore this |
| 117 | /// extra info of course. |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 118 | SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV, |
| 119 | const TargetMachine &TM){ |
| 120 | assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() && |
| 121 | "Can only be used for global definitions"); |
| 122 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 123 | Reloc::Model ReloModel = TM.getRelocationModel(); |
| 124 | |
| 125 | // Early exit - functions should be always in text sections. |
| 126 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); |
| 127 | if (GVar == 0) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 128 | return SectionKind::getText(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 129 | |
| 130 | |
| 131 | // Handle thread-local data first. |
| 132 | if (GVar->isThreadLocal()) { |
| 133 | if (isSuitableForBSS(GVar)) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 134 | return SectionKind::getThreadBSS(); |
| 135 | return SectionKind::getThreadData(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // Variable can be easily put to BSS section. |
| 139 | if (isSuitableForBSS(GVar)) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 140 | return SectionKind::getBSS(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 141 | |
| 142 | Constant *C = GVar->getInitializer(); |
| 143 | |
| 144 | // If the global is marked constant, we can put it into a mergable section, |
| 145 | // a mergable string section, or general .data if it contains relocations. |
| 146 | if (GVar->isConstant()) { |
| 147 | // If the initializer for the global contains something that requires a |
| 148 | // relocation, then we may have to drop this into a wriable data section |
| 149 | // even though it is marked const. |
| 150 | switch (C->getRelocationInfo()) { |
| 151 | default: llvm_unreachable("unknown relocation info kind"); |
| 152 | case Constant::NoRelocation: |
| 153 | // If initializer is a null-terminated string, put it in a "cstring" |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 154 | // section of the right width. |
| 155 | if (const ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) { |
| 156 | if (const IntegerType *ITy = |
| 157 | dyn_cast<IntegerType>(ATy->getElementType())) { |
| 158 | if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 || |
| 159 | ITy->getBitWidth() == 32) && |
| 160 | IsNullTerminatedString(C)) { |
| 161 | if (ITy->getBitWidth() == 8) |
| 162 | return SectionKind::getMergeable1ByteCString(); |
| 163 | if (ITy->getBitWidth() == 16) |
| 164 | return SectionKind::getMergeable2ByteCString(); |
| 165 | |
| 166 | assert(ITy->getBitWidth() == 32 && "Unknown width"); |
| 167 | return SectionKind::getMergeable4ByteCString(); |
| 168 | } |
| 169 | } |
| 170 | } |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 171 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 172 | // Otherwise, just drop it into a mergable constant section. If we have |
| 173 | // a section for this size, use it, otherwise use the arbitrary sized |
| 174 | // mergable section. |
| 175 | switch (TM.getTargetData()->getTypeAllocSize(C->getType())) { |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 176 | case 4: return SectionKind::getMergeableConst4(); |
| 177 | case 8: return SectionKind::getMergeableConst8(); |
| 178 | case 16: return SectionKind::getMergeableConst16(); |
| 179 | default: return SectionKind::getMergeableConst(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | case Constant::LocalRelocation: |
| 183 | // In static relocation model, the linker will resolve all addresses, so |
| 184 | // the relocation entries will actually be constants by the time the app |
| 185 | // starts up. However, we can't put this into a mergable section, because |
| 186 | // the linker doesn't take relocations into consideration when it tries to |
| 187 | // merge entries in the section. |
| 188 | if (ReloModel == Reloc::Static) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 189 | return SectionKind::getReadOnly(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 190 | |
| 191 | // Otherwise, the dynamic linker needs to fix it up, put it in the |
| 192 | // writable data.rel.local section. |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 193 | return SectionKind::getReadOnlyWithRelLocal(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 194 | |
| 195 | case Constant::GlobalRelocations: |
| 196 | // In static relocation model, the linker will resolve all addresses, so |
| 197 | // the relocation entries will actually be constants by the time the app |
| 198 | // starts up. However, we can't put this into a mergable section, because |
| 199 | // the linker doesn't take relocations into consideration when it tries to |
| 200 | // merge entries in the section. |
| 201 | if (ReloModel == Reloc::Static) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 202 | return SectionKind::getReadOnly(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 203 | |
| 204 | // Otherwise, the dynamic linker needs to fix it up, put it in the |
| 205 | // writable data.rel section. |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 206 | return SectionKind::getReadOnlyWithRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
| 210 | // Okay, this isn't a constant. If the initializer for the global is going |
| 211 | // to require a runtime relocation by the dynamic linker, put it into a more |
| 212 | // specific section to improve startup time of the app. This coalesces these |
| 213 | // globals together onto fewer pages, improving the locality of the dynamic |
| 214 | // linker. |
| 215 | if (ReloModel == Reloc::Static) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 216 | return SectionKind::getDataNoRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 217 | |
| 218 | switch (C->getRelocationInfo()) { |
| 219 | default: llvm_unreachable("unknown relocation info kind"); |
| 220 | case Constant::NoRelocation: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 221 | return SectionKind::getDataNoRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 222 | case Constant::LocalRelocation: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 223 | return SectionKind::getDataRelLocal(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 224 | case Constant::GlobalRelocations: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 225 | return SectionKind::getDataRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | /// SectionForGlobal - This method computes the appropriate section to emit |
| 230 | /// the specified global variable or function definition. This should not |
| 231 | /// be passed external (or available externally) globals. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 232 | const MCSection *TargetLoweringObjectFile:: |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 233 | SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 234 | const TargetMachine &TM) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 235 | // Select section name. |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 236 | if (GV->hasSection()) |
| 237 | return getExplicitSectionGlobal(GV, Kind, Mang, TM); |
| 238 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 239 | |
| 240 | // Use default section depending on the 'type' of global |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 241 | return SelectSectionForGlobal(GV, Kind, Mang, TM); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 244 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 245 | // Lame default implementation. Calculate the section name for global. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 246 | const MCSection * |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 247 | TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV, |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 248 | SectionKind Kind, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 249 | Mangler *Mang, |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 250 | const TargetMachine &TM) const{ |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 251 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 252 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 253 | if (Kind.isText()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 254 | return getTextSection(); |
| 255 | |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 256 | if (Kind.isBSS() && BSSSection != 0) |
| 257 | return BSSSection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 258 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 259 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 260 | return ReadOnlySection; |
| 261 | |
| 262 | return getDataSection(); |
| 263 | } |
| 264 | |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 265 | /// getSectionForConstant - Given a mergable constant with the |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 266 | /// specified size and relocation information, return a section that it |
| 267 | /// should be placed in. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 268 | const MCSection * |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 269 | TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 270 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
| 271 | return ReadOnlySection; |
| 272 | |
| 273 | return DataSection; |
| 274 | } |
| 275 | |
| 276 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 277 | |
| 278 | //===----------------------------------------------------------------------===// |
| 279 | // ELF |
| 280 | //===----------------------------------------------------------------------===// |
| 281 | |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame^] | 282 | const MCSection *TargetLoweringObjectFileELF:: |
| 283 | getOrCreateSection(const char *Name, bool isDirective, SectionKind Kind) const { |
| 284 | if (MCSection *S = getContext().GetSection(Name)) |
| 285 | return S; |
| 286 | return MCSection::Create(Name, isDirective, Kind, getContext()); |
| 287 | } |
| 288 | |
Chris Lattner | f26e03b | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 289 | void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, |
| 290 | const TargetMachine &TM) { |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 291 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 292 | if (!HasCrazyBSS) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 293 | BSSSection = getOrCreateSection("\t.bss", true, SectionKind::getBSS()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 294 | else |
| 295 | // PPC/Linux doesn't support the .bss directive, it needs .section .bss. |
| 296 | // FIXME: Does .section .bss work everywhere?? |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 297 | // FIXME2: this should just be handle by the section printer. We should get |
| 298 | // away from syntactic view of the sections and MCSection should just be a |
| 299 | // semantic view. |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 300 | BSSSection = getOrCreateSection("\t.bss", false, SectionKind::getBSS()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 301 | |
| 302 | |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 303 | TextSection = getOrCreateSection("\t.text", true, SectionKind::getText()); |
| 304 | DataSection = getOrCreateSection("\t.data", true, SectionKind::getDataRel()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 305 | ReadOnlySection = |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 306 | getOrCreateSection("\t.rodata", false, SectionKind::getReadOnly()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 307 | TLSDataSection = |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 308 | getOrCreateSection("\t.tdata", false, SectionKind::getThreadData()); |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 309 | |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 310 | TLSBSSSection = getOrCreateSection("\t.tbss", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 311 | SectionKind::getThreadBSS()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 312 | |
| 313 | DataRelSection = getOrCreateSection("\t.data.rel", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 314 | SectionKind::getDataRel()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 315 | DataRelLocalSection = getOrCreateSection("\t.data.rel.local", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 316 | SectionKind::getDataRelLocal()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 317 | DataRelROSection = getOrCreateSection("\t.data.rel.ro", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 318 | SectionKind::getReadOnlyWithRel()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 319 | DataRelROLocalSection = |
| 320 | getOrCreateSection("\t.data.rel.ro.local", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 321 | SectionKind::getReadOnlyWithRelLocal()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 322 | |
| 323 | MergeableConst4Section = getOrCreateSection(".rodata.cst4", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 324 | SectionKind::getMergeableConst4()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 325 | MergeableConst8Section = getOrCreateSection(".rodata.cst8", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 326 | SectionKind::getMergeableConst8()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 327 | MergeableConst16Section = getOrCreateSection(".rodata.cst16", false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 328 | SectionKind::getMergeableConst16()); |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 329 | |
| 330 | StaticCtorSection = |
| 331 | getOrCreateSection(".ctors", false, SectionKind::getDataRel()); |
| 332 | StaticDtorSection = |
| 333 | getOrCreateSection(".dtors", false, SectionKind::getDataRel()); |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 334 | |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 335 | // Exception Handling Sections. |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 336 | |
| 337 | // FIXME: We're emitting LSDA info into a readonly section on ELF, even though |
| 338 | // it contains relocatable pointers. In PIC mode, this is probably a big |
| 339 | // runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 340 | // adjusted or this should be a data section. |
| 341 | LSDASection = |
| 342 | getOrCreateSection(".gcc_except_table", false, SectionKind::getReadOnly()); |
Chris Lattner | 35039ac | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 343 | EHFrameSection = |
| 344 | getOrCreateSection(".eh_frame", false, SectionKind::getDataRel()); |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 345 | |
| 346 | // Debug Info Sections. |
| 347 | DwarfAbbrevSection = |
| 348 | getOrCreateSection(".debug_abbrev", false, SectionKind::getMetadata()); |
| 349 | DwarfInfoSection = |
| 350 | getOrCreateSection(".debug_info", false, SectionKind::getMetadata()); |
| 351 | DwarfLineSection = |
| 352 | getOrCreateSection(".debug_line", false, SectionKind::getMetadata()); |
| 353 | DwarfFrameSection = |
| 354 | getOrCreateSection(".debug_frame", false, SectionKind::getMetadata()); |
| 355 | DwarfPubNamesSection = |
| 356 | getOrCreateSection(".debug_pubnames", false, SectionKind::getMetadata()); |
| 357 | DwarfPubTypesSection = |
| 358 | getOrCreateSection(".debug_pubtypes", false, SectionKind::getMetadata()); |
| 359 | DwarfStrSection = |
| 360 | getOrCreateSection(".debug_str", false, SectionKind::getMetadata()); |
| 361 | DwarfLocSection = |
| 362 | getOrCreateSection(".debug_loc", false, SectionKind::getMetadata()); |
| 363 | DwarfARangesSection = |
| 364 | getOrCreateSection(".debug_aranges", false, SectionKind::getMetadata()); |
| 365 | DwarfRangesSection = |
| 366 | getOrCreateSection(".debug_ranges", false, SectionKind::getMetadata()); |
| 367 | DwarfMacroInfoSection = |
| 368 | getOrCreateSection(".debug_macinfo", false, SectionKind::getMetadata()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 372 | static SectionKind |
| 373 | getELFKindForNamedSection(const char *Name, SectionKind K) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 374 | if (Name[0] != '.') return K; |
| 375 | |
| 376 | // Some lame default implementation based on some magic section names. |
| 377 | if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 || |
| 378 | strncmp(Name, ".llvm.linkonce.b.", 17) == 0 || |
| 379 | strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 || |
| 380 | strncmp(Name, ".llvm.linkonce.sb.", 18) == 0) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 381 | return SectionKind::getBSS(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 382 | |
| 383 | if (strcmp(Name, ".tdata") == 0 || |
| 384 | strncmp(Name, ".tdata.", 7) == 0 || |
| 385 | strncmp(Name, ".gnu.linkonce.td.", 17) == 0 || |
| 386 | strncmp(Name, ".llvm.linkonce.td.", 18) == 0) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 387 | return SectionKind::getThreadData(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 388 | |
| 389 | if (strcmp(Name, ".tbss") == 0 || |
| 390 | strncmp(Name, ".tbss.", 6) == 0 || |
| 391 | strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 || |
| 392 | strncmp(Name, ".llvm.linkonce.tb.", 18) == 0) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 393 | return SectionKind::getThreadBSS(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 394 | |
| 395 | return K; |
| 396 | } |
| 397 | |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 398 | const MCSection *TargetLoweringObjectFileELF:: |
| 399 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 400 | Mangler *Mang, const TargetMachine &TM) const { |
| 401 | // Infer section flags from the section name if we can. |
| 402 | Kind = getELFKindForNamedSection(GV->getSection().c_str(), Kind); |
| 403 | |
| 404 | return getOrCreateSection(GV->getSection().c_str(), false, Kind); |
| 405 | } |
| 406 | |
| 407 | |
| 408 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 409 | void TargetLoweringObjectFileELF:: |
| 410 | getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const { |
| 411 | Str.push_back(','); |
| 412 | Str.push_back('"'); |
| 413 | |
| 414 | if (!Kind.isMetadata()) |
| 415 | Str.push_back('a'); |
| 416 | if (Kind.isText()) |
| 417 | Str.push_back('x'); |
| 418 | if (Kind.isWriteable()) |
| 419 | Str.push_back('w'); |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 420 | if (Kind.isMergeable1ByteCString() || |
| 421 | Kind.isMergeable2ByteCString() || |
| 422 | Kind.isMergeable4ByteCString() || |
Chris Lattner | 82987bf | 2009-07-31 16:17:13 +0000 | [diff] [blame] | 423 | Kind.isMergeableConst4() || |
| 424 | Kind.isMergeableConst8() || |
| 425 | Kind.isMergeableConst16()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 426 | Str.push_back('M'); |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 427 | if (Kind.isMergeable1ByteCString() || |
| 428 | Kind.isMergeable2ByteCString() || |
| 429 | Kind.isMergeable4ByteCString()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 430 | Str.push_back('S'); |
| 431 | if (Kind.isThreadLocal()) |
| 432 | Str.push_back('T'); |
| 433 | |
| 434 | Str.push_back('"'); |
| 435 | Str.push_back(','); |
| 436 | |
| 437 | // If comment string is '@', e.g. as on ARM - use '%' instead |
| 438 | if (AtIsCommentChar) |
| 439 | Str.push_back('%'); |
| 440 | else |
| 441 | Str.push_back('@'); |
| 442 | |
| 443 | const char *KindStr; |
Chris Lattner | bf15e43 | 2009-07-28 17:57:51 +0000 | [diff] [blame] | 444 | if (Kind.isBSS() || Kind.isThreadBSS()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 445 | KindStr = "nobits"; |
| 446 | else |
| 447 | KindStr = "progbits"; |
| 448 | |
| 449 | Str.append(KindStr, KindStr+strlen(KindStr)); |
| 450 | |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 451 | if (Kind.isMergeable1ByteCString()) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 452 | Str.push_back(','); |
| 453 | Str.push_back('1'); |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 454 | } else if (Kind.isMergeable2ByteCString()) { |
| 455 | Str.push_back(','); |
| 456 | Str.push_back('2'); |
| 457 | } else if (Kind.isMergeable4ByteCString()) { |
| 458 | Str.push_back(','); |
| 459 | Str.push_back('4'); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 460 | } else if (Kind.isMergeableConst4()) { |
| 461 | Str.push_back(','); |
| 462 | Str.push_back('4'); |
| 463 | } else if (Kind.isMergeableConst8()) { |
| 464 | Str.push_back(','); |
| 465 | Str.push_back('8'); |
| 466 | } else if (Kind.isMergeableConst16()) { |
| 467 | Str.push_back(','); |
| 468 | Str.push_back('1'); |
| 469 | Str.push_back('6'); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | |
| 474 | static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) { |
| 475 | if (Kind.isText()) return ".gnu.linkonce.t."; |
| 476 | if (Kind.isReadOnly()) return ".gnu.linkonce.r."; |
| 477 | |
| 478 | if (Kind.isThreadData()) return ".gnu.linkonce.td."; |
| 479 | if (Kind.isThreadBSS()) return ".gnu.linkonce.tb."; |
| 480 | |
| 481 | if (Kind.isBSS()) return ".gnu.linkonce.b."; |
| 482 | if (Kind.isDataNoRel()) return ".gnu.linkonce.d."; |
| 483 | if (Kind.isDataRelLocal()) return ".gnu.linkonce.d.rel.local."; |
| 484 | if (Kind.isDataRel()) return ".gnu.linkonce.d.rel."; |
| 485 | if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local."; |
| 486 | |
| 487 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 488 | return ".gnu.linkonce.d.rel.ro."; |
| 489 | } |
| 490 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 491 | const MCSection *TargetLoweringObjectFileELF:: |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 492 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 493 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 494 | |
| 495 | // If this global is linkonce/weak and the target handles this by emitting it |
| 496 | // into a 'uniqued' section name, create and return the section now. |
Chris Lattner | 27602b8 | 2009-08-01 21:42:58 +0000 | [diff] [blame] | 497 | if (GV->isWeakForLinker()) { |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 498 | const char *Prefix = getSectionPrefixForUniqueGlobal(Kind); |
Chris Lattner | b8f396b | 2009-07-29 05:20:33 +0000 | [diff] [blame] | 499 | std::string Name = Mang->makeNameProper(GV->getNameStr()); |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 500 | return getOrCreateSection((Prefix+Name).c_str(), false, Kind); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 503 | if (Kind.isText()) return TextSection; |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 504 | |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 505 | if (Kind.isMergeable1ByteCString() || |
| 506 | Kind.isMergeable2ByteCString() || |
| 507 | Kind.isMergeable4ByteCString()) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 508 | |
Chris Lattner | 067fe1a | 2009-07-29 04:54:38 +0000 | [diff] [blame] | 509 | // We also need alignment here. |
| 510 | // FIXME: this is getting the alignment of the character, not the |
| 511 | // alignment of the global! |
| 512 | unsigned Align = |
| 513 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 514 | |
Chris Lattner | 7e88a50 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 515 | const char *SizeSpec = ".rodata.str1."; |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 516 | if (Kind.isMergeable2ByteCString()) |
Chris Lattner | 7e88a50 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 517 | SizeSpec = ".rodata.str2."; |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 518 | else if (Kind.isMergeable4ByteCString()) |
Chris Lattner | 7e88a50 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 519 | SizeSpec = ".rodata.str4."; |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 520 | else |
| 521 | assert(Kind.isMergeable1ByteCString() && "unknown string width"); |
| 522 | |
| 523 | |
Chris Lattner | 7e88a50 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 524 | std::string Name = SizeSpec + utostr(Align); |
Chris Lattner | 3b24c01 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 525 | return getOrCreateSection(Name.c_str(), false, Kind); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 528 | if (Kind.isMergeableConst()) { |
| 529 | if (Kind.isMergeableConst4()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 530 | return MergeableConst4Section; |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 531 | if (Kind.isMergeableConst8()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 532 | return MergeableConst8Section; |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 533 | if (Kind.isMergeableConst16()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 534 | return MergeableConst16Section; |
| 535 | return ReadOnlySection; // .const |
| 536 | } |
| 537 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 538 | if (Kind.isReadOnly()) return ReadOnlySection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 539 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 540 | if (Kind.isThreadData()) return TLSDataSection; |
| 541 | if (Kind.isThreadBSS()) return TLSBSSSection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 542 | |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 543 | if (Kind.isBSS()) return BSSSection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 544 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 545 | if (Kind.isDataNoRel()) return DataSection; |
| 546 | if (Kind.isDataRelLocal()) return DataRelLocalSection; |
| 547 | if (Kind.isDataRel()) return DataRelSection; |
| 548 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 549 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 550 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 551 | return DataRelROSection; |
| 552 | } |
| 553 | |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 554 | /// getSectionForConstant - Given a mergeable constant with the |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 555 | /// specified size and relocation information, return a section that it |
| 556 | /// should be placed in. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 557 | const MCSection *TargetLoweringObjectFileELF:: |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 558 | getSectionForConstant(SectionKind Kind) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 559 | if (Kind.isMergeableConst4()) |
| 560 | return MergeableConst4Section; |
| 561 | if (Kind.isMergeableConst8()) |
| 562 | return MergeableConst8Section; |
| 563 | if (Kind.isMergeableConst16()) |
| 564 | return MergeableConst16Section; |
| 565 | if (Kind.isReadOnly()) |
| 566 | return ReadOnlySection; |
| 567 | |
| 568 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
| 569 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 570 | return DataRelROSection; |
| 571 | } |
| 572 | |
| 573 | //===----------------------------------------------------------------------===// |
| 574 | // MachO |
| 575 | //===----------------------------------------------------------------------===// |
| 576 | |
Chris Lattner | 11e9657 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 577 | const MCSection *TargetLoweringObjectFileMachO:: |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame^] | 578 | getOrCreateSection(const char *Name, bool isDirective, SectionKind Kind) const { |
| 579 | if (MCSection *S = getContext().GetSection(Name)) |
| 580 | return S; |
| 581 | return MCSection::Create(Name, isDirective, Kind, getContext()); |
| 582 | } |
| 583 | |
| 584 | const MCSection *TargetLoweringObjectFileMachO:: |
Chris Lattner | 11e9657 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 585 | getMachOSection(const char *Name, bool isDirective, SectionKind K) { |
| 586 | // FOR NOW, Just forward. |
| 587 | return getOrCreateSection(Name, isDirective, K); |
| 588 | } |
| 589 | |
| 590 | |
| 591 | |
Chris Lattner | f26e03b | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 592 | void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, |
| 593 | const TargetMachine &TM) { |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 594 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 595 | TextSection = getOrCreateSection("\t.text", true, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 596 | SectionKind::getText()); |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 597 | DataSection = getOrCreateSection("\t.data", true, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 598 | SectionKind::getDataRel()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 599 | |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 600 | CStringSection = getOrCreateSection("\t.cstring", true, |
Chris Lattner | ec40975 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 601 | SectionKind::getMergeable1ByteCString()); |
| 602 | UStringSection = getOrCreateSection("__TEXT,__ustring", false, |
| 603 | SectionKind::getMergeable2ByteCString()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 604 | FourByteConstantSection = getOrCreateSection("\t.literal4\n", true, |
Chris Lattner | ec40975 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 605 | SectionKind::getMergeableConst4()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 606 | EightByteConstantSection = getOrCreateSection("\t.literal8\n", true, |
Chris Lattner | ec40975 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 607 | SectionKind::getMergeableConst8()); |
Chris Lattner | 4bb253c | 2009-07-28 17:50:28 +0000 | [diff] [blame] | 608 | |
| 609 | // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back |
| 610 | // to using it in -static mode. |
| 611 | if (TM.getRelocationModel() != Reloc::Static && |
| 612 | TM.getTargetData()->getPointerSize() == 32) |
| 613 | SixteenByteConstantSection = |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 614 | getOrCreateSection("\t.literal16\n", true, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 615 | SectionKind::getMergeableConst16()); |
Chris Lattner | 4bb253c | 2009-07-28 17:50:28 +0000 | [diff] [blame] | 616 | else |
| 617 | SixteenByteConstantSection = 0; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 618 | |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 619 | ReadOnlySection = getOrCreateSection("\t.const", true, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 620 | SectionKind::getReadOnly()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 621 | |
| 622 | TextCoalSection = |
| 623 | getOrCreateSection("\t__TEXT,__textcoal_nt,coalesced,pure_instructions", |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 624 | false, SectionKind::getText()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 625 | ConstTextCoalSection = getOrCreateSection("\t__TEXT,__const_coal,coalesced", |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 626 | false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 627 | SectionKind::getText()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 628 | ConstDataCoalSection = getOrCreateSection("\t__DATA,__const_coal,coalesced", |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 629 | false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 630 | SectionKind::getText()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 631 | ConstDataSection = getOrCreateSection("\t.const_data", true, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 632 | SectionKind::getReadOnlyWithRel()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 633 | DataCoalSection = getOrCreateSection("\t__DATA,__datacoal_nt,coalesced", |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 634 | false, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 635 | SectionKind::getDataRel()); |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 636 | |
| 637 | if (TM.getRelocationModel() == Reloc::Static) { |
| 638 | StaticCtorSection = |
| 639 | getOrCreateSection(".constructor", true, SectionKind::getDataRel()); |
| 640 | StaticDtorSection = |
| 641 | getOrCreateSection(".destructor", true, SectionKind::getDataRel()); |
| 642 | } else { |
| 643 | StaticCtorSection = |
| 644 | getOrCreateSection(".mod_init_func", true, SectionKind::getDataRel()); |
| 645 | StaticDtorSection = |
| 646 | getOrCreateSection(".mod_term_func", true, SectionKind::getDataRel()); |
| 647 | } |
| 648 | |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 649 | // Exception Handling. |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 650 | LSDASection = getOrCreateSection("__DATA,__gcc_except_tab", false, |
| 651 | SectionKind::getDataRel()); |
Chris Lattner | 35039ac | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 652 | EHFrameSection = |
| 653 | getOrCreateSection("__TEXT,__eh_frame,coalesced,no_toc+strip_static_syms" |
| 654 | "+live_support", false, SectionKind::getReadOnly()); |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 655 | |
| 656 | // Debug Information. |
| 657 | // FIXME: Don't use 'directive' syntax: need flags for debug/regular?? |
| 658 | // FIXME: Need __DWARF segment. |
| 659 | DwarfAbbrevSection = |
| 660 | getOrCreateSection(".section __DWARF,__debug_abbrev,regular,debug", true, |
| 661 | SectionKind::getMetadata()); |
| 662 | DwarfInfoSection = |
| 663 | getOrCreateSection(".section __DWARF,__debug_info,regular,debug", true, |
| 664 | SectionKind::getMetadata()); |
| 665 | DwarfLineSection = |
| 666 | getOrCreateSection(".section __DWARF,__debug_line,regular,debug", true, |
| 667 | SectionKind::getMetadata()); |
| 668 | DwarfFrameSection = |
| 669 | getOrCreateSection(".section __DWARF,__debug_frame,regular,debug", true, |
| 670 | SectionKind::getMetadata()); |
| 671 | DwarfPubNamesSection = |
| 672 | getOrCreateSection(".section __DWARF,__debug_pubnames,regular,debug", true, |
| 673 | SectionKind::getMetadata()); |
| 674 | DwarfPubTypesSection = |
| 675 | getOrCreateSection(".section __DWARF,__debug_pubtypes,regular,debug", true, |
| 676 | SectionKind::getMetadata()); |
| 677 | DwarfStrSection = |
| 678 | getOrCreateSection(".section __DWARF,__debug_str,regular,debug", true, |
| 679 | SectionKind::getMetadata()); |
| 680 | DwarfLocSection = |
| 681 | getOrCreateSection(".section __DWARF,__debug_loc,regular,debug", true, |
| 682 | SectionKind::getMetadata()); |
| 683 | DwarfARangesSection = |
| 684 | getOrCreateSection(".section __DWARF,__debug_aranges,regular,debug", true, |
| 685 | SectionKind::getMetadata()); |
| 686 | DwarfRangesSection = |
| 687 | getOrCreateSection(".section __DWARF,__debug_ranges,regular,debug", true, |
| 688 | SectionKind::getMetadata()); |
| 689 | DwarfMacroInfoSection = |
| 690 | getOrCreateSection(".section __DWARF,__debug_macinfo,regular,debug", true, |
| 691 | SectionKind::getMetadata()); |
| 692 | DwarfDebugInlineSection = |
| 693 | getOrCreateSection(".section __DWARF,__debug_inlined,regular,debug", true, |
| 694 | SectionKind::getMetadata()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 697 | const MCSection *TargetLoweringObjectFileMachO:: |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 698 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 699 | Mangler *Mang, const TargetMachine &TM) const { |
| 700 | return getOrCreateSection(GV->getSection().c_str(), false, Kind); |
| 701 | } |
| 702 | |
| 703 | const MCSection *TargetLoweringObjectFileMachO:: |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 704 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 705 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 706 | assert(!Kind.isThreadLocal() && "Darwin doesn't support TLS"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 707 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 708 | if (Kind.isText()) |
Chris Lattner | 27602b8 | 2009-08-01 21:42:58 +0000 | [diff] [blame] | 709 | return GV->isWeakForLinker() ? TextCoalSection : TextSection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 710 | |
| 711 | // If this is weak/linkonce, put this in a coalescable section, either in text |
| 712 | // or data depending on if it is writable. |
Chris Lattner | 27602b8 | 2009-08-01 21:42:58 +0000 | [diff] [blame] | 713 | if (GV->isWeakForLinker()) { |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 714 | if (Kind.isReadOnly()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 715 | return ConstTextCoalSection; |
| 716 | return DataCoalSection; |
| 717 | } |
| 718 | |
| 719 | // FIXME: Alignment check should be handled by section classifier. |
Chris Lattner | ec40975 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 720 | if (Kind.isMergeable1ByteCString() || |
| 721 | Kind.isMergeable2ByteCString()) { |
| 722 | if (TM.getTargetData()->getPreferredAlignment( |
| 723 | cast<GlobalVariable>(GV)) < 32) { |
| 724 | if (Kind.isMergeable1ByteCString()) |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 725 | return CStringSection; |
Chris Lattner | ec40975 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 726 | assert(Kind.isMergeable2ByteCString()); |
| 727 | return UStringSection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 728 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 731 | if (Kind.isMergeableConst()) { |
| 732 | if (Kind.isMergeableConst4()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 733 | return FourByteConstantSection; |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 734 | if (Kind.isMergeableConst8()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 735 | return EightByteConstantSection; |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 736 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 737 | return SixteenByteConstantSection; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 738 | } |
Chris Lattner | ec40975 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 739 | |
| 740 | // Otherwise, if it is readonly, but not something we can specially optimize, |
| 741 | // just drop it in .const. |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 742 | if (Kind.isReadOnly()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 743 | return ReadOnlySection; |
| 744 | |
| 745 | // If this is marked const, put it into a const section. But if the dynamic |
| 746 | // linker needs to write to it, put it in the data segment. |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 747 | if (Kind.isReadOnlyWithRel()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 748 | return ConstDataSection; |
| 749 | |
| 750 | // Otherwise, just drop the variable in the normal data section. |
| 751 | return DataSection; |
| 752 | } |
| 753 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 754 | const MCSection * |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 755 | TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 756 | // If this constant requires a relocation, we have to put it in the data |
| 757 | // segment, not in the text segment. |
| 758 | if (Kind.isDataRel()) |
| 759 | return ConstDataSection; |
| 760 | |
| 761 | if (Kind.isMergeableConst4()) |
| 762 | return FourByteConstantSection; |
| 763 | if (Kind.isMergeableConst8()) |
| 764 | return EightByteConstantSection; |
Chris Lattner | 4bb253c | 2009-07-28 17:50:28 +0000 | [diff] [blame] | 765 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 766 | return SixteenByteConstantSection; |
| 767 | return ReadOnlySection; // .const |
| 768 | } |
| 769 | |
Chris Lattner | 26630c1 | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 770 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively decide |
| 771 | /// not to emit the UsedDirective for some symbols in llvm.used. |
| 772 | // FIXME: REMOVE this (rdar://7071300) |
| 773 | bool TargetLoweringObjectFileMachO:: |
| 774 | shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const { |
| 775 | /// On Darwin, internally linked data beginning with "L" or "l" does not have |
| 776 | /// the directive emitted (this occurs in ObjC metadata). |
| 777 | if (!GV) return false; |
| 778 | |
| 779 | // Check whether the mangled name has the "Private" or "LinkerPrivate" prefix. |
| 780 | if (GV->hasLocalLinkage() && !isa<Function>(GV)) { |
| 781 | // FIXME: ObjC metadata is currently emitted as internal symbols that have |
| 782 | // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and |
| 783 | // this horrible hack can go away. |
| 784 | const std::string &Name = Mang->getMangledName(GV); |
| 785 | if (Name[0] == 'L' || Name[0] == 'l') |
| 786 | return false; |
| 787 | } |
| 788 | |
| 789 | return true; |
| 790 | } |
| 791 | |
| 792 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 793 | //===----------------------------------------------------------------------===// |
| 794 | // COFF |
| 795 | //===----------------------------------------------------------------------===// |
| 796 | |
Chris Lattner | 11e9657 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 797 | const MCSection *TargetLoweringObjectFileCOFF:: |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame^] | 798 | getOrCreateSection(const char *Name, bool isDirective, SectionKind Kind) const { |
| 799 | if (MCSection *S = getContext().GetSection(Name)) |
| 800 | return S; |
| 801 | return MCSection::Create(Name, isDirective, Kind, getContext()); |
| 802 | } |
| 803 | |
| 804 | const MCSection *TargetLoweringObjectFileCOFF:: |
Chris Lattner | 11e9657 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 805 | getCOFFSection(const char *Name, bool isDirective, SectionKind K) { |
| 806 | return getOrCreateSection(Name, isDirective, K); |
| 807 | } |
| 808 | |
Chris Lattner | f26e03b | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 809 | void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx, |
| 810 | const TargetMachine &TM) { |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 811 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 812 | TextSection = getOrCreateSection("\t.text", true, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 813 | SectionKind::getText()); |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 814 | DataSection = getOrCreateSection("\t.data", true, |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 815 | SectionKind::getDataRel()); |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 816 | StaticCtorSection = |
| 817 | getOrCreateSection(".ctors", false, SectionKind::getDataRel()); |
| 818 | StaticDtorSection = |
| 819 | getOrCreateSection(".dtors", false, SectionKind::getDataRel()); |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 820 | |
| 821 | |
| 822 | // Debug info. |
| 823 | // FIXME: Don't use 'directive' mode here. |
| 824 | DwarfAbbrevSection = |
| 825 | getOrCreateSection("\t.section\t.debug_abbrev,\"dr\"", |
| 826 | true, SectionKind::getMetadata()); |
| 827 | DwarfInfoSection = |
| 828 | getOrCreateSection("\t.section\t.debug_info,\"dr\"", |
| 829 | true, SectionKind::getMetadata()); |
| 830 | DwarfLineSection = |
| 831 | getOrCreateSection("\t.section\t.debug_line,\"dr\"", |
| 832 | true, SectionKind::getMetadata()); |
| 833 | DwarfFrameSection = |
| 834 | getOrCreateSection("\t.section\t.debug_frame,\"dr\"", |
| 835 | true, SectionKind::getMetadata()); |
| 836 | DwarfPubNamesSection = |
| 837 | getOrCreateSection("\t.section\t.debug_pubnames,\"dr\"", |
| 838 | true, SectionKind::getMetadata()); |
| 839 | DwarfPubTypesSection = |
| 840 | getOrCreateSection("\t.section\t.debug_pubtypes,\"dr\"", |
| 841 | true, SectionKind::getMetadata()); |
| 842 | DwarfStrSection = |
| 843 | getOrCreateSection("\t.section\t.debug_str,\"dr\"", |
| 844 | true, SectionKind::getMetadata()); |
| 845 | DwarfLocSection = |
| 846 | getOrCreateSection("\t.section\t.debug_loc,\"dr\"", |
| 847 | true, SectionKind::getMetadata()); |
| 848 | DwarfARangesSection = |
| 849 | getOrCreateSection("\t.section\t.debug_aranges,\"dr\"", |
| 850 | true, SectionKind::getMetadata()); |
| 851 | DwarfRangesSection = |
| 852 | getOrCreateSection("\t.section\t.debug_ranges,\"dr\"", |
| 853 | true, SectionKind::getMetadata()); |
| 854 | DwarfMacroInfoSection = |
| 855 | getOrCreateSection("\t.section\t.debug_macinfo,\"dr\"", |
| 856 | true, SectionKind::getMetadata()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 859 | const MCSection *TargetLoweringObjectFileCOFF:: |
| 860 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 861 | Mangler *Mang, const TargetMachine &TM) const { |
| 862 | return getOrCreateSection(GV->getSection().c_str(), false, Kind); |
| 863 | } |
| 864 | |
| 865 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 866 | void TargetLoweringObjectFileCOFF:: |
| 867 | getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const { |
| 868 | // FIXME: Inefficient. |
| 869 | std::string Res = ",\""; |
| 870 | if (Kind.isText()) |
| 871 | Res += 'x'; |
| 872 | if (Kind.isWriteable()) |
| 873 | Res += 'w'; |
| 874 | Res += "\""; |
| 875 | |
| 876 | Str.append(Res.begin(), Res.end()); |
| 877 | } |
| 878 | |
| 879 | static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) { |
| 880 | if (Kind.isText()) |
| 881 | return ".text$linkonce"; |
| 882 | if (Kind.isWriteable()) |
| 883 | return ".data$linkonce"; |
| 884 | return ".rdata$linkonce"; |
| 885 | } |
| 886 | |
| 887 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 888 | const MCSection *TargetLoweringObjectFileCOFF:: |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 889 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 890 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 891 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 892 | |
| 893 | // If this global is linkonce/weak and the target handles this by emitting it |
| 894 | // into a 'uniqued' section name, create and return the section now. |
Chris Lattner | 27602b8 | 2009-08-01 21:42:58 +0000 | [diff] [blame] | 895 | if (GV->isWeakForLinker()) { |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 896 | const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind); |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 897 | std::string Name = Mang->makeNameProper(GV->getNameStr()); |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 898 | return getOrCreateSection((Prefix+Name).c_str(), false, Kind); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 901 | if (Kind.isText()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 902 | return getTextSection(); |
| 903 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 904 | return getDataSection(); |
| 905 | } |
| 906 | |