MCObjectFileInfo.cpp revision 263508
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/ADT/Triple.h" 12#include "llvm/MC/MCContext.h" 13#include "llvm/MC/MCSection.h" 14#include "llvm/MC/MCSectionCOFF.h" 15#include "llvm/MC/MCSectionELF.h" 16#include "llvm/MC/MCSectionMachO.h" 17using namespace llvm; 18 19void 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 TextSection // .text 35 = Ctx->getMachOSection("__TEXT", "__text", 36 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 37 SectionKind::getText()); 38 DataSection // .data 39 = Ctx->getMachOSection("__DATA", "__data", 0, 40 SectionKind::getDataRel()); 41 42 // BSSSection might not be expected initialized on msvc. 43 BSSSection = 0; 44 45 TLSDataSection // .tdata 46 = Ctx->getMachOSection("__DATA", "__thread_data", 47 MCSectionMachO::S_THREAD_LOCAL_REGULAR, 48 SectionKind::getDataRel()); 49 TLSBSSSection // .tbss 50 = Ctx->getMachOSection("__DATA", "__thread_bss", 51 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL, 52 SectionKind::getThreadBSS()); 53 54 // TODO: Verify datarel below. 55 TLSTLVSection // .tlv 56 = Ctx->getMachOSection("__DATA", "__thread_vars", 57 MCSectionMachO::S_THREAD_LOCAL_VARIABLES, 58 SectionKind::getDataRel()); 59 60 TLSThreadInitSection 61 = Ctx->getMachOSection("__DATA", "__thread_init", 62 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 63 SectionKind::getDataRel()); 64 65 CStringSection // .cstring 66 = Ctx->getMachOSection("__TEXT", "__cstring", 67 MCSectionMachO::S_CSTRING_LITERALS, 68 SectionKind::getMergeable1ByteCString()); 69 UStringSection 70 = Ctx->getMachOSection("__TEXT","__ustring", 0, 71 SectionKind::getMergeable2ByteCString()); 72 FourByteConstantSection // .literal4 73 = Ctx->getMachOSection("__TEXT", "__literal4", 74 MCSectionMachO::S_4BYTE_LITERALS, 75 SectionKind::getMergeableConst4()); 76 EightByteConstantSection // .literal8 77 = Ctx->getMachOSection("__TEXT", "__literal8", 78 MCSectionMachO::S_8BYTE_LITERALS, 79 SectionKind::getMergeableConst8()); 80 81 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back 82 // to using it in -static mode. 83 SixteenByteConstantSection = 0; 84 if (RelocM != Reloc::Static && 85 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 && 86 T.getArch() != Triple::ppc64le) 87 SixteenByteConstantSection = // .literal16 88 Ctx->getMachOSection("__TEXT", "__literal16", 89 MCSectionMachO::S_16BYTE_LITERALS, 90 SectionKind::getMergeableConst16()); 91 92 ReadOnlySection // .const 93 = Ctx->getMachOSection("__TEXT", "__const", 0, 94 SectionKind::getReadOnly()); 95 96 TextCoalSection 97 = Ctx->getMachOSection("__TEXT", "__textcoal_nt", 98 MCSectionMachO::S_COALESCED | 99 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 100 SectionKind::getText()); 101 ConstTextCoalSection 102 = Ctx->getMachOSection("__TEXT", "__const_coal", 103 MCSectionMachO::S_COALESCED, 104 SectionKind::getReadOnly()); 105 ConstDataSection // .const_data 106 = Ctx->getMachOSection("__DATA", "__const", 0, 107 SectionKind::getReadOnlyWithRel()); 108 DataCoalSection 109 = Ctx->getMachOSection("__DATA","__datacoal_nt", 110 MCSectionMachO::S_COALESCED, 111 SectionKind::getDataRel()); 112 DataCommonSection 113 = Ctx->getMachOSection("__DATA","__common", 114 MCSectionMachO::S_ZEROFILL, 115 SectionKind::getBSS()); 116 DataBSSSection 117 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL, 118 SectionKind::getBSS()); 119 120 121 LazySymbolPointerSection 122 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr", 123 MCSectionMachO::S_LAZY_SYMBOL_POINTERS, 124 SectionKind::getMetadata()); 125 NonLazySymbolPointerSection 126 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr", 127 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, 128 SectionKind::getMetadata()); 129 130 if (RelocM == Reloc::Static) { 131 StaticCtorSection 132 = Ctx->getMachOSection("__TEXT", "__constructor", 0, 133 SectionKind::getDataRel()); 134 StaticDtorSection 135 = Ctx->getMachOSection("__TEXT", "__destructor", 0, 136 SectionKind::getDataRel()); 137 } else { 138 StaticCtorSection 139 = Ctx->getMachOSection("__DATA", "__mod_init_func", 140 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, 141 SectionKind::getDataRel()); 142 StaticDtorSection 143 = Ctx->getMachOSection("__DATA", "__mod_term_func", 144 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, 145 SectionKind::getDataRel()); 146 } 147 148 // Exception Handling. 149 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0, 150 SectionKind::getReadOnlyWithRel()); 151 152 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) { 153 CompactUnwindSection = 154 Ctx->getMachOSection("__LD", "__compact_unwind", 155 MCSectionMachO::S_ATTR_DEBUG, 156 SectionKind::getReadOnly()); 157 158 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86) 159 CompactUnwindDwarfEHFrameOnly = 0x04000000; 160 } 161 162 // Debug Information. 163 DwarfAccelNamesSection = 164 Ctx->getMachOSection("__DWARF", "__apple_names", 165 MCSectionMachO::S_ATTR_DEBUG, 166 SectionKind::getMetadata()); 167 DwarfAccelObjCSection = 168 Ctx->getMachOSection("__DWARF", "__apple_objc", 169 MCSectionMachO::S_ATTR_DEBUG, 170 SectionKind::getMetadata()); 171 // 16 character section limit... 172 DwarfAccelNamespaceSection = 173 Ctx->getMachOSection("__DWARF", "__apple_namespac", 174 MCSectionMachO::S_ATTR_DEBUG, 175 SectionKind::getMetadata()); 176 DwarfAccelTypesSection = 177 Ctx->getMachOSection("__DWARF", "__apple_types", 178 MCSectionMachO::S_ATTR_DEBUG, 179 SectionKind::getMetadata()); 180 181 DwarfAbbrevSection = 182 Ctx->getMachOSection("__DWARF", "__debug_abbrev", 183 MCSectionMachO::S_ATTR_DEBUG, 184 SectionKind::getMetadata()); 185 DwarfInfoSection = 186 Ctx->getMachOSection("__DWARF", "__debug_info", 187 MCSectionMachO::S_ATTR_DEBUG, 188 SectionKind::getMetadata()); 189 DwarfLineSection = 190 Ctx->getMachOSection("__DWARF", "__debug_line", 191 MCSectionMachO::S_ATTR_DEBUG, 192 SectionKind::getMetadata()); 193 DwarfFrameSection = 194 Ctx->getMachOSection("__DWARF", "__debug_frame", 195 MCSectionMachO::S_ATTR_DEBUG, 196 SectionKind::getMetadata()); 197 DwarfPubNamesSection = 198 Ctx->getMachOSection("__DWARF", "__debug_pubnames", 199 MCSectionMachO::S_ATTR_DEBUG, 200 SectionKind::getMetadata()); 201 DwarfPubTypesSection = 202 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", 203 MCSectionMachO::S_ATTR_DEBUG, 204 SectionKind::getMetadata()); 205 DwarfGnuPubNamesSection = 206 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", 207 MCSectionMachO::S_ATTR_DEBUG, 208 SectionKind::getMetadata()); 209 DwarfGnuPubTypesSection = 210 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", 211 MCSectionMachO::S_ATTR_DEBUG, 212 SectionKind::getMetadata()); 213 DwarfStrSection = 214 Ctx->getMachOSection("__DWARF", "__debug_str", 215 MCSectionMachO::S_ATTR_DEBUG, 216 SectionKind::getMetadata()); 217 DwarfLocSection = 218 Ctx->getMachOSection("__DWARF", "__debug_loc", 219 MCSectionMachO::S_ATTR_DEBUG, 220 SectionKind::getMetadata()); 221 DwarfARangesSection = 222 Ctx->getMachOSection("__DWARF", "__debug_aranges", 223 MCSectionMachO::S_ATTR_DEBUG, 224 SectionKind::getMetadata()); 225 DwarfRangesSection = 226 Ctx->getMachOSection("__DWARF", "__debug_ranges", 227 MCSectionMachO::S_ATTR_DEBUG, 228 SectionKind::getMetadata()); 229 DwarfMacroInfoSection = 230 Ctx->getMachOSection("__DWARF", "__debug_macinfo", 231 MCSectionMachO::S_ATTR_DEBUG, 232 SectionKind::getMetadata()); 233 DwarfDebugInlineSection = 234 Ctx->getMachOSection("__DWARF", "__debug_inlined", 235 MCSectionMachO::S_ATTR_DEBUG, 236 SectionKind::getMetadata()); 237 StackMapSection = 238 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0, 239 SectionKind::getMetadata()); 240 241 TLSExtraDataSection = TLSTLVSection; 242} 243 244void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { 245 if (T.getArch() == Triple::mips || 246 T.getArch() == Triple::mipsel) 247 FDECFIEncoding = dwarf::DW_EH_PE_sdata4; 248 else if (T.getArch() == Triple::mips64 || 249 T.getArch() == Triple::mips64el) 250 FDECFIEncoding = dwarf::DW_EH_PE_sdata8; 251 else 252 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 253 254 if (T.getArch() == Triple::x86) { 255 PersonalityEncoding = (RelocM == Reloc::PIC_) 256 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 257 : dwarf::DW_EH_PE_absptr; 258 LSDAEncoding = (RelocM == Reloc::PIC_) 259 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 260 : dwarf::DW_EH_PE_absptr; 261 FDEEncoding = (RelocM == Reloc::PIC_) 262 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 263 : dwarf::DW_EH_PE_absptr; 264 TTypeEncoding = (RelocM == Reloc::PIC_) 265 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 266 : dwarf::DW_EH_PE_absptr; 267 } else if (T.getArch() == Triple::x86_64) { 268 if (RelocM == Reloc::PIC_) { 269 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 270 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium) 271 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8); 272 LSDAEncoding = dwarf::DW_EH_PE_pcrel | 273 (CMModel == CodeModel::Small 274 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8); 275 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 276 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 277 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium) 278 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8); 279 } else { 280 PersonalityEncoding = 281 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium) 282 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; 283 LSDAEncoding = (CMModel == CodeModel::Small) 284 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; 285 FDEEncoding = dwarf::DW_EH_PE_udata4; 286 TTypeEncoding = (CMModel == CodeModel::Small) 287 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; 288 } 289 } else if (T.getArch() == Triple::aarch64) { 290 // The small model guarantees static code/data size < 4GB, but not where it 291 // will be in memory. Most of these could end up >2GB away so even a signed 292 // pc-relative 32-bit address is insufficient, theoretically. 293 if (RelocM == Reloc::PIC_) { 294 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 295 dwarf::DW_EH_PE_sdata8; 296 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8; 297 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 298 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 299 dwarf::DW_EH_PE_sdata8; 300 } else { 301 PersonalityEncoding = dwarf::DW_EH_PE_absptr; 302 LSDAEncoding = dwarf::DW_EH_PE_absptr; 303 FDEEncoding = dwarf::DW_EH_PE_udata4; 304 TTypeEncoding = dwarf::DW_EH_PE_absptr; 305 } 306 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) { 307 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 308 dwarf::DW_EH_PE_udata8; 309 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8; 310 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8; 311 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 312 dwarf::DW_EH_PE_udata8; 313 } else if (T.getArch() == Triple::systemz) { 314 // All currently-defined code models guarantee that 4-byte PC-relative 315 // values will be in range. 316 if (RelocM == Reloc::PIC_) { 317 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 318 dwarf::DW_EH_PE_sdata4; 319 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 320 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 321 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | 322 dwarf::DW_EH_PE_sdata4; 323 } else { 324 PersonalityEncoding = dwarf::DW_EH_PE_absptr; 325 LSDAEncoding = dwarf::DW_EH_PE_absptr; 326 FDEEncoding = dwarf::DW_EH_PE_absptr; 327 TTypeEncoding = dwarf::DW_EH_PE_absptr; 328 } 329 } 330 331 // Solaris requires different flags for .eh_frame to seemingly every other 332 // platform. 333 EHSectionType = ELF::SHT_PROGBITS; 334 EHSectionFlags = ELF::SHF_ALLOC; 335 if (T.getOS() == Triple::Solaris) { 336 if (T.getArch() == Triple::x86_64) 337 EHSectionType = ELF::SHT_X86_64_UNWIND; 338 else 339 EHSectionFlags |= ELF::SHF_WRITE; 340 } 341 342 343 // ELF 344 BSSSection = 345 Ctx->getELFSection(".bss", ELF::SHT_NOBITS, 346 ELF::SHF_WRITE | ELF::SHF_ALLOC, 347 SectionKind::getBSS()); 348 349 TextSection = 350 Ctx->getELFSection(".text", ELF::SHT_PROGBITS, 351 ELF::SHF_EXECINSTR | 352 ELF::SHF_ALLOC, 353 SectionKind::getText()); 354 355 DataSection = 356 Ctx->getELFSection(".data", ELF::SHT_PROGBITS, 357 ELF::SHF_WRITE |ELF::SHF_ALLOC, 358 SectionKind::getDataRel()); 359 360 ReadOnlySection = 361 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, 362 ELF::SHF_ALLOC, 363 SectionKind::getReadOnly()); 364 365 TLSDataSection = 366 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS, 367 ELF::SHF_ALLOC | ELF::SHF_TLS | 368 ELF::SHF_WRITE, 369 SectionKind::getThreadData()); 370 371 TLSBSSSection = 372 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS, 373 ELF::SHF_ALLOC | ELF::SHF_TLS | 374 ELF::SHF_WRITE, 375 SectionKind::getThreadBSS()); 376 377 DataRelSection = 378 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS, 379 ELF::SHF_ALLOC |ELF::SHF_WRITE, 380 SectionKind::getDataRel()); 381 382 DataRelLocalSection = 383 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS, 384 ELF::SHF_ALLOC |ELF::SHF_WRITE, 385 SectionKind::getDataRelLocal()); 386 387 DataRelROSection = 388 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, 389 ELF::SHF_ALLOC |ELF::SHF_WRITE, 390 SectionKind::getReadOnlyWithRel()); 391 392 DataRelROLocalSection = 393 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS, 394 ELF::SHF_ALLOC |ELF::SHF_WRITE, 395 SectionKind::getReadOnlyWithRelLocal()); 396 397 MergeableConst4Section = 398 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, 399 ELF::SHF_ALLOC |ELF::SHF_MERGE, 400 SectionKind::getMergeableConst4()); 401 402 MergeableConst8Section = 403 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, 404 ELF::SHF_ALLOC |ELF::SHF_MERGE, 405 SectionKind::getMergeableConst8()); 406 407 MergeableConst16Section = 408 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, 409 ELF::SHF_ALLOC |ELF::SHF_MERGE, 410 SectionKind::getMergeableConst16()); 411 412 StaticCtorSection = 413 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS, 414 ELF::SHF_ALLOC |ELF::SHF_WRITE, 415 SectionKind::getDataRel()); 416 417 StaticDtorSection = 418 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS, 419 ELF::SHF_ALLOC |ELF::SHF_WRITE, 420 SectionKind::getDataRel()); 421 422 // Exception Handling Sections. 423 424 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though 425 // it contains relocatable pointers. In PIC mode, this is probably a big 426 // 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->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, 430 ELF::SHF_ALLOC, 431 SectionKind::getReadOnly()); 432 433 // Debug Info Sections. 434 DwarfAbbrevSection = 435 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0, 436 SectionKind::getMetadata()); 437 DwarfInfoSection = 438 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, 439 SectionKind::getMetadata()); 440 DwarfLineSection = 441 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0, 442 SectionKind::getMetadata()); 443 DwarfFrameSection = 444 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0, 445 SectionKind::getMetadata()); 446 DwarfPubNamesSection = 447 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0, 448 SectionKind::getMetadata()); 449 DwarfPubTypesSection = 450 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0, 451 SectionKind::getMetadata()); 452 DwarfGnuPubNamesSection = 453 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0, 454 SectionKind::getMetadata()); 455 DwarfGnuPubTypesSection = 456 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0, 457 SectionKind::getMetadata()); 458 DwarfStrSection = 459 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS, 460 ELF::SHF_MERGE | ELF::SHF_STRINGS, 461 SectionKind::getMergeable1ByteCString()); 462 DwarfLocSection = 463 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0, 464 SectionKind::getMetadata()); 465 DwarfARangesSection = 466 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0, 467 SectionKind::getMetadata()); 468 DwarfRangesSection = 469 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, 470 SectionKind::getMetadata()); 471 DwarfMacroInfoSection = 472 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0, 473 SectionKind::getMetadata()); 474 475 // DWARF5 Experimental Debug Info 476 477 // Accelerator Tables 478 DwarfAccelNamesSection = 479 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, 480 SectionKind::getMetadata()); 481 DwarfAccelObjCSection = 482 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, 483 SectionKind::getMetadata()); 484 DwarfAccelNamespaceSection = 485 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0, 486 SectionKind::getMetadata()); 487 DwarfAccelTypesSection = 488 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, 489 SectionKind::getMetadata()); 490 491 // Fission Sections 492 DwarfInfoDWOSection = 493 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0, 494 SectionKind::getMetadata()); 495 DwarfAbbrevDWOSection = 496 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0, 497 SectionKind::getMetadata()); 498 DwarfStrDWOSection = 499 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS, 500 ELF::SHF_MERGE | ELF::SHF_STRINGS, 501 SectionKind::getMergeable1ByteCString()); 502 DwarfLineDWOSection = 503 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0, 504 SectionKind::getMetadata()); 505 DwarfLocDWOSection = 506 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, 507 SectionKind::getMetadata()); 508 DwarfStrOffDWOSection = 509 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0, 510 SectionKind::getMetadata()); 511 DwarfAddrSection = 512 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, 513 SectionKind::getMetadata()); 514} 515 516 517void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) { 518 // COFF 519 BSSSection = 520 Ctx->getCOFFSection(".bss", 521 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | 522 COFF::IMAGE_SCN_MEM_READ | 523 COFF::IMAGE_SCN_MEM_WRITE, 524 SectionKind::getBSS()); 525 TextSection = 526 Ctx->getCOFFSection(".text", 527 COFF::IMAGE_SCN_CNT_CODE | 528 COFF::IMAGE_SCN_MEM_EXECUTE | 529 COFF::IMAGE_SCN_MEM_READ, 530 SectionKind::getText()); 531 DataSection = 532 Ctx->getCOFFSection(".data", 533 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 534 COFF::IMAGE_SCN_MEM_READ | 535 COFF::IMAGE_SCN_MEM_WRITE, 536 SectionKind::getDataRel()); 537 ReadOnlySection = 538 Ctx->getCOFFSection(".rdata", 539 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 540 COFF::IMAGE_SCN_MEM_READ, 541 SectionKind::getReadOnly()); 542 if (T.getOS() == Triple::Win32) { 543 StaticCtorSection = 544 Ctx->getCOFFSection(".CRT$XCU", 545 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 546 COFF::IMAGE_SCN_MEM_READ, 547 SectionKind::getReadOnly()); 548 } else { 549 StaticCtorSection = 550 Ctx->getCOFFSection(".ctors", 551 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 552 COFF::IMAGE_SCN_MEM_READ | 553 COFF::IMAGE_SCN_MEM_WRITE, 554 SectionKind::getDataRel()); 555 } 556 557 558 if (T.getOS() == Triple::Win32) { 559 StaticDtorSection = 560 Ctx->getCOFFSection(".CRT$XTX", 561 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 562 COFF::IMAGE_SCN_MEM_READ, 563 SectionKind::getReadOnly()); 564 } else { 565 StaticDtorSection = 566 Ctx->getCOFFSection(".dtors", 567 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 568 COFF::IMAGE_SCN_MEM_READ | 569 COFF::IMAGE_SCN_MEM_WRITE, 570 SectionKind::getDataRel()); 571 } 572 573 // FIXME: We're emitting LSDA info into a readonly section on COFF, even 574 // though it contains relocatable pointers. In PIC mode, this is probably a 575 // big runtime hit for C++ apps. Either the contents of the LSDA need to be 576 // adjusted or this should be a data section. 577 LSDASection = 578 Ctx->getCOFFSection(".gcc_except_table", 579 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 580 COFF::IMAGE_SCN_MEM_READ, 581 SectionKind::getReadOnly()); 582 583 // Debug info. 584 DwarfAbbrevSection = 585 Ctx->getCOFFSection(".debug_abbrev", 586 COFF::IMAGE_SCN_MEM_DISCARDABLE | 587 COFF::IMAGE_SCN_MEM_READ, 588 SectionKind::getMetadata()); 589 DwarfInfoSection = 590 Ctx->getCOFFSection(".debug_info", 591 COFF::IMAGE_SCN_MEM_DISCARDABLE | 592 COFF::IMAGE_SCN_MEM_READ, 593 SectionKind::getMetadata()); 594 DwarfLineSection = 595 Ctx->getCOFFSection(".debug_line", 596 COFF::IMAGE_SCN_MEM_DISCARDABLE | 597 COFF::IMAGE_SCN_MEM_READ, 598 SectionKind::getMetadata()); 599 DwarfFrameSection = 600 Ctx->getCOFFSection(".debug_frame", 601 COFF::IMAGE_SCN_MEM_DISCARDABLE | 602 COFF::IMAGE_SCN_MEM_READ, 603 SectionKind::getMetadata()); 604 DwarfPubNamesSection = 605 Ctx->getCOFFSection(".debug_pubnames", 606 COFF::IMAGE_SCN_MEM_DISCARDABLE | 607 COFF::IMAGE_SCN_MEM_READ, 608 SectionKind::getMetadata()); 609 DwarfPubTypesSection = 610 Ctx->getCOFFSection(".debug_pubtypes", 611 COFF::IMAGE_SCN_MEM_DISCARDABLE | 612 COFF::IMAGE_SCN_MEM_READ, 613 SectionKind::getMetadata()); 614 DwarfGnuPubNamesSection = 615 Ctx->getCOFFSection(".debug_gnu_pubnames", 616 COFF::IMAGE_SCN_MEM_DISCARDABLE | 617 COFF::IMAGE_SCN_MEM_READ, 618 SectionKind::getMetadata()); 619 DwarfGnuPubTypesSection = 620 Ctx->getCOFFSection(".debug_gnu_pubtypes", 621 COFF::IMAGE_SCN_MEM_DISCARDABLE | 622 COFF::IMAGE_SCN_MEM_READ, 623 SectionKind::getMetadata()); 624 DwarfStrSection = 625 Ctx->getCOFFSection(".debug_str", 626 COFF::IMAGE_SCN_MEM_DISCARDABLE | 627 COFF::IMAGE_SCN_MEM_READ, 628 SectionKind::getMetadata()); 629 DwarfLocSection = 630 Ctx->getCOFFSection(".debug_loc", 631 COFF::IMAGE_SCN_MEM_DISCARDABLE | 632 COFF::IMAGE_SCN_MEM_READ, 633 SectionKind::getMetadata()); 634 DwarfARangesSection = 635 Ctx->getCOFFSection(".debug_aranges", 636 COFF::IMAGE_SCN_MEM_DISCARDABLE | 637 COFF::IMAGE_SCN_MEM_READ, 638 SectionKind::getMetadata()); 639 DwarfRangesSection = 640 Ctx->getCOFFSection(".debug_ranges", 641 COFF::IMAGE_SCN_MEM_DISCARDABLE | 642 COFF::IMAGE_SCN_MEM_READ, 643 SectionKind::getMetadata()); 644 DwarfMacroInfoSection = 645 Ctx->getCOFFSection(".debug_macinfo", 646 COFF::IMAGE_SCN_MEM_DISCARDABLE | 647 COFF::IMAGE_SCN_MEM_READ, 648 SectionKind::getMetadata()); 649 650 DrectveSection = 651 Ctx->getCOFFSection(".drectve", 652 COFF::IMAGE_SCN_LNK_INFO, 653 SectionKind::getMetadata()); 654 655 PDataSection = 656 Ctx->getCOFFSection(".pdata", 657 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 658 COFF::IMAGE_SCN_MEM_READ, 659 SectionKind::getDataRel()); 660 661 XDataSection = 662 Ctx->getCOFFSection(".xdata", 663 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 664 COFF::IMAGE_SCN_MEM_READ, 665 SectionKind::getDataRel()); 666 TLSDataSection = 667 Ctx->getCOFFSection(".tls$", 668 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 669 COFF::IMAGE_SCN_MEM_READ | 670 COFF::IMAGE_SCN_MEM_WRITE, 671 SectionKind::getDataRel()); 672} 673 674void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm, 675 CodeModel::Model cm, 676 MCContext &ctx) { 677 RelocM = relocm; 678 CMModel = cm; 679 Ctx = &ctx; 680 681 // Common. 682 CommDirectiveSupportsAlignment = true; 683 SupportsWeakOmittedEHFrame = true; 684 IsFunctionEHFrameSymbolPrivate = true; 685 686 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding = 687 TTypeEncoding = dwarf::DW_EH_PE_absptr; 688 689 CompactUnwindDwarfEHFrameOnly = 0; 690 691 EHFrameSection = 0; // Created on demand. 692 CompactUnwindSection = 0; // Used only by selected targets. 693 DwarfAccelNamesSection = 0; // Used only by selected targets. 694 DwarfAccelObjCSection = 0; // Used only by selected targets. 695 DwarfAccelNamespaceSection = 0; // Used only by selected targets. 696 DwarfAccelTypesSection = 0; // Used only by selected targets. 697 698 Triple T(TT); 699 Triple::ArchType Arch = T.getArch(); 700 // FIXME: Checking for Arch here to filter out bogus triples such as 701 // cellspu-apple-darwin. Perhaps we should fix in Triple? 702 if ((Arch == Triple::x86 || Arch == Triple::x86_64 || 703 Arch == Triple::arm || Arch == Triple::thumb || 704 Arch == Triple::ppc || Arch == Triple::ppc64 || 705 Arch == Triple::UnknownArch) && 706 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) { 707 Env = IsMachO; 708 InitMachOMCObjectFileInfo(T); 709 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) && 710 (T.getEnvironment() != Triple::ELF) && 711 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin || 712 T.getOS() == Triple::Win32)) { 713 Env = IsCOFF; 714 InitCOFFMCObjectFileInfo(T); 715 } else { 716 Env = IsELF; 717 InitELFMCObjectFileInfo(T); 718 } 719} 720 721void MCObjectFileInfo::InitEHFrameSection() { 722 if (Env == IsMachO) 723 EHFrameSection = 724 Ctx->getMachOSection("__TEXT", "__eh_frame", 725 MCSectionMachO::S_COALESCED | 726 MCSectionMachO::S_ATTR_NO_TOC | 727 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS | 728 MCSectionMachO::S_ATTR_LIVE_SUPPORT, 729 SectionKind::getReadOnly()); 730 else if (Env == IsELF) 731 EHFrameSection = 732 Ctx->getELFSection(".eh_frame", EHSectionType, 733 EHSectionFlags, 734 SectionKind::getDataRel()); 735 else 736 EHFrameSection = 737 Ctx->getCOFFSection(".eh_frame", 738 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 739 COFF::IMAGE_SCN_MEM_READ | 740 COFF::IMAGE_SCN_MEM_WRITE, 741 SectionKind::getDataRel()); 742} 743