1 //===-- MObjectFileInfo.cpp - Object File Information ---------------------===// 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 #include "llvm/MC/MCObjectFileInfo.h" 11 #include "llvm/MC/MCContext.h" 12 #include "llvm/MC/MCSection.h" 13 #include "llvm/MC/MCSectionCOFF.h" 14 #include "llvm/MC/MCSectionELF.h" 15 #include "llvm/MC/MCSectionMachO.h" 16 #include "llvm/ADT/Triple.h" 17 using namespace llvm; 18 19 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) { 20 // MachO 21 IsFunctionEHFrameSymbolPrivate = false; 22 SupportsWeakOmittedEHFrame = false; 23 24 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel 25 | dwarf::DW_EH_PE_sdata4; 26 LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel; 27 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 28 dwarf::DW_EH_PE_sdata4; 29 30 // .comm doesn't support alignment before Leopard. 31 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5)) 32 CommDirectiveSupportsAlignment = false; 33 34 StructorOutputOrder = Structors::PriorityOrder; 35 36 TextSection // .text 37 = Ctx->getMachOSection("__TEXT", "__text", 38 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 39 SectionKind::getText()); 40 DataSection // .data 41 = Ctx->getMachOSection("__DATA", "__data", 0, 42 SectionKind::getDataRel()); 43 44 TLSDataSection // .tdata 45 = Ctx->getMachOSection("__DATA", "__thread_data", 46 MCSectionMachO::S_THREAD_LOCAL_REGULAR, 47 SectionKind::getDataRel()); 48 TLSBSSSection // .tbss 49 = Ctx->getMachOSection("__DATA", "__thread_bss", 50 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL, 51 SectionKind::getThreadBSS()); 52 53 // TODO: Verify datarel below. 54 TLSTLVSection // .tlv 55 = Ctx->getMachOSection("__DATA", "__thread_vars", 56 MCSectionMachO::S_THREAD_LOCAL_VARIABLES, 57 SectionKind::getDataRel()); 58 59 TLSThreadInitSection 60 = Ctx->getMachOSection("__DATA", "__thread_init", 61 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 62 SectionKind::getDataRel()); 63 64 CStringSection // .cstring 65 = Ctx->getMachOSection("__TEXT", "__cstring", 66 MCSectionMachO::S_CSTRING_LITERALS, 67 SectionKind::getMergeable1ByteCString()); 68 UStringSection 69 = Ctx->getMachOSection("__TEXT","__ustring", 0, 70 SectionKind::getMergeable2ByteCString()); 71 FourByteConstantSection // .literal4 72 = Ctx->getMachOSection("__TEXT", "__literal4", 73 MCSectionMachO::S_4BYTE_LITERALS, 74 SectionKind::getMergeableConst4()); 75 EightByteConstantSection // .literal8 76 = Ctx->getMachOSection("__TEXT", "__literal8", 77 MCSectionMachO::S_8BYTE_LITERALS, 78 SectionKind::getMergeableConst8()); 79 80 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back 81 // to using it in -static mode. 82 SixteenByteConstantSection = 0; 83 if (RelocM != Reloc::Static && 84 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64) 85 SixteenByteConstantSection = // .literal16 86 Ctx->getMachOSection("__TEXT", "__literal16", 87 MCSectionMachO::S_16BYTE_LITERALS, 88 SectionKind::getMergeableConst16()); 89 90 ReadOnlySection // .const 91 = Ctx->getMachOSection("__TEXT", "__const", 0, 92 SectionKind::getReadOnly()); 93 94 TextCoalSection 95 = Ctx->getMachOSection("__TEXT", "__textcoal_nt", 96 MCSectionMachO::S_COALESCED | 97 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 98 SectionKind::getText()); 99 ConstTextCoalSection 100 = Ctx->getMachOSection("__TEXT", "__const_coal", 101 MCSectionMachO::S_COALESCED, 102 SectionKind::getReadOnly()); 103 ConstDataSection // .const_data 104 = Ctx->getMachOSection("__DATA", "__const", 0, 105 SectionKind::getReadOnlyWithRel()); 106 DataCoalSection 107 = Ctx->getMachOSection("__DATA","__datacoal_nt", 108 MCSectionMachO::S_COALESCED, 109 SectionKind::getDataRel()); 110 DataCommonSection 111 = Ctx->getMachOSection("__DATA","__common", 112 MCSectionMachO::S_ZEROFILL, 113 SectionKind::getBSS()); 114 DataBSSSection 115 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL, 116 SectionKind::getBSS()); 117 118 119 LazySymbolPointerSection 120 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr", 121 MCSectionMachO::S_LAZY_SYMBOL_POINTERS, 122 SectionKind::getMetadata()); 123 NonLazySymbolPointerSection 124 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr", 125 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, 126 SectionKind::getMetadata()); 127 128 if (RelocM == Reloc::Static) { 129 StaticCtorSection 130 = Ctx->getMachOSection("__TEXT", "__constructor", 0, 131 SectionKind::getDataRel()); 132 StaticDtorSection 133 = Ctx->getMachOSection("__TEXT", "__destructor", 0, 134 SectionKind::getDataRel()); 135 } else { 136 StaticCtorSection 137 = Ctx->getMachOSection("__DATA", "__mod_init_func", 138 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, 139 SectionKind::getDataRel()); 140 StaticDtorSection 141 = Ctx->getMachOSection("__DATA", "__mod_term_func", 142 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, 143 SectionKind::getDataRel()); 144 } 145 146 // Exception Handling. 147 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0, 148 SectionKind::getReadOnlyWithRel()); 149 150 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) 151 CompactUnwindSection = 152 Ctx->getMachOSection("__LD", "__compact_unwind", 153 MCSectionMachO::S_ATTR_DEBUG, 154 SectionKind::getReadOnly()); 155 156 // Debug Information. 157 DwarfAccelNamesSection = 158 Ctx->getMachOSection("__DWARF", "__apple_names", 159 MCSectionMachO::S_ATTR_DEBUG, 160 SectionKind::getMetadata()); 161 DwarfAccelObjCSection = 162 Ctx->getMachOSection("__DWARF", "__apple_objc", 163 MCSectionMachO::S_ATTR_DEBUG, 164 SectionKind::getMetadata()); 165 // 16 character section limit... 166 DwarfAccelNamespaceSection = 167 Ctx->getMachOSection("__DWARF", "__apple_namespac", 168 MCSectionMachO::S_ATTR_DEBUG, 169 SectionKind::getMetadata()); 170 DwarfAccelTypesSection = 171 Ctx->getMachOSection("__DWARF", "__apple_types", 172 MCSectionMachO::S_ATTR_DEBUG, 173 SectionKind::getMetadata()); 174 175 DwarfAbbrevSection = 176 Ctx->getMachOSection("__DWARF", "__debug_abbrev", 177 MCSectionMachO::S_ATTR_DEBUG, 178 SectionKind::getMetadata()); 179 DwarfInfoSection = 180 Ctx->getMachOSection("__DWARF", "__debug_info", 181 MCSectionMachO::S_ATTR_DEBUG, 182 SectionKind::getMetadata()); 183 DwarfLineSection = 184 Ctx->getMachOSection("__DWARF", "__debug_line", 185 MCSectionMachO::S_ATTR_DEBUG, 186 SectionKind::getMetadata()); 187 DwarfFrameSection = 188 Ctx->getMachOSection("__DWARF", "__debug_frame", 189 MCSectionMachO::S_ATTR_DEBUG, 190 SectionKind::getMetadata()); 191 DwarfPubTypesSection = 192 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", 193 MCSectionMachO::S_ATTR_DEBUG, 194 SectionKind::getMetadata()); 195 DwarfStrSection = 196 Ctx->getMachOSection("__DWARF", "__debug_str", 197 MCSectionMachO::S_ATTR_DEBUG, 198 SectionKind::getMetadata()); 199 DwarfLocSection = 200 Ctx->getMachOSection("__DWARF", "__debug_loc", 201 MCSectionMachO::S_ATTR_DEBUG, 202 SectionKind::getMetadata()); 203 DwarfARangesSection = 204 Ctx->getMachOSection("__DWARF", "__debug_aranges", 205 MCSectionMachO::S_ATTR_DEBUG, 206 SectionKind::getMetadata()); 207 DwarfRangesSection = 208 Ctx->getMachOSection("__DWARF", "__debug_ranges", 209 MCSectionMachO::S_ATTR_DEBUG, 210 SectionKind::getMetadata()); 211 DwarfMacroInfoSection = 212 Ctx->getMachOSection("__DWARF", "__debug_macinfo", 213 MCSectionMachO::S_ATTR_DEBUG, 214 SectionKind::getMetadata()); 215 DwarfDebugInlineSection = 216 Ctx->getMachOSection("__DWARF", "__debug_inlined", 217 MCSectionMachO::S_ATTR_DEBUG, 218 SectionKind::getMetadata()); 219 220 TLSExtraDataSection = TLSTLVSection; 221 } 222 223 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { 224 if (T.getArch() == Triple::x86) { 225 PersonalityEncoding = (RelocM == Reloc::PIC_) 226 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 227 : dwarf::DW_EH_PE_absptr; 228 LSDAEncoding = (RelocM == Reloc::PIC_) 229 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 230 : dwarf::DW_EH_PE_absptr; 231 FDEEncoding = FDECFIEncoding = (RelocM == Reloc::PIC_) 232 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 233 : dwarf::DW_EH_PE_absptr; 234 TTypeEncoding = (RelocM == Reloc::PIC_) 235 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 236 : dwarf::DW_EH_PE_absptr; 237 } else if (T.getArch() == Triple::x86_64) { 238 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 239 240 if (RelocM == Reloc::PIC_) { 241 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 242 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium) 243 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8); 244 LSDAEncoding = dwarf::DW_EH_PE_pcrel | 245 (CMModel == CodeModel::Small 246 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8); 247 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 248 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 249 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium) 250 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8); 251 } else { 252 PersonalityEncoding = 253 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium) 254 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; 255 LSDAEncoding = (CMModel == CodeModel::Small) 256 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; 257 FDEEncoding = dwarf::DW_EH_PE_udata4; 258 TTypeEncoding = (CMModel == CodeModel::Small) 259 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; 260 } 261 } 262 263 StructorOutputOrder = Structors::ReversePriorityOrder; 264 265 // ELF 266 BSSSection = 267 Ctx->getELFSection(".bss", ELF::SHT_NOBITS, 268 ELF::SHF_WRITE |ELF::SHF_ALLOC, 269 SectionKind::getBSS()); 270 271 TextSection = 272 Ctx->getELFSection(".text", ELF::SHT_PROGBITS, 273 ELF::SHF_EXECINSTR | 274 ELF::SHF_ALLOC, 275 SectionKind::getText()); 276 277 DataSection = 278 Ctx->getELFSection(".data", ELF::SHT_PROGBITS, 279 ELF::SHF_WRITE |ELF::SHF_ALLOC, 280 SectionKind::getDataRel()); 281 282 ReadOnlySection = 283 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, 284 ELF::SHF_ALLOC, 285 SectionKind::getReadOnly()); 286 287 TLSDataSection = 288 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS, 289 ELF::SHF_ALLOC | ELF::SHF_TLS | 290 ELF::SHF_WRITE, 291 SectionKind::getThreadData()); 292 293 TLSBSSSection = 294 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS, 295 ELF::SHF_ALLOC | ELF::SHF_TLS | 296 ELF::SHF_WRITE, 297 SectionKind::getThreadBSS()); 298 299 DataRelSection = 300 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS, 301 ELF::SHF_ALLOC |ELF::SHF_WRITE, 302 SectionKind::getDataRel()); 303 304 DataRelLocalSection = 305 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS, 306 ELF::SHF_ALLOC |ELF::SHF_WRITE, 307 SectionKind::getDataRelLocal()); 308 309 DataRelROSection = 310 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, 311 ELF::SHF_ALLOC |ELF::SHF_WRITE, 312 SectionKind::getReadOnlyWithRel()); 313 314 DataRelROLocalSection = 315 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS, 316 ELF::SHF_ALLOC |ELF::SHF_WRITE, 317 SectionKind::getReadOnlyWithRelLocal()); 318 319 MergeableConst4Section = 320 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, 321 ELF::SHF_ALLOC |ELF::SHF_MERGE, 322 SectionKind::getMergeableConst4()); 323 324 MergeableConst8Section = 325 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, 326 ELF::SHF_ALLOC |ELF::SHF_MERGE, 327 SectionKind::getMergeableConst8()); 328 329 MergeableConst16Section = 330 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, 331 ELF::SHF_ALLOC |ELF::SHF_MERGE, 332 SectionKind::getMergeableConst16()); 333 334 StaticCtorSection = 335 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS, 336 ELF::SHF_ALLOC |ELF::SHF_WRITE, 337 SectionKind::getDataRel()); 338 339 StaticDtorSection = 340 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS, 341 ELF::SHF_ALLOC |ELF::SHF_WRITE, 342 SectionKind::getDataRel()); 343 344 // Exception Handling Sections. 345 346 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though 347 // it contains relocatable pointers. In PIC mode, this is probably a big 348 // runtime hit for C++ apps. Either the contents of the LSDA need to be 349 // adjusted or this should be a data section. 350 LSDASection = 351 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, 352 ELF::SHF_ALLOC, 353 SectionKind::getReadOnly()); 354 355 // Debug Info Sections. 356 DwarfAbbrevSection = 357 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0, 358 SectionKind::getMetadata()); 359 DwarfInfoSection = 360 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, 361 SectionKind::getMetadata()); 362 DwarfLineSection = 363 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0, 364 SectionKind::getMetadata()); 365 DwarfFrameSection = 366 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0, 367 SectionKind::getMetadata()); 368 DwarfPubTypesSection = 369 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0, 370 SectionKind::getMetadata()); 371 DwarfStrSection = 372 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS, 373 ELF::SHF_MERGE | ELF::SHF_STRINGS, 374 SectionKind::getMergeable1ByteCString()); 375 DwarfLocSection = 376 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0, 377 SectionKind::getMetadata()); 378 DwarfARangesSection = 379 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0, 380 SectionKind::getMetadata()); 381 DwarfRangesSection = 382 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, 383 SectionKind::getMetadata()); 384 DwarfMacroInfoSection = 385 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0, 386 SectionKind::getMetadata()); 387 } 388 389 390 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) { 391 // COFF 392 StructorOutputOrder = Structors::ReversePriorityOrder; 393 394 TextSection = 395 Ctx->getCOFFSection(".text", 396 COFF::IMAGE_SCN_CNT_CODE | 397 COFF::IMAGE_SCN_MEM_EXECUTE | 398 COFF::IMAGE_SCN_MEM_READ, 399 SectionKind::getText()); 400 DataSection = 401 Ctx->getCOFFSection(".data", 402 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 403 COFF::IMAGE_SCN_MEM_READ | 404 COFF::IMAGE_SCN_MEM_WRITE, 405 SectionKind::getDataRel()); 406 ReadOnlySection = 407 Ctx->getCOFFSection(".rdata", 408 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 409 COFF::IMAGE_SCN_MEM_READ, 410 SectionKind::getReadOnly()); 411 StaticCtorSection = 412 Ctx->getCOFFSection(".ctors", 413 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 414 COFF::IMAGE_SCN_MEM_READ | 415 COFF::IMAGE_SCN_MEM_WRITE, 416 SectionKind::getDataRel()); 417 StaticDtorSection = 418 Ctx->getCOFFSection(".dtors", 419 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 420 COFF::IMAGE_SCN_MEM_READ | 421 COFF::IMAGE_SCN_MEM_WRITE, 422 SectionKind::getDataRel()); 423 424 // FIXME: We're emitting LSDA info into a readonly section on COFF, even 425 // though it contains relocatable pointers. In PIC mode, this is probably a 426 // big runtime hit for C++ apps. Either the contents of the LSDA need to be 427 // adjusted or this should be a data section. 428 LSDASection = 429 Ctx->getCOFFSection(".gcc_except_table", 430 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 431 COFF::IMAGE_SCN_MEM_READ, 432 SectionKind::getReadOnly()); 433 434 // Debug info. 435 DwarfAbbrevSection = 436 Ctx->getCOFFSection(".debug_abbrev", 437 COFF::IMAGE_SCN_MEM_DISCARDABLE | 438 COFF::IMAGE_SCN_MEM_READ, 439 SectionKind::getMetadata()); 440 DwarfInfoSection = 441 Ctx->getCOFFSection(".debug_info", 442 COFF::IMAGE_SCN_MEM_DISCARDABLE | 443 COFF::IMAGE_SCN_MEM_READ, 444 SectionKind::getMetadata()); 445 DwarfLineSection = 446 Ctx->getCOFFSection(".debug_line", 447 COFF::IMAGE_SCN_MEM_DISCARDABLE | 448 COFF::IMAGE_SCN_MEM_READ, 449 SectionKind::getMetadata()); 450 DwarfFrameSection = 451 Ctx->getCOFFSection(".debug_frame", 452 COFF::IMAGE_SCN_MEM_DISCARDABLE | 453 COFF::IMAGE_SCN_MEM_READ, 454 SectionKind::getMetadata()); 455 DwarfPubTypesSection = 456 Ctx->getCOFFSection(".debug_pubtypes", 457 COFF::IMAGE_SCN_MEM_DISCARDABLE | 458 COFF::IMAGE_SCN_MEM_READ, 459 SectionKind::getMetadata()); 460 DwarfStrSection = 461 Ctx->getCOFFSection(".debug_str", 462 COFF::IMAGE_SCN_MEM_DISCARDABLE | 463 COFF::IMAGE_SCN_MEM_READ, 464 SectionKind::getMetadata()); 465 DwarfLocSection = 466 Ctx->getCOFFSection(".debug_loc", 467 COFF::IMAGE_SCN_MEM_DISCARDABLE | 468 COFF::IMAGE_SCN_MEM_READ, 469 SectionKind::getMetadata()); 470 DwarfARangesSection = 471 Ctx->getCOFFSection(".debug_aranges", 472 COFF::IMAGE_SCN_MEM_DISCARDABLE | 473 COFF::IMAGE_SCN_MEM_READ, 474 SectionKind::getMetadata()); 475 DwarfRangesSection = 476 Ctx->getCOFFSection(".debug_ranges", 477 COFF::IMAGE_SCN_MEM_DISCARDABLE | 478 COFF::IMAGE_SCN_MEM_READ, 479 SectionKind::getMetadata()); 480 DwarfMacroInfoSection = 481 Ctx->getCOFFSection(".debug_macinfo", 482 COFF::IMAGE_SCN_MEM_DISCARDABLE | 483 COFF::IMAGE_SCN_MEM_READ, 484 SectionKind::getMetadata()); 485 486 DrectveSection = 487 Ctx->getCOFFSection(".drectve", 488 COFF::IMAGE_SCN_LNK_INFO, 489 SectionKind::getMetadata()); 490 491 PDataSection = 492 Ctx->getCOFFSection(".pdata", 493 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 494 COFF::IMAGE_SCN_MEM_READ | 495 COFF::IMAGE_SCN_MEM_WRITE, 496 SectionKind::getDataRel()); 497 498 XDataSection = 499 Ctx->getCOFFSection(".xdata", 500 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 501 COFF::IMAGE_SCN_MEM_READ | 502 COFF::IMAGE_SCN_MEM_WRITE, 503 SectionKind::getDataRel()); 504 } 505 506 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm, 507 CodeModel::Model cm, 508 MCContext &ctx) { 509 RelocM = relocm; 510 CMModel = cm; 511 Ctx = &ctx; 512 513 // Common. 514 CommDirectiveSupportsAlignment = true; 515 SupportsWeakOmittedEHFrame = true; 516 IsFunctionEHFrameSymbolPrivate = true; 517 518 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding = 519 TTypeEncoding = dwarf::DW_EH_PE_absptr; 520 521 EHFrameSection = 0; // Created on demand. 522 CompactUnwindSection = 0; // Used only by selected targets. 523 DwarfAccelNamesSection = 0; // Used only by selected targets. 524 DwarfAccelObjCSection = 0; // Used only by selected targets. 525 DwarfAccelNamespaceSection = 0; // Used only by selected targets. 526 DwarfAccelTypesSection = 0; // Used only by selected targets. 527 528 Triple T(TT); 529 Triple::ArchType Arch = T.getArch(); 530 // FIXME: Checking for Arch here to filter out bogus triples such as 531 // cellspu-apple-darwin. Perhaps we should fix in Triple? 532 if ((Arch == Triple::x86 || Arch == Triple::x86_64 || 533 Arch == Triple::arm || Arch == Triple::thumb || 534 Arch == Triple::ppc || Arch == Triple::ppc64 || 535 Arch == Triple::UnknownArch) && 536 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) { 537 Env = IsMachO; 538 InitMachOMCObjectFileInfo(T); 539 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) && 540 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin || 541 T.getOS() == Triple::Win32)) { 542 Env = IsCOFF; 543 InitCOFFMCObjectFileInfo(T); 544 } else { 545 Env = IsELF; 546 InitELFMCObjectFileInfo(T); 547 } 548 } 549 550 void MCObjectFileInfo::InitEHFrameSection() { 551 if (Env == IsMachO) 552 EHFrameSection = 553 Ctx->getMachOSection("__TEXT", "__eh_frame", 554 MCSectionMachO::S_COALESCED | 555 MCSectionMachO::S_ATTR_NO_TOC | 556 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS | 557 MCSectionMachO::S_ATTR_LIVE_SUPPORT, 558 SectionKind::getReadOnly()); 559 else if (Env == IsELF) 560 EHFrameSection = 561 Ctx->getELFSection(".eh_frame", ELF::SHT_PROGBITS, 562 ELF::SHF_ALLOC, 563 SectionKind::getDataRel()); 564 else 565 EHFrameSection = 566 Ctx->getCOFFSection(".eh_frame", 567 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 568 COFF::IMAGE_SCN_MEM_READ | 569 COFF::IMAGE_SCN_MEM_WRITE, 570 SectionKind::getDataRel()); 571 } 572