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" |
Dan Gohman | ffef8ac | 2009-08-11 16:02:12 +0000 | [diff] [blame] | 18 | #include "llvm/Function.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 19 | #include "llvm/GlobalVariable.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 8da8d4b | 2010-01-13 21:29:21 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 23 | #include "llvm/Target/Mangler.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 5277b22 | 2009-08-08 20:43:12 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | 8f9b0f6 | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 8da8d4b | 2010-01-13 21:29:21 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 5dc47ff | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 31 | using namespace llvm; |
| 32 | |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | // Generic Code |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 37 | TargetLoweringObjectFile::TargetLoweringObjectFile() : Ctx(0) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 38 | TextSection = 0; |
| 39 | DataSection = 0; |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 40 | BSSSection = 0; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 41 | ReadOnlySection = 0; |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 42 | StaticCtorSection = 0; |
| 43 | StaticDtorSection = 0; |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 44 | LSDASection = 0; |
Chris Lattner | 35039ac | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 45 | EHFrameSection = 0; |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 46 | |
| 47 | DwarfAbbrevSection = 0; |
| 48 | DwarfInfoSection = 0; |
| 49 | DwarfLineSection = 0; |
| 50 | DwarfFrameSection = 0; |
| 51 | DwarfPubNamesSection = 0; |
| 52 | DwarfPubTypesSection = 0; |
| 53 | DwarfDebugInlineSection = 0; |
| 54 | DwarfStrSection = 0; |
| 55 | DwarfLocSection = 0; |
| 56 | DwarfARangesSection = 0; |
| 57 | DwarfRangesSection = 0; |
| 58 | DwarfMacroInfoSection = 0; |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 59 | |
| 60 | IsFunctionEHSymbolGlobal = false; |
| 61 | IsFunctionEHFrameSymbolPrivate = true; |
| 62 | SupportsWeakOmittedEHFrame = true; |
Chris Lattner | f014412 | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 70 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 71 | // Must have zero initializer. |
| 72 | if (!C->isNullValue()) |
| 73 | return false; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 74 | |
Chris Lattner | f014412 | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 78 | |
Chris Lattner | f014412 | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 82 | |
Chris Lattner | f014412 | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 86 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 87 | // Otherwise, put it in BSS! |
| 88 | return true; |
| 89 | } |
| 90 | |
Chris Lattner | 1850e5a | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 96 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 97 | // First check: is we have constant array of i8 terminated with zero |
Chris Lattner | 1850e5a | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 105 | |
Chris Lattner | 1850e5a | 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 | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 112 | return true; |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 113 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 114 | |
| 115 | // Another possibility: [1 x i8] zeroinitializer |
| 116 | if (isa<ConstantAggregateZero>(C)) |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 117 | return ATy->getNumElements() == 1; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 122 | /// getKindForGlobal - This is a top-level target-independent classifier for |
Chris Lattner | 968ff11 | 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 | 58bed8f | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 131 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 132 | Reloc::Model ReloModel = TM.getRelocationModel(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 133 | |
Chris Lattner | f014412 | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 137 | return SectionKind::getText(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 138 | |
Chris Lattner | f014412 | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 142 | return SectionKind::getThreadBSS(); |
| 143 | return SectionKind::getThreadData(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Chris Lattner | a3839bc | 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 | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 150 | // Variable can be easily put to BSS section. |
Chris Lattner | ce8749e | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 156 | return SectionKind::getBSS(); |
Chris Lattner | ce8749e | 2010-01-19 04:15:51 +0000 | [diff] [blame] | 157 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 158 | |
| 159 | Constant *C = GVar->getInitializer(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 160 | |
Chris Lattner | f014412 | 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 | 8f9b0f6 | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 168 | default: assert(0 && "unknown relocation info kind"); |
Chris Lattner | f014412 | 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 | 1850e5a | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 173 | if (const IntegerType *ITy = |
Chris Lattner | 1850e5a | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 182 | |
Chris Lattner | 1850e5a | 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 | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 188 | |
Chris Lattner | f014412 | 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 | 2798119 | 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 | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 197 | } |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 198 | |
Chris Lattner | f014412 | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 206 | return SectionKind::getReadOnly(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 207 | |
Chris Lattner | f014412 | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 210 | return SectionKind::getReadOnlyWithRelLocal(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 211 | |
Chris Lattner | f014412 | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 219 | return SectionKind::getReadOnly(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 220 | |
Chris Lattner | f014412 | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 223 | return SectionKind::getReadOnlyWithRel(); |
Chris Lattner | f014412 | 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 | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 233 | return SectionKind::getDataNoRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 234 | |
| 235 | switch (C->getRelocationInfo()) { |
Chris Lattner | 8f9b0f6 | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 236 | default: assert(0 && "unknown relocation info kind"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 237 | case Constant::NoRelocation: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 238 | return SectionKind::getDataNoRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 239 | case Constant::LocalRelocation: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 240 | return SectionKind::getDataRelLocal(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 241 | case Constant::GlobalRelocations: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 242 | return SectionKind::getDataRel(); |
Chris Lattner | f014412 | 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 | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 249 | const MCSection *TargetLoweringObjectFile:: |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 250 | SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 251 | const TargetMachine &TM) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 252 | // Select section name. |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 253 | if (GV->hasSection()) |
| 254 | return getExplicitSectionGlobal(GV, Kind, Mang, TM); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 255 | |
| 256 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 257 | // Use default section depending on the 'type' of global |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 258 | return SelectSectionForGlobal(GV, Kind, Mang, TM); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 261 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 262 | // Lame default implementation. Calculate the section name for global. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 263 | const MCSection * |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 264 | TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV, |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 265 | SectionKind Kind, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 266 | Mangler *Mang, |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 267 | const TargetMachine &TM) const{ |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 268 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 269 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 270 | if (Kind.isText()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 271 | return getTextSection(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 272 | |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 273 | if (Kind.isBSS() && BSSSection != 0) |
| 274 | return BSSSection; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 275 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 276 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 277 | return ReadOnlySection; |
| 278 | |
| 279 | return getDataSection(); |
| 280 | } |
| 281 | |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 282 | /// getSectionForConstant - Given a mergable constant with the |
Chris Lattner | f014412 | 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 | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 285 | const MCSection * |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 286 | TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 287 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
| 288 | return ReadOnlySection; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 289 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 290 | return DataSection; |
| 291 | } |
| 292 | |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 293 | /// getExprForDwarfGlobalReference - Return an MCExpr to use for a |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 294 | /// reference to the specified global variable from exception |
| 295 | /// handling information. |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 296 | const MCExpr *TargetLoweringObjectFile:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 297 | getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 298 | MachineModuleInfo *MMI, unsigned Encoding, |
| 299 | MCStreamer &Streamer) const { |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 300 | // FIXME: Use GetGlobalValueSymbol. |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 301 | SmallString<128> Name; |
| 302 | Mang->getNameWithPrefix(Name, GV, false); |
Chris Lattner | 98cdab5 | 2010-03-10 02:25:11 +0000 | [diff] [blame] | 303 | const MCSymbol *Sym; |
| 304 | |
| 305 | if (GV->hasPrivateLinkage()) |
| 306 | Sym = getContext().GetOrCreateTemporarySymbol(Name.str()); |
| 307 | else |
| 308 | Sym = getContext().GetOrCreateSymbol(Name.str()); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 309 | |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 310 | return getExprForDwarfReference(Sym, MMI, Encoding, Streamer); |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 311 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 312 | |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 313 | const MCExpr *TargetLoweringObjectFile:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 314 | getExprForDwarfReference(const MCSymbol *Sym, MachineModuleInfo *MMI, |
| 315 | unsigned Encoding, MCStreamer &Streamer) const { |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 316 | const MCExpr *Res = MCSymbolRefExpr::Create(Sym, getContext()); |
| 317 | |
| 318 | switch (Encoding & 0xF0) { |
| 319 | default: |
Bill Wendling | b76beda | 2010-02-16 22:47:14 +0000 | [diff] [blame] | 320 | llvm_report_error("We do not support this DWARF encoding yet!"); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 321 | break; |
| 322 | case dwarf::DW_EH_PE_absptr: |
| 323 | // Do nothing special |
| 324 | break; |
| 325 | case dwarf::DW_EH_PE_pcrel: |
| 326 | // FIXME: PCSymbol |
| 327 | const MCExpr *PC = MCSymbolRefExpr::Create(".", getContext()); |
| 328 | Res = MCBinaryExpr::CreateSub(Res, PC, getContext()); |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | return Res; |
| 333 | } |
| 334 | |
| 335 | unsigned TargetLoweringObjectFile::getPersonalityEncoding() const { |
| 336 | return dwarf::DW_EH_PE_absptr; |
| 337 | } |
| 338 | |
| 339 | unsigned TargetLoweringObjectFile::getLSDAEncoding() const { |
| 340 | return dwarf::DW_EH_PE_absptr; |
| 341 | } |
| 342 | |
| 343 | unsigned TargetLoweringObjectFile::getFDEEncoding() const { |
| 344 | return dwarf::DW_EH_PE_absptr; |
| 345 | } |
| 346 | |
| 347 | unsigned TargetLoweringObjectFile::getTTypeEncoding() const { |
| 348 | return dwarf::DW_EH_PE_absptr; |
| 349 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 350 | |