Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/TargetLoweringObjectFileImpl.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/CodeGen/TargetLoweringObjectFileImpl.h" |
| 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/GlobalVariable.h" |
| 20 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
| 21 | #include "llvm/MC/MCContext.h" |
| 22 | #include "llvm/MC/MCExpr.h" |
| 23 | #include "llvm/MC/MCSectionMachO.h" |
| 24 | #include "llvm/MC/MCSectionELF.h" |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCSectionCOFF.h" |
Rafael Espindola | 30deafc | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCStreamer.h" |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCSymbol.h" |
| 28 | #include "llvm/Target/Mangler.h" |
| 29 | #include "llvm/Target/TargetData.h" |
| 30 | #include "llvm/Target/TargetMachine.h" |
| 31 | #include "llvm/Target/TargetOptions.h" |
| 32 | #include "llvm/Support/Dwarf.h" |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ELF.h" |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 34 | #include "llvm/Support/ErrorHandling.h" |
| 35 | #include "llvm/Support/raw_ostream.h" |
| 36 | #include "llvm/ADT/SmallString.h" |
| 37 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 8048ebe | 2010-09-27 06:44:54 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/Triple.h" |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 39 | using namespace llvm; |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 40 | using namespace dwarf; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 41 | |
| 42 | //===----------------------------------------------------------------------===// |
| 43 | // ELF |
| 44 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 45 | |
Rafael Espindola | 30deafc | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 46 | MCSymbol * |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 47 | TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV, |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 48 | Mangler *Mang, |
| 49 | MachineModuleInfo *MMI) const { |
Rafael Espindola | 60246a9 | 2011-04-27 23:17:57 +0000 | [diff] [blame] | 50 | unsigned Encoding = getPersonalityEncoding(); |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 51 | switch (Encoding & 0x70) { |
| 52 | default: |
| 53 | report_fatal_error("We do not support this DWARF encoding yet!"); |
| 54 | case dwarf::DW_EH_PE_absptr: |
| 55 | return Mang->getSymbol(GV); |
| 56 | break; |
| 57 | case dwarf::DW_EH_PE_pcrel: { |
Rafael Espindola | fb66f47 | 2011-06-13 03:09:13 +0000 | [diff] [blame] | 58 | return getContext().GetOrCreateSymbol(StringRef("DW.ref.") + |
| 59 | Mang->getSymbol(GV)->getName()); |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 60 | break; |
| 61 | } |
| 62 | } |
Rafael Espindola | 30deafc | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer, |
| 66 | const TargetMachine &TM, |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 67 | const MCSymbol *Sym) const { |
Rafael Espindola | fb66f47 | 2011-06-13 03:09:13 +0000 | [diff] [blame] | 68 | SmallString<64> NameData("DW.ref."); |
| 69 | NameData += Sym->getName(); |
| 70 | MCSymbol *Label = getContext().GetOrCreateSymbol(NameData); |
Rafael Espindola | 018e38c | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 71 | Streamer.EmitSymbolAttribute(Label, MCSA_Hidden); |
| 72 | Streamer.EmitSymbolAttribute(Label, MCSA_Weak); |
Rafael Espindola | fb66f47 | 2011-06-13 03:09:13 +0000 | [diff] [blame] | 73 | StringRef Prefix = ".data."; |
| 74 | NameData.insert(NameData.begin(), Prefix.begin(), Prefix.end()); |
Rafael Espindola | 018e38c | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 75 | unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP; |
| 76 | const MCSection *Sec = getContext().getELFSection(NameData, |
| 77 | ELF::SHT_PROGBITS, |
| 78 | Flags, |
| 79 | SectionKind::getDataRel(), |
| 80 | 0, Label->getName()); |
| 81 | Streamer.SwitchSection(Sec); |
| 82 | Streamer.EmitValueToAlignment(8); |
| 83 | Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject); |
| 84 | const MCExpr *E = MCConstantExpr::Create(8, getContext()); |
| 85 | Streamer.EmitELFSize(Label, E); |
| 86 | Streamer.EmitLabel(Label); |
Rafael Espindola | 30deafc | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 87 | |
Rafael Espindola | 018e38c | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 88 | unsigned Size = TM.getTargetData()->getPointerSize(); |
| 89 | Streamer.EmitSymbolValue(Sym, Size); |
Rafael Espindola | 30deafc | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 92 | static SectionKind |
| 93 | getELFKindForNamedSection(StringRef Name, SectionKind K) { |
Rafael Espindola | e665798 | 2011-05-24 03:10:31 +0000 | [diff] [blame] | 94 | // N.B.: The defaults used in here are no the same ones used in MC. |
| 95 | // We follow gcc, MC follows gas. For example, given ".section .eh_frame", |
| 96 | // both gas and MC will produce a section with no flags. Given |
| 97 | // section(".eh_frame") gcc will produce |
| 98 | // .section .eh_frame,"a",@progbits |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 99 | if (Name.empty() || Name[0] != '.') return K; |
| 100 | |
| 101 | // Some lame default implementation based on some magic section names. |
| 102 | if (Name == ".bss" || |
| 103 | Name.startswith(".bss.") || |
| 104 | Name.startswith(".gnu.linkonce.b.") || |
| 105 | Name.startswith(".llvm.linkonce.b.") || |
| 106 | Name == ".sbss" || |
| 107 | Name.startswith(".sbss.") || |
| 108 | Name.startswith(".gnu.linkonce.sb.") || |
| 109 | Name.startswith(".llvm.linkonce.sb.")) |
| 110 | return SectionKind::getBSS(); |
| 111 | |
| 112 | if (Name == ".tdata" || |
| 113 | Name.startswith(".tdata.") || |
| 114 | Name.startswith(".gnu.linkonce.td.") || |
| 115 | Name.startswith(".llvm.linkonce.td.")) |
| 116 | return SectionKind::getThreadData(); |
| 117 | |
| 118 | if (Name == ".tbss" || |
| 119 | Name.startswith(".tbss.") || |
| 120 | Name.startswith(".gnu.linkonce.tb.") || |
| 121 | Name.startswith(".llvm.linkonce.tb.")) |
| 122 | return SectionKind::getThreadBSS(); |
| 123 | |
| 124 | return K; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | static unsigned getELFSectionType(StringRef Name, SectionKind K) { |
| 129 | |
| 130 | if (Name == ".init_array") |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 131 | return ELF::SHT_INIT_ARRAY; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 132 | |
| 133 | if (Name == ".fini_array") |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 134 | return ELF::SHT_FINI_ARRAY; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 135 | |
| 136 | if (Name == ".preinit_array") |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 137 | return ELF::SHT_PREINIT_ARRAY; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 138 | |
| 139 | if (K.isBSS() || K.isThreadBSS()) |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 140 | return ELF::SHT_NOBITS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 141 | |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 142 | return ELF::SHT_PROGBITS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
| 146 | static unsigned |
| 147 | getELFSectionFlags(SectionKind K) { |
| 148 | unsigned Flags = 0; |
| 149 | |
| 150 | if (!K.isMetadata()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 151 | Flags |= ELF::SHF_ALLOC; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 152 | |
| 153 | if (K.isText()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 154 | Flags |= ELF::SHF_EXECINSTR; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 155 | |
Rafael Espindola | d846e3f | 2011-06-07 23:26:45 +0000 | [diff] [blame] | 156 | if (K.isWriteable()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 157 | Flags |= ELF::SHF_WRITE; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 158 | |
| 159 | if (K.isThreadLocal()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 160 | Flags |= ELF::SHF_TLS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 161 | |
| 162 | // K.isMergeableConst() is left out to honour PR4650 |
| 163 | if (K.isMergeableCString() || K.isMergeableConst4() || |
| 164 | K.isMergeableConst8() || K.isMergeableConst16()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 165 | Flags |= ELF::SHF_MERGE; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 166 | |
| 167 | if (K.isMergeableCString()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 168 | Flags |= ELF::SHF_STRINGS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 169 | |
| 170 | return Flags; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | const MCSection *TargetLoweringObjectFileELF:: |
| 175 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 176 | Mangler *Mang, const TargetMachine &TM) const { |
| 177 | StringRef SectionName = GV->getSection(); |
| 178 | |
| 179 | // Infer section flags from the section name if we can. |
| 180 | Kind = getELFKindForNamedSection(SectionName, Kind); |
| 181 | |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 182 | return getContext().getELFSection(SectionName, |
| 183 | getELFSectionType(SectionName, Kind), |
Rafael Espindola | 34be396 | 2010-11-09 23:42:07 +0000 | [diff] [blame] | 184 | getELFSectionFlags(Kind), Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 187 | /// getSectionPrefixForGlobal - Return the section prefix name used by options |
| 188 | /// FunctionsSections and DataSections. |
| 189 | static const char *getSectionPrefixForGlobal(SectionKind Kind) { |
| 190 | if (Kind.isText()) return ".text."; |
| 191 | if (Kind.isReadOnly()) return ".rodata."; |
| 192 | |
| 193 | if (Kind.isThreadData()) return ".tdata."; |
| 194 | if (Kind.isThreadBSS()) return ".tbss."; |
| 195 | |
| 196 | if (Kind.isDataNoRel()) return ".data."; |
| 197 | if (Kind.isDataRelLocal()) return ".data.rel.local."; |
| 198 | if (Kind.isDataRel()) return ".data.rel."; |
| 199 | if (Kind.isReadOnlyWithRelLocal()) return ".data.rel.ro.local."; |
| 200 | |
| 201 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 202 | return ".data.rel.ro."; |
| 203 | } |
| 204 | |
| 205 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 206 | const MCSection *TargetLoweringObjectFileELF:: |
| 207 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
| 208 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 209 | // If we have -ffunction-section or -fdata-section then we should emit the |
| 210 | // global value to a uniqued section specifically for it. |
| 211 | bool EmitUniquedSection; |
| 212 | if (Kind.isText()) |
| 213 | EmitUniquedSection = TM.getFunctionSections(); |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 214 | else |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 215 | EmitUniquedSection = TM.getDataSections(); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 216 | |
| 217 | // If this global is linkonce/weak and the target handles this by emitting it |
| 218 | // into a 'uniqued' section name, create and return the section now. |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 219 | if ((GV->isWeakForLinker() || EmitUniquedSection) && |
| 220 | !Kind.isCommon() && !Kind.isBSS()) { |
| 221 | const char *Prefix; |
Rafael Espindola | 5d618ef | 2011-02-14 22:23:49 +0000 | [diff] [blame] | 222 | Prefix = getSectionPrefixForGlobal(Kind); |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 223 | |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 224 | SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); |
| 225 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 226 | Name.append(Sym->getName().begin(), Sym->getName().end()); |
Rafael Espindola | 5d618ef | 2011-02-14 22:23:49 +0000 | [diff] [blame] | 227 | StringRef Group = ""; |
| 228 | unsigned Flags = getELFSectionFlags(Kind); |
| 229 | if (GV->isWeakForLinker()) { |
| 230 | Group = Sym->getName(); |
| 231 | Flags |= ELF::SHF_GROUP; |
| 232 | } |
| 233 | |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 234 | return getContext().getELFSection(Name.str(), |
| 235 | getELFSectionType(Name.str(), Kind), |
Rafael Espindola | 5d618ef | 2011-02-14 22:23:49 +0000 | [diff] [blame] | 236 | Flags, Kind, 0, Group); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | if (Kind.isText()) return TextSection; |
| 240 | |
| 241 | if (Kind.isMergeable1ByteCString() || |
| 242 | Kind.isMergeable2ByteCString() || |
| 243 | Kind.isMergeable4ByteCString()) { |
| 244 | |
| 245 | // We also need alignment here. |
| 246 | // FIXME: this is getting the alignment of the character, not the |
| 247 | // alignment of the global! |
| 248 | unsigned Align = |
| 249 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)); |
| 250 | |
| 251 | const char *SizeSpec = ".rodata.str1."; |
| 252 | if (Kind.isMergeable2ByteCString()) |
| 253 | SizeSpec = ".rodata.str2."; |
| 254 | else if (Kind.isMergeable4ByteCString()) |
| 255 | SizeSpec = ".rodata.str4."; |
| 256 | else |
| 257 | assert(Kind.isMergeable1ByteCString() && "unknown string width"); |
| 258 | |
| 259 | |
| 260 | std::string Name = SizeSpec + utostr(Align); |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 261 | return getContext().getELFSection(Name, ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 262 | ELF::SHF_ALLOC | |
| 263 | ELF::SHF_MERGE | |
| 264 | ELF::SHF_STRINGS, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 265 | Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | if (Kind.isMergeableConst()) { |
| 269 | if (Kind.isMergeableConst4() && MergeableConst4Section) |
| 270 | return MergeableConst4Section; |
| 271 | if (Kind.isMergeableConst8() && MergeableConst8Section) |
| 272 | return MergeableConst8Section; |
| 273 | if (Kind.isMergeableConst16() && MergeableConst16Section) |
| 274 | return MergeableConst16Section; |
| 275 | return ReadOnlySection; // .const |
| 276 | } |
| 277 | |
| 278 | if (Kind.isReadOnly()) return ReadOnlySection; |
| 279 | |
| 280 | if (Kind.isThreadData()) return TLSDataSection; |
| 281 | if (Kind.isThreadBSS()) return TLSBSSSection; |
| 282 | |
| 283 | // Note: we claim that common symbols are put in BSSSection, but they are |
| 284 | // really emitted with the magic .comm directive, which creates a symbol table |
| 285 | // entry but not a section. |
| 286 | if (Kind.isBSS() || Kind.isCommon()) return BSSSection; |
| 287 | |
| 288 | if (Kind.isDataNoRel()) return DataSection; |
| 289 | if (Kind.isDataRelLocal()) return DataRelLocalSection; |
| 290 | if (Kind.isDataRel()) return DataRelSection; |
| 291 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
| 292 | |
| 293 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 294 | return DataRelROSection; |
| 295 | } |
| 296 | |
| 297 | /// getSectionForConstant - Given a mergeable constant with the |
| 298 | /// specified size and relocation information, return a section that it |
| 299 | /// should be placed in. |
| 300 | const MCSection *TargetLoweringObjectFileELF:: |
| 301 | getSectionForConstant(SectionKind Kind) const { |
| 302 | if (Kind.isMergeableConst4() && MergeableConst4Section) |
| 303 | return MergeableConst4Section; |
| 304 | if (Kind.isMergeableConst8() && MergeableConst8Section) |
| 305 | return MergeableConst8Section; |
| 306 | if (Kind.isMergeableConst16() && MergeableConst16Section) |
| 307 | return MergeableConst16Section; |
| 308 | if (Kind.isReadOnly()) |
| 309 | return ReadOnlySection; |
| 310 | |
| 311 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
| 312 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 313 | return DataRelROSection; |
| 314 | } |
| 315 | |
| 316 | const MCExpr *TargetLoweringObjectFileELF:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 317 | getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 318 | MachineModuleInfo *MMI, |
| 319 | unsigned Encoding, MCStreamer &Streamer) const { |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 320 | |
| 321 | if (Encoding & dwarf::DW_EH_PE_indirect) { |
| 322 | MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>(); |
| 323 | |
| 324 | SmallString<128> Name; |
| 325 | Mang->getNameWithPrefix(Name, GV, true); |
| 326 | Name += ".DW.stub"; |
| 327 | |
| 328 | // Add information about the stub reference to ELFMMI so that the stub |
| 329 | // gets emitted by the asmprinter. |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 330 | MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 331 | MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 332 | if (StubSym.getPointer() == 0) { |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 333 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 334 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | return TargetLoweringObjectFile:: |
Rafael Espindola | 4788c3e | 2011-04-20 03:08:09 +0000 | [diff] [blame] | 338 | getExprForDwarfReference(SSym, Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | return TargetLoweringObjectFile:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 342 | getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | //===----------------------------------------------------------------------===// |
| 346 | // MachO |
| 347 | //===----------------------------------------------------------------------===// |
| 348 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 349 | const MCSection *TargetLoweringObjectFileMachO:: |
| 350 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 351 | Mangler *Mang, const TargetMachine &TM) const { |
| 352 | // Parse the section specifier and create it if valid. |
| 353 | StringRef Segment, Section; |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 354 | unsigned TAA = 0, StubSize = 0; |
| 355 | bool TAAParsed; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 356 | std::string ErrorCode = |
| 357 | MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section, |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 358 | TAA, TAAParsed, StubSize); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 359 | if (!ErrorCode.empty()) { |
Chris Lattner | 75361b6 | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 360 | // If invalid, report the error with report_fatal_error. |
Benjamin Kramer | a7b0cb7 | 2011-11-15 16:27:03 +0000 | [diff] [blame^] | 361 | report_fatal_error("Global variable '" + GV->getName() + |
| 362 | "' has an invalid section specifier '" + |
| 363 | GV->getSection() + "': " + ErrorCode + "."); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 364 | // Fall back to dropping it into the data section. |
| 365 | return DataSection; |
| 366 | } |
| 367 | |
| 368 | // Get the section. |
| 369 | const MCSectionMachO *S = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 370 | getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 371 | |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 372 | // If TAA wasn't set by ParseSectionSpecifier() above, |
| 373 | // use the value returned by getMachOSection() as a default. |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 374 | if (!TAAParsed) |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 375 | TAA = S->getTypeAndAttributes(); |
| 376 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 377 | // Okay, now that we got the section, verify that the TAA & StubSize agree. |
| 378 | // If the user declared multiple globals with different section flags, we need |
| 379 | // to reject it here. |
| 380 | if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) { |
Chris Lattner | 75361b6 | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 381 | // If invalid, report the error with report_fatal_error. |
Benjamin Kramer | a7b0cb7 | 2011-11-15 16:27:03 +0000 | [diff] [blame^] | 382 | report_fatal_error("Global variable '" + GV->getName() + |
| 383 | "' section type or attributes does not match previous" |
| 384 | " section specifier"); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | return S; |
| 388 | } |
| 389 | |
| 390 | const MCSection *TargetLoweringObjectFileMachO:: |
| 391 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Eric Christopher | 8116ca5 | 2010-05-22 00:10:22 +0000 | [diff] [blame] | 392 | Mangler *Mang, const TargetMachine &TM) const { |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 393 | |
Eric Christopher | 02b46bc | 2010-05-25 21:28:50 +0000 | [diff] [blame] | 394 | // Handle thread local data. |
Eric Christopher | 8116ca5 | 2010-05-22 00:10:22 +0000 | [diff] [blame] | 395 | if (Kind.isThreadBSS()) return TLSBSSSection; |
Eric Christopher | 02b46bc | 2010-05-25 21:28:50 +0000 | [diff] [blame] | 396 | if (Kind.isThreadData()) return TLSDataSection; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 397 | |
| 398 | if (Kind.isText()) |
| 399 | return GV->isWeakForLinker() ? TextCoalSection : TextSection; |
| 400 | |
| 401 | // If this is weak/linkonce, put this in a coalescable section, either in text |
| 402 | // or data depending on if it is writable. |
| 403 | if (GV->isWeakForLinker()) { |
| 404 | if (Kind.isReadOnly()) |
| 405 | return ConstTextCoalSection; |
| 406 | return DataCoalSection; |
| 407 | } |
| 408 | |
| 409 | // FIXME: Alignment check should be handled by section classifier. |
Chris Lattner | 98f15d2 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 410 | if (Kind.isMergeable1ByteCString() && |
| 411 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32) |
| 412 | return CStringSection; |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 413 | |
Chris Lattner | 98f15d2 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 414 | // Do not put 16-bit arrays in the UString section if they have an |
| 415 | // externally visible label, this runs into issues with certain linker |
| 416 | // versions. |
| 417 | if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() && |
| 418 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32) |
| 419 | return UStringSection; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 420 | |
| 421 | if (Kind.isMergeableConst()) { |
| 422 | if (Kind.isMergeableConst4()) |
| 423 | return FourByteConstantSection; |
| 424 | if (Kind.isMergeableConst8()) |
| 425 | return EightByteConstantSection; |
| 426 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
| 427 | return SixteenByteConstantSection; |
| 428 | } |
| 429 | |
| 430 | // Otherwise, if it is readonly, but not something we can specially optimize, |
| 431 | // just drop it in .const. |
| 432 | if (Kind.isReadOnly()) |
| 433 | return ReadOnlySection; |
| 434 | |
| 435 | // If this is marked const, put it into a const section. But if the dynamic |
| 436 | // linker needs to write to it, put it in the data segment. |
| 437 | if (Kind.isReadOnlyWithRel()) |
| 438 | return ConstDataSection; |
| 439 | |
| 440 | // Put zero initialized globals with strong external linkage in the |
| 441 | // DATA, __common section with the .zerofill directive. |
| 442 | if (Kind.isBSSExtern()) |
| 443 | return DataCommonSection; |
| 444 | |
| 445 | // Put zero initialized globals with local linkage in __DATA,__bss directive |
| 446 | // with the .zerofill directive (aka .lcomm). |
| 447 | if (Kind.isBSSLocal()) |
| 448 | return DataBSSSection; |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 449 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 450 | // Otherwise, just drop the variable in the normal data section. |
| 451 | return DataSection; |
| 452 | } |
| 453 | |
| 454 | const MCSection * |
| 455 | TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const { |
| 456 | // If this constant requires a relocation, we have to put it in the data |
| 457 | // segment, not in the text segment. |
| 458 | if (Kind.isDataRel() || Kind.isReadOnlyWithRel()) |
| 459 | return ConstDataSection; |
| 460 | |
| 461 | if (Kind.isMergeableConst4()) |
| 462 | return FourByteConstantSection; |
| 463 | if (Kind.isMergeableConst8()) |
| 464 | return EightByteConstantSection; |
| 465 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
| 466 | return SixteenByteConstantSection; |
| 467 | return ReadOnlySection; // .const |
| 468 | } |
| 469 | |
| 470 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively decide |
| 471 | /// not to emit the UsedDirective for some symbols in llvm.used. |
| 472 | // FIXME: REMOVE this (rdar://7071300) |
| 473 | bool TargetLoweringObjectFileMachO:: |
| 474 | shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const { |
| 475 | /// On Darwin, internally linked data beginning with "L" or "l" does not have |
| 476 | /// the directive emitted (this occurs in ObjC metadata). |
| 477 | if (!GV) return false; |
| 478 | |
Bill Wendling | 07d3177 | 2010-06-29 22:34:52 +0000 | [diff] [blame] | 479 | // Check whether the mangled name has the "Private" or "LinkerPrivate" prefix. |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 480 | if (GV->hasLocalLinkage() && !isa<Function>(GV)) { |
| 481 | // FIXME: ObjC metadata is currently emitted as internal symbols that have |
Bill Wendling | 07d3177 | 2010-06-29 22:34:52 +0000 | [diff] [blame] | 482 | // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and |
| 483 | // this horrible hack can go away. |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 484 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 485 | if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l') |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 486 | return false; |
| 487 | } |
| 488 | |
| 489 | return true; |
| 490 | } |
| 491 | |
| 492 | const MCExpr *TargetLoweringObjectFileMachO:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 493 | getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 494 | MachineModuleInfo *MMI, unsigned Encoding, |
| 495 | MCStreamer &Streamer) const { |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 496 | // The mach-o version of this method defaults to returning a stub reference. |
| 497 | |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 498 | if (Encoding & DW_EH_PE_indirect) { |
| 499 | MachineModuleInfoMachO &MachOMMI = |
| 500 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 501 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 502 | SmallString<128> Name; |
| 503 | Mang->getNameWithPrefix(Name, GV, true); |
| 504 | Name += "$non_lazy_ptr"; |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 505 | |
| 506 | // Add information about the stub reference to MachOMMI so that the stub |
| 507 | // gets emitted by the asmprinter. |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 508 | MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); |
Bill Wendling | 6712154 | 2011-10-24 23:05:43 +0000 | [diff] [blame] | 509 | MachineModuleInfoImpl::StubValueTy &StubSym = |
| 510 | GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) : |
| 511 | MachOMMI.getGVStubEntry(SSym); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 512 | if (StubSym.getPointer() == 0) { |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 513 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 514 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 515 | } |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 516 | |
| 517 | return TargetLoweringObjectFile:: |
Rafael Espindola | 4788c3e | 2011-04-20 03:08:09 +0000 | [diff] [blame] | 518 | getExprForDwarfReference(SSym, Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | return TargetLoweringObjectFile:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 522 | getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 525 | MCSymbol *TargetLoweringObjectFileMachO:: |
Rafael Espindola | 60246a9 | 2011-04-27 23:17:57 +0000 | [diff] [blame] | 526 | getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 527 | MachineModuleInfo *MMI) const { |
| 528 | // The mach-o version of this method defaults to returning a stub reference. |
| 529 | MachineModuleInfoMachO &MachOMMI = |
| 530 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 531 | |
| 532 | SmallString<128> Name; |
| 533 | Mang->getNameWithPrefix(Name, GV, true); |
| 534 | Name += "$non_lazy_ptr"; |
| 535 | |
| 536 | // Add information about the stub reference to MachOMMI so that the stub |
| 537 | // gets emitted by the asmprinter. |
| 538 | MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); |
Bill Wendling | 6712154 | 2011-10-24 23:05:43 +0000 | [diff] [blame] | 539 | MachineModuleInfoImpl::StubValueTy &StubSym = |
| 540 | GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) : |
| 541 | MachOMMI.getGVStubEntry(SSym); |
Rafael Espindola | 7afec9c | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 542 | if (StubSym.getPointer() == 0) { |
| 543 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 544 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
| 545 | } |
| 546 | |
| 547 | return SSym; |
| 548 | } |
| 549 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 550 | //===----------------------------------------------------------------------===// |
| 551 | // COFF |
| 552 | //===----------------------------------------------------------------------===// |
| 553 | |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 554 | static unsigned |
| 555 | getCOFFSectionFlags(SectionKind K) { |
| 556 | unsigned Flags = 0; |
| 557 | |
Anton Korobeynikov | 36335be | 2010-07-06 15:24:56 +0000 | [diff] [blame] | 558 | if (K.isMetadata()) |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 559 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 560 | COFF::IMAGE_SCN_MEM_DISCARDABLE; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 561 | else if (K.isText()) |
| 562 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 563 | COFF::IMAGE_SCN_MEM_EXECUTE | |
Michael J. Spencer | 3931b54 | 2010-10-27 18:52:29 +0000 | [diff] [blame] | 564 | COFF::IMAGE_SCN_MEM_READ | |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 565 | COFF::IMAGE_SCN_CNT_CODE; |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 566 | else if (K.isBSS ()) |
| 567 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 568 | COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
| 569 | COFF::IMAGE_SCN_MEM_READ | |
| 570 | COFF::IMAGE_SCN_MEM_WRITE; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 571 | else if (K.isReadOnly()) |
| 572 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 573 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 574 | COFF::IMAGE_SCN_MEM_READ; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 575 | else if (K.isWriteable()) |
| 576 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 577 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 578 | COFF::IMAGE_SCN_MEM_READ | |
| 579 | COFF::IMAGE_SCN_MEM_WRITE; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 580 | |
| 581 | return Flags; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | const MCSection *TargetLoweringObjectFileCOFF:: |
| 585 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 586 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 587 | return getContext().getCOFFSection(GV->getSection(), |
| 588 | getCOFFSectionFlags(Kind), |
| 589 | Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) { |
| 593 | if (Kind.isText()) |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 594 | return ".text$"; |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 595 | if (Kind.isBSS ()) |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 596 | return ".bss$"; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 597 | if (Kind.isWriteable()) |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 598 | return ".data$"; |
| 599 | return ".rdata$"; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
| 603 | const MCSection *TargetLoweringObjectFileCOFF:: |
| 604 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
| 605 | Mangler *Mang, const TargetMachine &TM) const { |
| 606 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
| 607 | |
| 608 | // If this global is linkonce/weak and the target handles this by emitting it |
| 609 | // into a 'uniqued' section name, create and return the section now. |
| 610 | if (GV->isWeakForLinker()) { |
| 611 | const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind); |
| 612 | SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 613 | MCSymbol *Sym = Mang->getSymbol(GV); |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 614 | Name.append(Sym->getName().begin() + 1, Sym->getName().end()); |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 615 | |
| 616 | unsigned Characteristics = getCOFFSectionFlags(Kind); |
| 617 | |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 618 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 619 | |
| 620 | return getContext().getCOFFSection(Name.str(), Characteristics, |
Anton Korobeynikov | 657985e | 2010-10-08 21:50:04 +0000 | [diff] [blame] | 621 | COFF::IMAGE_COMDAT_SELECT_ANY, Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | if (Kind.isText()) |
| 625 | return getTextSection(); |
| 626 | |
| 627 | return getDataSection(); |
| 628 | } |
| 629 | |