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 | 42263e2 | 2010-03-11 21:55:20 +0000 | [diff] [blame^] | 22 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 8da8d4b | 2010-01-13 21:29:21 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 24 | #include "llvm/Target/Mangler.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 5277b22 | 2009-08-08 20:43:12 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | 8f9b0f6 | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 8da8d4b | 2010-01-13 21:29:21 +0000 | [diff] [blame] | 30 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 5dc47ff | 2009-08-12 23:55:02 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 32 | using namespace llvm; |
| 33 | |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | // Generic Code |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 38 | TargetLoweringObjectFile::TargetLoweringObjectFile() : Ctx(0) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 39 | TextSection = 0; |
| 40 | DataSection = 0; |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 41 | BSSSection = 0; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 42 | ReadOnlySection = 0; |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 43 | StaticCtorSection = 0; |
| 44 | StaticDtorSection = 0; |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 45 | LSDASection = 0; |
Chris Lattner | 35039ac | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 46 | EHFrameSection = 0; |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 47 | |
| 48 | DwarfAbbrevSection = 0; |
| 49 | DwarfInfoSection = 0; |
| 50 | DwarfLineSection = 0; |
| 51 | DwarfFrameSection = 0; |
| 52 | DwarfPubNamesSection = 0; |
| 53 | DwarfPubTypesSection = 0; |
| 54 | DwarfDebugInlineSection = 0; |
| 55 | DwarfStrSection = 0; |
| 56 | DwarfLocSection = 0; |
| 57 | DwarfARangesSection = 0; |
| 58 | DwarfRangesSection = 0; |
| 59 | DwarfMacroInfoSection = 0; |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 60 | |
| 61 | IsFunctionEHSymbolGlobal = false; |
| 62 | IsFunctionEHFrameSymbolPrivate = true; |
| 63 | SupportsWeakOmittedEHFrame = true; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | TargetLoweringObjectFile::~TargetLoweringObjectFile() { |
| 67 | } |
| 68 | |
| 69 | static bool isSuitableForBSS(const GlobalVariable *GV) { |
| 70 | Constant *C = GV->getInitializer(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 71 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 72 | // Must have zero initializer. |
| 73 | if (!C->isNullValue()) |
| 74 | return false; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 75 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 76 | // Leave constant zeros in readonly constant sections, so they can be shared. |
| 77 | if (GV->isConstant()) |
| 78 | return false; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 79 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 80 | // If the global has an explicit section specified, don't put it in BSS. |
| 81 | if (!GV->getSection().empty()) |
| 82 | return false; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 83 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 84 | // If -nozero-initialized-in-bss is specified, don't ever use BSS. |
| 85 | if (NoZerosInBSS) |
| 86 | return false; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 87 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 88 | // Otherwise, put it in BSS! |
| 89 | return true; |
| 90 | } |
| 91 | |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 92 | /// IsNullTerminatedString - Return true if the specified constant (which is |
| 93 | /// known to have a type that is an array of 1/2/4 byte elements) ends with a |
| 94 | /// nul value and contains no other nuls in it. |
| 95 | static bool IsNullTerminatedString(const Constant *C) { |
| 96 | const ArrayType *ATy = cast<ArrayType>(C->getType()); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 97 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 98 | // First check: is we have constant array of i8 terminated with zero |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 99 | if (const ConstantArray *CVA = dyn_cast<ConstantArray>(C)) { |
| 100 | if (ATy->getNumElements() == 0) return false; |
| 101 | |
| 102 | ConstantInt *Null = |
| 103 | dyn_cast<ConstantInt>(CVA->getOperand(ATy->getNumElements()-1)); |
| 104 | if (Null == 0 || Null->getZExtValue() != 0) |
| 105 | return false; // Not null terminated. |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 106 | |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 107 | // Verify that the null doesn't occur anywhere else in the string. |
| 108 | for (unsigned i = 0, e = ATy->getNumElements()-1; i != e; ++i) |
| 109 | // Reject constantexpr elements etc. |
| 110 | if (!isa<ConstantInt>(CVA->getOperand(i)) || |
| 111 | CVA->getOperand(i) == Null) |
| 112 | return false; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 113 | return true; |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 114 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 115 | |
| 116 | // Another possibility: [1 x i8] zeroinitializer |
| 117 | if (isa<ConstantAggregateZero>(C)) |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 118 | return ATy->getNumElements() == 1; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 119 | |
| 120 | return false; |
| 121 | } |
| 122 | |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 123 | /// getKindForGlobal - This is a top-level target-independent classifier for |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 124 | /// a global variable. Given an global variable and information from TM, it |
| 125 | /// classifies the global in a variety of ways that make various target |
| 126 | /// implementations simpler. The target implementation is free to ignore this |
| 127 | /// extra info of course. |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 128 | SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV, |
| 129 | const TargetMachine &TM){ |
| 130 | assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() && |
| 131 | "Can only be used for global definitions"); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 132 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 133 | Reloc::Model ReloModel = TM.getRelocationModel(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 134 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 135 | // Early exit - functions should be always in text sections. |
| 136 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); |
| 137 | if (GVar == 0) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 138 | return SectionKind::getText(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 139 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 140 | // Handle thread-local data first. |
| 141 | if (GVar->isThreadLocal()) { |
| 142 | if (isSuitableForBSS(GVar)) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 143 | return SectionKind::getThreadBSS(); |
| 144 | return SectionKind::getThreadData(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Chris Lattner | a3839bc | 2010-01-19 02:48:26 +0000 | [diff] [blame] | 147 | // Variables with common linkage always get classified as common. |
| 148 | if (GVar->hasCommonLinkage()) |
| 149 | return SectionKind::getCommon(); |
| 150 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 151 | // Variable can be easily put to BSS section. |
Chris Lattner | ce8749e | 2010-01-19 04:15:51 +0000 | [diff] [blame] | 152 | if (isSuitableForBSS(GVar)) { |
| 153 | if (GVar->hasLocalLinkage()) |
| 154 | return SectionKind::getBSSLocal(); |
| 155 | else if (GVar->hasExternalLinkage()) |
| 156 | return SectionKind::getBSSExtern(); |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 157 | return SectionKind::getBSS(); |
Chris Lattner | ce8749e | 2010-01-19 04:15:51 +0000 | [diff] [blame] | 158 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 159 | |
| 160 | Constant *C = GVar->getInitializer(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 161 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 162 | // If the global is marked constant, we can put it into a mergable section, |
| 163 | // a mergable string section, or general .data if it contains relocations. |
| 164 | if (GVar->isConstant()) { |
| 165 | // If the initializer for the global contains something that requires a |
| 166 | // relocation, then we may have to drop this into a wriable data section |
| 167 | // even though it is marked const. |
| 168 | switch (C->getRelocationInfo()) { |
Chris Lattner | 8f9b0f6 | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 169 | default: assert(0 && "unknown relocation info kind"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 170 | case Constant::NoRelocation: |
| 171 | // If initializer is a null-terminated string, put it in a "cstring" |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 172 | // section of the right width. |
| 173 | if (const ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) { |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 174 | if (const IntegerType *ITy = |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 175 | dyn_cast<IntegerType>(ATy->getElementType())) { |
| 176 | if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 || |
| 177 | ITy->getBitWidth() == 32) && |
| 178 | IsNullTerminatedString(C)) { |
| 179 | if (ITy->getBitWidth() == 8) |
| 180 | return SectionKind::getMergeable1ByteCString(); |
| 181 | if (ITy->getBitWidth() == 16) |
| 182 | return SectionKind::getMergeable2ByteCString(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 183 | |
Chris Lattner | 1850e5a | 2009-08-04 16:13:09 +0000 | [diff] [blame] | 184 | assert(ITy->getBitWidth() == 32 && "Unknown width"); |
| 185 | return SectionKind::getMergeable4ByteCString(); |
| 186 | } |
| 187 | } |
| 188 | } |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 189 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 190 | // Otherwise, just drop it into a mergable constant section. If we have |
| 191 | // a section for this size, use it, otherwise use the arbitrary sized |
| 192 | // mergable section. |
| 193 | switch (TM.getTargetData()->getTypeAllocSize(C->getType())) { |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 194 | case 4: return SectionKind::getMergeableConst4(); |
| 195 | case 8: return SectionKind::getMergeableConst8(); |
| 196 | case 16: return SectionKind::getMergeableConst16(); |
| 197 | default: return SectionKind::getMergeableConst(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 198 | } |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 199 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 200 | case Constant::LocalRelocation: |
| 201 | // In static relocation model, the linker will resolve all addresses, so |
| 202 | // the relocation entries will actually be constants by the time the app |
| 203 | // starts up. However, we can't put this into a mergable section, because |
| 204 | // the linker doesn't take relocations into consideration when it tries to |
| 205 | // merge entries in the section. |
| 206 | if (ReloModel == Reloc::Static) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 207 | return SectionKind::getReadOnly(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 208 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 209 | // Otherwise, the dynamic linker needs to fix it up, put it in the |
| 210 | // writable data.rel.local section. |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 211 | return SectionKind::getReadOnlyWithRelLocal(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 212 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 213 | case Constant::GlobalRelocations: |
| 214 | // In static relocation model, the linker will resolve all addresses, so |
| 215 | // the relocation entries will actually be constants by the time the app |
| 216 | // starts up. However, we can't put this into a mergable section, because |
| 217 | // the linker doesn't take relocations into consideration when it tries to |
| 218 | // merge entries in the section. |
| 219 | if (ReloModel == Reloc::Static) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 220 | return SectionKind::getReadOnly(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 221 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 222 | // Otherwise, the dynamic linker needs to fix it up, put it in the |
| 223 | // writable data.rel section. |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 224 | return SectionKind::getReadOnlyWithRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | // Okay, this isn't a constant. If the initializer for the global is going |
| 229 | // to require a runtime relocation by the dynamic linker, put it into a more |
| 230 | // specific section to improve startup time of the app. This coalesces these |
| 231 | // globals together onto fewer pages, improving the locality of the dynamic |
| 232 | // linker. |
| 233 | if (ReloModel == Reloc::Static) |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 234 | return SectionKind::getDataNoRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 235 | |
| 236 | switch (C->getRelocationInfo()) { |
Chris Lattner | 8f9b0f6 | 2009-11-07 09:20:54 +0000 | [diff] [blame] | 237 | default: assert(0 && "unknown relocation info kind"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 238 | case Constant::NoRelocation: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 239 | return SectionKind::getDataNoRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 240 | case Constant::LocalRelocation: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 241 | return SectionKind::getDataRelLocal(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 242 | case Constant::GlobalRelocations: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 243 | return SectionKind::getDataRel(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | /// SectionForGlobal - This method computes the appropriate section to emit |
| 248 | /// the specified global variable or function definition. This should not |
| 249 | /// be passed external (or available externally) globals. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 250 | const MCSection *TargetLoweringObjectFile:: |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 251 | SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 252 | const TargetMachine &TM) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 253 | // Select section name. |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 254 | if (GV->hasSection()) |
| 255 | return getExplicitSectionGlobal(GV, Kind, Mang, TM); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 256 | |
| 257 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 258 | // Use default section depending on the 'type' of global |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 259 | return SelectSectionForGlobal(GV, Kind, Mang, TM); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Chris Lattner | 58bed8f | 2009-08-05 04:25:40 +0000 | [diff] [blame] | 262 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 263 | // Lame default implementation. Calculate the section name for global. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 264 | const MCSection * |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 265 | TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV, |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 266 | SectionKind Kind, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 267 | Mangler *Mang, |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 268 | const TargetMachine &TM) const{ |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 269 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 270 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 271 | if (Kind.isText()) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 272 | return getTextSection(); |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 273 | |
Chris Lattner | 8245838 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 274 | if (Kind.isBSS() && BSSSection != 0) |
| 275 | return BSSSection; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 276 | |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 277 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 278 | return ReadOnlySection; |
| 279 | |
| 280 | return getDataSection(); |
| 281 | } |
| 282 | |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 283 | /// getSectionForConstant - Given a mergable constant with the |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 284 | /// specified size and relocation information, return a section that it |
| 285 | /// should be placed in. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 286 | const MCSection * |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 287 | TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 288 | if (Kind.isReadOnly() && ReadOnlySection != 0) |
| 289 | return ReadOnlySection; |
Anton Korobeynikov | 8ddb569 | 2009-09-09 08:41:20 +0000 | [diff] [blame] | 290 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 291 | return DataSection; |
| 292 | } |
| 293 | |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 294 | /// getExprForDwarfGlobalReference - Return an MCExpr to use for a |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 295 | /// reference to the specified global variable from exception |
| 296 | /// handling information. |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 297 | const MCExpr *TargetLoweringObjectFile:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 298 | getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 299 | MachineModuleInfo *MMI, unsigned Encoding, |
| 300 | MCStreamer &Streamer) const { |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 301 | // FIXME: Use GetGlobalValueSymbol. |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 302 | SmallString<128> Name; |
| 303 | Mang->getNameWithPrefix(Name, GV, false); |
Chris Lattner | 98cdab5 | 2010-03-10 02:25:11 +0000 | [diff] [blame] | 304 | const MCSymbol *Sym; |
| 305 | |
| 306 | if (GV->hasPrivateLinkage()) |
| 307 | Sym = getContext().GetOrCreateTemporarySymbol(Name.str()); |
| 308 | else |
| 309 | Sym = getContext().GetOrCreateSymbol(Name.str()); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 310 | |
Chris Lattner | 42263e2 | 2010-03-11 21:55:20 +0000 | [diff] [blame^] | 311 | return getExprForDwarfReference(Sym, Mang, MMI, Encoding, Streamer); |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 312 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 313 | |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 314 | const MCExpr *TargetLoweringObjectFile:: |
Chris Lattner | 42263e2 | 2010-03-11 21:55:20 +0000 | [diff] [blame^] | 315 | getExprForDwarfReference(const MCSymbol *Sym, Mangler *Mang, |
| 316 | MachineModuleInfo *MMI, unsigned Encoding, |
| 317 | MCStreamer &Streamer) const { |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 318 | const MCExpr *Res = MCSymbolRefExpr::Create(Sym, getContext()); |
| 319 | |
| 320 | switch (Encoding & 0xF0) { |
| 321 | default: |
Bill Wendling | b76beda | 2010-02-16 22:47:14 +0000 | [diff] [blame] | 322 | llvm_report_error("We do not support this DWARF encoding yet!"); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 323 | case dwarf::DW_EH_PE_absptr: |
| 324 | // Do nothing special |
Chris Lattner | 42263e2 | 2010-03-11 21:55:20 +0000 | [diff] [blame^] | 325 | return Res; |
| 326 | case dwarf::DW_EH_PE_pcrel: { |
| 327 | // Emit a label to the streamer for the current position. This gives us |
| 328 | // .-foo addressing. |
| 329 | SmallString<128> Name; |
| 330 | Mang->getNameWithPrefix(Name, Twine("PCtemp") + Twine(Mang->getUniqueID()), |
| 331 | Mangler::Private); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 332 | |
Chris Lattner | 42263e2 | 2010-03-11 21:55:20 +0000 | [diff] [blame^] | 333 | MCSymbol *PCSym = getContext().GetOrCreateTemporarySymbol(Name.str()); |
| 334 | Streamer.EmitLabel(PCSym); |
| 335 | const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext()); |
| 336 | return MCBinaryExpr::CreateSub(Res, PC, getContext()); |
| 337 | } |
| 338 | } |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | unsigned TargetLoweringObjectFile::getPersonalityEncoding() const { |
| 342 | return dwarf::DW_EH_PE_absptr; |
| 343 | } |
| 344 | |
| 345 | unsigned TargetLoweringObjectFile::getLSDAEncoding() const { |
| 346 | return dwarf::DW_EH_PE_absptr; |
| 347 | } |
| 348 | |
| 349 | unsigned TargetLoweringObjectFile::getFDEEncoding() const { |
| 350 | return dwarf::DW_EH_PE_absptr; |
| 351 | } |
| 352 | |
| 353 | unsigned TargetLoweringObjectFile::getTTypeEncoding() const { |
| 354 | return dwarf::DW_EH_PE_absptr; |
| 355 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 356 | |