Jim Laskey | 7c95ad4 | 2006-09-06 19:21:41 +0000 | [diff] [blame] | 1 | //===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==// |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 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 | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines target asm properties related what form asm statements |
| 11 | // should take. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
| 16 | #include "llvm/GlobalVariable.h" |
| 17 | #include "llvm/Function.h" |
| 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/Type.h" |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetAsmInfo.h" |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Dwarf.h" |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 23 | #include <cctype> |
| 24 | #include <cstring> |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace llvm; |
| 27 | |
| 28 | TargetAsmInfo::TargetAsmInfo() : |
Dan Gohman | 9570165 | 2007-05-03 18:46:30 +0000 | [diff] [blame] | 29 | TextSection("\t.text"), |
| 30 | DataSection("\t.data"), |
| 31 | BSSSection("\t.bss"), |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 32 | TLSDataSection("\t.section .tdata,\"awT\",@progbits"), |
| 33 | TLSBSSSection("\t.section .tbss,\"awT\",@nobits"), |
Chris Lattner | 6f198df | 2007-01-17 17:42:42 +0000 | [diff] [blame] | 34 | ZeroFillDirective(0), |
Dan Gohman | a779a98 | 2008-05-05 00:28:39 +0000 | [diff] [blame] | 35 | NonexecutableStackDirective(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 36 | NeedsSet(false), |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 37 | MaxInstLength(4), |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 38 | PCSymbol("$"), |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 39 | SeparatorChar(';'), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 40 | CommentString("#"), |
| 41 | GlobalPrefix(""), |
| 42 | PrivateGlobalPrefix("."), |
Chris Lattner | 393a8ee | 2007-01-18 01:12:56 +0000 | [diff] [blame] | 43 | JumpTableSpecialLabelPrefix(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 44 | GlobalVarAddrPrefix(""), |
| 45 | GlobalVarAddrSuffix(""), |
| 46 | FunctionAddrPrefix(""), |
| 47 | FunctionAddrSuffix(""), |
Bill Wendling | d60da49 | 2007-09-11 08:27:17 +0000 | [diff] [blame] | 48 | PersonalityPrefix(""), |
| 49 | PersonalitySuffix(""), |
Bill Wendling | ef4a661 | 2007-09-11 17:20:55 +0000 | [diff] [blame] | 50 | NeedsIndirectEncoding(false), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 51 | InlineAsmStart("#APP"), |
| 52 | InlineAsmEnd("#NO_APP"), |
Bill Wendling | eb9a42c | 2007-01-16 03:42:04 +0000 | [diff] [blame] | 53 | AssemblerDialect(0), |
Dale Johannesen | 428ac54 | 2008-06-03 18:09:06 +0000 | [diff] [blame] | 54 | StringConstantPrefix(".str"), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 55 | ZeroDirective("\t.zero\t"), |
| 56 | ZeroDirectiveSuffix(0), |
| 57 | AsciiDirective("\t.ascii\t"), |
| 58 | AscizDirective("\t.asciz\t"), |
| 59 | Data8bitsDirective("\t.byte\t"), |
| 60 | Data16bitsDirective("\t.short\t"), |
| 61 | Data32bitsDirective("\t.long\t"), |
| 62 | Data64bitsDirective("\t.quad\t"), |
| 63 | AlignDirective("\t.align\t"), |
| 64 | AlignmentIsInBytes(true), |
Lauro Ramos Venancio | f3c630e | 2008-02-28 22:14:09 +0000 | [diff] [blame] | 65 | TextAlignFillValue(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 66 | SwitchToSectionDirective("\t.section\t"), |
| 67 | TextSectionStartSuffix(""), |
| 68 | DataSectionStartSuffix(""), |
| 69 | SectionEndDirectiveSuffix(0), |
Dan Gohman | af67ea7 | 2007-06-14 15:00:27 +0000 | [diff] [blame] | 70 | ConstantPoolSection("\t.section .rodata"), |
| 71 | JumpTableDataSection("\t.section .rodata"), |
Andrew Lenharth | beec30e | 2006-09-24 19:45:58 +0000 | [diff] [blame] | 72 | JumpTableDirective(0), |
Reid Spencer | c50209b | 2006-10-27 16:14:06 +0000 | [diff] [blame] | 73 | CStringSection(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 74 | StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"), |
| 75 | StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"), |
| 76 | FourByteConstantSection(0), |
| 77 | EightByteConstantSection(0), |
| 78 | SixteenByteConstantSection(0), |
Evan Cheng | be346c9 | 2007-03-08 01:00:38 +0000 | [diff] [blame] | 79 | ReadOnlySection(0), |
Gordon Henriksen | 81361d6 | 2007-12-23 20:58:16 +0000 | [diff] [blame] | 80 | GlobalDirective("\t.globl\t"), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 81 | SetDirective(0), |
| 82 | LCOMMDirective(0), |
| 83 | COMMDirective("\t.comm\t"), |
| 84 | COMMDirectiveTakesAlignment(true), |
| 85 | HasDotTypeDotSizeDirective(true), |
Chris Lattner | cb05af8 | 2006-09-26 03:38:18 +0000 | [diff] [blame] | 86 | UsedDirective(0), |
Evan Cheng | 8752ce6 | 2006-12-01 20:47:11 +0000 | [diff] [blame] | 87 | WeakRefDirective(0), |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 88 | WeakDefDirective(0), |
Chris Lattner | 9784bc7 | 2007-01-14 06:27:21 +0000 | [diff] [blame] | 89 | HiddenDirective("\t.hidden\t"), |
Anton Korobeynikov | 6f9896f | 2007-04-29 18:35:00 +0000 | [diff] [blame] | 90 | ProtectedDirective("\t.protected\t"), |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 91 | AbsoluteDebugSectionOffsets(false), |
| 92 | AbsoluteEHSectionOffsets(false), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 93 | HasLEB128(false), |
Dan Gohman | 7225273 | 2007-09-24 21:09:53 +0000 | [diff] [blame] | 94 | HasDotLocAndDotFile(false), |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 95 | SupportsDebugInformation(false), |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 96 | SupportsExceptionHandling(false), |
Reid Spencer | 02b8511 | 2006-10-30 22:32:30 +0000 | [diff] [blame] | 97 | DwarfRequiresFrameSection(true), |
Dale Johannesen | 9305dcb | 2007-11-21 00:45:00 +0000 | [diff] [blame] | 98 | GlobalEHDirective(0), |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 99 | SupportsWeakOmittedEHFrame(true), |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 100 | DwarfSectionOffsetDirective(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 101 | DwarfAbbrevSection(".debug_abbrev"), |
| 102 | DwarfInfoSection(".debug_info"), |
| 103 | DwarfLineSection(".debug_line"), |
| 104 | DwarfFrameSection(".debug_frame"), |
| 105 | DwarfPubNamesSection(".debug_pubnames"), |
| 106 | DwarfPubTypesSection(".debug_pubtypes"), |
| 107 | DwarfStrSection(".debug_str"), |
| 108 | DwarfLocSection(".debug_loc"), |
| 109 | DwarfARangesSection(".debug_aranges"), |
| 110 | DwarfRangesSection(".debug_ranges"), |
Andrew Lenharth | 3655de6 | 2006-11-28 19:52:20 +0000 | [diff] [blame] | 111 | DwarfMacInfoSection(".debug_macinfo"), |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 112 | DwarfEHFrameSection(".eh_frame"), |
Jim Laskey | a15be8c | 2007-02-21 22:43:40 +0000 | [diff] [blame] | 113 | DwarfExceptionSection(".gcc_except_table"), |
Andrew Lenharth | 3655de6 | 2006-11-28 19:52:20 +0000 | [diff] [blame] | 114 | AsmTransCBE(0) { |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 115 | } |
Chris Lattner | f5b10ec | 2006-10-05 00:35:16 +0000 | [diff] [blame] | 116 | |
| 117 | TargetAsmInfo::~TargetAsmInfo() { |
| 118 | } |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 119 | |
| 120 | /// Measure the specified inline asm to determine an approximation of its |
| 121 | /// length. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 122 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 123 | /// count as an instruction. |
| 124 | /// Any other non-whitespace text is considered an instruction, with |
| 125 | /// multiple instructions separated by SeparatorChar or newlines. |
| 126 | /// Variable-length instructions are not handled here; this function |
| 127 | /// may be overloaded in the target code to do that. |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 128 | unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const { |
| 129 | // Count the number of instructions in the asm. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 130 | bool atInsnStart = true; |
| 131 | unsigned Length = 0; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 132 | for (; *Str; ++Str) { |
| 133 | if (*Str == '\n' || *Str == SeparatorChar) |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 134 | atInsnStart = true; |
| 135 | if (atInsnStart && !isspace(*Str)) { |
| 136 | Length += MaxInstLength; |
| 137 | atInsnStart = false; |
| 138 | } |
| 139 | if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0) |
| 140 | atInsnStart = false; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 143 | return Length; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 144 | } |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 145 | |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 146 | unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 147 | bool Global) const { |
| 148 | return dwarf::DW_EH_PE_absptr; |
| 149 | } |
| 150 | |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 151 | static bool isSuitableForBSS(const GlobalVariable *GV) { |
| 152 | if (!GV->hasInitializer()) |
| 153 | return true; |
| 154 | |
| 155 | // Leave constant zeros in readonly constant sections, so they can be shared |
| 156 | Constant *C = GV->getInitializer(); |
| 157 | return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS); |
| 158 | } |
| 159 | |
| 160 | SectionKind::Kind |
| 161 | TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const { |
| 162 | // Early exit - functions should be always in text sections. |
| 163 | if (isa<Function>(GV)) |
| 164 | return SectionKind::Text; |
| 165 | |
| 166 | const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV); |
| 167 | bool isThreadLocal = GVar->isThreadLocal(); |
| 168 | assert(GVar && "Invalid global value for section selection"); |
| 169 | |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 170 | if (isSuitableForBSS(GVar)) { |
| 171 | // Variable can be easily put to BSS section. |
| 172 | return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS); |
| 173 | } else if (GVar->isConstant() && !isThreadLocal) { |
| 174 | // Now we know, that varible has initializer and it is constant. We need to |
| 175 | // check its initializer to decide, which section to output it into. Also |
| 176 | // note, there is no thread-local r/o section. |
| 177 | Constant *C = GVar->getInitializer(); |
| 178 | if (C->ContainsRelocations()) |
Anton Korobeynikov | 0e48a0c | 2008-07-09 13:24:38 +0000 | [diff] [blame] | 179 | return SectionKind::ROData; |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 180 | else { |
| 181 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
| 182 | // Check, if initializer is a null-terminated string |
| 183 | if (CVA && CVA->isCString()) |
Anton Korobeynikov | 0e48a0c | 2008-07-09 13:24:38 +0000 | [diff] [blame] | 184 | return SectionKind::RODataMergeStr; |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 185 | else |
Anton Korobeynikov | 0e48a0c | 2008-07-09 13:24:38 +0000 | [diff] [blame] | 186 | return SectionKind::RODataMergeConst; |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | // Variable is not constant or thread-local - emit to generic data section. |
| 191 | return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data); |
| 192 | } |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 193 | |
| 194 | unsigned |
| 195 | TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV, |
Anton Korobeynikov | 8cc948d | 2008-07-09 13:17:36 +0000 | [diff] [blame] | 196 | const char* name) const { |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 197 | unsigned flags = SectionFlags::None; |
| 198 | |
| 199 | // Decode flags from global itself. |
| 200 | if (GV) { |
| 201 | SectionKind::Kind kind = SectionKindForGlobal(GV); |
| 202 | switch (kind) { |
| 203 | case SectionKind::Text: |
| 204 | flags |= SectionFlags::Code; |
| 205 | break; |
| 206 | case SectionKind::ThreadData: |
| 207 | flags |= SectionFlags::TLS; |
| 208 | // FALLS THROUGH |
| 209 | case SectionKind::Data: |
| 210 | flags |= SectionFlags::Writeable; |
| 211 | break; |
| 212 | case SectionKind::ThreadBSS: |
| 213 | flags |= SectionFlags::TLS; |
| 214 | // FALLS THROUGH |
| 215 | case SectionKind::BSS: |
| 216 | flags |= SectionFlags::BSS; |
| 217 | break; |
| 218 | case SectionKind::ROData: |
| 219 | // No additional flags here |
| 220 | break; |
| 221 | case SectionKind::RODataMergeStr: |
| 222 | flags |= SectionFlags::Strings; |
| 223 | // FALLS THROUGH |
| 224 | case SectionKind::RODataMergeConst: |
| 225 | flags |= SectionFlags::Mergeable; |
| 226 | break; |
| 227 | default: |
| 228 | assert(0 && "Unexpected section kind!"); |
| 229 | } |
| 230 | |
| 231 | if (GV->hasLinkOnceLinkage() || |
| 232 | GV->hasWeakLinkage() || |
| 233 | GV->hasCommonLinkage()) |
| 234 | flags |= SectionFlags::Linkonce; |
| 235 | } |
| 236 | |
| 237 | // Add flags from sections, if any. |
| 238 | if (name) { |
| 239 | // Some lame default implementation |
| 240 | if (strcmp(name, ".bss") == 0 || |
| 241 | strncmp(name, ".bss.", 5) == 0 || |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 242 | strncmp(name, ".gnu.linkonce.b.", 16) == 0 || |
Anton Korobeynikov | a2d3307 | 2008-07-09 13:18:38 +0000 | [diff] [blame] | 243 | strncmp(name, ".llvm.linkonce.b.", 17) == 0) |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 244 | flags |= SectionFlags::BSS; |
| 245 | else if (strcmp(name, ".tdata") == 0 || |
| 246 | strncmp(name, ".tdata.", 7) == 0 || |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 247 | strncmp(name, ".gnu.linkonce.td.", 17) == 0 || |
Anton Korobeynikov | a2d3307 | 2008-07-09 13:18:38 +0000 | [diff] [blame] | 248 | strncmp(name, ".llvm.linkonce.td.", 18) == 0) |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 249 | flags |= SectionFlags::TLS; |
| 250 | else if (strcmp(name, ".tbss") == 0 || |
| 251 | strncmp(name, ".tbss.", 6) == 0 || |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 252 | strncmp(name, ".gnu.linkonce.tb.", 17) == 0 || |
Anton Korobeynikov | a2d3307 | 2008-07-09 13:18:38 +0000 | [diff] [blame] | 253 | strncmp(name, ".llvm.linkonce.tb.", 18) == 0) |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 254 | flags |= SectionFlags::BSS | SectionFlags::TLS; |
| 255 | } |
| 256 | |
| 257 | return flags; |
| 258 | } |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 259 | |
Anton Korobeynikov | c0f41db | 2008-07-09 13:19:08 +0000 | [diff] [blame] | 260 | std::string |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 261 | TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 262 | unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str()); |
| 263 | |
| 264 | std::string Name; |
| 265 | |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 266 | // FIXME: Should we use some hashing based on section name and just check |
| 267 | // flags? |
| 268 | |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 269 | // Select section name |
| 270 | if (GV->hasSection()) { |
| 271 | // Honour section already set, if any |
| 272 | Name = GV->getSection(); |
| 273 | } else { |
| 274 | // Use default section depending on the 'type' of global |
| 275 | Name = SelectSectionForGlobal(GV); |
| 276 | } |
| 277 | |
| 278 | Name += PrintSectionFlags(flags); |
| 279 | return Name; |
| 280 | } |
| 281 | |
| 282 | // Lame default implementation. Calculate the section name for global. |
| 283 | std::string |
| 284 | TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 285 | SectionKind::Kind kind = SectionKindForGlobal(GV); |
| 286 | |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 287 | if (GV->hasLinkOnceLinkage() || |
| 288 | GV->hasWeakLinkage() || |
| 289 | GV->hasCommonLinkage()) |
| 290 | return UniqueSectionForGlobal(GV, kind); |
| 291 | else { |
| 292 | if (kind == SectionKind::Text) |
| 293 | return getTextSection(); |
| 294 | else if (kind == SectionKind::BSS && getBSSSection()) |
| 295 | return getBSSSection(); |
| 296 | else if (getReadOnlySection() && |
| 297 | (kind == SectionKind::ROData || |
| 298 | kind == SectionKind::RODataMergeConst || |
| 299 | kind == SectionKind::RODataMergeStr)) |
| 300 | return getReadOnlySection(); |
| 301 | } |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 302 | |
| 303 | return getDataSection(); |
| 304 | } |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 305 | |
| 306 | std::string |
| 307 | TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 308 | SectionKind::Kind kind) const { |
| 309 | switch (kind) { |
| 310 | case SectionKind::Text: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 311 | return ".gnu.linkonce.t." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 312 | case SectionKind::Data: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 313 | return ".gnu.linkonce.d." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 314 | case SectionKind::BSS: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 315 | return ".gnu.linkonce.b." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 316 | case SectionKind::ROData: |
| 317 | case SectionKind::RODataMergeConst: |
| 318 | case SectionKind::RODataMergeStr: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 319 | return ".gnu.linkonce.r." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 320 | case SectionKind::ThreadData: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 321 | return ".gnu.linkonce.td." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 322 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame^] | 323 | return ".gnu.linkonce.tb." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 324 | default: |
| 325 | assert(0 && "Unknown section kind"); |
| 326 | } |
| 327 | } |