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" 25 #include "llvm/MC/MCSectionCOFF.h" 26 #include "llvm/MC/MCStreamer.h" 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" 33 #include "llvm/Support/ELF.h" 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" 38 #include "llvm/ADT/Triple.h" 39 using namespace llvm; 40 using namespace dwarf; 41 42 //===----------------------------------------------------------------------===// 43 // ELF 44 //===----------------------------------------------------------------------===// 45 46 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, 47 const TargetMachine &TM) { 48 TargetLoweringObjectFile::Initialize(Ctx, TM); 49 50 BSSSection = 51 getContext().getELFSection(".bss", ELF::SHT_NOBITS, 52 ELF::SHF_WRITE |ELF::SHF_ALLOC, 53 SectionKind::getBSS()); 54 55 TextSection = 56 getContext().getELFSection(".text", ELF::SHT_PROGBITS, 57 ELF::SHF_EXECINSTR | 58 ELF::SHF_ALLOC, 59 SectionKind::getText()); 60 61 DataSection = 62 getContext().getELFSection(".data", ELF::SHT_PROGBITS, 63 ELF::SHF_WRITE |ELF::SHF_ALLOC, 64 SectionKind::getDataRel()); 65 66 ReadOnlySection = 67 getContext().getELFSection(".rodata", ELF::SHT_PROGBITS, 68 ELF::SHF_ALLOC, 69 SectionKind::getReadOnly()); 70 71 TLSDataSection = 72 getContext().getELFSection(".tdata", ELF::SHT_PROGBITS, 73 ELF::SHF_ALLOC | ELF::SHF_TLS | 74 ELF::SHF_WRITE, 75 SectionKind::getThreadData()); 76 77 TLSBSSSection = 78 getContext().getELFSection(".tbss", ELF::SHT_NOBITS, 79 ELF::SHF_ALLOC | ELF::SHF_TLS | 80 ELF::SHF_WRITE, 81 SectionKind::getThreadBSS()); 82 83 DataRelSection = 84 getContext().getELFSection(".data.rel", ELF::SHT_PROGBITS, 85 ELF::SHF_ALLOC |ELF::SHF_WRITE, 86 SectionKind::getDataRel()); 87 88 DataRelLocalSection = 89 getContext().getELFSection(".data.rel.local", ELF::SHT_PROGBITS, 90 ELF::SHF_ALLOC |ELF::SHF_WRITE, 91 SectionKind::getDataRelLocal()); 92 93 DataRelROSection = 94 getContext().getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, 95 ELF::SHF_ALLOC |ELF::SHF_WRITE, 96 SectionKind::getReadOnlyWithRel()); 97 98 DataRelROLocalSection = 99 getContext().getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS, 100 ELF::SHF_ALLOC |ELF::SHF_WRITE, 101 SectionKind::getReadOnlyWithRelLocal()); 102 103 MergeableConst4Section = 104 getContext().getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, 105 ELF::SHF_ALLOC |ELF::SHF_MERGE, 106 SectionKind::getMergeableConst4()); 107 108 MergeableConst8Section = 109 getContext().getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, 110 ELF::SHF_ALLOC |ELF::SHF_MERGE, 111 SectionKind::getMergeableConst8()); 112 113 MergeableConst16Section = 114 getContext().getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, 115 ELF::SHF_ALLOC |ELF::SHF_MERGE, 116 SectionKind::getMergeableConst16()); 117 118 StaticCtorSection = 119 getContext().getELFSection(".ctors", ELF::SHT_PROGBITS, 120 ELF::SHF_ALLOC |ELF::SHF_WRITE, 121 SectionKind::getDataRel()); 122 123 StaticDtorSection = 124 getContext().getELFSection(".dtors", ELF::SHT_PROGBITS, 125 ELF::SHF_ALLOC |ELF::SHF_WRITE, 126 SectionKind::getDataRel()); 127 128 // Exception Handling Sections. 129 130 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though 131 // it contains relocatable pointers. In PIC mode, this is probably a big 132 // runtime hit for C++ apps. Either the contents of the LSDA need to be 133 // adjusted or this should be a data section. 134 LSDASection = 135 getContext().getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, 136 ELF::SHF_ALLOC, 137 SectionKind::getReadOnly()); 138 // Debug Info Sections. 139 DwarfAbbrevSection = 140 getContext().getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0, 141 SectionKind::getMetadata()); 142 DwarfInfoSection = 143 getContext().getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, 144 SectionKind::getMetadata()); 145 DwarfLineSection = 146 getContext().getELFSection(".debug_line", ELF::SHT_PROGBITS, 0, 147 SectionKind::getMetadata()); 148 DwarfFrameSection = 149 getContext().getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0, 150 SectionKind::getMetadata()); 151 DwarfPubNamesSection = 152 getContext().getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0, 153 SectionKind::getMetadata()); 154 DwarfPubTypesSection = 155 getContext().getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0, 156 SectionKind::getMetadata()); 157 DwarfStrSection = 158 getContext().getELFSection(".debug_str", ELF::SHT_PROGBITS, 0, 159 SectionKind::getMetadata()); 160 DwarfLocSection = 161 getContext().getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0, 162 SectionKind::getMetadata()); 163 DwarfARangesSection = 164 getContext().getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0, 165 SectionKind::getMetadata()); 166 DwarfRangesSection = 167 getContext().getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, 168 SectionKind::getMetadata()); 169 DwarfMacroInfoSection = 170 getContext().getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0, 171 SectionKind::getMetadata()); 172 } 173 174 const MCSection *TargetLoweringObjectFileELF::getEHFrameSection() const { 175 return getContext().getELFSection(".eh_frame", ELF::SHT_PROGBITS, 176 ELF::SHF_ALLOC, 177 SectionKind::getDataRel()); 178 } 179 180 MCSymbol * 181 TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV, 182 Mangler *Mang, 183 MachineModuleInfo *MMI) const { 184 unsigned Encoding = getPersonalityEncoding(); 185 switch (Encoding & 0x70) { 186 default: 187 report_fatal_error("We do not support this DWARF encoding yet!"); 188 case dwarf::DW_EH_PE_absptr: 189 return Mang->getSymbol(GV); 190 break; 191 case dwarf::DW_EH_PE_pcrel: { 192 return getContext().GetOrCreateSymbol(StringRef("DW.ref.") + 193 Mang->getSymbol(GV)->getName()); 194 break; 195 } 196 } 197 } 198 199 void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer, 200 const TargetMachine &TM, 201 const MCSymbol *Sym) const { 202 SmallString<64> NameData("DW.ref."); 203 NameData += Sym->getName(); 204 MCSymbol *Label = getContext().GetOrCreateSymbol(NameData); 205 Streamer.EmitSymbolAttribute(Label, MCSA_Hidden); 206 Streamer.EmitSymbolAttribute(Label, MCSA_Weak); 207 StringRef Prefix = ".data."; 208 NameData.insert(NameData.begin(), Prefix.begin(), Prefix.end()); 209 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP; 210 const MCSection *Sec = getContext().getELFSection(NameData, 211 ELF::SHT_PROGBITS, 212 Flags, 213 SectionKind::getDataRel(), 214 0, Label->getName()); 215 Streamer.SwitchSection(Sec); 216 Streamer.EmitValueToAlignment(8); 217 Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject); 218 const MCExpr *E = MCConstantExpr::Create(8, getContext()); 219 Streamer.EmitELFSize(Label, E); 220 Streamer.EmitLabel(Label); 221 222 unsigned Size = TM.getTargetData()->getPointerSize(); 223 Streamer.EmitSymbolValue(Sym, Size); 224 } 225 226 static SectionKind 227 getELFKindForNamedSection(StringRef Name, SectionKind K) { 228 // N.B.: The defaults used in here are no the same ones used in MC. 229 // We follow gcc, MC follows gas. For example, given ".section .eh_frame", 230 // both gas and MC will produce a section with no flags. Given 231 // section(".eh_frame") gcc will produce 232 // .section .eh_frame,"a",@progbits 233 if (Name.empty() || Name[0] != '.') return K; 234 235 // Some lame default implementation based on some magic section names. 236 if (Name == ".bss" || 237 Name.startswith(".bss.") || 238 Name.startswith(".gnu.linkonce.b.") || 239 Name.startswith(".llvm.linkonce.b.") || 240 Name == ".sbss" || 241 Name.startswith(".sbss.") || 242 Name.startswith(".gnu.linkonce.sb.") || 243 Name.startswith(".llvm.linkonce.sb.")) 244 return SectionKind::getBSS(); 245 246 if (Name == ".tdata" || 247 Name.startswith(".tdata.") || 248 Name.startswith(".gnu.linkonce.td.") || 249 Name.startswith(".llvm.linkonce.td.")) 250 return SectionKind::getThreadData(); 251 252 if (Name == ".tbss" || 253 Name.startswith(".tbss.") || 254 Name.startswith(".gnu.linkonce.tb.") || 255 Name.startswith(".llvm.linkonce.tb.")) 256 return SectionKind::getThreadBSS(); 257 258 return K; 259 } 260 261 262 static unsigned getELFSectionType(StringRef Name, SectionKind K) { 263 264 if (Name == ".init_array") 265 return ELF::SHT_INIT_ARRAY; 266 267 if (Name == ".fini_array") 268 return ELF::SHT_FINI_ARRAY; 269 270 if (Name == ".preinit_array") 271 return ELF::SHT_PREINIT_ARRAY; 272 273 if (K.isBSS() || K.isThreadBSS()) 274 return ELF::SHT_NOBITS; 275 276 return ELF::SHT_PROGBITS; 277 } 278 279 280 static unsigned 281 getELFSectionFlags(SectionKind K) { 282 unsigned Flags = 0; 283 284 if (!K.isMetadata()) 285 Flags |= ELF::SHF_ALLOC; 286 287 if (K.isText()) 288 Flags |= ELF::SHF_EXECINSTR; 289 290 if (K.isWriteable()) 291 Flags |= ELF::SHF_WRITE; 292 293 if (K.isThreadLocal()) 294 Flags |= ELF::SHF_TLS; 295 296 // K.isMergeableConst() is left out to honour PR4650 297 if (K.isMergeableCString() || K.isMergeableConst4() || 298 K.isMergeableConst8() || K.isMergeableConst16()) 299 Flags |= ELF::SHF_MERGE; 300 301 if (K.isMergeableCString()) 302 Flags |= ELF::SHF_STRINGS; 303 304 return Flags; 305 } 306 307 308 const MCSection *TargetLoweringObjectFileELF:: 309 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 310 Mangler *Mang, const TargetMachine &TM) const { 311 StringRef SectionName = GV->getSection(); 312 313 // Infer section flags from the section name if we can. 314 Kind = getELFKindForNamedSection(SectionName, Kind); 315 316 return getContext().getELFSection(SectionName, 317 getELFSectionType(SectionName, Kind), 318 getELFSectionFlags(Kind), Kind); 319 } 320 321 /// getSectionPrefixForGlobal - Return the section prefix name used by options 322 /// FunctionsSections and DataSections. 323 static const char *getSectionPrefixForGlobal(SectionKind Kind) { 324 if (Kind.isText()) return ".text."; 325 if (Kind.isReadOnly()) return ".rodata."; 326 327 if (Kind.isThreadData()) return ".tdata."; 328 if (Kind.isThreadBSS()) return ".tbss."; 329 330 if (Kind.isDataNoRel()) return ".data."; 331 if (Kind.isDataRelLocal()) return ".data.rel.local."; 332 if (Kind.isDataRel()) return ".data.rel."; 333 if (Kind.isReadOnlyWithRelLocal()) return ".data.rel.ro.local."; 334 335 assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); 336 return ".data.rel.ro."; 337 } 338 339 340 const MCSection *TargetLoweringObjectFileELF:: 341 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 342 Mangler *Mang, const TargetMachine &TM) const { 343 // If we have -ffunction-section or -fdata-section then we should emit the 344 // global value to a uniqued section specifically for it. 345 bool EmitUniquedSection; 346 if (Kind.isText()) 347 EmitUniquedSection = TM.getFunctionSections(); 348 else 349 EmitUniquedSection = TM.getDataSections(); 350 351 // If this global is linkonce/weak and the target handles this by emitting it 352 // into a 'uniqued' section name, create and return the section now. 353 if ((GV->isWeakForLinker() || EmitUniquedSection) && 354 !Kind.isCommon() && !Kind.isBSS()) { 355 const char *Prefix; 356 Prefix = getSectionPrefixForGlobal(Kind); 357 358 SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); 359 MCSymbol *Sym = Mang->getSymbol(GV); 360 Name.append(Sym->getName().begin(), Sym->getName().end()); 361 StringRef Group = ""; 362 unsigned Flags = getELFSectionFlags(Kind); 363 if (GV->isWeakForLinker()) { 364 Group = Sym->getName(); 365 Flags |= ELF::SHF_GROUP; 366 } 367 368 return getContext().getELFSection(Name.str(), 369 getELFSectionType(Name.str(), Kind), 370 Flags, Kind, 0, Group); 371 } 372 373 if (Kind.isText()) return TextSection; 374 375 if (Kind.isMergeable1ByteCString() || 376 Kind.isMergeable2ByteCString() || 377 Kind.isMergeable4ByteCString()) { 378 379 // We also need alignment here. 380 // FIXME: this is getting the alignment of the character, not the 381 // alignment of the global! 382 unsigned Align = 383 TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)); 384 385 const char *SizeSpec = ".rodata.str1."; 386 if (Kind.isMergeable2ByteCString()) 387 SizeSpec = ".rodata.str2."; 388 else if (Kind.isMergeable4ByteCString()) 389 SizeSpec = ".rodata.str4."; 390 else 391 assert(Kind.isMergeable1ByteCString() && "unknown string width"); 392 393 394 std::string Name = SizeSpec + utostr(Align); 395 return getContext().getELFSection(Name, ELF::SHT_PROGBITS, 396 ELF::SHF_ALLOC | 397 ELF::SHF_MERGE | 398 ELF::SHF_STRINGS, 399 Kind); 400 } 401 402 if (Kind.isMergeableConst()) { 403 if (Kind.isMergeableConst4() && MergeableConst4Section) 404 return MergeableConst4Section; 405 if (Kind.isMergeableConst8() && MergeableConst8Section) 406 return MergeableConst8Section; 407 if (Kind.isMergeableConst16() && MergeableConst16Section) 408 return MergeableConst16Section; 409 return ReadOnlySection; // .const 410 } 411 412 if (Kind.isReadOnly()) return ReadOnlySection; 413 414 if (Kind.isThreadData()) return TLSDataSection; 415 if (Kind.isThreadBSS()) return TLSBSSSection; 416 417 // Note: we claim that common symbols are put in BSSSection, but they are 418 // really emitted with the magic .comm directive, which creates a symbol table 419 // entry but not a section. 420 if (Kind.isBSS() || Kind.isCommon()) return BSSSection; 421 422 if (Kind.isDataNoRel()) return DataSection; 423 if (Kind.isDataRelLocal()) return DataRelLocalSection; 424 if (Kind.isDataRel()) return DataRelSection; 425 if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; 426 427 assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); 428 return DataRelROSection; 429 } 430 431 /// getSectionForConstant - Given a mergeable constant with the 432 /// specified size and relocation information, return a section that it 433 /// should be placed in. 434 const MCSection *TargetLoweringObjectFileELF:: 435 getSectionForConstant(SectionKind Kind) const { 436 if (Kind.isMergeableConst4() && MergeableConst4Section) 437 return MergeableConst4Section; 438 if (Kind.isMergeableConst8() && MergeableConst8Section) 439 return MergeableConst8Section; 440 if (Kind.isMergeableConst16() && MergeableConst16Section) 441 return MergeableConst16Section; 442 if (Kind.isReadOnly()) 443 return ReadOnlySection; 444 445 if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; 446 assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); 447 return DataRelROSection; 448 } 449 450 const MCExpr *TargetLoweringObjectFileELF:: 451 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, 452 MachineModuleInfo *MMI, 453 unsigned Encoding, MCStreamer &Streamer) const { 454 455 if (Encoding & dwarf::DW_EH_PE_indirect) { 456 MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>(); 457 458 SmallString<128> Name; 459 Mang->getNameWithPrefix(Name, GV, true); 460 Name += ".DW.stub"; 461 462 // Add information about the stub reference to ELFMMI so that the stub 463 // gets emitted by the asmprinter. 464 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); 465 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym); 466 if (StubSym.getPointer() == 0) { 467 MCSymbol *Sym = Mang->getSymbol(GV); 468 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); 469 } 470 471 return TargetLoweringObjectFile:: 472 getExprForDwarfReference(SSym, Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); 473 } 474 475 return TargetLoweringObjectFile:: 476 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); 477 } 478 479 //===----------------------------------------------------------------------===// 480 // MachO 481 //===----------------------------------------------------------------------===// 482 483 void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, 484 const TargetMachine &TM) { 485 IsFunctionEHFrameSymbolPrivate = false; 486 SupportsWeakOmittedEHFrame = false; 487 488 // .comm doesn't support alignment before Leopard. 489 Triple T(((LLVMTargetMachine&)TM).getTargetTriple()); 490 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5)) 491 CommDirectiveSupportsAlignment = false; 492 493 TargetLoweringObjectFile::Initialize(Ctx, TM); 494 495 TextSection // .text 496 = getContext().getMachOSection("__TEXT", "__text", 497 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 498 SectionKind::getText()); 499 DataSection // .data 500 = getContext().getMachOSection("__DATA", "__data", 0, 501 SectionKind::getDataRel()); 502 503 TLSDataSection // .tdata 504 = getContext().getMachOSection("__DATA", "__thread_data", 505 MCSectionMachO::S_THREAD_LOCAL_REGULAR, 506 SectionKind::getDataRel()); 507 TLSBSSSection // .tbss 508 = getContext().getMachOSection("__DATA", "__thread_bss", 509 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL, 510 SectionKind::getThreadBSS()); 511 512 // TODO: Verify datarel below. 513 TLSTLVSection // .tlv 514 = getContext().getMachOSection("__DATA", "__thread_vars", 515 MCSectionMachO::S_THREAD_LOCAL_VARIABLES, 516 SectionKind::getDataRel()); 517 518 TLSThreadInitSection 519 = getContext().getMachOSection("__DATA", "__thread_init", 520 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 521 SectionKind::getDataRel()); 522 523 CStringSection // .cstring 524 = getContext().getMachOSection("__TEXT", "__cstring", 525 MCSectionMachO::S_CSTRING_LITERALS, 526 SectionKind::getMergeable1ByteCString()); 527 UStringSection 528 = getContext().getMachOSection("__TEXT","__ustring", 0, 529 SectionKind::getMergeable2ByteCString()); 530 FourByteConstantSection // .literal4 531 = getContext().getMachOSection("__TEXT", "__literal4", 532 MCSectionMachO::S_4BYTE_LITERALS, 533 SectionKind::getMergeableConst4()); 534 EightByteConstantSection // .literal8 535 = getContext().getMachOSection("__TEXT", "__literal8", 536 MCSectionMachO::S_8BYTE_LITERALS, 537 SectionKind::getMergeableConst8()); 538 539 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back 540 // to using it in -static mode. 541 SixteenByteConstantSection = 0; 542 if (TM.getRelocationModel() != Reloc::Static && 543 TM.getTargetData()->getPointerSize() == 32) 544 SixteenByteConstantSection = // .literal16 545 getContext().getMachOSection("__TEXT", "__literal16", 546 MCSectionMachO::S_16BYTE_LITERALS, 547 SectionKind::getMergeableConst16()); 548 549 ReadOnlySection // .const 550 = getContext().getMachOSection("__TEXT", "__const", 0, 551 SectionKind::getReadOnly()); 552 553 TextCoalSection 554 = getContext().getMachOSection("__TEXT", "__textcoal_nt", 555 MCSectionMachO::S_COALESCED | 556 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 557 SectionKind::getText()); 558 ConstTextCoalSection 559 = getContext().getMachOSection("__TEXT", "__const_coal", 560 MCSectionMachO::S_COALESCED, 561 SectionKind::getReadOnly()); 562 ConstDataSection // .const_data 563 = getContext().getMachOSection("__DATA", "__const", 0, 564 SectionKind::getReadOnlyWithRel()); 565 DataCoalSection 566 = getContext().getMachOSection("__DATA","__datacoal_nt", 567 MCSectionMachO::S_COALESCED, 568 SectionKind::getDataRel()); 569 DataCommonSection 570 = getContext().getMachOSection("__DATA","__common", 571 MCSectionMachO::S_ZEROFILL, 572 SectionKind::getBSS()); 573 DataBSSSection 574 = getContext().getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL, 575 SectionKind::getBSS()); 576 577 578 LazySymbolPointerSection 579 = getContext().getMachOSection("__DATA", "__la_symbol_ptr", 580 MCSectionMachO::S_LAZY_SYMBOL_POINTERS, 581 SectionKind::getMetadata()); 582 NonLazySymbolPointerSection 583 = getContext().getMachOSection("__DATA", "__nl_symbol_ptr", 584 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, 585 SectionKind::getMetadata()); 586 587 if (TM.getRelocationModel() == Reloc::Static) { 588 StaticCtorSection 589 = getContext().getMachOSection("__TEXT", "__constructor", 0, 590 SectionKind::getDataRel()); 591 StaticDtorSection 592 = getContext().getMachOSection("__TEXT", "__destructor", 0, 593 SectionKind::getDataRel()); 594 } else { 595 StaticCtorSection 596 = getContext().getMachOSection("__DATA", "__mod_init_func", 597 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, 598 SectionKind::getDataRel()); 599 StaticDtorSection 600 = getContext().getMachOSection("__DATA", "__mod_term_func", 601 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, 602 SectionKind::getDataRel()); 603 } 604 605 // Exception Handling. 606 LSDASection = getContext().getMachOSection("__TEXT", "__gcc_except_tab", 0, 607 SectionKind::getReadOnlyWithRel()); 608 609 CompactUnwindSection = 610 getContext().getMachOSection("__LD", "__compact_unwind", 611 MCSectionMachO::S_ATTR_DEBUG, 612 SectionKind::getReadOnly()); 613 614 // Debug Information. 615 DwarfAbbrevSection = 616 getContext().getMachOSection("__DWARF", "__debug_abbrev", 617 MCSectionMachO::S_ATTR_DEBUG, 618 SectionKind::getMetadata()); 619 DwarfInfoSection = 620 getContext().getMachOSection("__DWARF", "__debug_info", 621 MCSectionMachO::S_ATTR_DEBUG, 622 SectionKind::getMetadata()); 623 DwarfLineSection = 624 getContext().getMachOSection("__DWARF", "__debug_line", 625 MCSectionMachO::S_ATTR_DEBUG, 626 SectionKind::getMetadata()); 627 DwarfFrameSection = 628 getContext().getMachOSection("__DWARF", "__debug_frame", 629 MCSectionMachO::S_ATTR_DEBUG, 630 SectionKind::getMetadata()); 631 DwarfPubNamesSection = 632 getContext().getMachOSection("__DWARF", "__debug_pubnames", 633 MCSectionMachO::S_ATTR_DEBUG, 634 SectionKind::getMetadata()); 635 DwarfPubTypesSection = 636 getContext().getMachOSection("__DWARF", "__debug_pubtypes", 637 MCSectionMachO::S_ATTR_DEBUG, 638 SectionKind::getMetadata()); 639 DwarfStrSection = 640 getContext().getMachOSection("__DWARF", "__debug_str", 641 MCSectionMachO::S_ATTR_DEBUG, 642 SectionKind::getMetadata()); 643 DwarfLocSection = 644 getContext().getMachOSection("__DWARF", "__debug_loc", 645 MCSectionMachO::S_ATTR_DEBUG, 646 SectionKind::getMetadata()); 647 DwarfARangesSection = 648 getContext().getMachOSection("__DWARF", "__debug_aranges", 649 MCSectionMachO::S_ATTR_DEBUG, 650 SectionKind::getMetadata()); 651 DwarfRangesSection = 652 getContext().getMachOSection("__DWARF", "__debug_ranges", 653 MCSectionMachO::S_ATTR_DEBUG, 654 SectionKind::getMetadata()); 655 DwarfMacroInfoSection = 656 getContext().getMachOSection("__DWARF", "__debug_macinfo", 657 MCSectionMachO::S_ATTR_DEBUG, 658 SectionKind::getMetadata()); 659 DwarfDebugInlineSection = 660 getContext().getMachOSection("__DWARF", "__debug_inlined", 661 MCSectionMachO::S_ATTR_DEBUG, 662 SectionKind::getMetadata()); 663 664 TLSExtraDataSection = TLSTLVSection; 665 } 666 667 const MCSection *TargetLoweringObjectFileMachO::getEHFrameSection() const { 668 return getContext().getMachOSection("__TEXT", "__eh_frame", 669 MCSectionMachO::S_COALESCED | 670 MCSectionMachO::S_ATTR_NO_TOC | 671 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS | 672 MCSectionMachO::S_ATTR_LIVE_SUPPORT, 673 SectionKind::getReadOnly()); 674 } 675 676 const MCSection *TargetLoweringObjectFileMachO:: 677 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 678 Mangler *Mang, const TargetMachine &TM) const { 679 // Parse the section specifier and create it if valid. 680 StringRef Segment, Section; 681 unsigned TAA = 0, StubSize = 0; 682 bool TAAParsed; 683 std::string ErrorCode = 684 MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section, 685 TAA, TAAParsed, StubSize); 686 if (!ErrorCode.empty()) { 687 // If invalid, report the error with report_fatal_error. 688 report_fatal_error("Global variable '" + GV->getNameStr() + 689 "' has an invalid section specifier '" + GV->getSection()+ 690 "': " + ErrorCode + "."); 691 // Fall back to dropping it into the data section. 692 return DataSection; 693 } 694 695 // Get the section. 696 const MCSectionMachO *S = 697 getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind); 698 699 // If TAA wasn't set by ParseSectionSpecifier() above, 700 // use the value returned by getMachOSection() as a default. 701 if (!TAAParsed) 702 TAA = S->getTypeAndAttributes(); 703 704 // Okay, now that we got the section, verify that the TAA & StubSize agree. 705 // If the user declared multiple globals with different section flags, we need 706 // to reject it here. 707 if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) { 708 // If invalid, report the error with report_fatal_error. 709 report_fatal_error("Global variable '" + GV->getNameStr() + 710 "' section type or attributes does not match previous" 711 " section specifier"); 712 } 713 714 return S; 715 } 716 717 const MCSection *TargetLoweringObjectFileMachO:: 718 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 719 Mangler *Mang, const TargetMachine &TM) const { 720 721 // Handle thread local data. 722 if (Kind.isThreadBSS()) return TLSBSSSection; 723 if (Kind.isThreadData()) return TLSDataSection; 724 725 if (Kind.isText()) 726 return GV->isWeakForLinker() ? TextCoalSection : TextSection; 727 728 // If this is weak/linkonce, put this in a coalescable section, either in text 729 // or data depending on if it is writable. 730 if (GV->isWeakForLinker()) { 731 if (Kind.isReadOnly()) 732 return ConstTextCoalSection; 733 return DataCoalSection; 734 } 735 736 // FIXME: Alignment check should be handled by section classifier. 737 if (Kind.isMergeable1ByteCString() && 738 TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32) 739 return CStringSection; 740 741 // Do not put 16-bit arrays in the UString section if they have an 742 // externally visible label, this runs into issues with certain linker 743 // versions. 744 if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() && 745 TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32) 746 return UStringSection; 747 748 if (Kind.isMergeableConst()) { 749 if (Kind.isMergeableConst4()) 750 return FourByteConstantSection; 751 if (Kind.isMergeableConst8()) 752 return EightByteConstantSection; 753 if (Kind.isMergeableConst16() && SixteenByteConstantSection) 754 return SixteenByteConstantSection; 755 } 756 757 // Otherwise, if it is readonly, but not something we can specially optimize, 758 // just drop it in .const. 759 if (Kind.isReadOnly()) 760 return ReadOnlySection; 761 762 // If this is marked const, put it into a const section. But if the dynamic 763 // linker needs to write to it, put it in the data segment. 764 if (Kind.isReadOnlyWithRel()) 765 return ConstDataSection; 766 767 // Put zero initialized globals with strong external linkage in the 768 // DATA, __common section with the .zerofill directive. 769 if (Kind.isBSSExtern()) 770 return DataCommonSection; 771 772 // Put zero initialized globals with local linkage in __DATA,__bss directive 773 // with the .zerofill directive (aka .lcomm). 774 if (Kind.isBSSLocal()) 775 return DataBSSSection; 776 777 // Otherwise, just drop the variable in the normal data section. 778 return DataSection; 779 } 780 781 const MCSection * 782 TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const { 783 // If this constant requires a relocation, we have to put it in the data 784 // segment, not in the text segment. 785 if (Kind.isDataRel() || Kind.isReadOnlyWithRel()) 786 return ConstDataSection; 787 788 if (Kind.isMergeableConst4()) 789 return FourByteConstantSection; 790 if (Kind.isMergeableConst8()) 791 return EightByteConstantSection; 792 if (Kind.isMergeableConst16() && SixteenByteConstantSection) 793 return SixteenByteConstantSection; 794 return ReadOnlySection; // .const 795 } 796 797 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively decide 798 /// not to emit the UsedDirective for some symbols in llvm.used. 799 // FIXME: REMOVE this (rdar://7071300) 800 bool TargetLoweringObjectFileMachO:: 801 shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const { 802 /// On Darwin, internally linked data beginning with "L" or "l" does not have 803 /// the directive emitted (this occurs in ObjC metadata). 804 if (!GV) return false; 805 806 // Check whether the mangled name has the "Private" or "LinkerPrivate" prefix. 807 if (GV->hasLocalLinkage() && !isa<Function>(GV)) { 808 // FIXME: ObjC metadata is currently emitted as internal symbols that have 809 // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and 810 // this horrible hack can go away. 811 MCSymbol *Sym = Mang->getSymbol(GV); 812 if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l') 813 return false; 814 } 815 816 return true; 817 } 818 819 const MCExpr *TargetLoweringObjectFileMachO:: 820 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, 821 MachineModuleInfo *MMI, unsigned Encoding, 822 MCStreamer &Streamer) const { 823 // The mach-o version of this method defaults to returning a stub reference. 824 825 if (Encoding & DW_EH_PE_indirect) { 826 MachineModuleInfoMachO &MachOMMI = 827 MMI->getObjFileInfo<MachineModuleInfoMachO>(); 828 829 SmallString<128> Name; 830 Mang->getNameWithPrefix(Name, GV, true); 831 Name += "$non_lazy_ptr"; 832 833 // Add information about the stub reference to MachOMMI so that the stub 834 // gets emitted by the asmprinter. 835 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); 836 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym); 837 if (StubSym.getPointer() == 0) { 838 MCSymbol *Sym = Mang->getSymbol(GV); 839 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); 840 } 841 842 return TargetLoweringObjectFile:: 843 getExprForDwarfReference(SSym, Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); 844 } 845 846 return TargetLoweringObjectFile:: 847 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); 848 } 849 850 MCSymbol *TargetLoweringObjectFileMachO:: 851 getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, 852 MachineModuleInfo *MMI) const { 853 // The mach-o version of this method defaults to returning a stub reference. 854 MachineModuleInfoMachO &MachOMMI = 855 MMI->getObjFileInfo<MachineModuleInfoMachO>(); 856 857 SmallString<128> Name; 858 Mang->getNameWithPrefix(Name, GV, true); 859 Name += "$non_lazy_ptr"; 860 861 // Add information about the stub reference to MachOMMI so that the stub 862 // gets emitted by the asmprinter. 863 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); 864 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym); 865 if (StubSym.getPointer() == 0) { 866 MCSymbol *Sym = Mang->getSymbol(GV); 867 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); 868 } 869 870 return SSym; 871 } 872 873 unsigned TargetLoweringObjectFileMachO::getPersonalityEncoding() const { 874 return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4; 875 } 876 877 unsigned TargetLoweringObjectFileMachO::getLSDAEncoding() const { 878 return DW_EH_PE_pcrel; 879 } 880 881 unsigned TargetLoweringObjectFileMachO::getFDEEncoding(bool CFI) const { 882 return DW_EH_PE_pcrel; 883 } 884 885 unsigned TargetLoweringObjectFileMachO::getTTypeEncoding() const { 886 return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4; 887 } 888 889 //===----------------------------------------------------------------------===// 890 // COFF 891 //===----------------------------------------------------------------------===// 892 893 void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx, 894 const TargetMachine &TM) { 895 TargetLoweringObjectFile::Initialize(Ctx, TM); 896 TextSection = 897 getContext().getCOFFSection(".text", 898 COFF::IMAGE_SCN_CNT_CODE | 899 COFF::IMAGE_SCN_MEM_EXECUTE | 900 COFF::IMAGE_SCN_MEM_READ, 901 SectionKind::getText()); 902 DataSection = 903 getContext().getCOFFSection(".data", 904 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 905 COFF::IMAGE_SCN_MEM_READ | 906 COFF::IMAGE_SCN_MEM_WRITE, 907 SectionKind::getDataRel()); 908 ReadOnlySection = 909 getContext().getCOFFSection(".rdata", 910 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 911 COFF::IMAGE_SCN_MEM_READ, 912 SectionKind::getReadOnly()); 913 StaticCtorSection = 914 getContext().getCOFFSection(".ctors", 915 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 916 COFF::IMAGE_SCN_MEM_READ | 917 COFF::IMAGE_SCN_MEM_WRITE, 918 SectionKind::getDataRel()); 919 StaticDtorSection = 920 getContext().getCOFFSection(".dtors", 921 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 922 COFF::IMAGE_SCN_MEM_READ | 923 COFF::IMAGE_SCN_MEM_WRITE, 924 SectionKind::getDataRel()); 925 926 // FIXME: We're emitting LSDA info into a readonly section on COFF, even 927 // though it contains relocatable pointers. In PIC mode, this is probably a 928 // big runtime hit for C++ apps. Either the contents of the LSDA need to be 929 // adjusted or this should be a data section. 930 LSDASection = 931 getContext().getCOFFSection(".gcc_except_table", 932 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 933 COFF::IMAGE_SCN_MEM_READ, 934 SectionKind::getReadOnly()); 935 // Debug info. 936 DwarfAbbrevSection = 937 getContext().getCOFFSection(".debug_abbrev", 938 COFF::IMAGE_SCN_MEM_DISCARDABLE | 939 COFF::IMAGE_SCN_MEM_READ, 940 SectionKind::getMetadata()); 941 DwarfInfoSection = 942 getContext().getCOFFSection(".debug_info", 943 COFF::IMAGE_SCN_MEM_DISCARDABLE | 944 COFF::IMAGE_SCN_MEM_READ, 945 SectionKind::getMetadata()); 946 DwarfLineSection = 947 getContext().getCOFFSection(".debug_line", 948 COFF::IMAGE_SCN_MEM_DISCARDABLE | 949 COFF::IMAGE_SCN_MEM_READ, 950 SectionKind::getMetadata()); 951 DwarfFrameSection = 952 getContext().getCOFFSection(".debug_frame", 953 COFF::IMAGE_SCN_MEM_DISCARDABLE | 954 COFF::IMAGE_SCN_MEM_READ, 955 SectionKind::getMetadata()); 956 DwarfPubNamesSection = 957 getContext().getCOFFSection(".debug_pubnames", 958 COFF::IMAGE_SCN_MEM_DISCARDABLE | 959 COFF::IMAGE_SCN_MEM_READ, 960 SectionKind::getMetadata()); 961 DwarfPubTypesSection = 962 getContext().getCOFFSection(".debug_pubtypes", 963 COFF::IMAGE_SCN_MEM_DISCARDABLE | 964 COFF::IMAGE_SCN_MEM_READ, 965 SectionKind::getMetadata()); 966 DwarfStrSection = 967 getContext().getCOFFSection(".debug_str", 968 COFF::IMAGE_SCN_MEM_DISCARDABLE | 969 COFF::IMAGE_SCN_MEM_READ, 970 SectionKind::getMetadata()); 971 DwarfLocSection = 972 getContext().getCOFFSection(".debug_loc", 973 COFF::IMAGE_SCN_MEM_DISCARDABLE | 974 COFF::IMAGE_SCN_MEM_READ, 975 SectionKind::getMetadata()); 976 DwarfARangesSection = 977 getContext().getCOFFSection(".debug_aranges", 978 COFF::IMAGE_SCN_MEM_DISCARDABLE | 979 COFF::IMAGE_SCN_MEM_READ, 980 SectionKind::getMetadata()); 981 DwarfRangesSection = 982 getContext().getCOFFSection(".debug_ranges", 983 COFF::IMAGE_SCN_MEM_DISCARDABLE | 984 COFF::IMAGE_SCN_MEM_READ, 985 SectionKind::getMetadata()); 986 DwarfMacroInfoSection = 987 getContext().getCOFFSection(".debug_macinfo", 988 COFF::IMAGE_SCN_MEM_DISCARDABLE | 989 COFF::IMAGE_SCN_MEM_READ, 990 SectionKind::getMetadata()); 991 992 DrectveSection = 993 getContext().getCOFFSection(".drectve", 994 COFF::IMAGE_SCN_LNK_INFO, 995 SectionKind::getMetadata()); 996 997 PDataSection = 998 getContext().getCOFFSection(".pdata", 999 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 1000 COFF::IMAGE_SCN_MEM_READ | 1001 COFF::IMAGE_SCN_MEM_WRITE, 1002 SectionKind::getDataRel()); 1003 1004 XDataSection = 1005 getContext().getCOFFSection(".xdata", 1006 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 1007 COFF::IMAGE_SCN_MEM_READ | 1008 COFF::IMAGE_SCN_MEM_WRITE, 1009 SectionKind::getDataRel()); 1010 } 1011 1012 const MCSection *TargetLoweringObjectFileCOFF::getEHFrameSection() const { 1013 return getContext().getCOFFSection(".eh_frame", 1014 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 1015 COFF::IMAGE_SCN_MEM_READ | 1016 COFF::IMAGE_SCN_MEM_WRITE, 1017 SectionKind::getDataRel()); 1018 } 1019 1020 const MCSection *TargetLoweringObjectFileCOFF::getWin64EHFuncTableSection( 1021 StringRef suffix) const { 1022 if (suffix == "") 1023 return PDataSection; 1024 return getContext().getCOFFSection((".pdata"+suffix).str(), 1025 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 1026 COFF::IMAGE_SCN_MEM_READ | 1027 COFF::IMAGE_SCN_MEM_WRITE, 1028 SectionKind::getDataRel()); 1029 } 1030 1031 const MCSection *TargetLoweringObjectFileCOFF::getWin64EHTableSection( 1032 StringRef suffix) const { 1033 if (suffix == "") 1034 return XDataSection; 1035 return getContext().getCOFFSection((".xdata"+suffix).str(), 1036 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 1037 COFF::IMAGE_SCN_MEM_READ | 1038 COFF::IMAGE_SCN_MEM_WRITE, 1039 SectionKind::getDataRel()); 1040 } 1041 1042 1043 static unsigned 1044 getCOFFSectionFlags(SectionKind K) { 1045 unsigned Flags = 0; 1046 1047 if (K.isMetadata()) 1048 Flags |= 1049 COFF::IMAGE_SCN_MEM_DISCARDABLE; 1050 else if (K.isText()) 1051 Flags |= 1052 COFF::IMAGE_SCN_MEM_EXECUTE | 1053 COFF::IMAGE_SCN_MEM_READ | 1054 COFF::IMAGE_SCN_CNT_CODE; 1055 else if (K.isBSS ()) 1056 Flags |= 1057 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | 1058 COFF::IMAGE_SCN_MEM_READ | 1059 COFF::IMAGE_SCN_MEM_WRITE; 1060 else if (K.isReadOnly()) 1061 Flags |= 1062 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 1063 COFF::IMAGE_SCN_MEM_READ; 1064 else if (K.isWriteable()) 1065 Flags |= 1066 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 1067 COFF::IMAGE_SCN_MEM_READ | 1068 COFF::IMAGE_SCN_MEM_WRITE; 1069 1070 return Flags; 1071 } 1072 1073 const MCSection *TargetLoweringObjectFileCOFF:: 1074 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 1075 Mangler *Mang, const TargetMachine &TM) const { 1076 return getContext().getCOFFSection(GV->getSection(), 1077 getCOFFSectionFlags(Kind), 1078 Kind); 1079 } 1080 1081 static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) { 1082 if (Kind.isText()) 1083 return ".text$"; 1084 if (Kind.isBSS ()) 1085 return ".bss$"; 1086 if (Kind.isWriteable()) 1087 return ".data$"; 1088 return ".rdata$"; 1089 } 1090 1091 1092 const MCSection *TargetLoweringObjectFileCOFF:: 1093 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 1094 Mangler *Mang, const TargetMachine &TM) const { 1095 assert(!Kind.isThreadLocal() && "Doesn't support TLS"); 1096 1097 // If this global is linkonce/weak and the target handles this by emitting it 1098 // into a 'uniqued' section name, create and return the section now. 1099 if (GV->isWeakForLinker()) { 1100 const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind); 1101 SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); 1102 MCSymbol *Sym = Mang->getSymbol(GV); 1103 Name.append(Sym->getName().begin() + 1, Sym->getName().end()); 1104 1105 unsigned Characteristics = getCOFFSectionFlags(Kind); 1106 1107 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; 1108 1109 return getContext().getCOFFSection(Name.str(), Characteristics, 1110 COFF::IMAGE_COMDAT_SELECT_ANY, Kind); 1111 } 1112 1113 if (Kind.isText()) 1114 return getTextSection(); 1115 1116 return getDataSection(); 1117 } 1118 1119