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