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