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; |
Jakob Stoklund Olesen | 83c6773 | 2014-01-28 02:52:26 +0000 | [diff] [blame] | 314 | } else if (T.getArch() == Triple::sparc) { |
| 315 | if (RelocM == Reloc::PIC_) { |
| 316 | LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 317 | PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | |
| 318 | dwarf::DW_EH_PE_sdata4; |
| 319 | FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 320 | TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | |
| 321 | dwarf::DW_EH_PE_sdata4; |
| 322 | } else { |
| 323 | LSDAEncoding = dwarf::DW_EH_PE_absptr; |
| 324 | PersonalityEncoding = dwarf::DW_EH_PE_absptr; |
| 325 | FDEEncoding = dwarf::DW_EH_PE_udata4; |
| 326 | TTypeEncoding = dwarf::DW_EH_PE_absptr; |
| 327 | } |
| 328 | } else if (T.getArch() == Triple::sparcv9) { |
| 329 | LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 330 | if (RelocM == Reloc::PIC_) { |
| 331 | PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | |
| 332 | dwarf::DW_EH_PE_sdata4; |
| 333 | FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 334 | TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | |
| 335 | dwarf::DW_EH_PE_sdata4; |
| 336 | } else { |
| 337 | PersonalityEncoding = dwarf::DW_EH_PE_absptr; |
| 338 | FDEEncoding = dwarf::DW_EH_PE_udata4; |
| 339 | TTypeEncoding = dwarf::DW_EH_PE_absptr; |
| 340 | } |
Ulrich Weigand | 0213e7f | 2013-05-06 16:11:12 +0000 | [diff] [blame] | 341 | } else if (T.getArch() == Triple::systemz) { |
| 342 | // All currently-defined code models guarantee that 4-byte PC-relative |
| 343 | // values will be in range. |
Ulrich Weigand | e7c6dfe | 2013-05-06 17:28:30 +0000 | [diff] [blame] | 344 | if (RelocM == Reloc::PIC_) { |
| 345 | PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | |
| 346 | dwarf::DW_EH_PE_sdata4; |
| 347 | LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 348 | FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 349 | TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | |
| 350 | dwarf::DW_EH_PE_sdata4; |
| 351 | } else { |
| 352 | PersonalityEncoding = dwarf::DW_EH_PE_absptr; |
| 353 | LSDAEncoding = dwarf::DW_EH_PE_absptr; |
| 354 | FDEEncoding = dwarf::DW_EH_PE_absptr; |
| 355 | TTypeEncoding = dwarf::DW_EH_PE_absptr; |
| 356 | } |
Evan Cheng | bbf3b0d | 2011-07-20 19:50:42 +0000 | [diff] [blame] | 357 | } |
| 358 | |
David Chisnall | 07f8d3e | 2012-02-17 17:31:15 +0000 | [diff] [blame] | 359 | // Solaris requires different flags for .eh_frame to seemingly every other |
| 360 | // platform. |
David Chisnall | bbec872 | 2012-04-10 11:44:33 +0000 | [diff] [blame] | 361 | EHSectionType = ELF::SHT_PROGBITS; |
David Chisnall | 07f8d3e | 2012-02-17 17:31:15 +0000 | [diff] [blame] | 362 | EHSectionFlags = ELF::SHF_ALLOC; |
David Chisnall | bbec872 | 2012-04-10 11:44:33 +0000 | [diff] [blame] | 363 | if (T.getOS() == Triple::Solaris) { |
| 364 | if (T.getArch() == Triple::x86_64) |
| 365 | EHSectionType = ELF::SHT_X86_64_UNWIND; |
| 366 | else |
| 367 | EHSectionFlags |= ELF::SHF_WRITE; |
| 368 | } |
David Chisnall | 07f8d3e | 2012-02-17 17:31:15 +0000 | [diff] [blame] | 369 | |
| 370 | |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 371 | // ELF |
| 372 | BSSSection = |
| 373 | Ctx->getELFSection(".bss", ELF::SHT_NOBITS, |
Anton Korobeynikov | 7722a2d | 2012-01-25 22:24:19 +0000 | [diff] [blame] | 374 | ELF::SHF_WRITE | ELF::SHF_ALLOC, |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 375 | SectionKind::getBSS()); |
| 376 | |
| 377 | TextSection = |
| 378 | Ctx->getELFSection(".text", ELF::SHT_PROGBITS, |
| 379 | ELF::SHF_EXECINSTR | |
| 380 | ELF::SHF_ALLOC, |
| 381 | SectionKind::getText()); |
| 382 | |
| 383 | DataSection = |
| 384 | Ctx->getELFSection(".data", ELF::SHT_PROGBITS, |
| 385 | ELF::SHF_WRITE |ELF::SHF_ALLOC, |
| 386 | SectionKind::getDataRel()); |
| 387 | |
| 388 | ReadOnlySection = |
| 389 | Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, |
| 390 | ELF::SHF_ALLOC, |
| 391 | SectionKind::getReadOnly()); |
| 392 | |
| 393 | TLSDataSection = |
| 394 | Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS, |
| 395 | ELF::SHF_ALLOC | ELF::SHF_TLS | |
| 396 | ELF::SHF_WRITE, |
| 397 | SectionKind::getThreadData()); |
| 398 | |
| 399 | TLSBSSSection = |
| 400 | Ctx->getELFSection(".tbss", ELF::SHT_NOBITS, |
| 401 | ELF::SHF_ALLOC | ELF::SHF_TLS | |
| 402 | ELF::SHF_WRITE, |
| 403 | SectionKind::getThreadBSS()); |
| 404 | |
| 405 | DataRelSection = |
| 406 | Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS, |
| 407 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
| 408 | SectionKind::getDataRel()); |
| 409 | |
| 410 | DataRelLocalSection = |
| 411 | Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS, |
| 412 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
| 413 | SectionKind::getDataRelLocal()); |
| 414 | |
| 415 | DataRelROSection = |
| 416 | Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, |
| 417 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
| 418 | SectionKind::getReadOnlyWithRel()); |
| 419 | |
| 420 | DataRelROLocalSection = |
| 421 | Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS, |
| 422 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
| 423 | SectionKind::getReadOnlyWithRelLocal()); |
| 424 | |
| 425 | MergeableConst4Section = |
| 426 | Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, |
| 427 | ELF::SHF_ALLOC |ELF::SHF_MERGE, |
| 428 | SectionKind::getMergeableConst4()); |
| 429 | |
| 430 | MergeableConst8Section = |
| 431 | Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, |
| 432 | ELF::SHF_ALLOC |ELF::SHF_MERGE, |
| 433 | SectionKind::getMergeableConst8()); |
| 434 | |
| 435 | MergeableConst16Section = |
| 436 | Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, |
| 437 | ELF::SHF_ALLOC |ELF::SHF_MERGE, |
| 438 | SectionKind::getMergeableConst16()); |
| 439 | |
| 440 | StaticCtorSection = |
| 441 | Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS, |
| 442 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
| 443 | SectionKind::getDataRel()); |
| 444 | |
| 445 | StaticDtorSection = |
| 446 | Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS, |
| 447 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
| 448 | SectionKind::getDataRel()); |
| 449 | |
| 450 | // Exception Handling Sections. |
| 451 | |
| 452 | // FIXME: We're emitting LSDA info into a readonly section on ELF, even though |
| 453 | // it contains relocatable pointers. In PIC mode, this is probably a big |
| 454 | // runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 455 | // adjusted or this should be a data section. |
| 456 | LSDASection = |
| 457 | Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, |
| 458 | ELF::SHF_ALLOC, |
| 459 | SectionKind::getReadOnly()); |
| 460 | |
| 461 | // Debug Info Sections. |
| 462 | DwarfAbbrevSection = |
| 463 | Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0, |
| 464 | SectionKind::getMetadata()); |
| 465 | DwarfInfoSection = |
| 466 | Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, |
| 467 | SectionKind::getMetadata()); |
| 468 | DwarfLineSection = |
| 469 | Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0, |
| 470 | SectionKind::getMetadata()); |
| 471 | DwarfFrameSection = |
| 472 | Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0, |
| 473 | SectionKind::getMetadata()); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 474 | DwarfPubNamesSection = |
| 475 | Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0, |
| 476 | SectionKind::getMetadata()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 477 | DwarfPubTypesSection = |
| 478 | Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0, |
| 479 | SectionKind::getMetadata()); |
Eric Christopher | b0e7694 | 2013-09-09 20:03:14 +0000 | [diff] [blame] | 480 | DwarfGnuPubNamesSection = |
| 481 | Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0, |
| 482 | SectionKind::getMetadata()); |
| 483 | DwarfGnuPubTypesSection = |
| 484 | Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0, |
| 485 | SectionKind::getMetadata()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 486 | DwarfStrSection = |
Nick Lewycky | 1a62d78 | 2011-10-26 18:44:32 +0000 | [diff] [blame] | 487 | Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS, |
| 488 | ELF::SHF_MERGE | ELF::SHF_STRINGS, |
| 489 | SectionKind::getMergeable1ByteCString()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 490 | DwarfLocSection = |
| 491 | Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0, |
| 492 | SectionKind::getMetadata()); |
| 493 | DwarfARangesSection = |
| 494 | Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0, |
| 495 | SectionKind::getMetadata()); |
| 496 | DwarfRangesSection = |
| 497 | Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, |
| 498 | SectionKind::getMetadata()); |
| 499 | DwarfMacroInfoSection = |
| 500 | Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0, |
| 501 | SectionKind::getMetadata()); |
Eric Christopher | 27ed8ec | 2012-11-28 02:49:34 +0000 | [diff] [blame] | 502 | |
| 503 | // DWARF5 Experimental Debug Info |
| 504 | |
| 505 | // Accelerator Tables |
Eric Christopher | a0ad67d | 2012-10-08 21:41:30 +0000 | [diff] [blame] | 506 | DwarfAccelNamesSection = |
| 507 | Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, |
| 508 | SectionKind::getMetadata()); |
| 509 | DwarfAccelObjCSection = |
| 510 | Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, |
| 511 | SectionKind::getMetadata()); |
| 512 | DwarfAccelNamespaceSection = |
| 513 | Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0, |
| 514 | SectionKind::getMetadata()); |
| 515 | DwarfAccelTypesSection = |
| 516 | Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, |
| 517 | SectionKind::getMetadata()); |
Eric Christopher | c3b434b | 2012-11-28 02:49:38 +0000 | [diff] [blame] | 518 | |
| 519 | // Fission Sections |
| 520 | DwarfInfoDWOSection = |
| 521 | Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0, |
| 522 | SectionKind::getMetadata()); |
Eric Christopher | 3c23009 | 2012-11-30 06:47:06 +0000 | [diff] [blame] | 523 | DwarfAbbrevDWOSection = |
| 524 | Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0, |
| 525 | SectionKind::getMetadata()); |
| 526 | DwarfStrDWOSection = |
| 527 | Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS, |
| 528 | ELF::SHF_MERGE | ELF::SHF_STRINGS, |
| 529 | SectionKind::getMergeable1ByteCString()); |
| 530 | DwarfLineDWOSection = |
| 531 | Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0, |
| 532 | SectionKind::getMetadata()); |
| 533 | DwarfLocDWOSection = |
| 534 | Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, |
| 535 | SectionKind::getMetadata()); |
Eric Christopher | c0fa867 | 2013-01-04 17:59:22 +0000 | [diff] [blame] | 536 | DwarfStrOffDWOSection = |
| 537 | Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0, |
| 538 | SectionKind::getMetadata()); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 539 | DwarfAddrSection = |
| 540 | Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, |
| 541 | SectionKind::getMetadata()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | |
| 545 | void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) { |
| 546 | // COFF |
David Majnemer | 3d96acb | 2013-08-13 01:23:53 +0000 | [diff] [blame] | 547 | BSSSection = |
| 548 | Ctx->getCOFFSection(".bss", |
| 549 | COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
| 550 | COFF::IMAGE_SCN_MEM_READ | |
| 551 | COFF::IMAGE_SCN_MEM_WRITE, |
| 552 | SectionKind::getBSS()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 553 | TextSection = |
| 554 | Ctx->getCOFFSection(".text", |
| 555 | COFF::IMAGE_SCN_CNT_CODE | |
| 556 | COFF::IMAGE_SCN_MEM_EXECUTE | |
| 557 | COFF::IMAGE_SCN_MEM_READ, |
| 558 | SectionKind::getText()); |
| 559 | DataSection = |
| 560 | Ctx->getCOFFSection(".data", |
| 561 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 562 | COFF::IMAGE_SCN_MEM_READ | |
| 563 | COFF::IMAGE_SCN_MEM_WRITE, |
| 564 | SectionKind::getDataRel()); |
| 565 | ReadOnlySection = |
| 566 | Ctx->getCOFFSection(".rdata", |
| 567 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 568 | COFF::IMAGE_SCN_MEM_READ, |
| 569 | SectionKind::getReadOnly()); |
Michael J. Spencer | b560d07 | 2012-02-23 21:56:08 +0000 | [diff] [blame] | 570 | if (T.getOS() == Triple::Win32) { |
| 571 | StaticCtorSection = |
| 572 | Ctx->getCOFFSection(".CRT$XCU", |
| 573 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 574 | COFF::IMAGE_SCN_MEM_READ, |
| 575 | SectionKind::getReadOnly()); |
| 576 | } else { |
| 577 | StaticCtorSection = |
| 578 | Ctx->getCOFFSection(".ctors", |
| 579 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 580 | COFF::IMAGE_SCN_MEM_READ | |
| 581 | COFF::IMAGE_SCN_MEM_WRITE, |
| 582 | SectionKind::getDataRel()); |
| 583 | } |
| 584 | |
| 585 | |
Anton Korobeynikov | 37d7300 | 2012-09-23 15:53:47 +0000 | [diff] [blame] | 586 | if (T.getOS() == Triple::Win32) { |
| 587 | StaticDtorSection = |
| 588 | Ctx->getCOFFSection(".CRT$XTX", |
| 589 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 590 | COFF::IMAGE_SCN_MEM_READ, |
| 591 | SectionKind::getReadOnly()); |
| 592 | } else { |
| 593 | StaticDtorSection = |
| 594 | Ctx->getCOFFSection(".dtors", |
| 595 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 596 | COFF::IMAGE_SCN_MEM_READ | |
| 597 | COFF::IMAGE_SCN_MEM_WRITE, |
| 598 | SectionKind::getDataRel()); |
| 599 | } |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 600 | |
| 601 | // FIXME: We're emitting LSDA info into a readonly section on COFF, even |
| 602 | // though it contains relocatable pointers. In PIC mode, this is probably a |
| 603 | // big runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 604 | // adjusted or this should be a data section. |
Kai Nacke | 4209730 | 2013-07-08 04:43:23 +0000 | [diff] [blame] | 605 | LSDASection = |
| 606 | Ctx->getCOFFSection(".gcc_except_table", |
| 607 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 608 | COFF::IMAGE_SCN_MEM_READ, |
| 609 | SectionKind::getReadOnly()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 610 | |
| 611 | // Debug info. |
Timur Iskhodzhanov | 31377c5 | 2014-01-28 03:48:44 +0000 | [diff] [blame^] | 612 | COFFDebugSymbolsSection = |
| 613 | Ctx->getCOFFSection(".debug$S", |
| 614 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 615 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 616 | COFF::IMAGE_SCN_MEM_READ, |
| 617 | SectionKind::getMetadata()); |
| 618 | |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 619 | DwarfAbbrevSection = |
| 620 | Ctx->getCOFFSection(".debug_abbrev", |
| 621 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 622 | COFF::IMAGE_SCN_MEM_READ, |
| 623 | SectionKind::getMetadata()); |
| 624 | DwarfInfoSection = |
| 625 | Ctx->getCOFFSection(".debug_info", |
| 626 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 627 | COFF::IMAGE_SCN_MEM_READ, |
| 628 | SectionKind::getMetadata()); |
| 629 | DwarfLineSection = |
| 630 | Ctx->getCOFFSection(".debug_line", |
| 631 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 632 | COFF::IMAGE_SCN_MEM_READ, |
| 633 | SectionKind::getMetadata()); |
| 634 | DwarfFrameSection = |
| 635 | Ctx->getCOFFSection(".debug_frame", |
| 636 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 637 | COFF::IMAGE_SCN_MEM_READ, |
| 638 | SectionKind::getMetadata()); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 639 | DwarfPubNamesSection = |
| 640 | Ctx->getCOFFSection(".debug_pubnames", |
| 641 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 642 | COFF::IMAGE_SCN_MEM_READ, |
| 643 | SectionKind::getMetadata()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 644 | DwarfPubTypesSection = |
| 645 | Ctx->getCOFFSection(".debug_pubtypes", |
| 646 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 647 | COFF::IMAGE_SCN_MEM_READ, |
| 648 | SectionKind::getMetadata()); |
NAKAMURA Takumi | 0229e35 | 2013-09-10 06:01:56 +0000 | [diff] [blame] | 649 | DwarfGnuPubNamesSection = |
Eric Christopher | b0e7694 | 2013-09-09 20:03:14 +0000 | [diff] [blame] | 650 | Ctx->getCOFFSection(".debug_gnu_pubnames", |
| 651 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 652 | COFF::IMAGE_SCN_MEM_READ, |
| 653 | SectionKind::getMetadata()); |
NAKAMURA Takumi | 0229e35 | 2013-09-10 06:01:56 +0000 | [diff] [blame] | 654 | DwarfGnuPubTypesSection = |
Eric Christopher | b0e7694 | 2013-09-09 20:03:14 +0000 | [diff] [blame] | 655 | Ctx->getCOFFSection(".debug_gnu_pubtypes", |
| 656 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 657 | COFF::IMAGE_SCN_MEM_READ, |
| 658 | SectionKind::getMetadata()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 659 | DwarfStrSection = |
| 660 | Ctx->getCOFFSection(".debug_str", |
| 661 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 662 | COFF::IMAGE_SCN_MEM_READ, |
| 663 | SectionKind::getMetadata()); |
| 664 | DwarfLocSection = |
| 665 | Ctx->getCOFFSection(".debug_loc", |
| 666 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 667 | COFF::IMAGE_SCN_MEM_READ, |
| 668 | SectionKind::getMetadata()); |
| 669 | DwarfARangesSection = |
| 670 | Ctx->getCOFFSection(".debug_aranges", |
| 671 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 672 | COFF::IMAGE_SCN_MEM_READ, |
| 673 | SectionKind::getMetadata()); |
| 674 | DwarfRangesSection = |
| 675 | Ctx->getCOFFSection(".debug_ranges", |
| 676 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 677 | COFF::IMAGE_SCN_MEM_READ, |
| 678 | SectionKind::getMetadata()); |
| 679 | DwarfMacroInfoSection = |
| 680 | Ctx->getCOFFSection(".debug_macinfo", |
| 681 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 682 | COFF::IMAGE_SCN_MEM_READ, |
| 683 | SectionKind::getMetadata()); |
| 684 | |
| 685 | DrectveSection = |
| 686 | Ctx->getCOFFSection(".drectve", |
| 687 | COFF::IMAGE_SCN_LNK_INFO, |
| 688 | SectionKind::getMetadata()); |
| 689 | |
| 690 | PDataSection = |
| 691 | Ctx->getCOFFSection(".pdata", |
| 692 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
Anton Korobeynikov | cc8c539 | 2012-08-08 12:46:46 +0000 | [diff] [blame] | 693 | COFF::IMAGE_SCN_MEM_READ, |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 694 | SectionKind::getDataRel()); |
| 695 | |
| 696 | XDataSection = |
| 697 | Ctx->getCOFFSection(".xdata", |
| 698 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
Anton Korobeynikov | cc8c539 | 2012-08-08 12:46:46 +0000 | [diff] [blame] | 699 | COFF::IMAGE_SCN_MEM_READ, |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 700 | SectionKind::getDataRel()); |
Anton Korobeynikov | c6b4017 | 2012-02-11 17:26:53 +0000 | [diff] [blame] | 701 | TLSDataSection = |
| 702 | Ctx->getCOFFSection(".tls$", |
| 703 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 704 | COFF::IMAGE_SCN_MEM_READ | |
| 705 | COFF::IMAGE_SCN_MEM_WRITE, |
| 706 | SectionKind::getDataRel()); |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm, |
Evan Cheng | bbf3b0d | 2011-07-20 19:50:42 +0000 | [diff] [blame] | 710 | CodeModel::Model cm, |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 711 | MCContext &ctx) { |
| 712 | RelocM = relocm; |
Evan Cheng | bbf3b0d | 2011-07-20 19:50:42 +0000 | [diff] [blame] | 713 | CMModel = cm; |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 714 | Ctx = &ctx; |
| 715 | |
| 716 | // Common. |
| 717 | CommDirectiveSupportsAlignment = true; |
| 718 | SupportsWeakOmittedEHFrame = true; |
| 719 | IsFunctionEHFrameSymbolPrivate = true; |
Evan Cheng | bbf3b0d | 2011-07-20 19:50:42 +0000 | [diff] [blame] | 720 | |
| 721 | PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding = |
| 722 | TTypeEncoding = dwarf::DW_EH_PE_absptr; |
| 723 | |
Bill Wendling | 2d1df6b | 2013-04-10 21:42:06 +0000 | [diff] [blame] | 724 | CompactUnwindDwarfEHFrameOnly = 0; |
| 725 | |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 726 | EHFrameSection = 0; // Created on demand. |
| 727 | CompactUnwindSection = 0; // Used only by selected targets. |
| 728 | DwarfAccelNamesSection = 0; // Used only by selected targets. |
| 729 | DwarfAccelObjCSection = 0; // Used only by selected targets. |
| 730 | DwarfAccelNamespaceSection = 0; // Used only by selected targets. |
| 731 | DwarfAccelTypesSection = 0; // Used only by selected targets. |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 732 | |
| 733 | Triple T(TT); |
| 734 | Triple::ArchType Arch = T.getArch(); |
| 735 | // FIXME: Checking for Arch here to filter out bogus triples such as |
| 736 | // cellspu-apple-darwin. Perhaps we should fix in Triple? |
| 737 | if ((Arch == Triple::x86 || Arch == Triple::x86_64 || |
| 738 | Arch == Triple::arm || Arch == Triple::thumb || |
| 739 | Arch == Triple::ppc || Arch == Triple::ppc64 || |
| 740 | Arch == Triple::UnknownArch) && |
| 741 | (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) { |
| 742 | Env = IsMachO; |
| 743 | InitMachOMCObjectFileInfo(T); |
Evan Cheng | c3035d6 | 2011-07-20 23:53:54 +0000 | [diff] [blame] | 744 | } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) && |
Andrew Kaylor | feb805f | 2012-10-02 18:38:34 +0000 | [diff] [blame] | 745 | (T.getEnvironment() != Triple::ELF) && |
Evan Cheng | c3035d6 | 2011-07-20 23:53:54 +0000 | [diff] [blame] | 746 | (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin || |
| 747 | T.getOS() == Triple::Win32)) { |
Evan Cheng | 7679299 | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 748 | Env = IsCOFF; |
| 749 | InitCOFFMCObjectFileInfo(T); |
| 750 | } else { |
| 751 | Env = IsELF; |
| 752 | InitELFMCObjectFileInfo(T); |
| 753 | } |
| 754 | } |
| 755 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 756 | const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const { |
| 757 | return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP, |
| 758 | SectionKind::getMetadata(), 0, utostr(Hash)); |
| 759 | } |
| 760 | |
| 761 | const MCSection * |
| 762 | MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const { |
David Blaikie | 15ed5eb | 2014-01-10 01:38:41 +0000 | [diff] [blame] | 763 | return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, |
| 764 | ELF::SHF_GROUP, SectionKind::getMetadata(), 0, |
| 765 | utostr(Hash)); |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 766 | } |
| 767 | |
David Chisnall | 85dd309 | 2012-02-17 16:51:02 +0000 | [diff] [blame] | 768 | void MCObjectFileInfo::InitEHFrameSection() { |
| 769 | if (Env == IsMachO) |
| 770 | EHFrameSection = |
| 771 | Ctx->getMachOSection("__TEXT", "__eh_frame", |
| 772 | MCSectionMachO::S_COALESCED | |
| 773 | MCSectionMachO::S_ATTR_NO_TOC | |
| 774 | MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS | |
| 775 | MCSectionMachO::S_ATTR_LIVE_SUPPORT, |
| 776 | SectionKind::getReadOnly()); |
| 777 | else if (Env == IsELF) |
| 778 | EHFrameSection = |
David Chisnall | bbec872 | 2012-04-10 11:44:33 +0000 | [diff] [blame] | 779 | Ctx->getELFSection(".eh_frame", EHSectionType, |
David Chisnall | 07f8d3e | 2012-02-17 17:31:15 +0000 | [diff] [blame] | 780 | EHSectionFlags, |
David Chisnall | 85dd309 | 2012-02-17 16:51:02 +0000 | [diff] [blame] | 781 | SectionKind::getDataRel()); |
| 782 | else |
| 783 | EHFrameSection = |
| 784 | Ctx->getCOFFSection(".eh_frame", |
| 785 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 786 | COFF::IMAGE_SCN_MEM_READ | |
| 787 | COFF::IMAGE_SCN_MEM_WRITE, |
| 788 | SectionKind::getDataRel()); |
| 789 | } |