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