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