Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 1 | //===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the declarations of the X86TargetAsmInfo properties. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "X86TargetAsmInfo.h" |
| 15 | #include "X86TargetMachine.h" |
| 16 | #include "X86Subtarget.h" |
Reid Spencer | 7aa8a45 | 2007-01-12 23:22:14 +0000 | [diff] [blame] | 17 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 18 | #include "llvm/InlineAsm.h" |
| 19 | #include "llvm/Instructions.h" |
Chris Lattner | 3e9f1d0 | 2007-04-01 20:49:36 +0000 | [diff] [blame] | 20 | #include "llvm/Intrinsics.h" |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 21 | #include "llvm/Module.h" |
| 22 | #include "llvm/ADT/StringExtras.h" |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Dwarf.h" |
| 24 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 25 | using namespace llvm; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 26 | using namespace llvm::dwarf; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 27 | |
Dan Gohman | cfbb2f0 | 2008-03-25 21:45:14 +0000 | [diff] [blame] | 28 | static const char *const x86_asm_table[] = { |
| 29 | "{si}", "S", |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 30 | "{di}", "D", |
| 31 | "{ax}", "a", |
| 32 | "{cx}", "c", |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 33 | "{memory}", "memory", |
| 34 | "{flags}", "", |
| 35 | "{dirflag}", "", |
| 36 | "{fpsr}", "", |
| 37 | "{cc}", "cc", |
| 38 | 0,0}; |
| 39 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 40 | X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) { |
| 41 | const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>(); |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 42 | X86TM = &TM; |
| 43 | |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 44 | AsmTransCBE = x86_asm_table; |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 45 | |
Bill Wendling | cb90099 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 46 | AssemblerDialect = Subtarget->getAsmFlavor(); |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 47 | } |
Chris Lattner | afbfded | 2006-10-05 02:43:52 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 49 | bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const { |
| 50 | // FIXME: this should verify that we are targetting a 486 or better. If not, |
| 51 | // we will turn this bswap into something that will be lowered to logical ops |
| 52 | // instead of emitting the bswap asm. For now, we don't support 486 or lower |
| 53 | // so don't worry about this. |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 55 | // Verify this is a simple bswap. |
| 56 | if (CI->getNumOperands() != 2 || |
| 57 | CI->getType() != CI->getOperand(1)->getType() || |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 58 | !CI->getType()->isInteger()) |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 59 | return false; |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 3e9f1d0 | 2007-04-01 20:49:36 +0000 | [diff] [blame] | 61 | const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| 62 | if (!Ty || Ty->getBitWidth() % 16 != 0) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 63 | return false; |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 64 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 65 | // Okay, we can do this xform, do so now. |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 66 | const Type *Tys[] = { Ty }; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 67 | Module *M = CI->getParent()->getParent()->getParent(); |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 68 | Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 70 | Value *Op = CI->getOperand(1); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 71 | Op = CallInst::Create(Int, Op, CI->getName(), CI); |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 73 | CI->replaceAllUsesWith(Op); |
| 74 | CI->eraseFromParent(); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const { |
| 80 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 81 | std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints(); |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 82 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 83 | std::string AsmStr = IA->getAsmString(); |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 85 | // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a" |
| 86 | std::vector<std::string> AsmPieces; |
| 87 | SplitString(AsmStr, AsmPieces, "\n"); // ; as separator? |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 88 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 89 | switch (AsmPieces.size()) { |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 90 | default: return false; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 91 | case 1: |
| 92 | AsmStr = AsmPieces[0]; |
| 93 | AsmPieces.clear(); |
| 94 | SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace. |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 95 | |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 96 | // bswap $0 |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 97 | if (AsmPieces.size() == 2 && |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 98 | AsmPieces[0] == "bswap" && AsmPieces[1] == "$0") { |
| 99 | // No need to check constraints, nothing other than the equivalent of |
| 100 | // "=r,0" would be valid here. |
| 101 | return LowerToBSwap(CI); |
| 102 | } |
| 103 | break; |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 104 | case 3: |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 105 | if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 && |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 106 | Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" && |
| 107 | Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") { |
| 108 | // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64 |
| 109 | std::vector<std::string> Words; |
| 110 | SplitString(AsmPieces[0], Words, " \t"); |
| 111 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") { |
| 112 | Words.clear(); |
| 113 | SplitString(AsmPieces[1], Words, " \t"); |
| 114 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") { |
| 115 | Words.clear(); |
| 116 | SplitString(AsmPieces[2], Words, " \t,"); |
| 117 | if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" && |
| 118 | Words[2] == "%edx") { |
| 119 | return LowerToBSwap(CI); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | break; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 125 | } |
| 126 | return false; |
| 127 | } |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 128 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 129 | X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM): |
| 130 | X86TargetAsmInfo(TM) { |
| 131 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 132 | |
| 133 | AlignmentIsInBytes = false; |
| 134 | TextAlignFillValue = 0x90; |
| 135 | GlobalPrefix = "_"; |
| 136 | if (!is64Bit) |
| 137 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 138 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 139 | PrivateGlobalPrefix = "L"; // Marker for constant pool idxs |
| 140 | BSSSection = 0; // no BSS section. |
| 141 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
Anton Korobeynikov | 7705ea3 | 2008-07-09 21:54:26 +0000 | [diff] [blame] | 142 | if (X86TM->getRelocationModel() != Reloc::Static) |
| 143 | ConstantPoolSection = "\t.const_data"; |
| 144 | else |
| 145 | ConstantPoolSection = "\t.const\n"; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 146 | JumpTableDataSection = "\t.const\n"; |
| 147 | CStringSection = "\t.cstring"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 148 | CStringSection_ = getUnnamedSection("\t.cstring", |
| 149 | SectionFlags::Mergeable | SectionFlags::Strings); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 150 | FourByteConstantSection = "\t.literal4\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 151 | FourByteConstantSection_ = getUnnamedSection("\t.literal4\n", |
| 152 | SectionFlags::Mergeable); |
Anton Korobeynikov | b126f3b | 2008-07-09 20:47:55 +0000 | [diff] [blame] | 153 | EightByteConstantSection = "\t.literal8\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 154 | EightByteConstantSection_ = getUnnamedSection("\t.literal8\n", |
| 155 | SectionFlags::Mergeable); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 156 | // FIXME: Why don't always use this section? |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 157 | if (is64Bit) { |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 158 | SixteenByteConstantSection = "\t.literal16\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 159 | SixteenByteConstantSection_ = getUnnamedSection("\t.literal16\n", |
| 160 | SectionFlags::Mergeable); |
| 161 | } |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 162 | ReadOnlySection = "\t.const\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 163 | ReadOnlySection_ = getUnnamedSection("\t.const\n", SectionFlags::None); |
Anton Korobeynikov | c5a7e40 | 2008-07-09 13:30:02 +0000 | [diff] [blame] | 164 | // FIXME: These should be named sections, really. |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 165 | TextCoalSection = |
| 166 | getUnnamedSection(".section __TEXT,__textcoal_nt,coalesced,pure_instructions", |
| 167 | SectionFlags::Code); |
| 168 | ConstDataCoalSection = |
| 169 | getUnnamedSection(".section __DATA,__const_coal,coalesced", |
| 170 | SectionFlags::None); |
| 171 | ConstDataSection = getUnnamedSection(".const_data", SectionFlags::None); |
| 172 | DataCoalSection = getUnnamedSection(".section __DATA,__datacoal_nt,coalesced", |
| 173 | SectionFlags::Writeable); |
| 174 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 175 | LCOMMDirective = "\t.lcomm\t"; |
| 176 | SwitchToSectionDirective = "\t.section "; |
| 177 | StringConstantPrefix = "\1LC"; |
| 178 | COMMDirectiveTakesAlignment = false; |
| 179 | HasDotTypeDotSizeDirective = false; |
| 180 | if (TM.getRelocationModel() == Reloc::Static) { |
| 181 | StaticCtorsSection = ".constructor"; |
| 182 | StaticDtorsSection = ".destructor"; |
| 183 | } else { |
| 184 | StaticCtorsSection = ".mod_init_func"; |
| 185 | StaticDtorsSection = ".mod_term_func"; |
| 186 | } |
| 187 | if (is64Bit) { |
| 188 | PersonalityPrefix = ""; |
| 189 | PersonalitySuffix = "+4@GOTPCREL"; |
| 190 | } else { |
| 191 | PersonalityPrefix = "L"; |
| 192 | PersonalitySuffix = "$non_lazy_ptr"; |
| 193 | } |
| 194 | NeedsIndirectEncoding = true; |
| 195 | InlineAsmStart = "## InlineAsm Start"; |
| 196 | InlineAsmEnd = "## InlineAsm End"; |
| 197 | CommentString = "##"; |
| 198 | SetDirective = "\t.set"; |
| 199 | PCSymbol = "."; |
| 200 | UsedDirective = "\t.no_dead_strip\t"; |
| 201 | WeakDefDirective = "\t.weak_definition "; |
| 202 | WeakRefDirective = "\t.weak_reference "; |
| 203 | HiddenDirective = "\t.private_extern "; |
| 204 | ProtectedDirective = "\t.globl\t"; |
| 205 | |
| 206 | // In non-PIC modes, emit a special label before jump tables so that the |
| 207 | // linker can perform more accurate dead code stripping. |
| 208 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 209 | // Emit a local label that is preserved until the linker runs. |
| 210 | JumpTableSpecialLabelPrefix = "l"; |
| 211 | } |
| 212 | |
| 213 | SupportsDebugInformation = true; |
| 214 | NeedsSet = true; |
| 215 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 216 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 217 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 218 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 219 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 220 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 221 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 222 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 223 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 224 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 225 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
| 226 | |
| 227 | // Exceptions handling |
| 228 | SupportsExceptionHandling = true; |
| 229 | GlobalEHDirective = "\t.globl\t"; |
| 230 | SupportsWeakOmittedEHFrame = false; |
| 231 | AbsoluteEHSectionOffsets = false; |
| 232 | DwarfEHFrameSection = |
| 233 | ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support"; |
| 234 | DwarfExceptionSection = ".section __DATA,__gcc_except_tab"; |
| 235 | } |
| 236 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 237 | unsigned |
| 238 | X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 239 | bool Global) const { |
| 240 | if (Reason == DwarfEncoding::Functions && Global) |
| 241 | return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4); |
| 242 | else if (Reason == DwarfEncoding::CodeLabels || !Global) |
| 243 | return DW_EH_PE_pcrel; |
| 244 | else |
| 245 | return DW_EH_PE_absptr; |
| 246 | } |
| 247 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 248 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 249 | X86DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
| 250 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
Anton Korobeynikov | c33a744 | 2008-07-09 13:27:59 +0000 | [diff] [blame] | 251 | bool isWeak = GV->isWeakForLinker(); |
Anton Korobeynikov | 9a06ed9 | 2008-07-09 20:01:42 +0000 | [diff] [blame] | 252 | bool isNonStatic = (X86TM->getRelocationModel() != Reloc::Static); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 253 | |
| 254 | switch (Kind) { |
| 255 | case SectionKind::Text: |
| 256 | if (isWeak) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 257 | return TextCoalSection; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 258 | else |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 259 | return getTextSection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 260 | case SectionKind::Data: |
| 261 | case SectionKind::ThreadData: |
| 262 | case SectionKind::BSS: |
| 263 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 264 | if (cast<GlobalVariable>(GV)->isConstant()) |
| 265 | return (isWeak ? ConstDataCoalSection : ConstDataSection); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 266 | else |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 267 | return (isWeak ? DataCoalSection : getDataSection_()); |
| 268 | case SectionKind::ROData: |
Anton Korobeynikov | 9a06ed9 | 2008-07-09 20:01:42 +0000 | [diff] [blame] | 269 | return (isWeak ? ConstDataCoalSection : |
| 270 | (isNonStatic ? ConstDataSection : getReadOnlySection_())); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 271 | case SectionKind::RODataMergeStr: |
Anton Korobeynikov | f56c2f7 | 2008-07-09 19:06:02 +0000 | [diff] [blame] | 272 | return (isWeak ? |
| 273 | ConstDataCoalSection : |
| 274 | MergeableStringSection(cast<GlobalVariable>(GV))); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 275 | case SectionKind::RODataMergeConst: |
Anton Korobeynikov | f56c2f7 | 2008-07-09 19:06:02 +0000 | [diff] [blame] | 276 | return (isWeak ? |
| 277 | ConstDataCoalSection: |
| 278 | MergeableConstSection(cast<GlobalVariable>(GV))); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 279 | default: |
| 280 | assert(0 && "Unsuported section kind for global"); |
| 281 | } |
| 282 | |
| 283 | // FIXME: Do we have any extra special weird cases? |
| 284 | } |
| 285 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 286 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 287 | X86DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 288 | const TargetData *TD = X86TM->getTargetData(); |
| 289 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 290 | const Type *Type = cast<ConstantArray>(C)->getType()->getElementType(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 291 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 292 | unsigned Size = TD->getABITypeSize(Type); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 293 | if (Size) { |
| 294 | const TargetData *TD = X86TM->getTargetData(); |
| 295 | unsigned Align = TD->getPreferredAlignment(GV); |
| 296 | if (Align <= 32) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 297 | return getCStringSection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 300 | return getReadOnlySection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 303 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 304 | X86DarwinTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 305 | const TargetData *TD = X86TM->getTargetData(); |
| 306 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 307 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 308 | unsigned Size = TD->getABITypeSize(C->getType()); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 309 | if (Size == 4) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 310 | return FourByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 311 | else if (Size == 8) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 312 | return EightByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 313 | else if (Size == 16 && X86TM->getSubtarget<X86Subtarget>().is64Bit()) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 314 | return SixteenByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 315 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 316 | return getReadOnlySection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | std::string |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 320 | X86DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 321 | SectionKind::Kind kind) const { |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 322 | assert(0 && "Darwin does not use unique sections"); |
| 323 | return ""; |
| 324 | } |
| 325 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 326 | X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM): |
| 327 | X86TargetAsmInfo(TM) { |
| 328 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 329 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 330 | TextSection_ = getUnnamedSection("\t.text", SectionFlags::Code); |
| 331 | DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable); |
| 332 | BSSSection_ = getUnnamedSection("\t.bss", |
| 333 | SectionFlags::Writeable | SectionFlags::BSS); |
Anton Korobeynikov | a3af0bf | 2008-07-09 13:29:27 +0000 | [diff] [blame] | 334 | ReadOnlySection_ = getNamedSection("\t.rodata", SectionFlags::None); |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 335 | TLSDataSection_ = getNamedSection("\t.tdata", |
| 336 | SectionFlags::Writeable | SectionFlags::TLS); |
| 337 | TLSBSSSection_ = getNamedSection("\t.tbss", |
| 338 | SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS); |
| 339 | |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 340 | ReadOnlySection = ".rodata"; |
Anton Korobeynikov | 2a88917 | 2008-07-09 13:25:46 +0000 | [diff] [blame] | 341 | FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4"; |
| 342 | EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8"; |
| 343 | SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16"; |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 344 | CStringSection = ".rodata.str"; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 345 | PrivateGlobalPrefix = ".L"; |
| 346 | WeakRefDirective = "\t.weak\t"; |
| 347 | SetDirective = "\t.set\t"; |
| 348 | PCSymbol = "."; |
| 349 | |
| 350 | // Set up DWARF directives |
| 351 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 352 | |
| 353 | // Debug Information |
| 354 | AbsoluteDebugSectionOffsets = true; |
| 355 | SupportsDebugInformation = true; |
| 356 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits"; |
| 357 | DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits"; |
| 358 | DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits"; |
| 359 | DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits"; |
| 360 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits"; |
| 361 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits"; |
| 362 | DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits"; |
| 363 | DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits"; |
| 364 | DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits"; |
| 365 | DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits"; |
| 366 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits"; |
| 367 | |
| 368 | // Exceptions handling |
| 369 | if (!is64Bit) |
| 370 | SupportsExceptionHandling = true; |
| 371 | AbsoluteEHSectionOffsets = false; |
| 372 | DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits"; |
| 373 | DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits"; |
| 374 | |
| 375 | // On Linux we must declare when we can use a non-executable stack. |
| 376 | if (X86TM->getSubtarget<X86Subtarget>().isLinux()) |
| 377 | NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits"; |
| 378 | } |
| 379 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 380 | unsigned |
| 381 | X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 382 | bool Global) const { |
| 383 | CodeModel::Model CM = X86TM->getCodeModel(); |
| 384 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 385 | |
| 386 | if (X86TM->getRelocationModel() == Reloc::PIC_) { |
| 387 | unsigned Format = 0; |
| 388 | |
| 389 | if (!is64Bit) |
| 390 | // 32 bit targets always encode pointers as 4 bytes |
| 391 | Format = DW_EH_PE_sdata4; |
| 392 | else { |
| 393 | // 64 bit targets encode pointers in 4 bytes iff: |
| 394 | // - code model is small OR |
| 395 | // - code model is medium and we're emitting externally visible symbols |
| 396 | // or any code symbols |
| 397 | if (CM == CodeModel::Small || |
| 398 | (CM == CodeModel::Medium && (Global || |
| 399 | Reason != DwarfEncoding::Data))) |
| 400 | Format = DW_EH_PE_sdata4; |
| 401 | else |
| 402 | Format = DW_EH_PE_sdata8; |
| 403 | } |
| 404 | |
| 405 | if (Global) |
| 406 | Format |= DW_EH_PE_indirect; |
| 407 | |
| 408 | return (Format | DW_EH_PE_pcrel); |
| 409 | } else { |
| 410 | if (is64Bit && |
| 411 | (CM == CodeModel::Small || |
| 412 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 413 | return DW_EH_PE_udata4; |
| 414 | else |
| 415 | return DW_EH_PE_absptr; |
| 416 | } |
| 417 | } |
| 418 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 419 | const Section* |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 420 | X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 421 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 422 | |
| 423 | if (const Function *F = dyn_cast<Function>(GV)) { |
| 424 | switch (F->getLinkage()) { |
| 425 | default: assert(0 && "Unknown linkage type!"); |
| 426 | case Function::InternalLinkage: |
| 427 | case Function::DLLExportLinkage: |
| 428 | case Function::ExternalLinkage: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 429 | return getTextSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 430 | case Function::WeakLinkage: |
| 431 | case Function::LinkOnceLinkage: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 432 | std::string Name = UniqueSectionForGlobal(GV, Kind); |
| 433 | unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); |
| 434 | return getNamedSection(Name.c_str(), Flags); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 435 | } |
| 436 | } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 437 | if (GVar->isWeakForLinker()) { |
| 438 | std::string Name = UniqueSectionForGlobal(GVar, Kind); |
| 439 | unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str()); |
| 440 | return getNamedSection(Name.c_str(), Flags); |
| 441 | } else { |
| 442 | switch (Kind) { |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 443 | case SectionKind::Data: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 444 | return getDataSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 445 | case SectionKind::BSS: |
| 446 | // ELF targets usually have BSS sections |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 447 | return getBSSSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 448 | case SectionKind::ROData: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 449 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 450 | case SectionKind::RODataMergeStr: |
| 451 | return MergeableStringSection(GVar); |
| 452 | case SectionKind::RODataMergeConst: |
| 453 | return MergeableConstSection(GVar); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 454 | case SectionKind::ThreadData: |
| 455 | // ELF targets usually support TLS stuff |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 456 | return getTLSDataSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 457 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 458 | return getTLSBSSSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 459 | default: |
| 460 | assert(0 && "Unsuported section kind for global"); |
| 461 | } |
| 462 | } |
| 463 | } else |
| 464 | assert(0 && "Unsupported global"); |
| 465 | } |
| 466 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 467 | const Section* |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 468 | X86ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 469 | const TargetData *TD = X86TM->getTargetData(); |
| 470 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 471 | const Type *Type = C->getType(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 472 | |
| 473 | // FIXME: string here is temporary, until stuff will fully land in. |
Anton Korobeynikov | 2a88917 | 2008-07-09 13:25:46 +0000 | [diff] [blame] | 474 | // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's |
| 475 | // currently directly used by asmprinter. |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 476 | unsigned Size = TD->getABITypeSize(Type); |
| 477 | if (Size == 4 || Size == 8 || Size == 16) { |
| 478 | std::string Name = ".rodata.cst" + utostr(Size); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 479 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 480 | return getNamedSection(Name.c_str(), |
| 481 | SectionFlags::setEntitySize(SectionFlags::Mergeable, |
| 482 | Size)); |
| 483 | } |
| 484 | |
| 485 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 488 | const Section* |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 489 | X86ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 490 | const TargetData *TD = X86TM->getTargetData(); |
| 491 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 492 | const ConstantArray *CVA = cast<ConstantArray>(C); |
| 493 | const Type *Type = CVA->getType()->getElementType(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 494 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 495 | unsigned Size = TD->getABITypeSize(Type); |
| 496 | if (Size <= 16) { |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 497 | // We also need alignment here |
| 498 | const TargetData *TD = X86TM->getTargetData(); |
| 499 | unsigned Align = TD->getPreferredAlignment(GV); |
| 500 | if (Align < Size) |
| 501 | Align = Size; |
| 502 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 503 | std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align); |
| 504 | unsigned Flags = SectionFlags::setEntitySize(SectionFlags::Mergeable | |
| 505 | SectionFlags::Strings, |
| 506 | Size); |
| 507 | return getNamedSection(Name.c_str(), Flags); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 510 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 513 | std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const { |
| 514 | std::string Flags = ",\""; |
| 515 | |
| 516 | if (!(flags & SectionFlags::Debug)) |
| 517 | Flags += 'a'; |
| 518 | if (flags & SectionFlags::Code) |
| 519 | Flags += 'x'; |
| 520 | if (flags & SectionFlags::Writeable) |
| 521 | Flags += 'w'; |
| 522 | if (flags & SectionFlags::Mergeable) |
| 523 | Flags += 'M'; |
| 524 | if (flags & SectionFlags::Strings) |
| 525 | Flags += 'S'; |
| 526 | if (flags & SectionFlags::TLS) |
| 527 | Flags += 'T'; |
| 528 | |
| 529 | Flags += "\""; |
| 530 | |
| 531 | // FIXME: There can be exceptions here |
| 532 | if (flags & SectionFlags::BSS) |
| 533 | Flags += ",@nobits"; |
| 534 | else |
| 535 | Flags += ",@progbits"; |
| 536 | |
Anton Korobeynikov | 6d82942 | 2008-07-09 13:22:17 +0000 | [diff] [blame] | 537 | if (unsigned entitySize = SectionFlags::getEntitySize(flags)) |
| 538 | Flags += "," + utostr(entitySize); |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 539 | |
| 540 | return Flags; |
| 541 | } |
| 542 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 543 | X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM): |
| 544 | X86TargetAsmInfo(TM) { |
| 545 | GlobalPrefix = "_"; |
| 546 | LCOMMDirective = "\t.lcomm\t"; |
| 547 | COMMDirectiveTakesAlignment = false; |
| 548 | HasDotTypeDotSizeDirective = false; |
| 549 | StaticCtorsSection = "\t.section .ctors,\"aw\""; |
| 550 | StaticDtorsSection = "\t.section .dtors,\"aw\""; |
| 551 | HiddenDirective = NULL; |
| 552 | PrivateGlobalPrefix = "L"; // Prefix for private global symbols |
| 553 | WeakRefDirective = "\t.weak\t"; |
| 554 | SetDirective = "\t.set\t"; |
| 555 | |
| 556 | // Set up DWARF directives |
| 557 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 558 | AbsoluteDebugSectionOffsets = true; |
| 559 | AbsoluteEHSectionOffsets = false; |
| 560 | SupportsDebugInformation = true; |
| 561 | DwarfSectionOffsetDirective = "\t.secrel32\t"; |
| 562 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\""; |
| 563 | DwarfInfoSection = "\t.section\t.debug_info,\"dr\""; |
| 564 | DwarfLineSection = "\t.section\t.debug_line,\"dr\""; |
| 565 | DwarfFrameSection = "\t.section\t.debug_frame,\"dr\""; |
| 566 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\""; |
| 567 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\""; |
| 568 | DwarfStrSection = "\t.section\t.debug_str,\"dr\""; |
| 569 | DwarfLocSection = "\t.section\t.debug_loc,\"dr\""; |
| 570 | DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\""; |
| 571 | DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\""; |
| 572 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\""; |
| 573 | } |
| 574 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 575 | unsigned |
| 576 | X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 577 | bool Global) const { |
| 578 | CodeModel::Model CM = X86TM->getCodeModel(); |
| 579 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 580 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 581 | if (X86TM->getRelocationModel() == Reloc::PIC_) { |
| 582 | unsigned Format = 0; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 583 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 584 | if (!is64Bit) |
| 585 | // 32 bit targets always encode pointers as 4 bytes |
| 586 | Format = DW_EH_PE_sdata4; |
| 587 | else { |
| 588 | // 64 bit targets encode pointers in 4 bytes iff: |
| 589 | // - code model is small OR |
| 590 | // - code model is medium and we're emitting externally visible symbols |
| 591 | // or any code symbols |
| 592 | if (CM == CodeModel::Small || |
| 593 | (CM == CodeModel::Medium && (Global || |
| 594 | Reason != DwarfEncoding::Data))) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 595 | Format = DW_EH_PE_sdata4; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 596 | else |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 597 | Format = DW_EH_PE_sdata8; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 598 | } |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 599 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 600 | if (Global) |
| 601 | Format |= DW_EH_PE_indirect; |
| 602 | |
| 603 | return (Format | DW_EH_PE_pcrel); |
| 604 | } else { |
| 605 | if (is64Bit && |
| 606 | (CM == CodeModel::Small || |
| 607 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 608 | return DW_EH_PE_udata4; |
| 609 | else |
| 610 | return DW_EH_PE_absptr; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 614 | std::string |
| 615 | X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 616 | SectionKind::Kind kind) const { |
| 617 | switch (kind) { |
| 618 | case SectionKind::Text: |
| 619 | return ".text$linkonce" + GV->getName(); |
| 620 | case SectionKind::Data: |
| 621 | case SectionKind::BSS: |
| 622 | case SectionKind::ThreadData: |
| 623 | case SectionKind::ThreadBSS: |
| 624 | return ".data$linkonce" + GV->getName(); |
| 625 | case SectionKind::ROData: |
| 626 | case SectionKind::RODataMergeConst: |
| 627 | case SectionKind::RODataMergeStr: |
| 628 | return ".rdata$linkonce" + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 629 | default: |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 630 | assert(0 && "Unknown section kind"); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 634 | std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const { |
| 635 | std::string Flags = ",\""; |
| 636 | |
| 637 | if (flags & SectionFlags::Code) |
| 638 | Flags += 'x'; |
| 639 | if (flags & SectionFlags::Writeable) |
| 640 | Flags += 'w'; |
| 641 | |
| 642 | Flags += "\""; |
| 643 | |
| 644 | return Flags; |
| 645 | } |
| 646 | |
| 647 | X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM): |
| 648 | X86TargetAsmInfo(TM) { |
| 649 | GlobalPrefix = "_"; |
| 650 | CommentString = ";"; |
| 651 | |
| 652 | PrivateGlobalPrefix = "$"; |
| 653 | AlignDirective = "\talign\t"; |
| 654 | ZeroDirective = "\tdb\t"; |
| 655 | ZeroDirectiveSuffix = " dup(0)"; |
| 656 | AsciiDirective = "\tdb\t"; |
| 657 | AscizDirective = 0; |
| 658 | Data8bitsDirective = "\tdb\t"; |
| 659 | Data16bitsDirective = "\tdw\t"; |
| 660 | Data32bitsDirective = "\tdd\t"; |
| 661 | Data64bitsDirective = "\tdq\t"; |
| 662 | HasDotTypeDotSizeDirective = false; |
| 663 | |
| 664 | TextSection = "_text"; |
| 665 | DataSection = "_data"; |
| 666 | JumpTableDataSection = NULL; |
| 667 | SwitchToSectionDirective = ""; |
| 668 | TextSectionStartSuffix = "\tsegment 'CODE'"; |
| 669 | DataSectionStartSuffix = "\tsegment 'DATA'"; |
| 670 | SectionEndDirectiveSuffix = "\tends\n"; |
| 671 | } |