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