Chris Lattner | c4c40a9 | 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" |
Dan Gohman | 45f13d4 | 2009-08-11 16:02:12 +0000 | [diff] [blame] | 18 | #include "llvm/Function.h" |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 19 | #include "llvm/GlobalVariable.h" |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 7f1ac7f | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSectionMachO.h" |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCSectionELF.h" |
Chris Lattner | 656aeb8 | 2010-01-13 21:29:21 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | 31a5474 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 26 | #include "llvm/Target/Mangler.h" |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetData.h" |
Chris Lattner | a8b97f4 | 2009-08-08 20:43:12 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | 2aaa75e | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 31 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 656aeb8 | 2010-01-13 21:29:21 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/StringExtras.h" |
| 35 | using namespace llvm; |
| 36 | |
| 37 | //===----------------------------------------------------------------------===// |
| 38 | // Generic Code |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 41 | TargetLoweringObjectFile::TargetLoweringObjectFile() : Ctx(0) { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 42 | TextSection = 0; |
| 43 | DataSection = 0; |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 44 | BSSSection = 0; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 45 | ReadOnlySection = 0; |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 46 | StaticCtorSection = 0; |
| 47 | StaticDtorSection = 0; |
Chris Lattner | 3d77805 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 48 | LSDASection = 0; |
Chris Lattner | c01e333 | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 49 | EHFrameSection = 0; |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 50 | |
| 51 | DwarfAbbrevSection = 0; |
| 52 | DwarfInfoSection = 0; |
| 53 | DwarfLineSection = 0; |
| 54 | DwarfFrameSection = 0; |
| 55 | DwarfPubNamesSection = 0; |
| 56 | DwarfPubTypesSection = 0; |
| 57 | DwarfDebugInlineSection = 0; |
| 58 | DwarfStrSection = 0; |
| 59 | DwarfLocSection = 0; |
| 60 | DwarfARangesSection = 0; |
| 61 | DwarfRangesSection = 0; |
| 62 | DwarfMacroInfoSection = 0; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | TargetLoweringObjectFile::~TargetLoweringObjectFile() { |
| 66 | } |
| 67 | |
| 68 | static bool isSuitableForBSS(const GlobalVariable *GV) { |
| 69 | Constant *C = GV->getInitializer(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 70 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 71 | // Must have zero initializer. |
| 72 | if (!C->isNullValue()) |
| 73 | return false; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 74 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 75 | // Leave constant zeros in readonly constant sections, so they can be shared. |
| 76 | if (GV->isConstant()) |
| 77 | return false; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 78 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 79 | // If the global has an explicit section specified, don't put it in BSS. |
| 80 | if (!GV->getSection().empty()) |
| 81 | return false; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 82 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 83 | // If -nozero-initialized-in-bss is specified, don't ever use BSS. |
| 84 | if (NoZerosInBSS) |
| 85 | return false; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 86 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 87 | // Otherwise, put it in BSS! |
| 88 | return true; |
| 89 | } |
| 90 | |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 91 | /// IsNullTerminatedString - Return true if the specified constant (which is |
| 92 | /// known to have a type that is an array of 1/2/4 byte elements) ends with a |
| 93 | /// nul value and contains no other nuls in it. |
| 94 | static bool IsNullTerminatedString(const Constant *C) { |
| 95 | const ArrayType *ATy = cast<ArrayType>(C->getType()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 96 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 97 | // First check: is we have constant array of i8 terminated with zero |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 98 | if (const ConstantArray *CVA = dyn_cast<ConstantArray>(C)) { |
| 99 | if (ATy->getNumElements() == 0) return false; |
| 100 | |
| 101 | ConstantInt *Null = |
| 102 | dyn_cast<ConstantInt>(CVA->getOperand(ATy->getNumElements()-1)); |
| 103 | if (Null == 0 || Null->getZExtValue() != 0) |
| 104 | return false; // Not null terminated. |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 105 | |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 106 | // Verify that the null doesn't occur anywhere else in the string. |
| 107 | for (unsigned i = 0, e = ATy->getNumElements()-1; i != e; ++i) |
| 108 | // Reject constantexpr elements etc. |
| 109 | if (!isa<ConstantInt>(CVA->getOperand(i)) || |
| 110 | CVA->getOperand(i) == Null) |
| 111 | return false; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 112 | return true; |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 113 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 114 | |
| 115 | // Another possibility: [1 x i8] zeroinitializer |
| 116 | if (isa<ConstantAggregateZero>(C)) |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 117 | return ATy->getNumElements() == 1; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
Chris Lattner | 7195a86 | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 122 | /// getKindForGlobal - This is a top-level target-independent classifier for |
Chris Lattner | 9de4876 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 123 | /// a global variable. Given an global variable and information from TM, it |
| 124 | /// classifies the global in a variety of ways that make various target |
| 125 | /// implementations simpler. The target implementation is free to ignore this |
| 126 | /// extra info of course. |
Chris Lattner | 7195a86 | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 127 | SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV, |
| 128 | const TargetMachine &TM){ |
| 129 | assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() && |
| 130 | "Can only be used for global definitions"); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 131 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 132 | Reloc::Model ReloModel = TM.getRelocationModel(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 133 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 134 | // Early exit - functions should be always in text sections. |
| 135 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); |
| 136 | if (GVar == 0) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 137 | return SectionKind::getText(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 138 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 139 | // Handle thread-local data first. |
| 140 | if (GVar->isThreadLocal()) { |
| 141 | if (isSuitableForBSS(GVar)) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 142 | return SectionKind::getThreadBSS(); |
| 143 | return SectionKind::getThreadData(); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Chris Lattner | 9b74005 | 2010-01-19 02:48:26 +0000 | [diff] [blame] | 146 | // Variables with common linkage always get classified as common. |
| 147 | if (GVar->hasCommonLinkage()) |
| 148 | return SectionKind::getCommon(); |
| 149 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 150 | // Variable can be easily put to BSS section. |
Chris Lattner | 66fa6a2 | 2010-01-19 04:15:51 +0000 | [diff] [blame] | 151 | if (isSuitableForBSS(GVar)) { |
| 152 | if (GVar->hasLocalLinkage()) |
| 153 | return SectionKind::getBSSLocal(); |
| 154 | else if (GVar->hasExternalLinkage()) |
| 155 | return SectionKind::getBSSExtern(); |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 156 | return SectionKind::getBSS(); |
Chris Lattner | 66fa6a2 | 2010-01-19 04:15:51 +0000 | [diff] [blame] | 157 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 158 | |
| 159 | Constant *C = GVar->getInitializer(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 160 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 161 | // If the global is marked constant, we can put it into a mergable section, |
| 162 | // a mergable string section, or general .data if it contains relocations. |
| 163 | if (GVar->isConstant()) { |
| 164 | // If the initializer for the global contains something that requires a |
| 165 | // relocation, then we may have to drop this into a wriable data section |
| 166 | // even though it is marked const. |
| 167 | switch (C->getRelocationInfo()) { |
Chris Lattner | 2aaa75e | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 168 | default: assert(0 && "unknown relocation info kind"); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 169 | case Constant::NoRelocation: |
| 170 | // If initializer is a null-terminated string, put it in a "cstring" |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 171 | // section of the right width. |
| 172 | if (const ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) { |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 173 | if (const IntegerType *ITy = |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 174 | dyn_cast<IntegerType>(ATy->getElementType())) { |
| 175 | if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 || |
| 176 | ITy->getBitWidth() == 32) && |
| 177 | IsNullTerminatedString(C)) { |
| 178 | if (ITy->getBitWidth() == 8) |
| 179 | return SectionKind::getMergeable1ByteCString(); |
| 180 | if (ITy->getBitWidth() == 16) |
| 181 | return SectionKind::getMergeable2ByteCString(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 182 | |
Chris Lattner | 1c81a6c | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 183 | assert(ITy->getBitWidth() == 32 && "Unknown width"); |
| 184 | return SectionKind::getMergeable4ByteCString(); |
| 185 | } |
| 186 | } |
| 187 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 188 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 189 | // Otherwise, just drop it into a mergable constant section. If we have |
| 190 | // a section for this size, use it, otherwise use the arbitrary sized |
| 191 | // mergable section. |
| 192 | switch (TM.getTargetData()->getTypeAllocSize(C->getType())) { |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 193 | case 4: return SectionKind::getMergeableConst4(); |
| 194 | case 8: return SectionKind::getMergeableConst8(); |
| 195 | case 16: return SectionKind::getMergeableConst16(); |
| 196 | default: return SectionKind::getMergeableConst(); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 197 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 198 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 199 | case Constant::LocalRelocation: |
| 200 | // In static relocation model, the linker will resolve all addresses, so |
| 201 | // the relocation entries will actually be constants by the time the app |
| 202 | // starts up. However, we can't put this into a mergable section, because |
| 203 | // the linker doesn't take relocations into consideration when it tries to |
| 204 | // merge entries in the section. |
| 205 | if (ReloModel == Reloc::Static) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 206 | return SectionKind::getReadOnly(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 207 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 208 | // Otherwise, the dynamic linker needs to fix it up, put it in the |
| 209 | // writable data.rel.local section. |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 210 | return SectionKind::getReadOnlyWithRelLocal(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 211 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 212 | case Constant::GlobalRelocations: |
| 213 | // In static relocation model, the linker will resolve all addresses, so |
| 214 | // the relocation entries will actually be constants by the time the app |
| 215 | // starts up. However, we can't put this into a mergable section, because |
| 216 | // the linker doesn't take relocations into consideration when it tries to |
| 217 | // merge entries in the section. |
| 218 | if (ReloModel == Reloc::Static) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 219 | return SectionKind::getReadOnly(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 220 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 221 | // Otherwise, the dynamic linker needs to fix it up, put it in the |
| 222 | // writable data.rel section. |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 223 | return SectionKind::getReadOnlyWithRel(); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | // Okay, this isn't a constant. If the initializer for the global is going |
| 228 | // to require a runtime relocation by the dynamic linker, put it into a more |
| 229 | // specific section to improve startup time of the app. This coalesces these |
| 230 | // globals together onto fewer pages, improving the locality of the dynamic |
| 231 | // linker. |
| 232 | if (ReloModel == Reloc::Static) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 233 | return SectionKind::getDataNoRel(); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 234 | |
| 235 | switch (C->getRelocationInfo()) { |
Chris Lattner | 2aaa75e | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 236 | default: assert(0 && "unknown relocation info kind"); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 237 | case Constant::NoRelocation: |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 238 | return SectionKind::getDataNoRel(); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 239 | case Constant::LocalRelocation: |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 240 | return SectionKind::getDataRelLocal(); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 241 | case Constant::GlobalRelocations: |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 242 | return SectionKind::getDataRel(); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | /// SectionForGlobal - This method computes the appropriate section to emit |
| 247 | /// the specified global variable or function definition. This should not |
| 248 | /// be passed external (or available externally) globals. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 249 | const MCSection *TargetLoweringObjectFile:: |
Chris Lattner | 7195a86 | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 250 | SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 251 | const TargetMachine &TM) const { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 252 | // Select section name. |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 253 | if (GV->hasSection()) |
| 254 | return getExplicitSectionGlobal(GV, Kind, Mang, TM); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 255 | |
| 256 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 257 | // Use default section depending on the 'type' of global |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 258 | return SelectSectionForGlobal(GV, Kind, Mang, TM); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Chris Lattner | 7195a86 | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 261 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 262 | // Lame default implementation. Calculate the section name for global. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 263 | const MCSection * |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 264 | TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV, |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 265 | SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 266 | Mangler *Mang, |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 267 | const TargetMachine &TM) const{ |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 268 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 269 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 270 | if (Kind.isText()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 271 | return getTextSection(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 272 | |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 273 | if (Kind.isBSS() && BSSSection != 0) |
| 274 | return BSSSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 275 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 276 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 277 | return ReadOnlySection; |
| 278 | |
| 279 | return getDataSection(); |
| 280 | } |
| 281 | |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 282 | /// getSectionForConstant - Given a mergable constant with the |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 283 | /// specified size and relocation information, return a section that it |
| 284 | /// should be placed in. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 285 | const MCSection * |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 286 | TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 287 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
| 288 | return ReadOnlySection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 289 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 290 | return DataSection; |
| 291 | } |
| 292 | |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 293 | /// getSymbolForDwarfGlobalReference - Return an MCExpr to use for a |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 294 | /// reference to the specified global variable from exception |
| 295 | /// handling information. |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 296 | const MCExpr *TargetLoweringObjectFile:: |
| 297 | getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 298 | MachineModuleInfo *MMI, unsigned Encoding) const { |
Chris Lattner | 31a5474 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 299 | // FIXME: Use GetGlobalValueSymbol. |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 300 | SmallString<128> Name; |
| 301 | Mang->getNameWithPrefix(Name, GV, false); |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 302 | const MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str()); |
| 303 | |
| 304 | return getSymbolForDwarfReference(Sym, MMI, Encoding); |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 305 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 306 | |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 307 | const MCExpr *TargetLoweringObjectFile:: |
| 308 | getSymbolForDwarfReference(const MCSymbol *Sym, MachineModuleInfo *MMI, |
| 309 | unsigned Encoding) const { |
| 310 | const MCExpr *Res = MCSymbolRefExpr::Create(Sym, getContext()); |
| 311 | |
| 312 | switch (Encoding & 0xF0) { |
| 313 | default: |
| 314 | llvm_report_error("Do not support this DWARF encoding yet!"); |
| 315 | break; |
| 316 | case dwarf::DW_EH_PE_absptr: |
| 317 | // Do nothing special |
| 318 | break; |
| 319 | case dwarf::DW_EH_PE_pcrel: |
| 320 | // FIXME: PCSymbol |
| 321 | const MCExpr *PC = MCSymbolRefExpr::Create(".", getContext()); |
| 322 | Res = MCBinaryExpr::CreateSub(Res, PC, getContext()); |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | return Res; |
| 327 | } |
| 328 | |
| 329 | unsigned TargetLoweringObjectFile::getPersonalityEncoding() const { |
| 330 | return dwarf::DW_EH_PE_absptr; |
| 331 | } |
| 332 | |
| 333 | unsigned TargetLoweringObjectFile::getLSDAEncoding() const { |
| 334 | return dwarf::DW_EH_PE_absptr; |
| 335 | } |
| 336 | |
| 337 | unsigned TargetLoweringObjectFile::getFDEEncoding() const { |
| 338 | return dwarf::DW_EH_PE_absptr; |
| 339 | } |
| 340 | |
| 341 | unsigned TargetLoweringObjectFile::getTTypeEncoding() const { |
| 342 | return dwarf::DW_EH_PE_absptr; |
| 343 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 344 | |
| 345 | //===----------------------------------------------------------------------===// |
| 346 | // ELF |
| 347 | //===----------------------------------------------------------------------===// |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 348 | typedef StringMap<const MCSectionELF*> ELFUniqueMapTy; |
| 349 | |
| 350 | TargetLoweringObjectFileELF::~TargetLoweringObjectFileELF() { |
| 351 | // If we have the section uniquing map, free it. |
| 352 | delete (ELFUniqueMapTy*)UniquingMap; |
| 353 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 354 | |
Chris Lattner | 8011f5f | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 355 | const MCSection *TargetLoweringObjectFileELF:: |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 356 | getELFSection(StringRef Section, unsigned Type, unsigned Flags, |
| 357 | SectionKind Kind, bool IsExplicit) const { |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 358 | if (UniquingMap == 0) |
| 359 | UniquingMap = new ELFUniqueMapTy(); |
| 360 | ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 361 | |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 362 | // Do the lookup, if we have a hit, return it. |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 363 | const MCSectionELF *&Entry = Map[Section]; |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 364 | if (Entry) return Entry; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 365 | |
Bruno Cardoso Lopes | 0ff6eff | 2009-08-13 23:30:21 +0000 | [diff] [blame] | 366 | return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, IsExplicit, |
| 367 | getContext()); |
Chris Lattner | 8011f5f | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 370 | void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, |
| 371 | const TargetMachine &TM) { |
Benjamin Kramer | 858ea8f | 2009-08-17 17:05:44 +0000 | [diff] [blame] | 372 | if (UniquingMap != 0) |
| 373 | ((ELFUniqueMapTy*)UniquingMap)->clear(); |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 374 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 375 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 376 | BSSSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 377 | getELFSection(".bss", MCSectionELF::SHT_NOBITS, |
| 378 | MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC, |
| 379 | SectionKind::getBSS()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 380 | |
| 381 | TextSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 382 | getELFSection(".text", MCSectionELF::SHT_PROGBITS, |
| 383 | MCSectionELF::SHF_EXECINSTR | MCSectionELF::SHF_ALLOC, |
| 384 | SectionKind::getText()); |
| 385 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 386 | DataSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 387 | getELFSection(".data", MCSectionELF::SHT_PROGBITS, |
| 388 | MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC, |
| 389 | SectionKind::getDataRel()); |
| 390 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 391 | ReadOnlySection = |
| 392 | getELFSection(".rodata", MCSectionELF::SHT_PROGBITS, |
| 393 | MCSectionELF::SHF_ALLOC, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 394 | SectionKind::getReadOnly()); |
| 395 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 396 | TLSDataSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 397 | getELFSection(".tdata", MCSectionELF::SHT_PROGBITS, |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 398 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_TLS | |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 399 | MCSectionELF::SHF_WRITE, SectionKind::getThreadData()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 400 | |
| 401 | TLSBSSSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 402 | getELFSection(".tbss", MCSectionELF::SHT_NOBITS, |
| 403 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_TLS | |
| 404 | MCSectionELF::SHF_WRITE, SectionKind::getThreadBSS()); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 405 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 406 | DataRelSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 407 | getELFSection(".data.rel", MCSectionELF::SHT_PROGBITS, |
| 408 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE, |
| 409 | SectionKind::getDataRel()); |
| 410 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 411 | DataRelLocalSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 412 | getELFSection(".data.rel.local", MCSectionELF::SHT_PROGBITS, |
| 413 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE, |
| 414 | SectionKind::getDataRelLocal()); |
| 415 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 416 | DataRelROSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 417 | getELFSection(".data.rel.ro", MCSectionELF::SHT_PROGBITS, |
| 418 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE, |
| 419 | SectionKind::getReadOnlyWithRel()); |
| 420 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 421 | DataRelROLocalSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 422 | getELFSection(".data.rel.ro.local", MCSectionELF::SHT_PROGBITS, |
| 423 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE, |
| 424 | SectionKind::getReadOnlyWithRelLocal()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 425 | |
| 426 | MergeableConst4Section = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 427 | getELFSection(".rodata.cst4", MCSectionELF::SHT_PROGBITS, |
| 428 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE, |
| 429 | SectionKind::getMergeableConst4()); |
| 430 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 431 | MergeableConst8Section = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 432 | getELFSection(".rodata.cst8", MCSectionELF::SHT_PROGBITS, |
| 433 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE, |
| 434 | SectionKind::getMergeableConst8()); |
| 435 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 436 | MergeableConst16Section = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 437 | getELFSection(".rodata.cst16", MCSectionELF::SHT_PROGBITS, |
| 438 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE, |
| 439 | SectionKind::getMergeableConst16()); |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 440 | |
| 441 | StaticCtorSection = |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 442 | getELFSection(".ctors", MCSectionELF::SHT_PROGBITS, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 443 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE, |
| 444 | SectionKind::getDataRel()); |
| 445 | |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 446 | StaticDtorSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 447 | getELFSection(".dtors", MCSectionELF::SHT_PROGBITS, |
| 448 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE, |
| 449 | SectionKind::getDataRel()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 450 | |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 451 | // Exception Handling Sections. |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 452 | |
Chris Lattner | 3d77805 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 453 | // FIXME: We're emitting LSDA info into a readonly section on ELF, even though |
| 454 | // it contains relocatable pointers. In PIC mode, this is probably a big |
| 455 | // runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 456 | // adjusted or this should be a data section. |
| 457 | LSDASection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 458 | getELFSection(".gcc_except_table", MCSectionELF::SHT_PROGBITS, |
| 459 | MCSectionELF::SHF_ALLOC, SectionKind::getReadOnly()); |
Chris Lattner | c01e333 | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 460 | EHFrameSection = |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 461 | getELFSection(".eh_frame", MCSectionELF::SHT_PROGBITS, |
Chris Lattner | dc4d793 | 2009-08-15 16:54:02 +0000 | [diff] [blame] | 462 | MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE, |
| 463 | SectionKind::getDataRel()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 464 | |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 465 | // Debug Info Sections. |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 466 | DwarfAbbrevSection = |
| 467 | getELFSection(".debug_abbrev", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 468 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 469 | DwarfInfoSection = |
| 470 | getELFSection(".debug_info", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 471 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 472 | DwarfLineSection = |
| 473 | getELFSection(".debug_line", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 474 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 475 | DwarfFrameSection = |
| 476 | getELFSection(".debug_frame", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 477 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 478 | DwarfPubNamesSection = |
| 479 | getELFSection(".debug_pubnames", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 480 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 481 | DwarfPubTypesSection = |
| 482 | getELFSection(".debug_pubtypes", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 483 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 484 | DwarfStrSection = |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 485 | getELFSection(".debug_str", MCSectionELF::SHT_PROGBITS, 0, |
| 486 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 487 | DwarfLocSection = |
| 488 | getELFSection(".debug_loc", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 489 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 490 | DwarfARangesSection = |
| 491 | getELFSection(".debug_aranges", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 492 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 493 | DwarfRangesSection = |
| 494 | getELFSection(".debug_ranges", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 495 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 496 | DwarfMacroInfoSection = |
| 497 | getELFSection(".debug_macinfo", MCSectionELF::SHT_PROGBITS, 0, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 498 | SectionKind::getMetadata()); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 502 | static SectionKind |
Benjamin Kramer | e3c0e10 | 2010-01-22 18:21:23 +0000 | [diff] [blame] | 503 | getELFKindForNamedSection(StringRef Name, SectionKind K) { |
| 504 | if (Name.empty() || Name[0] != '.') return K; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 505 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 506 | // Some lame default implementation based on some magic section names. |
Benjamin Kramer | e3c0e10 | 2010-01-22 18:21:23 +0000 | [diff] [blame] | 507 | if (Name == ".bss" || |
| 508 | Name.startswith(".bss.") || |
| 509 | Name.startswith(".gnu.linkonce.b.") || |
| 510 | Name.startswith(".llvm.linkonce.b.") || |
| 511 | Name == ".sbss" || |
| 512 | Name.startswith(".sbss.") || |
| 513 | Name.startswith(".gnu.linkonce.sb.") || |
| 514 | Name.startswith(".llvm.linkonce.sb.")) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 515 | return SectionKind::getBSS(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 516 | |
Benjamin Kramer | e3c0e10 | 2010-01-22 18:21:23 +0000 | [diff] [blame] | 517 | if (Name == ".tdata" || |
| 518 | Name.startswith(".tdata.") || |
| 519 | Name.startswith(".gnu.linkonce.td.") || |
| 520 | Name.startswith(".llvm.linkonce.td.")) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 521 | return SectionKind::getThreadData(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 522 | |
Benjamin Kramer | e3c0e10 | 2010-01-22 18:21:23 +0000 | [diff] [blame] | 523 | if (Name == ".tbss" || |
| 524 | Name.startswith(".tbss.") || |
| 525 | Name.startswith(".gnu.linkonce.tb.") || |
| 526 | Name.startswith(".llvm.linkonce.tb.")) |
Chris Lattner | a945341 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 527 | return SectionKind::getThreadBSS(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 528 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 529 | return K; |
| 530 | } |
| 531 | |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 532 | |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 533 | static unsigned getELFSectionType(StringRef Name, SectionKind K) { |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 534 | |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 535 | if (Name == ".init_array") |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 536 | return MCSectionELF::SHT_INIT_ARRAY; |
| 537 | |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 538 | if (Name == ".fini_array") |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 539 | return MCSectionELF::SHT_FINI_ARRAY; |
| 540 | |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 541 | if (Name == ".preinit_array") |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 542 | return MCSectionELF::SHT_PREINIT_ARRAY; |
| 543 | |
| 544 | if (K.isBSS() || K.isThreadBSS()) |
| 545 | return MCSectionELF::SHT_NOBITS; |
| 546 | |
| 547 | return MCSectionELF::SHT_PROGBITS; |
| 548 | } |
| 549 | |
| 550 | |
| 551 | static unsigned |
| 552 | getELFSectionFlags(SectionKind K) { |
| 553 | unsigned Flags = 0; |
| 554 | |
| 555 | if (!K.isMetadata()) |
| 556 | Flags |= MCSectionELF::SHF_ALLOC; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 557 | |
Anton Korobeynikov | 5840945 | 2009-08-18 14:06:12 +0000 | [diff] [blame] | 558 | if (K.isText()) |
| 559 | Flags |= MCSectionELF::SHF_EXECINSTR; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 560 | |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 561 | if (K.isWriteable()) |
| 562 | Flags |= MCSectionELF::SHF_WRITE; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 563 | |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 564 | if (K.isThreadLocal()) |
| 565 | Flags |= MCSectionELF::SHF_TLS; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 566 | |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 567 | // K.isMergeableConst() is left out to honour PR4650 |
| 568 | if (K.isMergeableCString() || K.isMergeableConst4() || |
| 569 | K.isMergeableConst8() || K.isMergeableConst16()) |
| 570 | Flags |= MCSectionELF::SHF_MERGE; |
| 571 | |
| 572 | if (K.isMergeableCString()) |
| 573 | Flags |= MCSectionELF::SHF_STRINGS; |
| 574 | |
| 575 | return Flags; |
| 576 | } |
| 577 | |
| 578 | |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 579 | const MCSection *TargetLoweringObjectFileELF:: |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 580 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 581 | Mangler *Mang, const TargetMachine &TM) const { |
Benjamin Kramer | e3c0e10 | 2010-01-22 18:21:23 +0000 | [diff] [blame] | 582 | StringRef SectionName = GV->getSection(); |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 583 | |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 584 | // Infer section flags from the section name if we can. |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 585 | Kind = getELFKindForNamedSection(SectionName, Kind); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 586 | |
| 587 | return getELFSection(SectionName, |
| 588 | getELFSectionType(SectionName, Kind), |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 589 | getELFSectionFlags(Kind), Kind, true); |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 590 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 591 | |
| 592 | static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) { |
| 593 | if (Kind.isText()) return ".gnu.linkonce.t."; |
| 594 | if (Kind.isReadOnly()) return ".gnu.linkonce.r."; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 595 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 596 | if (Kind.isThreadData()) return ".gnu.linkonce.td."; |
| 597 | if (Kind.isThreadBSS()) return ".gnu.linkonce.tb."; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 598 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 599 | if (Kind.isDataNoRel()) return ".gnu.linkonce.d."; |
| 600 | if (Kind.isDataRelLocal()) return ".gnu.linkonce.d.rel.local."; |
| 601 | if (Kind.isDataRel()) return ".gnu.linkonce.d.rel."; |
| 602 | if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local."; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 603 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 604 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 605 | return ".gnu.linkonce.d.rel.ro."; |
| 606 | } |
| 607 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 608 | const MCSection *TargetLoweringObjectFileELF:: |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 609 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 610 | Mangler *Mang, const TargetMachine &TM) const { |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 611 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 612 | // If this global is linkonce/weak and the target handles this by emitting it |
| 613 | // into a 'uniqued' section name, create and return the section now. |
Chris Lattner | ea96f15 | 2010-01-19 03:06:01 +0000 | [diff] [blame] | 614 | if (GV->isWeakForLinker() && !Kind.isCommon() && !Kind.isBSS()) { |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 615 | const char *Prefix = getSectionPrefixForUniqueGlobal(Kind); |
Chris Lattner | e295e55 | 2010-01-17 19:23:46 +0000 | [diff] [blame] | 616 | SmallString<128> Name; |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 617 | Name.append(Prefix, Prefix+strlen(Prefix)); |
Chris Lattner | 656aeb8 | 2010-01-13 21:29:21 +0000 | [diff] [blame] | 618 | Mang->getNameWithPrefix(Name, GV, false); |
Chris Lattner | e295e55 | 2010-01-17 19:23:46 +0000 | [diff] [blame] | 619 | return getELFSection(Name.str(), getELFSectionType(Name.str(), Kind), |
| 620 | getELFSectionFlags(Kind), Kind); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 621 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 622 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 623 | if (Kind.isText()) return TextSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 624 | |
Chris Lattner | db72793 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 625 | if (Kind.isMergeable1ByteCString() || |
| 626 | Kind.isMergeable2ByteCString() || |
| 627 | Kind.isMergeable4ByteCString()) { |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 628 | |
Chris Lattner | d94d60f | 2009-07-29 04:54:38 +0000 | [diff] [blame] | 629 | // We also need alignment here. |
| 630 | // FIXME: this is getting the alignment of the character, not the |
| 631 | // alignment of the global! |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 632 | unsigned Align = |
Chris Lattner | d94d60f | 2009-07-29 04:54:38 +0000 | [diff] [blame] | 633 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 634 | |
Chris Lattner | bf9abe5 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 635 | const char *SizeSpec = ".rodata.str1."; |
Chris Lattner | db72793 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 636 | if (Kind.isMergeable2ByteCString()) |
Chris Lattner | bf9abe5 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 637 | SizeSpec = ".rodata.str2."; |
Chris Lattner | db72793 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 638 | else if (Kind.isMergeable4ByteCString()) |
Chris Lattner | bf9abe5 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 639 | SizeSpec = ".rodata.str4."; |
Chris Lattner | db72793 | 2009-08-04 05:35:56 +0000 | [diff] [blame] | 640 | else |
| 641 | assert(Kind.isMergeable1ByteCString() && "unknown string width"); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 642 | |
| 643 | |
Chris Lattner | bf9abe5 | 2009-08-04 16:19:50 +0000 | [diff] [blame] | 644 | std::string Name = SizeSpec + utostr(Align); |
Benjamin Kramer | e3c0e10 | 2010-01-22 18:21:23 +0000 | [diff] [blame] | 645 | return getELFSection(Name, MCSectionELF::SHT_PROGBITS, |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 646 | MCSectionELF::SHF_ALLOC | |
| 647 | MCSectionELF::SHF_MERGE | |
| 648 | MCSectionELF::SHF_STRINGS, |
Bruno Cardoso Lopes | 26d7ecd | 2009-08-13 05:07:35 +0000 | [diff] [blame] | 649 | Kind); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 650 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 651 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 652 | if (Kind.isMergeableConst()) { |
Chris Lattner | 0a9ec09 | 2009-08-15 06:08:34 +0000 | [diff] [blame] | 653 | if (Kind.isMergeableConst4() && MergeableConst4Section) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 654 | return MergeableConst4Section; |
Chris Lattner | 0a9ec09 | 2009-08-15 06:08:34 +0000 | [diff] [blame] | 655 | if (Kind.isMergeableConst8() && MergeableConst8Section) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 656 | return MergeableConst8Section; |
Chris Lattner | 0a9ec09 | 2009-08-15 06:08:34 +0000 | [diff] [blame] | 657 | if (Kind.isMergeableConst16() && MergeableConst16Section) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 658 | return MergeableConst16Section; |
| 659 | return ReadOnlySection; // .const |
| 660 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 661 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 662 | if (Kind.isReadOnly()) return ReadOnlySection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 663 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 664 | if (Kind.isThreadData()) return TLSDataSection; |
| 665 | if (Kind.isThreadBSS()) return TLSBSSSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 666 | |
Chris Lattner | ea96f15 | 2010-01-19 03:06:01 +0000 | [diff] [blame] | 667 | // Note: we claim that common symbols are put in BSSSection, but they are |
| 668 | // really emitted with the magic .comm directive, which creates a symbol table |
| 669 | // entry but not a section. |
Chris Lattner | 9b74005 | 2010-01-19 02:48:26 +0000 | [diff] [blame] | 670 | if (Kind.isBSS() || Kind.isCommon()) return BSSSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 671 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 672 | if (Kind.isDataNoRel()) return DataSection; |
| 673 | if (Kind.isDataRelLocal()) return DataRelLocalSection; |
| 674 | if (Kind.isDataRel()) return DataRelSection; |
| 675 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 676 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 677 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 678 | return DataRelROSection; |
| 679 | } |
| 680 | |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 681 | /// getSectionForConstant - Given a mergeable constant with the |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 682 | /// specified size and relocation information, return a section that it |
| 683 | /// should be placed in. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 684 | const MCSection *TargetLoweringObjectFileELF:: |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 685 | getSectionForConstant(SectionKind Kind) const { |
Richard Osborne | 24214f3 | 2009-08-17 16:37:11 +0000 | [diff] [blame] | 686 | if (Kind.isMergeableConst4() && MergeableConst4Section) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 687 | return MergeableConst4Section; |
Richard Osborne | 24214f3 | 2009-08-17 16:37:11 +0000 | [diff] [blame] | 688 | if (Kind.isMergeableConst8() && MergeableConst8Section) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 689 | return MergeableConst8Section; |
Richard Osborne | 24214f3 | 2009-08-17 16:37:11 +0000 | [diff] [blame] | 690 | if (Kind.isMergeableConst16() && MergeableConst16Section) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 691 | return MergeableConst16Section; |
| 692 | if (Kind.isReadOnly()) |
| 693 | return ReadOnlySection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 694 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 695 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
| 696 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 697 | return DataRelROSection; |
| 698 | } |
| 699 | |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 700 | const MCExpr *TargetLoweringObjectFileELF:: |
| 701 | getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 702 | MachineModuleInfo *MMI, unsigned Encoding) const { |
| 703 | |
| 704 | if (Encoding & dwarf::DW_EH_PE_indirect) { |
| 705 | MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>(); |
| 706 | |
| 707 | SmallString<128> Name; |
| 708 | Mang->getNameWithPrefix(Name, GV, true); |
Anton Korobeynikov | fb37d02 | 2010-02-15 22:36:26 +0000 | [diff] [blame^] | 709 | Name += ".DW.stub"; |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 710 | |
| 711 | // Add information about the stub reference to ELFMMI so that the stub |
| 712 | // gets emitted by the asmprinter. |
| 713 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str()); |
| 714 | MCSymbol *&StubSym = ELFMMI.getGVStubEntry(Sym); |
| 715 | if (StubSym == 0) { |
| 716 | Name.clear(); |
| 717 | Mang->getNameWithPrefix(Name, GV, false); |
| 718 | StubSym = getContext().GetOrCreateSymbol(Name.str()); |
| 719 | } |
| 720 | |
| 721 | return TargetLoweringObjectFile:: |
| 722 | getSymbolForDwarfReference(Sym, MMI, |
| 723 | Encoding & ~dwarf::DW_EH_PE_indirect); |
| 724 | } |
| 725 | |
| 726 | return TargetLoweringObjectFile:: |
| 727 | getSymbolForDwarfGlobalReference(GV, Mang, MMI, Encoding); |
| 728 | } |
| 729 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 730 | //===----------------------------------------------------------------------===// |
| 731 | // MachO |
| 732 | //===----------------------------------------------------------------------===// |
| 733 | |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 734 | typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 735 | |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 736 | TargetLoweringObjectFileMachO::~TargetLoweringObjectFileMachO() { |
| 737 | // If we have the MachO uniquing map, free it. |
| 738 | delete (MachOUniqueMapTy*)UniquingMap; |
| 739 | } |
| 740 | |
| 741 | |
| 742 | const MCSectionMachO *TargetLoweringObjectFileMachO:: |
Daniel Dunbar | de46a5b | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 743 | getMachOSection(StringRef Segment, StringRef Section, |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 744 | unsigned TypeAndAttributes, |
| 745 | unsigned Reserved2, SectionKind Kind) const { |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 746 | // We unique sections by their segment/section pair. The returned section |
| 747 | // may not have the same flags as the requested section, if so this should be |
| 748 | // diagnosed by the client as an error. |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 749 | |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 750 | // Create the map if it doesn't already exist. |
| 751 | if (UniquingMap == 0) |
| 752 | UniquingMap = new MachOUniqueMapTy(); |
| 753 | MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)UniquingMap; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 754 | |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 755 | // Form the name to look up. |
| 756 | SmallString<64> Name; |
Daniel Dunbar | b5b99e6 | 2009-08-26 23:12:33 +0000 | [diff] [blame] | 757 | Name += Segment; |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 758 | Name.push_back(','); |
Daniel Dunbar | b5b99e6 | 2009-08-26 23:12:33 +0000 | [diff] [blame] | 759 | Name += Section; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 760 | |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 761 | // Do the lookup, if we have a hit, return it. |
Daniel Dunbar | b5b99e6 | 2009-08-26 23:12:33 +0000 | [diff] [blame] | 762 | const MCSectionMachO *&Entry = Map[Name.str()]; |
Chris Lattner | af4bf00 | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 763 | if (Entry) return Entry; |
| 764 | |
| 765 | // Otherwise, return a new section. |
| 766 | return Entry = MCSectionMachO::Create(Segment, Section, TypeAndAttributes, |
| 767 | Reserved2, Kind, getContext()); |
Chris Lattner | 8011f5f | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Chris Lattner | 9287346 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 770 | |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 771 | void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, |
| 772 | const TargetMachine &TM) { |
Benjamin Kramer | 858ea8f | 2009-08-17 17:05:44 +0000 | [diff] [blame] | 773 | if (UniquingMap != 0) |
| 774 | ((MachOUniqueMapTy*)UniquingMap)->clear(); |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 775 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 776 | |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 777 | TextSection // .text |
| 778 | = getMachOSection("__TEXT", "__text", |
| 779 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 780 | SectionKind::getText()); |
| 781 | DataSection // .data |
| 782 | = getMachOSection("__DATA", "__data", 0, SectionKind::getDataRel()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 783 | |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 784 | CStringSection // .cstring |
| 785 | = getMachOSection("__TEXT", "__cstring", MCSectionMachO::S_CSTRING_LITERALS, |
| 786 | SectionKind::getMergeable1ByteCString()); |
| 787 | UStringSection |
| 788 | = getMachOSection("__TEXT","__ustring", 0, |
| 789 | SectionKind::getMergeable2ByteCString()); |
| 790 | FourByteConstantSection // .literal4 |
| 791 | = getMachOSection("__TEXT", "__literal4", MCSectionMachO::S_4BYTE_LITERALS, |
| 792 | SectionKind::getMergeableConst4()); |
| 793 | EightByteConstantSection // .literal8 |
| 794 | = getMachOSection("__TEXT", "__literal8", MCSectionMachO::S_8BYTE_LITERALS, |
| 795 | SectionKind::getMergeableConst8()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 796 | |
Chris Lattner | 28faffe | 2009-07-28 17:50:28 +0000 | [diff] [blame] | 797 | // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back |
| 798 | // to using it in -static mode. |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 799 | SixteenByteConstantSection = 0; |
Chris Lattner | 28faffe | 2009-07-28 17:50:28 +0000 | [diff] [blame] | 800 | if (TM.getRelocationModel() != Reloc::Static && |
| 801 | TM.getTargetData()->getPointerSize() == 32) |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 802 | SixteenByteConstantSection = // .literal16 |
| 803 | getMachOSection("__TEXT", "__literal16",MCSectionMachO::S_16BYTE_LITERALS, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 804 | SectionKind::getMergeableConst16()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 805 | |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 806 | ReadOnlySection // .const |
| 807 | = getMachOSection("__TEXT", "__const", 0, SectionKind::getReadOnly()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 808 | |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 809 | TextCoalSection |
| 810 | = getMachOSection("__TEXT", "__textcoal_nt", |
| 811 | MCSectionMachO::S_COALESCED | |
| 812 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 813 | SectionKind::getText()); |
| 814 | ConstTextCoalSection |
| 815 | = getMachOSection("__TEXT", "__const_coal", MCSectionMachO::S_COALESCED, |
| 816 | SectionKind::getText()); |
| 817 | ConstDataCoalSection |
| 818 | = getMachOSection("__DATA","__const_coal", MCSectionMachO::S_COALESCED, |
| 819 | SectionKind::getText()); |
| 820 | ConstDataSection // .const_data |
| 821 | = getMachOSection("__DATA", "__const", 0, |
| 822 | SectionKind::getReadOnlyWithRel()); |
| 823 | DataCoalSection |
| 824 | = getMachOSection("__DATA","__datacoal_nt", MCSectionMachO::S_COALESCED, |
| 825 | SectionKind::getDataRel()); |
Chris Lattner | f26c779 | 2010-01-19 06:25:51 +0000 | [diff] [blame] | 826 | DataCommonSection |
| 827 | = getMachOSection("__DATA","__common", MCSectionMachO::S_ZEROFILL, |
| 828 | SectionKind::getBSS()); |
| 829 | DataBSSSection |
| 830 | = getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL, |
| 831 | SectionKind::getBSS()); |
| 832 | |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 833 | |
Chris Lattner | 0fcad8a | 2009-08-13 00:05:07 +0000 | [diff] [blame] | 834 | LazySymbolPointerSection |
| 835 | = getMachOSection("__DATA", "__la_symbol_ptr", |
| 836 | MCSectionMachO::S_LAZY_SYMBOL_POINTERS, |
| 837 | SectionKind::getMetadata()); |
| 838 | NonLazySymbolPointerSection |
| 839 | = getMachOSection("__DATA", "__nl_symbol_ptr", |
| 840 | MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, |
| 841 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 842 | |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 843 | if (TM.getRelocationModel() == Reloc::Static) { |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 844 | StaticCtorSection |
| 845 | = getMachOSection("__TEXT", "__constructor", 0,SectionKind::getDataRel()); |
| 846 | StaticDtorSection |
| 847 | = getMachOSection("__TEXT", "__destructor", 0, SectionKind::getDataRel()); |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 848 | } else { |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 849 | StaticCtorSection |
| 850 | = getMachOSection("__DATA", "__mod_init_func", |
| 851 | MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, |
| 852 | SectionKind::getDataRel()); |
| 853 | StaticDtorSection |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 854 | = getMachOSection("__DATA", "__mod_term_func", |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 855 | MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, |
| 856 | SectionKind::getDataRel()); |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 857 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 858 | |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 859 | // Exception Handling. |
Bill Wendling | f0e65b8 | 2009-11-19 19:21:09 +0000 | [diff] [blame] | 860 | LSDASection = getMachOSection("__DATA", "__gcc_except_tab", 0, |
| 861 | SectionKind::getDataRel()); |
Chris Lattner | c01e333 | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 862 | EHFrameSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 863 | getMachOSection("__TEXT", "__eh_frame", |
| 864 | MCSectionMachO::S_COALESCED | |
| 865 | MCSectionMachO::S_ATTR_NO_TOC | |
| 866 | MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS | |
| 867 | MCSectionMachO::S_ATTR_LIVE_SUPPORT, |
| 868 | SectionKind::getReadOnly()); |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 869 | |
| 870 | // Debug Information. |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 871 | DwarfAbbrevSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 872 | getMachOSection("__DWARF", "__debug_abbrev", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 873 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 874 | DwarfInfoSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 875 | getMachOSection("__DWARF", "__debug_info", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 876 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 877 | DwarfLineSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 878 | getMachOSection("__DWARF", "__debug_line", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 879 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 880 | DwarfFrameSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 881 | getMachOSection("__DWARF", "__debug_frame", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 882 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 883 | DwarfPubNamesSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 884 | getMachOSection("__DWARF", "__debug_pubnames", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 885 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 886 | DwarfPubTypesSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 887 | getMachOSection("__DWARF", "__debug_pubtypes", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 888 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 889 | DwarfStrSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 890 | getMachOSection("__DWARF", "__debug_str", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 891 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 892 | DwarfLocSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 893 | getMachOSection("__DWARF", "__debug_loc", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 894 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 895 | DwarfARangesSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 896 | getMachOSection("__DWARF", "__debug_aranges", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 897 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 898 | DwarfRangesSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 899 | getMachOSection("__DWARF", "__debug_ranges", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 900 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 901 | DwarfMacroInfoSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 902 | getMachOSection("__DWARF", "__debug_macinfo", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 903 | SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 904 | DwarfDebugInlineSection = |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 905 | getMachOSection("__DWARF", "__debug_inlined", MCSectionMachO::S_ATTR_DEBUG, |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 906 | SectionKind::getMetadata()); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 909 | const MCSection *TargetLoweringObjectFileMachO:: |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 910 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 911 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | 72a676a | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 912 | // Parse the section specifier and create it if valid. |
| 913 | StringRef Segment, Section; |
| 914 | unsigned TAA, StubSize; |
| 915 | std::string ErrorCode = |
| 916 | MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section, |
| 917 | TAA, StubSize); |
Chris Lattner | 0fcad8a | 2009-08-13 00:05:07 +0000 | [diff] [blame] | 918 | if (!ErrorCode.empty()) { |
| 919 | // If invalid, report the error with llvm_report_error. |
| 920 | llvm_report_error("Global variable '" + GV->getNameStr() + |
| 921 | "' has an invalid section specifier '" + GV->getSection()+ |
| 922 | "': " + ErrorCode + "."); |
| 923 | // Fall back to dropping it into the data section. |
| 924 | return DataSection; |
| 925 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 926 | |
Chris Lattner | 0fcad8a | 2009-08-13 00:05:07 +0000 | [diff] [blame] | 927 | // Get the section. |
| 928 | const MCSectionMachO *S = |
| 929 | getMachOSection(Segment, Section, TAA, StubSize, Kind); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 930 | |
Chris Lattner | 0fcad8a | 2009-08-13 00:05:07 +0000 | [diff] [blame] | 931 | // Okay, now that we got the section, verify that the TAA & StubSize agree. |
| 932 | // If the user declared multiple globals with different section flags, we need |
| 933 | // to reject it here. |
| 934 | if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) { |
| 935 | // If invalid, report the error with llvm_report_error. |
| 936 | llvm_report_error("Global variable '" + GV->getNameStr() + |
| 937 | "' section type or attributes does not match previous" |
| 938 | " section specifier"); |
| 939 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 940 | |
Chris Lattner | 0fcad8a | 2009-08-13 00:05:07 +0000 | [diff] [blame] | 941 | return S; |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | const MCSection *TargetLoweringObjectFileMachO:: |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 945 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 946 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 947 | assert(!Kind.isThreadLocal() && "Darwin doesn't support TLS"); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 948 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 949 | if (Kind.isText()) |
Chris Lattner | a741b02 | 2009-08-01 21:42:58 +0000 | [diff] [blame] | 950 | return GV->isWeakForLinker() ? TextCoalSection : TextSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 951 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 952 | // If this is weak/linkonce, put this in a coalescable section, either in text |
| 953 | // or data depending on if it is writable. |
Chris Lattner | a741b02 | 2009-08-01 21:42:58 +0000 | [diff] [blame] | 954 | if (GV->isWeakForLinker()) { |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 955 | if (Kind.isReadOnly()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 956 | return ConstTextCoalSection; |
| 957 | return DataCoalSection; |
| 958 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 959 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 960 | // FIXME: Alignment check should be handled by section classifier. |
Chris Lattner | 01567a8 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 961 | if (Kind.isMergeable1ByteCString() || |
| 962 | Kind.isMergeable2ByteCString()) { |
| 963 | if (TM.getTargetData()->getPreferredAlignment( |
| 964 | cast<GlobalVariable>(GV)) < 32) { |
| 965 | if (Kind.isMergeable1ByteCString()) |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 966 | return CStringSection; |
Chris Lattner | 01567a8 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 967 | assert(Kind.isMergeable2ByteCString()); |
| 968 | return UStringSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 969 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 970 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 971 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 972 | if (Kind.isMergeableConst()) { |
| 973 | if (Kind.isMergeableConst4()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 974 | return FourByteConstantSection; |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 975 | if (Kind.isMergeableConst8()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 976 | return EightByteConstantSection; |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 977 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 978 | return SixteenByteConstantSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 979 | } |
Chris Lattner | 01567a8 | 2009-08-04 16:27:13 +0000 | [diff] [blame] | 980 | |
| 981 | // Otherwise, if it is readonly, but not something we can specially optimize, |
| 982 | // just drop it in .const. |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 983 | if (Kind.isReadOnly()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 984 | return ReadOnlySection; |
| 985 | |
| 986 | // If this is marked const, put it into a const section. But if the dynamic |
| 987 | // linker needs to write to it, put it in the data segment. |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 988 | if (Kind.isReadOnlyWithRel()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 989 | return ConstDataSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 990 | |
Chris Lattner | 87edd27 | 2010-01-19 02:09:44 +0000 | [diff] [blame] | 991 | // Put zero initialized globals with strong external linkage in the |
| 992 | // DATA, __common section with the .zerofill directive. |
Chris Lattner | 66fa6a2 | 2010-01-19 04:15:51 +0000 | [diff] [blame] | 993 | if (Kind.isBSSExtern()) |
Chris Lattner | 87edd27 | 2010-01-19 02:09:44 +0000 | [diff] [blame] | 994 | return DataCommonSection; |
Chris Lattner | f26c779 | 2010-01-19 06:25:51 +0000 | [diff] [blame] | 995 | |
| 996 | // Put zero initialized globals with local linkage in __DATA,__bss directive |
| 997 | // with the .zerofill directive (aka .lcomm). |
| 998 | if (Kind.isBSSLocal()) |
| 999 | return DataBSSSection; |
Chris Lattner | 87edd27 | 2010-01-19 02:09:44 +0000 | [diff] [blame] | 1000 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1001 | // Otherwise, just drop the variable in the normal data section. |
| 1002 | return DataSection; |
| 1003 | } |
| 1004 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 1005 | const MCSection * |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 1006 | TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1007 | // If this constant requires a relocation, we have to put it in the data |
| 1008 | // segment, not in the text segment. |
Eric Christopher | 41df3e3 | 2010-01-07 19:44:05 +0000 | [diff] [blame] | 1009 | if (Kind.isDataRel() || Kind.isReadOnlyWithRel()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1010 | return ConstDataSection; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1011 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1012 | if (Kind.isMergeableConst4()) |
| 1013 | return FourByteConstantSection; |
| 1014 | if (Kind.isMergeableConst8()) |
| 1015 | return EightByteConstantSection; |
Chris Lattner | 28faffe | 2009-07-28 17:50:28 +0000 | [diff] [blame] | 1016 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1017 | return SixteenByteConstantSection; |
| 1018 | return ReadOnlySection; // .const |
| 1019 | } |
| 1020 | |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 1021 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively decide |
| 1022 | /// not to emit the UsedDirective for some symbols in llvm.used. |
| 1023 | // FIXME: REMOVE this (rdar://7071300) |
| 1024 | bool TargetLoweringObjectFileMachO:: |
| 1025 | shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const { |
| 1026 | /// On Darwin, internally linked data beginning with "L" or "l" does not have |
| 1027 | /// the directive emitted (this occurs in ObjC metadata). |
| 1028 | if (!GV) return false; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1029 | |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 1030 | // Check whether the mangled name has the "Private" or "LinkerPrivate" prefix. |
| 1031 | if (GV->hasLocalLinkage() && !isa<Function>(GV)) { |
| 1032 | // FIXME: ObjC metadata is currently emitted as internal symbols that have |
| 1033 | // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and |
| 1034 | // this horrible hack can go away. |
Chris Lattner | 47177f7 | 2010-01-16 02:16:09 +0000 | [diff] [blame] | 1035 | SmallString<64> Name; |
Chris Lattner | a1ed068 | 2010-01-16 03:38:27 +0000 | [diff] [blame] | 1036 | Mang->getNameWithPrefix(Name, GV, false); |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 1037 | if (Name[0] == 'L' || Name[0] == 'l') |
| 1038 | return false; |
| 1039 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1040 | |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 1041 | return true; |
| 1042 | } |
| 1043 | |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 1044 | const MCExpr *TargetLoweringObjectFileMachO:: |
| 1045 | getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 1046 | MachineModuleInfo *MMI, unsigned Encoding) const { |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 1047 | // The mach-o version of this method defaults to returning a stub reference. |
Anton Korobeynikov | d779bcb | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 1048 | |
| 1049 | if (Encoding & dwarf::DW_EH_PE_indirect) { |
| 1050 | SmallString<128> Name; |
| 1051 | Mang->getNameWithPrefix(Name, GV, true); |
| 1052 | Name += "$non_lazy_ptr"; |
| 1053 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str()); |
| 1054 | |
| 1055 | return TargetLoweringObjectFile:: |
| 1056 | getSymbolForDwarfReference(Sym, MMI, |
| 1057 | Encoding & ~dwarf::DW_EH_PE_indirect); |
| 1058 | } |
| 1059 | |
| 1060 | return TargetLoweringObjectFile:: |
| 1061 | getSymbolForDwarfGlobalReference(GV, Mang, MMI, Encoding); |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 1064 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1065 | //===----------------------------------------------------------------------===// |
| 1066 | // COFF |
| 1067 | //===----------------------------------------------------------------------===// |
| 1068 | |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 1069 | typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy; |
| 1070 | |
| 1071 | TargetLoweringObjectFileCOFF::~TargetLoweringObjectFileCOFF() { |
| 1072 | delete (COFFUniqueMapTy*)UniquingMap; |
| 1073 | } |
| 1074 | |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1075 | |
Chris Lattner | 9287346 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 1076 | const MCSection *TargetLoweringObjectFileCOFF:: |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 1077 | getCOFFSection(StringRef Name, bool isDirective, SectionKind Kind) const { |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 1078 | // Create the map if it doesn't already exist. |
| 1079 | if (UniquingMap == 0) |
| 1080 | UniquingMap = new MachOUniqueMapTy(); |
| 1081 | COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)UniquingMap; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1082 | |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 1083 | // Do the lookup, if we have a hit, return it. |
| 1084 | const MCSectionCOFF *&Entry = Map[Name]; |
| 1085 | if (Entry) return Entry; |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1086 | |
Chris Lattner | a93ce3b | 2009-08-13 00:37:15 +0000 | [diff] [blame] | 1087 | return Entry = MCSectionCOFF::Create(Name, isDirective, Kind, getContext()); |
Chris Lattner | 8011f5f | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 1090 | void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx, |
| 1091 | const TargetMachine &TM) { |
Benjamin Kramer | 858ea8f | 2009-08-17 17:05:44 +0000 | [diff] [blame] | 1092 | if (UniquingMap != 0) |
| 1093 | ((COFFUniqueMapTy*)UniquingMap)->clear(); |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 1094 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1095 | TextSection = getCOFFSection("\t.text", true, SectionKind::getText()); |
| 1096 | DataSection = getCOFFSection("\t.data", true, SectionKind::getDataRel()); |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 1097 | StaticCtorSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1098 | getCOFFSection(".ctors", false, SectionKind::getDataRel()); |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 1099 | StaticDtorSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1100 | getCOFFSection(".dtors", false, SectionKind::getDataRel()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1101 | |
Chris Lattner | 2c3026d | 2009-08-18 16:56:17 +0000 | [diff] [blame] | 1102 | // FIXME: We're emitting LSDA info into a readonly section on COFF, even |
| 1103 | // though it contains relocatable pointers. In PIC mode, this is probably a |
| 1104 | // big runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 1105 | // adjusted or this should be a data section. |
| 1106 | LSDASection = |
| 1107 | getCOFFSection(".gcc_except_table", false, SectionKind::getReadOnly()); |
| 1108 | EHFrameSection = |
| 1109 | getCOFFSection(".eh_frame", false, SectionKind::getDataRel()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1110 | |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 1111 | // Debug info. |
| 1112 | // FIXME: Don't use 'directive' mode here. |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1113 | DwarfAbbrevSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1114 | getCOFFSection("\t.section\t.debug_abbrev,\"dr\"", |
| 1115 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1116 | DwarfInfoSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1117 | getCOFFSection("\t.section\t.debug_info,\"dr\"", |
| 1118 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1119 | DwarfLineSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1120 | getCOFFSection("\t.section\t.debug_line,\"dr\"", |
| 1121 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1122 | DwarfFrameSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1123 | getCOFFSection("\t.section\t.debug_frame,\"dr\"", |
| 1124 | true, SectionKind::getMetadata()); |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 1125 | DwarfPubNamesSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1126 | getCOFFSection("\t.section\t.debug_pubnames,\"dr\"", |
| 1127 | true, SectionKind::getMetadata()); |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 1128 | DwarfPubTypesSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1129 | getCOFFSection("\t.section\t.debug_pubtypes,\"dr\"", |
| 1130 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1131 | DwarfStrSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1132 | getCOFFSection("\t.section\t.debug_str,\"dr\"", |
| 1133 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1134 | DwarfLocSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1135 | getCOFFSection("\t.section\t.debug_loc,\"dr\"", |
| 1136 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1137 | DwarfARangesSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1138 | getCOFFSection("\t.section\t.debug_aranges,\"dr\"", |
| 1139 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1140 | DwarfRangesSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1141 | getCOFFSection("\t.section\t.debug_ranges,\"dr\"", |
| 1142 | true, SectionKind::getMetadata()); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1143 | DwarfMacroInfoSection = |
Chris Lattner | 849290a | 2009-08-08 20:22:20 +0000 | [diff] [blame] | 1144 | getCOFFSection("\t.section\t.debug_macinfo,\"dr\"", |
| 1145 | true, SectionKind::getMetadata()); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 1148 | const MCSection *TargetLoweringObjectFileCOFF:: |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1149 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 1150 | Mangler *Mang, const TargetMachine &TM) const { |
Benjamin Kramer | e3c0e10 | 2010-01-22 18:21:23 +0000 | [diff] [blame] | 1151 | return getCOFFSection(GV->getSection(), false, Kind); |
Chris Lattner | 36c2b91 | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1154 | static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) { |
| 1155 | if (Kind.isText()) |
| 1156 | return ".text$linkonce"; |
| 1157 | if (Kind.isWriteable()) |
| 1158 | return ".data$linkonce"; |
| 1159 | return ".rdata$linkonce"; |
| 1160 | } |
| 1161 | |
| 1162 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 1163 | const MCSection *TargetLoweringObjectFileCOFF:: |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 1164 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 1165 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 1166 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1167 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1168 | // If this global is linkonce/weak and the target handles this by emitting it |
| 1169 | // into a 'uniqued' section name, create and return the section now. |
Chris Lattner | a741b02 | 2009-08-01 21:42:58 +0000 | [diff] [blame] | 1170 | if (GV->isWeakForLinker()) { |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 1171 | const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind); |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 1172 | SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); |
Chris Lattner | 9d95736 | 2010-01-13 19:19:17 +0000 | [diff] [blame] | 1173 | Mang->getNameWithPrefix(Name, GV, false); |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 1174 | return getCOFFSection(Name.str(), false, Kind); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1175 | } |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1176 | |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 1177 | if (Kind.isText()) |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1178 | return getTextSection(); |
Anton Korobeynikov | 5e258a3 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 1179 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1180 | return getDataSection(); |
| 1181 | } |
Chris Lattner | 8886dc2 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 1182 | |