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 |
| 142 | ConstantPoolSection = "\t.const\n"; |
| 143 | JumpTableDataSection = "\t.const\n"; |
| 144 | CStringSection = "\t.cstring"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 145 | CStringSection_ = getUnnamedSection("\t.cstring", |
| 146 | SectionFlags::Mergeable | SectionFlags::Strings); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 147 | FourByteConstantSection = "\t.literal4\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 148 | FourByteConstantSection_ = getUnnamedSection("\t.literal4\n", |
| 149 | SectionFlags::Mergeable); |
Anton Korobeynikov | b126f3b | 2008-07-09 20:47:55 +0000 | [diff] [blame^] | 150 | EightByteConstantSection = "\t.literal8\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 151 | EightByteConstantSection_ = getUnnamedSection("\t.literal8\n", |
| 152 | SectionFlags::Mergeable); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 153 | // FIXME: Why don't always use this section? |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 154 | if (is64Bit) { |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 155 | SixteenByteConstantSection = "\t.literal16\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 156 | SixteenByteConstantSection_ = getUnnamedSection("\t.literal16\n", |
| 157 | SectionFlags::Mergeable); |
| 158 | } |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 159 | ReadOnlySection = "\t.const\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 160 | ReadOnlySection_ = getUnnamedSection("\t.const\n", SectionFlags::None); |
Anton Korobeynikov | c5a7e40 | 2008-07-09 13:30:02 +0000 | [diff] [blame] | 161 | // FIXME: These should be named sections, really. |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 162 | TextCoalSection = |
| 163 | getUnnamedSection(".section __TEXT,__textcoal_nt,coalesced,pure_instructions", |
| 164 | SectionFlags::Code); |
| 165 | ConstDataCoalSection = |
| 166 | getUnnamedSection(".section __DATA,__const_coal,coalesced", |
| 167 | SectionFlags::None); |
| 168 | ConstDataSection = getUnnamedSection(".const_data", SectionFlags::None); |
| 169 | DataCoalSection = getUnnamedSection(".section __DATA,__datacoal_nt,coalesced", |
| 170 | SectionFlags::Writeable); |
| 171 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 172 | LCOMMDirective = "\t.lcomm\t"; |
| 173 | SwitchToSectionDirective = "\t.section "; |
| 174 | StringConstantPrefix = "\1LC"; |
| 175 | COMMDirectiveTakesAlignment = false; |
| 176 | HasDotTypeDotSizeDirective = false; |
| 177 | if (TM.getRelocationModel() == Reloc::Static) { |
| 178 | StaticCtorsSection = ".constructor"; |
| 179 | StaticDtorsSection = ".destructor"; |
| 180 | } else { |
| 181 | StaticCtorsSection = ".mod_init_func"; |
| 182 | StaticDtorsSection = ".mod_term_func"; |
| 183 | } |
| 184 | if (is64Bit) { |
| 185 | PersonalityPrefix = ""; |
| 186 | PersonalitySuffix = "+4@GOTPCREL"; |
| 187 | } else { |
| 188 | PersonalityPrefix = "L"; |
| 189 | PersonalitySuffix = "$non_lazy_ptr"; |
| 190 | } |
| 191 | NeedsIndirectEncoding = true; |
| 192 | InlineAsmStart = "## InlineAsm Start"; |
| 193 | InlineAsmEnd = "## InlineAsm End"; |
| 194 | CommentString = "##"; |
| 195 | SetDirective = "\t.set"; |
| 196 | PCSymbol = "."; |
| 197 | UsedDirective = "\t.no_dead_strip\t"; |
| 198 | WeakDefDirective = "\t.weak_definition "; |
| 199 | WeakRefDirective = "\t.weak_reference "; |
| 200 | HiddenDirective = "\t.private_extern "; |
| 201 | ProtectedDirective = "\t.globl\t"; |
| 202 | |
| 203 | // In non-PIC modes, emit a special label before jump tables so that the |
| 204 | // linker can perform more accurate dead code stripping. |
| 205 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 206 | // Emit a local label that is preserved until the linker runs. |
| 207 | JumpTableSpecialLabelPrefix = "l"; |
| 208 | } |
| 209 | |
| 210 | SupportsDebugInformation = true; |
| 211 | NeedsSet = true; |
| 212 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 213 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 214 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 215 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 216 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 217 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 218 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 219 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 220 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 221 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 222 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
| 223 | |
| 224 | // Exceptions handling |
| 225 | SupportsExceptionHandling = true; |
| 226 | GlobalEHDirective = "\t.globl\t"; |
| 227 | SupportsWeakOmittedEHFrame = false; |
| 228 | AbsoluteEHSectionOffsets = false; |
| 229 | DwarfEHFrameSection = |
| 230 | ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support"; |
| 231 | DwarfExceptionSection = ".section __DATA,__gcc_except_tab"; |
| 232 | } |
| 233 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 234 | unsigned |
| 235 | X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 236 | bool Global) const { |
| 237 | if (Reason == DwarfEncoding::Functions && Global) |
| 238 | return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4); |
| 239 | else if (Reason == DwarfEncoding::CodeLabels || !Global) |
| 240 | return DW_EH_PE_pcrel; |
| 241 | else |
| 242 | return DW_EH_PE_absptr; |
| 243 | } |
| 244 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 245 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 246 | X86DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
| 247 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
Anton Korobeynikov | c33a744 | 2008-07-09 13:27:59 +0000 | [diff] [blame] | 248 | bool isWeak = GV->isWeakForLinker(); |
Anton Korobeynikov | 9a06ed9 | 2008-07-09 20:01:42 +0000 | [diff] [blame] | 249 | bool isNonStatic = (X86TM->getRelocationModel() != Reloc::Static); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 250 | |
| 251 | switch (Kind) { |
| 252 | case SectionKind::Text: |
| 253 | if (isWeak) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 254 | return TextCoalSection; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 255 | else |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 256 | return getTextSection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 257 | case SectionKind::Data: |
| 258 | case SectionKind::ThreadData: |
| 259 | case SectionKind::BSS: |
| 260 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 261 | if (cast<GlobalVariable>(GV)->isConstant()) |
| 262 | return (isWeak ? ConstDataCoalSection : ConstDataSection); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 263 | else |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 264 | return (isWeak ? DataCoalSection : getDataSection_()); |
| 265 | case SectionKind::ROData: |
Anton Korobeynikov | 9a06ed9 | 2008-07-09 20:01:42 +0000 | [diff] [blame] | 266 | return (isWeak ? ConstDataCoalSection : |
| 267 | (isNonStatic ? ConstDataSection : getReadOnlySection_())); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 268 | case SectionKind::RODataMergeStr: |
Anton Korobeynikov | f56c2f7 | 2008-07-09 19:06:02 +0000 | [diff] [blame] | 269 | return (isWeak ? |
| 270 | ConstDataCoalSection : |
| 271 | MergeableStringSection(cast<GlobalVariable>(GV))); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 272 | case SectionKind::RODataMergeConst: |
Anton Korobeynikov | f56c2f7 | 2008-07-09 19:06:02 +0000 | [diff] [blame] | 273 | return (isWeak ? |
| 274 | ConstDataCoalSection: |
| 275 | MergeableConstSection(cast<GlobalVariable>(GV))); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 276 | default: |
| 277 | assert(0 && "Unsuported section kind for global"); |
| 278 | } |
| 279 | |
| 280 | // FIXME: Do we have any extra special weird cases? |
| 281 | } |
| 282 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 283 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 284 | X86DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 285 | const TargetData *TD = X86TM->getTargetData(); |
| 286 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 287 | const Type *Type = cast<ConstantArray>(C)->getType()->getElementType(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 288 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 289 | unsigned Size = TD->getABITypeSize(Type); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 290 | if (Size) { |
| 291 | const TargetData *TD = X86TM->getTargetData(); |
| 292 | unsigned Align = TD->getPreferredAlignment(GV); |
| 293 | if (Align <= 32) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 294 | return getCStringSection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 297 | return getReadOnlySection_(); |
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 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 301 | X86DarwinTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 302 | const TargetData *TD = X86TM->getTargetData(); |
| 303 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 304 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 305 | unsigned Size = TD->getABITypeSize(C->getType()); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 306 | if (Size == 4) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 307 | return FourByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 308 | else if (Size == 8) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 309 | return EightByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 310 | else if (Size == 16 && X86TM->getSubtarget<X86Subtarget>().is64Bit()) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 311 | return SixteenByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 312 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 313 | return getReadOnlySection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | std::string |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 317 | X86DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 318 | SectionKind::Kind kind) const { |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 319 | assert(0 && "Darwin does not use unique sections"); |
| 320 | return ""; |
| 321 | } |
| 322 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 323 | X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM): |
| 324 | X86TargetAsmInfo(TM) { |
| 325 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 326 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 327 | TextSection_ = getUnnamedSection("\t.text", SectionFlags::Code); |
| 328 | DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable); |
| 329 | BSSSection_ = getUnnamedSection("\t.bss", |
| 330 | SectionFlags::Writeable | SectionFlags::BSS); |
Anton Korobeynikov | a3af0bf | 2008-07-09 13:29:27 +0000 | [diff] [blame] | 331 | ReadOnlySection_ = getNamedSection("\t.rodata", SectionFlags::None); |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 332 | TLSDataSection_ = getNamedSection("\t.tdata", |
| 333 | SectionFlags::Writeable | SectionFlags::TLS); |
| 334 | TLSBSSSection_ = getNamedSection("\t.tbss", |
| 335 | SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS); |
| 336 | |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 337 | ReadOnlySection = ".rodata"; |
Anton Korobeynikov | 2a88917 | 2008-07-09 13:25:46 +0000 | [diff] [blame] | 338 | FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4"; |
| 339 | EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8"; |
| 340 | SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16"; |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 341 | CStringSection = ".rodata.str"; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 342 | PrivateGlobalPrefix = ".L"; |
| 343 | WeakRefDirective = "\t.weak\t"; |
| 344 | SetDirective = "\t.set\t"; |
| 345 | PCSymbol = "."; |
| 346 | |
| 347 | // Set up DWARF directives |
| 348 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 349 | |
| 350 | // Debug Information |
| 351 | AbsoluteDebugSectionOffsets = true; |
| 352 | SupportsDebugInformation = true; |
| 353 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits"; |
| 354 | DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits"; |
| 355 | DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits"; |
| 356 | DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits"; |
| 357 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits"; |
| 358 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits"; |
| 359 | DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits"; |
| 360 | DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits"; |
| 361 | DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits"; |
| 362 | DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits"; |
| 363 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits"; |
| 364 | |
| 365 | // Exceptions handling |
| 366 | if (!is64Bit) |
| 367 | SupportsExceptionHandling = true; |
| 368 | AbsoluteEHSectionOffsets = false; |
| 369 | DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits"; |
| 370 | DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits"; |
| 371 | |
| 372 | // On Linux we must declare when we can use a non-executable stack. |
| 373 | if (X86TM->getSubtarget<X86Subtarget>().isLinux()) |
| 374 | NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits"; |
| 375 | } |
| 376 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 377 | unsigned |
| 378 | X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 379 | bool Global) const { |
| 380 | CodeModel::Model CM = X86TM->getCodeModel(); |
| 381 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 382 | |
| 383 | if (X86TM->getRelocationModel() == Reloc::PIC_) { |
| 384 | unsigned Format = 0; |
| 385 | |
| 386 | if (!is64Bit) |
| 387 | // 32 bit targets always encode pointers as 4 bytes |
| 388 | Format = DW_EH_PE_sdata4; |
| 389 | else { |
| 390 | // 64 bit targets encode pointers in 4 bytes iff: |
| 391 | // - code model is small OR |
| 392 | // - code model is medium and we're emitting externally visible symbols |
| 393 | // or any code symbols |
| 394 | if (CM == CodeModel::Small || |
| 395 | (CM == CodeModel::Medium && (Global || |
| 396 | Reason != DwarfEncoding::Data))) |
| 397 | Format = DW_EH_PE_sdata4; |
| 398 | else |
| 399 | Format = DW_EH_PE_sdata8; |
| 400 | } |
| 401 | |
| 402 | if (Global) |
| 403 | Format |= DW_EH_PE_indirect; |
| 404 | |
| 405 | return (Format | DW_EH_PE_pcrel); |
| 406 | } else { |
| 407 | if (is64Bit && |
| 408 | (CM == CodeModel::Small || |
| 409 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 410 | return DW_EH_PE_udata4; |
| 411 | else |
| 412 | return DW_EH_PE_absptr; |
| 413 | } |
| 414 | } |
| 415 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 416 | const Section* |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 417 | X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 418 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 419 | |
| 420 | if (const Function *F = dyn_cast<Function>(GV)) { |
| 421 | switch (F->getLinkage()) { |
| 422 | default: assert(0 && "Unknown linkage type!"); |
| 423 | case Function::InternalLinkage: |
| 424 | case Function::DLLExportLinkage: |
| 425 | case Function::ExternalLinkage: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 426 | return getTextSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 427 | case Function::WeakLinkage: |
| 428 | case Function::LinkOnceLinkage: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 429 | std::string Name = UniqueSectionForGlobal(GV, Kind); |
| 430 | unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); |
| 431 | return getNamedSection(Name.c_str(), Flags); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 432 | } |
| 433 | } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 434 | if (GVar->isWeakForLinker()) { |
| 435 | std::string Name = UniqueSectionForGlobal(GVar, Kind); |
| 436 | unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str()); |
| 437 | return getNamedSection(Name.c_str(), Flags); |
| 438 | } else { |
| 439 | switch (Kind) { |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 440 | case SectionKind::Data: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 441 | return getDataSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 442 | case SectionKind::BSS: |
| 443 | // ELF targets usually have BSS sections |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 444 | return getBSSSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 445 | case SectionKind::ROData: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 446 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 447 | case SectionKind::RODataMergeStr: |
| 448 | return MergeableStringSection(GVar); |
| 449 | case SectionKind::RODataMergeConst: |
| 450 | return MergeableConstSection(GVar); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 451 | case SectionKind::ThreadData: |
| 452 | // ELF targets usually support TLS stuff |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 453 | return getTLSDataSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 454 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 455 | return getTLSBSSSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 456 | default: |
| 457 | assert(0 && "Unsuported section kind for global"); |
| 458 | } |
| 459 | } |
| 460 | } else |
| 461 | assert(0 && "Unsupported global"); |
| 462 | } |
| 463 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 464 | const Section* |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 465 | X86ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 466 | const TargetData *TD = X86TM->getTargetData(); |
| 467 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 468 | const Type *Type = C->getType(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 469 | |
| 470 | // FIXME: string here is temporary, until stuff will fully land in. |
Anton Korobeynikov | 2a88917 | 2008-07-09 13:25:46 +0000 | [diff] [blame] | 471 | // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's |
| 472 | // currently directly used by asmprinter. |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 473 | unsigned Size = TD->getABITypeSize(Type); |
| 474 | if (Size == 4 || Size == 8 || Size == 16) { |
| 475 | std::string Name = ".rodata.cst" + utostr(Size); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 476 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 477 | return getNamedSection(Name.c_str(), |
| 478 | SectionFlags::setEntitySize(SectionFlags::Mergeable, |
| 479 | Size)); |
| 480 | } |
| 481 | |
| 482 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 485 | const Section* |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 486 | X86ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 487 | const TargetData *TD = X86TM->getTargetData(); |
| 488 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 489 | const ConstantArray *CVA = cast<ConstantArray>(C); |
| 490 | const Type *Type = CVA->getType()->getElementType(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 491 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 492 | unsigned Size = TD->getABITypeSize(Type); |
| 493 | if (Size <= 16) { |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 494 | // We also need alignment here |
| 495 | const TargetData *TD = X86TM->getTargetData(); |
| 496 | unsigned Align = TD->getPreferredAlignment(GV); |
| 497 | if (Align < Size) |
| 498 | Align = Size; |
| 499 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 500 | std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align); |
| 501 | unsigned Flags = SectionFlags::setEntitySize(SectionFlags::Mergeable | |
| 502 | SectionFlags::Strings, |
| 503 | Size); |
| 504 | return getNamedSection(Name.c_str(), Flags); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 507 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 510 | std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const { |
| 511 | std::string Flags = ",\""; |
| 512 | |
| 513 | if (!(flags & SectionFlags::Debug)) |
| 514 | Flags += 'a'; |
| 515 | if (flags & SectionFlags::Code) |
| 516 | Flags += 'x'; |
| 517 | if (flags & SectionFlags::Writeable) |
| 518 | Flags += 'w'; |
| 519 | if (flags & SectionFlags::Mergeable) |
| 520 | Flags += 'M'; |
| 521 | if (flags & SectionFlags::Strings) |
| 522 | Flags += 'S'; |
| 523 | if (flags & SectionFlags::TLS) |
| 524 | Flags += 'T'; |
| 525 | |
| 526 | Flags += "\""; |
| 527 | |
| 528 | // FIXME: There can be exceptions here |
| 529 | if (flags & SectionFlags::BSS) |
| 530 | Flags += ",@nobits"; |
| 531 | else |
| 532 | Flags += ",@progbits"; |
| 533 | |
Anton Korobeynikov | 6d82942 | 2008-07-09 13:22:17 +0000 | [diff] [blame] | 534 | if (unsigned entitySize = SectionFlags::getEntitySize(flags)) |
| 535 | Flags += "," + utostr(entitySize); |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 536 | |
| 537 | return Flags; |
| 538 | } |
| 539 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 540 | X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM): |
| 541 | X86TargetAsmInfo(TM) { |
| 542 | GlobalPrefix = "_"; |
| 543 | LCOMMDirective = "\t.lcomm\t"; |
| 544 | COMMDirectiveTakesAlignment = false; |
| 545 | HasDotTypeDotSizeDirective = false; |
| 546 | StaticCtorsSection = "\t.section .ctors,\"aw\""; |
| 547 | StaticDtorsSection = "\t.section .dtors,\"aw\""; |
| 548 | HiddenDirective = NULL; |
| 549 | PrivateGlobalPrefix = "L"; // Prefix for private global symbols |
| 550 | WeakRefDirective = "\t.weak\t"; |
| 551 | SetDirective = "\t.set\t"; |
| 552 | |
| 553 | // Set up DWARF directives |
| 554 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 555 | AbsoluteDebugSectionOffsets = true; |
| 556 | AbsoluteEHSectionOffsets = false; |
| 557 | SupportsDebugInformation = true; |
| 558 | DwarfSectionOffsetDirective = "\t.secrel32\t"; |
| 559 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\""; |
| 560 | DwarfInfoSection = "\t.section\t.debug_info,\"dr\""; |
| 561 | DwarfLineSection = "\t.section\t.debug_line,\"dr\""; |
| 562 | DwarfFrameSection = "\t.section\t.debug_frame,\"dr\""; |
| 563 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\""; |
| 564 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\""; |
| 565 | DwarfStrSection = "\t.section\t.debug_str,\"dr\""; |
| 566 | DwarfLocSection = "\t.section\t.debug_loc,\"dr\""; |
| 567 | DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\""; |
| 568 | DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\""; |
| 569 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\""; |
| 570 | } |
| 571 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 572 | unsigned |
| 573 | X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 574 | bool Global) const { |
| 575 | CodeModel::Model CM = X86TM->getCodeModel(); |
| 576 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 577 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 578 | if (X86TM->getRelocationModel() == Reloc::PIC_) { |
| 579 | unsigned Format = 0; |
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 (!is64Bit) |
| 582 | // 32 bit targets always encode pointers as 4 bytes |
| 583 | Format = DW_EH_PE_sdata4; |
| 584 | else { |
| 585 | // 64 bit targets encode pointers in 4 bytes iff: |
| 586 | // - code model is small OR |
| 587 | // - code model is medium and we're emitting externally visible symbols |
| 588 | // or any code symbols |
| 589 | if (CM == CodeModel::Small || |
| 590 | (CM == CodeModel::Medium && (Global || |
| 591 | Reason != DwarfEncoding::Data))) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 592 | Format = DW_EH_PE_sdata4; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 593 | else |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 594 | Format = DW_EH_PE_sdata8; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 595 | } |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 596 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 597 | if (Global) |
| 598 | Format |= DW_EH_PE_indirect; |
| 599 | |
| 600 | return (Format | DW_EH_PE_pcrel); |
| 601 | } else { |
| 602 | if (is64Bit && |
| 603 | (CM == CodeModel::Small || |
| 604 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 605 | return DW_EH_PE_udata4; |
| 606 | else |
| 607 | return DW_EH_PE_absptr; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 611 | std::string |
| 612 | X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 613 | SectionKind::Kind kind) const { |
| 614 | switch (kind) { |
| 615 | case SectionKind::Text: |
| 616 | return ".text$linkonce" + GV->getName(); |
| 617 | case SectionKind::Data: |
| 618 | case SectionKind::BSS: |
| 619 | case SectionKind::ThreadData: |
| 620 | case SectionKind::ThreadBSS: |
| 621 | return ".data$linkonce" + GV->getName(); |
| 622 | case SectionKind::ROData: |
| 623 | case SectionKind::RODataMergeConst: |
| 624 | case SectionKind::RODataMergeStr: |
| 625 | return ".rdata$linkonce" + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 626 | default: |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 627 | assert(0 && "Unknown section kind"); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 631 | std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const { |
| 632 | std::string Flags = ",\""; |
| 633 | |
| 634 | if (flags & SectionFlags::Code) |
| 635 | Flags += 'x'; |
| 636 | if (flags & SectionFlags::Writeable) |
| 637 | Flags += 'w'; |
| 638 | |
| 639 | Flags += "\""; |
| 640 | |
| 641 | return Flags; |
| 642 | } |
| 643 | |
| 644 | X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM): |
| 645 | X86TargetAsmInfo(TM) { |
| 646 | GlobalPrefix = "_"; |
| 647 | CommentString = ";"; |
| 648 | |
| 649 | PrivateGlobalPrefix = "$"; |
| 650 | AlignDirective = "\talign\t"; |
| 651 | ZeroDirective = "\tdb\t"; |
| 652 | ZeroDirectiveSuffix = " dup(0)"; |
| 653 | AsciiDirective = "\tdb\t"; |
| 654 | AscizDirective = 0; |
| 655 | Data8bitsDirective = "\tdb\t"; |
| 656 | Data16bitsDirective = "\tdw\t"; |
| 657 | Data32bitsDirective = "\tdd\t"; |
| 658 | Data64bitsDirective = "\tdq\t"; |
| 659 | HasDotTypeDotSizeDirective = false; |
| 660 | |
| 661 | TextSection = "_text"; |
| 662 | DataSection = "_data"; |
| 663 | JumpTableDataSection = NULL; |
| 664 | SwitchToSectionDirective = ""; |
| 665 | TextSectionStartSuffix = "\tsegment 'CODE'"; |
| 666 | DataSectionStartSuffix = "\tsegment 'DATA'"; |
| 667 | SectionEndDirectiveSuffix = "\tends\n"; |
| 668 | } |