Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/TargetLoweringObjectFileImpl.cpp - Object File Info --===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements classes used to handle lowerings specific to common |
| 11 | // object file formats. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" |
| 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/GlobalVariable.h" |
| 20 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
| 21 | #include "llvm/MC/MCContext.h" |
| 22 | #include "llvm/MC/MCExpr.h" |
| 23 | #include "llvm/MC/MCSectionMachO.h" |
| 24 | #include "llvm/MC/MCSectionELF.h" |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCSectionCOFF.h" |
Rafael Espindola | 30deafc | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCStreamer.h" |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCSymbol.h" |
| 28 | #include "llvm/Target/Mangler.h" |
| 29 | #include "llvm/Target/TargetData.h" |
| 30 | #include "llvm/Target/TargetMachine.h" |
| 31 | #include "llvm/Target/TargetOptions.h" |
| 32 | #include "llvm/Support/Dwarf.h" |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ELF.h" |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 34 | #include "llvm/Support/ErrorHandling.h" |
| 35 | #include "llvm/Support/raw_ostream.h" |
| 36 | #include "llvm/ADT/SmallString.h" |
| 37 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 8048ebe | 2010-09-27 06:44:54 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/Triple.h" |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 39 | using namespace llvm; |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 40 | using namespace dwarf; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 41 | |
| 42 | //===----------------------------------------------------------------------===// |
| 43 | // ELF |
| 44 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 45 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 46 | void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, |
| 47 | const TargetMachine &TM) { |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 48 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
| 49 | |
| 50 | BSSSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 51 | getContext().getELFSection(".bss", ELF::SHT_NOBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 52 | ELF::SHF_WRITE |ELF::SHF_ALLOC, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 53 | SectionKind::getBSS()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 54 | |
| 55 | TextSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 56 | getContext().getELFSection(".text", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 57 | ELF::SHF_EXECINSTR | |
| 58 | ELF::SHF_ALLOC, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 59 | SectionKind::getText()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 60 | |
| 61 | DataSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 62 | getContext().getELFSection(".data", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 63 | ELF::SHF_WRITE |ELF::SHF_ALLOC, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 64 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 65 | |
| 66 | ReadOnlySection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 67 | getContext().getELFSection(".rodata", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 68 | ELF::SHF_ALLOC, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 69 | SectionKind::getReadOnly()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 70 | |
| 71 | TLSDataSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 72 | getContext().getELFSection(".tdata", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 73 | ELF::SHF_ALLOC | ELF::SHF_TLS | |
| 74 | ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 75 | SectionKind::getThreadData()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 76 | |
| 77 | TLSBSSSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 78 | getContext().getELFSection(".tbss", ELF::SHT_NOBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 79 | ELF::SHF_ALLOC | ELF::SHF_TLS | |
| 80 | ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 81 | SectionKind::getThreadBSS()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 82 | |
| 83 | DataRelSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 84 | getContext().getELFSection(".data.rel", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 85 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 86 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 87 | |
| 88 | DataRelLocalSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 89 | getContext().getELFSection(".data.rel.local", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 90 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 91 | SectionKind::getDataRelLocal()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 92 | |
| 93 | DataRelROSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 94 | getContext().getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 95 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 96 | SectionKind::getReadOnlyWithRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 97 | |
| 98 | DataRelROLocalSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 99 | getContext().getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 100 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 101 | SectionKind::getReadOnlyWithRelLocal()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 102 | |
| 103 | MergeableConst4Section = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 104 | getContext().getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 105 | ELF::SHF_ALLOC |ELF::SHF_MERGE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 106 | SectionKind::getMergeableConst4()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 107 | |
| 108 | MergeableConst8Section = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 109 | getContext().getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 110 | ELF::SHF_ALLOC |ELF::SHF_MERGE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 111 | SectionKind::getMergeableConst8()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 112 | |
| 113 | MergeableConst16Section = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 114 | getContext().getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 115 | ELF::SHF_ALLOC |ELF::SHF_MERGE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 116 | SectionKind::getMergeableConst16()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 117 | |
| 118 | StaticCtorSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 119 | getContext().getELFSection(".ctors", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 120 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 121 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 122 | |
| 123 | StaticDtorSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 124 | getContext().getELFSection(".dtors", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 125 | ELF::SHF_ALLOC |ELF::SHF_WRITE, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 126 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 127 | |
| 128 | // Exception Handling Sections. |
| 129 | |
| 130 | // FIXME: We're emitting LSDA info into a readonly section on ELF, even though |
| 131 | // it contains relocatable pointers. In PIC mode, this is probably a big |
| 132 | // runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 133 | // adjusted or this should be a data section. |
| 134 | LSDASection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 135 | getContext().getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 136 | ELF::SHF_ALLOC, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 137 | SectionKind::getReadOnly()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 138 | // Debug Info Sections. |
| 139 | DwarfAbbrevSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 140 | getContext().getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 141 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 142 | DwarfInfoSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 143 | getContext().getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 144 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 145 | DwarfLineSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 146 | getContext().getELFSection(".debug_line", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 147 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 148 | DwarfFrameSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 149 | getContext().getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 150 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 151 | DwarfPubNamesSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 152 | getContext().getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 153 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 154 | DwarfPubTypesSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 155 | getContext().getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 156 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 157 | DwarfStrSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 158 | getContext().getELFSection(".debug_str", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 159 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 160 | DwarfLocSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 161 | getContext().getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 162 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 163 | DwarfARangesSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 164 | getContext().getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 165 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 166 | DwarfRangesSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 167 | getContext().getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 168 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 169 | DwarfMacroInfoSection = |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 170 | getContext().getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 171 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Rafael Espindola | 0cf5e3d | 2011-01-23 05:43:40 +0000 | [diff] [blame] | 174 | const MCSection *TargetLoweringObjectFileELF::getEHFrameSection() const { |
| 175 | return getContext().getELFSection(".eh_frame", ELF::SHT_PROGBITS, |
| 176 | ELF::SHF_ALLOC, |
| 177 | SectionKind::getDataRel()); |
| 178 | } |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 179 | |
Rafael Espindola | 30deafc | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 180 | MCSymbol * |
| 181 | TargetLoweringObjectFileELF::getPersonalityPICSymbol(StringRef Name) const { |
| 182 | Twine FullName = StringRef("DW.ref.") + Name; |
| 183 | return getContext().GetOrCreateSymbol(FullName); |
| 184 | } |
| 185 | |
| 186 | void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer, |
| 187 | const TargetMachine &TM, |
| 188 | const MCSymbol *Sym) const { |
| 189 | MCSymbol *Label = getPersonalityPICSymbol(Sym->getName()); |
| 190 | Streamer.EmitSymbolAttribute(Label, MCSA_Hidden); |
| 191 | Streamer.EmitSymbolAttribute(Label, MCSA_Weak); |
| 192 | Twine SectionName = StringRef(".data.") + Label->getName(); |
| 193 | SmallString<64> NameData; |
| 194 | SectionName.toVector(NameData); |
| 195 | unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP; |
| 196 | const MCSection *Sec = getContext().getELFSection(NameData, |
| 197 | ELF::SHT_PROGBITS, |
| 198 | Flags, |
| 199 | SectionKind::getDataRel(), |
| 200 | 0, Label->getName()); |
| 201 | Streamer.SwitchSection(Sec); |
| 202 | Streamer.EmitValueToAlignment(8); |
| 203 | Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject); |
| 204 | const MCExpr *E = MCConstantExpr::Create(8, getContext()); |
| 205 | Streamer.EmitELFSize(Label, E); |
| 206 | Streamer.EmitLabel(Label); |
| 207 | |
| 208 | unsigned Size = TM.getTargetData()->getPointerSize(); |
| 209 | Streamer.EmitSymbolValue(Sym, Size); |
| 210 | } |
| 211 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 212 | static SectionKind |
| 213 | getELFKindForNamedSection(StringRef Name, SectionKind K) { |
Rafael Espindola | 0412d5b | 2011-02-24 20:18:01 +0000 | [diff] [blame] | 214 | // FIXME: Why is this here? Codegen is should not be in the business |
| 215 | // of figuring section flags. If the user wrote section(".eh_frame"), |
| 216 | // we should just pass that to MC which will defer to the assembly |
| 217 | // or use its default if producing an object file. |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 218 | if (Name.empty() || Name[0] != '.') return K; |
| 219 | |
| 220 | // Some lame default implementation based on some magic section names. |
| 221 | if (Name == ".bss" || |
| 222 | Name.startswith(".bss.") || |
| 223 | Name.startswith(".gnu.linkonce.b.") || |
| 224 | Name.startswith(".llvm.linkonce.b.") || |
| 225 | Name == ".sbss" || |
| 226 | Name.startswith(".sbss.") || |
| 227 | Name.startswith(".gnu.linkonce.sb.") || |
| 228 | Name.startswith(".llvm.linkonce.sb.")) |
| 229 | return SectionKind::getBSS(); |
| 230 | |
| 231 | if (Name == ".tdata" || |
| 232 | Name.startswith(".tdata.") || |
| 233 | Name.startswith(".gnu.linkonce.td.") || |
| 234 | Name.startswith(".llvm.linkonce.td.")) |
| 235 | return SectionKind::getThreadData(); |
| 236 | |
| 237 | if (Name == ".tbss" || |
| 238 | Name.startswith(".tbss.") || |
| 239 | Name.startswith(".gnu.linkonce.tb.") || |
| 240 | Name.startswith(".llvm.linkonce.tb.")) |
| 241 | return SectionKind::getThreadBSS(); |
| 242 | |
Rafael Espindola | 0412d5b | 2011-02-24 20:18:01 +0000 | [diff] [blame] | 243 | if (Name == ".eh_frame") |
| 244 | return SectionKind::getDataRel(); |
| 245 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 246 | return K; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | static unsigned getELFSectionType(StringRef Name, SectionKind K) { |
| 251 | |
| 252 | if (Name == ".init_array") |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 253 | return ELF::SHT_INIT_ARRAY; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 254 | |
| 255 | if (Name == ".fini_array") |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 256 | return ELF::SHT_FINI_ARRAY; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 257 | |
| 258 | if (Name == ".preinit_array") |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 259 | return ELF::SHT_PREINIT_ARRAY; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 260 | |
| 261 | if (K.isBSS() || K.isThreadBSS()) |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 262 | return ELF::SHT_NOBITS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 263 | |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 264 | return ELF::SHT_PROGBITS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | |
| 268 | static unsigned |
| 269 | getELFSectionFlags(SectionKind K) { |
| 270 | unsigned Flags = 0; |
| 271 | |
| 272 | if (!K.isMetadata()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 273 | Flags |= ELF::SHF_ALLOC; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 274 | |
| 275 | if (K.isText()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 276 | Flags |= ELF::SHF_EXECINSTR; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 277 | |
| 278 | if (K.isWriteable()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 279 | Flags |= ELF::SHF_WRITE; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 280 | |
| 281 | if (K.isThreadLocal()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 282 | Flags |= ELF::SHF_TLS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 283 | |
| 284 | // K.isMergeableConst() is left out to honour PR4650 |
| 285 | if (K.isMergeableCString() || K.isMergeableConst4() || |
| 286 | K.isMergeableConst8() || K.isMergeableConst16()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 287 | Flags |= ELF::SHF_MERGE; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 288 | |
| 289 | if (K.isMergeableCString()) |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 290 | Flags |= ELF::SHF_STRINGS; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 291 | |
| 292 | return Flags; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | const MCSection *TargetLoweringObjectFileELF:: |
| 297 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 298 | Mangler *Mang, const TargetMachine &TM) const { |
| 299 | StringRef SectionName = GV->getSection(); |
| 300 | |
| 301 | // Infer section flags from the section name if we can. |
| 302 | Kind = getELFKindForNamedSection(SectionName, Kind); |
| 303 | |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 304 | return getContext().getELFSection(SectionName, |
| 305 | getELFSectionType(SectionName, Kind), |
Rafael Espindola | 34be396 | 2010-11-09 23:42:07 +0000 | [diff] [blame] | 306 | getELFSectionFlags(Kind), Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 309 | /// getSectionPrefixForGlobal - Return the section prefix name used by options |
| 310 | /// FunctionsSections and DataSections. |
| 311 | static const char *getSectionPrefixForGlobal(SectionKind Kind) { |
| 312 | if (Kind.isText()) return ".text."; |
| 313 | if (Kind.isReadOnly()) return ".rodata."; |
| 314 | |
| 315 | if (Kind.isThreadData()) return ".tdata."; |
| 316 | if (Kind.isThreadBSS()) return ".tbss."; |
| 317 | |
| 318 | if (Kind.isDataNoRel()) return ".data."; |
| 319 | if (Kind.isDataRelLocal()) return ".data.rel.local."; |
| 320 | if (Kind.isDataRel()) return ".data.rel."; |
| 321 | if (Kind.isReadOnlyWithRelLocal()) return ".data.rel.ro.local."; |
| 322 | |
| 323 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 324 | return ".data.rel.ro."; |
| 325 | } |
| 326 | |
| 327 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 328 | const MCSection *TargetLoweringObjectFileELF:: |
| 329 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
| 330 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 331 | // If we have -ffunction-section or -fdata-section then we should emit the |
| 332 | // global value to a uniqued section specifically for it. |
| 333 | bool EmitUniquedSection; |
| 334 | if (Kind.isText()) |
| 335 | EmitUniquedSection = TM.getFunctionSections(); |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 336 | else |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 337 | EmitUniquedSection = TM.getDataSections(); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 338 | |
| 339 | // If this global is linkonce/weak and the target handles this by emitting it |
| 340 | // into a 'uniqued' section name, create and return the section now. |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 341 | if ((GV->isWeakForLinker() || EmitUniquedSection) && |
| 342 | !Kind.isCommon() && !Kind.isBSS()) { |
| 343 | const char *Prefix; |
Rafael Espindola | 5d618ef | 2011-02-14 22:23:49 +0000 | [diff] [blame] | 344 | Prefix = getSectionPrefixForGlobal(Kind); |
Chris Lattner | 43ac721 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 345 | |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 346 | SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); |
| 347 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 348 | Name.append(Sym->getName().begin(), Sym->getName().end()); |
Rafael Espindola | 5d618ef | 2011-02-14 22:23:49 +0000 | [diff] [blame] | 349 | StringRef Group = ""; |
| 350 | unsigned Flags = getELFSectionFlags(Kind); |
| 351 | if (GV->isWeakForLinker()) { |
| 352 | Group = Sym->getName(); |
| 353 | Flags |= ELF::SHF_GROUP; |
| 354 | } |
| 355 | |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 356 | return getContext().getELFSection(Name.str(), |
| 357 | getELFSectionType(Name.str(), Kind), |
Rafael Espindola | 5d618ef | 2011-02-14 22:23:49 +0000 | [diff] [blame] | 358 | Flags, Kind, 0, Group); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | if (Kind.isText()) return TextSection; |
| 362 | |
| 363 | if (Kind.isMergeable1ByteCString() || |
| 364 | Kind.isMergeable2ByteCString() || |
| 365 | Kind.isMergeable4ByteCString()) { |
| 366 | |
| 367 | // We also need alignment here. |
| 368 | // FIXME: this is getting the alignment of the character, not the |
| 369 | // alignment of the global! |
| 370 | unsigned Align = |
| 371 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)); |
| 372 | |
| 373 | const char *SizeSpec = ".rodata.str1."; |
| 374 | if (Kind.isMergeable2ByteCString()) |
| 375 | SizeSpec = ".rodata.str2."; |
| 376 | else if (Kind.isMergeable4ByteCString()) |
| 377 | SizeSpec = ".rodata.str4."; |
| 378 | else |
| 379 | assert(Kind.isMergeable1ByteCString() && "unknown string width"); |
| 380 | |
| 381 | |
| 382 | std::string Name = SizeSpec + utostr(Align); |
Rafael Espindola | c85dca6 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 383 | return getContext().getELFSection(Name, ELF::SHT_PROGBITS, |
Rafael Espindola | 1c13026 | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 384 | ELF::SHF_ALLOC | |
| 385 | ELF::SHF_MERGE | |
| 386 | ELF::SHF_STRINGS, |
Chris Lattner | 287df1b | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 387 | Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | if (Kind.isMergeableConst()) { |
| 391 | if (Kind.isMergeableConst4() && MergeableConst4Section) |
| 392 | return MergeableConst4Section; |
| 393 | if (Kind.isMergeableConst8() && MergeableConst8Section) |
| 394 | return MergeableConst8Section; |
| 395 | if (Kind.isMergeableConst16() && MergeableConst16Section) |
| 396 | return MergeableConst16Section; |
| 397 | return ReadOnlySection; // .const |
| 398 | } |
| 399 | |
| 400 | if (Kind.isReadOnly()) return ReadOnlySection; |
| 401 | |
| 402 | if (Kind.isThreadData()) return TLSDataSection; |
| 403 | if (Kind.isThreadBSS()) return TLSBSSSection; |
| 404 | |
| 405 | // Note: we claim that common symbols are put in BSSSection, but they are |
| 406 | // really emitted with the magic .comm directive, which creates a symbol table |
| 407 | // entry but not a section. |
| 408 | if (Kind.isBSS() || Kind.isCommon()) return BSSSection; |
| 409 | |
| 410 | if (Kind.isDataNoRel()) return DataSection; |
| 411 | if (Kind.isDataRelLocal()) return DataRelLocalSection; |
| 412 | if (Kind.isDataRel()) return DataRelSection; |
| 413 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
| 414 | |
| 415 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 416 | return DataRelROSection; |
| 417 | } |
| 418 | |
| 419 | /// getSectionForConstant - Given a mergeable constant with the |
| 420 | /// specified size and relocation information, return a section that it |
| 421 | /// should be placed in. |
| 422 | const MCSection *TargetLoweringObjectFileELF:: |
| 423 | getSectionForConstant(SectionKind Kind) const { |
| 424 | if (Kind.isMergeableConst4() && MergeableConst4Section) |
| 425 | return MergeableConst4Section; |
| 426 | if (Kind.isMergeableConst8() && MergeableConst8Section) |
| 427 | return MergeableConst8Section; |
| 428 | if (Kind.isMergeableConst16() && MergeableConst16Section) |
| 429 | return MergeableConst16Section; |
| 430 | if (Kind.isReadOnly()) |
| 431 | return ReadOnlySection; |
| 432 | |
| 433 | if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection; |
| 434 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 435 | return DataRelROSection; |
| 436 | } |
| 437 | |
| 438 | const MCExpr *TargetLoweringObjectFileELF:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 439 | getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 440 | MachineModuleInfo *MMI, |
| 441 | unsigned Encoding, MCStreamer &Streamer) const { |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 442 | |
| 443 | if (Encoding & dwarf::DW_EH_PE_indirect) { |
| 444 | MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>(); |
| 445 | |
| 446 | SmallString<128> Name; |
| 447 | Mang->getNameWithPrefix(Name, GV, true); |
| 448 | Name += ".DW.stub"; |
| 449 | |
| 450 | // Add information about the stub reference to ELFMMI so that the stub |
| 451 | // gets emitted by the asmprinter. |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 452 | MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 453 | MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 454 | if (StubSym.getPointer() == 0) { |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 455 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 456 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | return TargetLoweringObjectFile:: |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 460 | getExprForDwarfReference(SSym, Mang, MMI, |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 461 | Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | return TargetLoweringObjectFile:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 465 | getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | //===----------------------------------------------------------------------===// |
| 469 | // MachO |
| 470 | //===----------------------------------------------------------------------===// |
| 471 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 472 | void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, |
| 473 | const TargetMachine &TM) { |
Bill Wendling | 2ff6e1e | 2010-09-28 23:11:55 +0000 | [diff] [blame] | 474 | // _foo.eh symbols are currently always exported so that the linker knows |
| 475 | // about them. This is not necessary on 10.6 and later, but it |
| 476 | // doesn't hurt anything. |
| 477 | // FIXME: I need to get this from Triple. |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 478 | IsFunctionEHSymbolGlobal = true; |
| 479 | IsFunctionEHFrameSymbolPrivate = false; |
| 480 | SupportsWeakOmittedEHFrame = false; |
Chris Lattner | 8048ebe | 2010-09-27 06:44:54 +0000 | [diff] [blame] | 481 | |
Daniel Dunbar | ebc5066 | 2011-04-19 20:32:39 +0000 | [diff] [blame] | 482 | // .comm doesn't support alignment before Leopard. |
Chris Lattner | 8048ebe | 2010-09-27 06:44:54 +0000 | [diff] [blame] | 483 | Triple T(((LLVMTargetMachine&)TM).getTargetTriple()); |
Daniel Dunbar | 558692f | 2011-04-20 00:14:25 +0000 | [diff] [blame^] | 484 | if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5)) |
Daniel Dunbar | ebc5066 | 2011-04-19 20:32:39 +0000 | [diff] [blame] | 485 | CommDirectiveSupportsAlignment = false; |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 486 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 487 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
| 488 | |
| 489 | TextSection // .text |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 490 | = getContext().getMachOSection("__TEXT", "__text", |
| 491 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 492 | SectionKind::getText()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 493 | DataSection // .data |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 494 | = getContext().getMachOSection("__DATA", "__data", 0, |
| 495 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 496 | |
Eric Christopher | 423c9e3 | 2010-05-17 21:02:07 +0000 | [diff] [blame] | 497 | TLSDataSection // .tdata |
| 498 | = getContext().getMachOSection("__DATA", "__thread_data", |
| 499 | MCSectionMachO::S_THREAD_LOCAL_REGULAR, |
| 500 | SectionKind::getDataRel()); |
| 501 | TLSBSSSection // .tbss |
| 502 | = getContext().getMachOSection("__DATA", "__thread_bss", |
| 503 | MCSectionMachO::S_THREAD_LOCAL_ZEROFILL, |
| 504 | SectionKind::getThreadBSS()); |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 505 | |
Eric Christopher | 423c9e3 | 2010-05-17 21:02:07 +0000 | [diff] [blame] | 506 | // TODO: Verify datarel below. |
| 507 | TLSTLVSection // .tlv |
| 508 | = getContext().getMachOSection("__DATA", "__thread_vars", |
| 509 | MCSectionMachO::S_THREAD_LOCAL_VARIABLES, |
| 510 | SectionKind::getDataRel()); |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 511 | |
Eric Christopher | c6177a4 | 2010-05-17 22:53:55 +0000 | [diff] [blame] | 512 | TLSThreadInitSection |
| 513 | = getContext().getMachOSection("__DATA", "__thread_init", |
| 514 | MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, |
| 515 | SectionKind::getDataRel()); |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 516 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 517 | CStringSection // .cstring |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 518 | = getContext().getMachOSection("__TEXT", "__cstring", |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 519 | MCSectionMachO::S_CSTRING_LITERALS, |
| 520 | SectionKind::getMergeable1ByteCString()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 521 | UStringSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 522 | = getContext().getMachOSection("__TEXT","__ustring", 0, |
| 523 | SectionKind::getMergeable2ByteCString()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 524 | FourByteConstantSection // .literal4 |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 525 | = getContext().getMachOSection("__TEXT", "__literal4", |
| 526 | MCSectionMachO::S_4BYTE_LITERALS, |
| 527 | SectionKind::getMergeableConst4()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 528 | EightByteConstantSection // .literal8 |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 529 | = getContext().getMachOSection("__TEXT", "__literal8", |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 530 | MCSectionMachO::S_8BYTE_LITERALS, |
| 531 | SectionKind::getMergeableConst8()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 532 | |
| 533 | // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back |
| 534 | // to using it in -static mode. |
| 535 | SixteenByteConstantSection = 0; |
| 536 | if (TM.getRelocationModel() != Reloc::Static && |
| 537 | TM.getTargetData()->getPointerSize() == 32) |
| 538 | SixteenByteConstantSection = // .literal16 |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 539 | getContext().getMachOSection("__TEXT", "__literal16", |
| 540 | MCSectionMachO::S_16BYTE_LITERALS, |
| 541 | SectionKind::getMergeableConst16()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 542 | |
| 543 | ReadOnlySection // .const |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 544 | = getContext().getMachOSection("__TEXT", "__const", 0, |
| 545 | SectionKind::getReadOnly()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 546 | |
| 547 | TextCoalSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 548 | = getContext().getMachOSection("__TEXT", "__textcoal_nt", |
| 549 | MCSectionMachO::S_COALESCED | |
| 550 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 551 | SectionKind::getText()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 552 | ConstTextCoalSection |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 553 | = getContext().getMachOSection("__TEXT", "__const_coal", |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 554 | MCSectionMachO::S_COALESCED, |
Chris Lattner | 6a624a6 | 2010-07-15 21:22:00 +0000 | [diff] [blame] | 555 | SectionKind::getReadOnly()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 556 | ConstDataSection // .const_data |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 557 | = getContext().getMachOSection("__DATA", "__const", 0, |
| 558 | SectionKind::getReadOnlyWithRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 559 | DataCoalSection |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 560 | = getContext().getMachOSection("__DATA","__datacoal_nt", |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 561 | MCSectionMachO::S_COALESCED, |
| 562 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 563 | DataCommonSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 564 | = getContext().getMachOSection("__DATA","__common", |
| 565 | MCSectionMachO::S_ZEROFILL, |
| 566 | SectionKind::getBSS()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 567 | DataBSSSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 568 | = getContext().getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL, |
| 569 | SectionKind::getBSS()); |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 570 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 571 | |
| 572 | LazySymbolPointerSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 573 | = getContext().getMachOSection("__DATA", "__la_symbol_ptr", |
| 574 | MCSectionMachO::S_LAZY_SYMBOL_POINTERS, |
| 575 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 576 | NonLazySymbolPointerSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 577 | = getContext().getMachOSection("__DATA", "__nl_symbol_ptr", |
| 578 | MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, |
| 579 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 580 | |
| 581 | if (TM.getRelocationModel() == Reloc::Static) { |
| 582 | StaticCtorSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 583 | = getContext().getMachOSection("__TEXT", "__constructor", 0, |
| 584 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 585 | StaticDtorSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 586 | = getContext().getMachOSection("__TEXT", "__destructor", 0, |
| 587 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 588 | } else { |
| 589 | StaticCtorSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 590 | = getContext().getMachOSection("__DATA", "__mod_init_func", |
| 591 | MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, |
| 592 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 593 | StaticDtorSection |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 594 | = getContext().getMachOSection("__DATA", "__mod_term_func", |
| 595 | MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, |
| 596 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | // Exception Handling. |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 600 | LSDASection = getContext().getMachOSection("__TEXT", "__gcc_except_tab", 0, |
| 601 | SectionKind::getReadOnlyWithRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 602 | // Debug Information. |
| 603 | DwarfAbbrevSection = |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 604 | getContext().getMachOSection("__DWARF", "__debug_abbrev", |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 605 | MCSectionMachO::S_ATTR_DEBUG, |
| 606 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 607 | DwarfInfoSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 608 | getContext().getMachOSection("__DWARF", "__debug_info", |
| 609 | MCSectionMachO::S_ATTR_DEBUG, |
| 610 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 611 | DwarfLineSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 612 | getContext().getMachOSection("__DWARF", "__debug_line", |
| 613 | MCSectionMachO::S_ATTR_DEBUG, |
| 614 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 615 | DwarfFrameSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 616 | getContext().getMachOSection("__DWARF", "__debug_frame", |
| 617 | MCSectionMachO::S_ATTR_DEBUG, |
| 618 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 619 | DwarfPubNamesSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 620 | getContext().getMachOSection("__DWARF", "__debug_pubnames", |
| 621 | MCSectionMachO::S_ATTR_DEBUG, |
| 622 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 623 | DwarfPubTypesSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 624 | getContext().getMachOSection("__DWARF", "__debug_pubtypes", |
| 625 | MCSectionMachO::S_ATTR_DEBUG, |
| 626 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 627 | DwarfStrSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 628 | getContext().getMachOSection("__DWARF", "__debug_str", |
| 629 | MCSectionMachO::S_ATTR_DEBUG, |
| 630 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 631 | DwarfLocSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 632 | getContext().getMachOSection("__DWARF", "__debug_loc", |
| 633 | MCSectionMachO::S_ATTR_DEBUG, |
| 634 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 635 | DwarfARangesSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 636 | getContext().getMachOSection("__DWARF", "__debug_aranges", |
| 637 | MCSectionMachO::S_ATTR_DEBUG, |
| 638 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 639 | DwarfRangesSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 640 | getContext().getMachOSection("__DWARF", "__debug_ranges", |
| 641 | MCSectionMachO::S_ATTR_DEBUG, |
| 642 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 643 | DwarfMacroInfoSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 644 | getContext().getMachOSection("__DWARF", "__debug_macinfo", |
| 645 | MCSectionMachO::S_ATTR_DEBUG, |
| 646 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 647 | DwarfDebugInlineSection = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 648 | getContext().getMachOSection("__DWARF", "__debug_inlined", |
| 649 | MCSectionMachO::S_ATTR_DEBUG, |
| 650 | SectionKind::getMetadata()); |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 651 | |
Eric Christopher | 8116ca5 | 2010-05-22 00:10:22 +0000 | [diff] [blame] | 652 | TLSExtraDataSection = TLSTLVSection; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Rafael Espindola | 0cf5e3d | 2011-01-23 05:43:40 +0000 | [diff] [blame] | 655 | const MCSection *TargetLoweringObjectFileMachO::getEHFrameSection() const { |
| 656 | return getContext().getMachOSection("__TEXT", "__eh_frame", |
| 657 | MCSectionMachO::S_COALESCED | |
| 658 | MCSectionMachO::S_ATTR_NO_TOC | |
| 659 | MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS | |
| 660 | MCSectionMachO::S_ATTR_LIVE_SUPPORT, |
| 661 | SectionKind::getReadOnly()); |
| 662 | } |
| 663 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 664 | const MCSection *TargetLoweringObjectFileMachO:: |
| 665 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 666 | Mangler *Mang, const TargetMachine &TM) const { |
| 667 | // Parse the section specifier and create it if valid. |
| 668 | StringRef Segment, Section; |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 669 | unsigned TAA = 0, StubSize = 0; |
| 670 | bool TAAParsed; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 671 | std::string ErrorCode = |
| 672 | MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section, |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 673 | TAA, TAAParsed, StubSize); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 674 | if (!ErrorCode.empty()) { |
Chris Lattner | 75361b6 | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 675 | // If invalid, report the error with report_fatal_error. |
| 676 | report_fatal_error("Global variable '" + GV->getNameStr() + |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 677 | "' has an invalid section specifier '" + GV->getSection()+ |
| 678 | "': " + ErrorCode + "."); |
| 679 | // Fall back to dropping it into the data section. |
| 680 | return DataSection; |
| 681 | } |
| 682 | |
| 683 | // Get the section. |
| 684 | const MCSectionMachO *S = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 685 | getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 686 | |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 687 | // If TAA wasn't set by ParseSectionSpecifier() above, |
| 688 | // use the value returned by getMachOSection() as a default. |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 689 | if (!TAAParsed) |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 690 | TAA = S->getTypeAndAttributes(); |
| 691 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 692 | // Okay, now that we got the section, verify that the TAA & StubSize agree. |
| 693 | // If the user declared multiple globals with different section flags, we need |
| 694 | // to reject it here. |
| 695 | if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) { |
Chris Lattner | 75361b6 | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 696 | // If invalid, report the error with report_fatal_error. |
| 697 | report_fatal_error("Global variable '" + GV->getNameStr() + |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 698 | "' section type or attributes does not match previous" |
| 699 | " section specifier"); |
| 700 | } |
| 701 | |
| 702 | return S; |
| 703 | } |
| 704 | |
| 705 | const MCSection *TargetLoweringObjectFileMachO:: |
| 706 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Eric Christopher | 8116ca5 | 2010-05-22 00:10:22 +0000 | [diff] [blame] | 707 | Mangler *Mang, const TargetMachine &TM) const { |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 708 | |
Eric Christopher | 02b46bc | 2010-05-25 21:28:50 +0000 | [diff] [blame] | 709 | // Handle thread local data. |
Eric Christopher | 8116ca5 | 2010-05-22 00:10:22 +0000 | [diff] [blame] | 710 | if (Kind.isThreadBSS()) return TLSBSSSection; |
Eric Christopher | 02b46bc | 2010-05-25 21:28:50 +0000 | [diff] [blame] | 711 | if (Kind.isThreadData()) return TLSDataSection; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 712 | |
| 713 | if (Kind.isText()) |
| 714 | return GV->isWeakForLinker() ? TextCoalSection : TextSection; |
| 715 | |
| 716 | // If this is weak/linkonce, put this in a coalescable section, either in text |
| 717 | // or data depending on if it is writable. |
| 718 | if (GV->isWeakForLinker()) { |
| 719 | if (Kind.isReadOnly()) |
| 720 | return ConstTextCoalSection; |
| 721 | return DataCoalSection; |
| 722 | } |
| 723 | |
| 724 | // FIXME: Alignment check should be handled by section classifier. |
Chris Lattner | 98f15d2 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 725 | if (Kind.isMergeable1ByteCString() && |
| 726 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32) |
| 727 | return CStringSection; |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 728 | |
Chris Lattner | 98f15d2 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 729 | // Do not put 16-bit arrays in the UString section if they have an |
| 730 | // externally visible label, this runs into issues with certain linker |
| 731 | // versions. |
| 732 | if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() && |
| 733 | TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32) |
| 734 | return UStringSection; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 735 | |
| 736 | if (Kind.isMergeableConst()) { |
| 737 | if (Kind.isMergeableConst4()) |
| 738 | return FourByteConstantSection; |
| 739 | if (Kind.isMergeableConst8()) |
| 740 | return EightByteConstantSection; |
| 741 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
| 742 | return SixteenByteConstantSection; |
| 743 | } |
| 744 | |
| 745 | // Otherwise, if it is readonly, but not something we can specially optimize, |
| 746 | // just drop it in .const. |
| 747 | if (Kind.isReadOnly()) |
| 748 | return ReadOnlySection; |
| 749 | |
| 750 | // If this is marked const, put it into a const section. But if the dynamic |
| 751 | // linker needs to write to it, put it in the data segment. |
| 752 | if (Kind.isReadOnlyWithRel()) |
| 753 | return ConstDataSection; |
| 754 | |
| 755 | // Put zero initialized globals with strong external linkage in the |
| 756 | // DATA, __common section with the .zerofill directive. |
| 757 | if (Kind.isBSSExtern()) |
| 758 | return DataCommonSection; |
| 759 | |
| 760 | // Put zero initialized globals with local linkage in __DATA,__bss directive |
| 761 | // with the .zerofill directive (aka .lcomm). |
| 762 | if (Kind.isBSSLocal()) |
| 763 | return DataBSSSection; |
Michael J. Spencer | 579d7a3 | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 764 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 765 | // Otherwise, just drop the variable in the normal data section. |
| 766 | return DataSection; |
| 767 | } |
| 768 | |
| 769 | const MCSection * |
| 770 | TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const { |
| 771 | // If this constant requires a relocation, we have to put it in the data |
| 772 | // segment, not in the text segment. |
| 773 | if (Kind.isDataRel() || Kind.isReadOnlyWithRel()) |
| 774 | return ConstDataSection; |
| 775 | |
| 776 | if (Kind.isMergeableConst4()) |
| 777 | return FourByteConstantSection; |
| 778 | if (Kind.isMergeableConst8()) |
| 779 | return EightByteConstantSection; |
| 780 | if (Kind.isMergeableConst16() && SixteenByteConstantSection) |
| 781 | return SixteenByteConstantSection; |
| 782 | return ReadOnlySection; // .const |
| 783 | } |
| 784 | |
| 785 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively decide |
| 786 | /// not to emit the UsedDirective for some symbols in llvm.used. |
| 787 | // FIXME: REMOVE this (rdar://7071300) |
| 788 | bool TargetLoweringObjectFileMachO:: |
| 789 | shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const { |
| 790 | /// On Darwin, internally linked data beginning with "L" or "l" does not have |
| 791 | /// the directive emitted (this occurs in ObjC metadata). |
| 792 | if (!GV) return false; |
| 793 | |
Bill Wendling | 07d3177 | 2010-06-29 22:34:52 +0000 | [diff] [blame] | 794 | // Check whether the mangled name has the "Private" or "LinkerPrivate" prefix. |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 795 | if (GV->hasLocalLinkage() && !isa<Function>(GV)) { |
| 796 | // FIXME: ObjC metadata is currently emitted as internal symbols that have |
Bill Wendling | 07d3177 | 2010-06-29 22:34:52 +0000 | [diff] [blame] | 797 | // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and |
| 798 | // this horrible hack can go away. |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 799 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 800 | if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l') |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 801 | return false; |
| 802 | } |
| 803 | |
| 804 | return true; |
| 805 | } |
| 806 | |
| 807 | const MCExpr *TargetLoweringObjectFileMachO:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 808 | getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 809 | MachineModuleInfo *MMI, unsigned Encoding, |
| 810 | MCStreamer &Streamer) const { |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 811 | // The mach-o version of this method defaults to returning a stub reference. |
| 812 | |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 813 | if (Encoding & DW_EH_PE_indirect) { |
| 814 | MachineModuleInfoMachO &MachOMMI = |
| 815 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 816 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 817 | SmallString<128> Name; |
| 818 | Mang->getNameWithPrefix(Name, GV, true); |
| 819 | Name += "$non_lazy_ptr"; |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 820 | |
| 821 | // Add information about the stub reference to MachOMMI so that the stub |
| 822 | // gets emitted by the asmprinter. |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 823 | MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 824 | MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 825 | if (StubSym.getPointer() == 0) { |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 826 | MCSymbol *Sym = Mang->getSymbol(GV); |
| 827 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 828 | } |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 829 | |
| 830 | return TargetLoweringObjectFile:: |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 831 | getExprForDwarfReference(SSym, Mang, MMI, |
Chris Lattner | 42263e2 | 2010-03-11 21:55:20 +0000 | [diff] [blame] | 832 | Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | return TargetLoweringObjectFile:: |
Chris Lattner | 3192d14 | 2010-03-11 19:41:58 +0000 | [diff] [blame] | 836 | getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 839 | unsigned TargetLoweringObjectFileMachO::getPersonalityEncoding() const { |
| 840 | return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4; |
| 841 | } |
| 842 | |
| 843 | unsigned TargetLoweringObjectFileMachO::getLSDAEncoding() const { |
| 844 | return DW_EH_PE_pcrel; |
| 845 | } |
| 846 | |
| 847 | unsigned TargetLoweringObjectFileMachO::getFDEEncoding() const { |
| 848 | return DW_EH_PE_pcrel; |
| 849 | } |
| 850 | |
| 851 | unsigned TargetLoweringObjectFileMachO::getTTypeEncoding() const { |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 852 | return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4; |
Anton Korobeynikov | 293d592 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 853 | } |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 854 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 855 | //===----------------------------------------------------------------------===// |
| 856 | // COFF |
| 857 | //===----------------------------------------------------------------------===// |
| 858 | |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 859 | void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx, |
| 860 | const TargetMachine &TM) { |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 861 | TargetLoweringObjectFile::Initialize(Ctx, TM); |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 862 | TextSection = |
| 863 | getContext().getCOFFSection(".text", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 864 | COFF::IMAGE_SCN_CNT_CODE | |
| 865 | COFF::IMAGE_SCN_MEM_EXECUTE | |
| 866 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 867 | SectionKind::getText()); |
| 868 | DataSection = |
| 869 | getContext().getCOFFSection(".data", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 870 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 871 | COFF::IMAGE_SCN_MEM_READ | |
| 872 | COFF::IMAGE_SCN_MEM_WRITE, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 873 | SectionKind::getDataRel()); |
| 874 | ReadOnlySection = |
| 875 | getContext().getCOFFSection(".rdata", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 876 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 877 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 878 | SectionKind::getReadOnly()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 879 | StaticCtorSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 880 | getContext().getCOFFSection(".ctors", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 881 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 882 | COFF::IMAGE_SCN_MEM_READ | |
| 883 | COFF::IMAGE_SCN_MEM_WRITE, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 884 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 885 | StaticDtorSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 886 | getContext().getCOFFSection(".dtors", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 887 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 888 | COFF::IMAGE_SCN_MEM_READ | |
| 889 | COFF::IMAGE_SCN_MEM_WRITE, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 890 | SectionKind::getDataRel()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 891 | |
| 892 | // FIXME: We're emitting LSDA info into a readonly section on COFF, even |
| 893 | // though it contains relocatable pointers. In PIC mode, this is probably a |
| 894 | // big runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 895 | // adjusted or this should be a data section. |
| 896 | LSDASection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 897 | getContext().getCOFFSection(".gcc_except_table", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 898 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 899 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 900 | SectionKind::getReadOnly()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 901 | // Debug info. |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 902 | DwarfAbbrevSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 903 | getContext().getCOFFSection(".debug_abbrev", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 904 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 905 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 906 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 907 | DwarfInfoSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 908 | getContext().getCOFFSection(".debug_info", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 909 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 910 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 911 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 912 | DwarfLineSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 913 | getContext().getCOFFSection(".debug_line", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 914 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 915 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 916 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 917 | DwarfFrameSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 918 | getContext().getCOFFSection(".debug_frame", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 919 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 920 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 921 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 922 | DwarfPubNamesSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 923 | getContext().getCOFFSection(".debug_pubnames", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 924 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 925 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 926 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 927 | DwarfPubTypesSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 928 | getContext().getCOFFSection(".debug_pubtypes", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 929 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 930 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 931 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 932 | DwarfStrSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 933 | getContext().getCOFFSection(".debug_str", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 934 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 935 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 936 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 937 | DwarfLocSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 938 | getContext().getCOFFSection(".debug_loc", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 939 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 940 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 941 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 942 | DwarfARangesSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 943 | getContext().getCOFFSection(".debug_aranges", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 944 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 945 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 946 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 947 | DwarfRangesSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 948 | getContext().getCOFFSection(".debug_ranges", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 949 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 950 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 951 | SectionKind::getMetadata()); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 952 | DwarfMacroInfoSection = |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 953 | getContext().getCOFFSection(".debug_macinfo", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 954 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 955 | COFF::IMAGE_SCN_MEM_READ, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 956 | SectionKind::getMetadata()); |
| 957 | |
| 958 | DrectveSection = |
| 959 | getContext().getCOFFSection(".drectve", |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 960 | COFF::IMAGE_SCN_LNK_INFO, |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 961 | SectionKind::getMetadata()); |
| 962 | } |
| 963 | |
Rafael Espindola | 0cf5e3d | 2011-01-23 05:43:40 +0000 | [diff] [blame] | 964 | const MCSection *TargetLoweringObjectFileCOFF::getEHFrameSection() const { |
| 965 | return getContext().getCOFFSection(".eh_frame", |
| 966 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 967 | COFF::IMAGE_SCN_MEM_READ | |
| 968 | COFF::IMAGE_SCN_MEM_WRITE, |
| 969 | SectionKind::getDataRel()); |
| 970 | } |
| 971 | |
| 972 | |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 973 | static unsigned |
| 974 | getCOFFSectionFlags(SectionKind K) { |
| 975 | unsigned Flags = 0; |
| 976 | |
Anton Korobeynikov | 36335be | 2010-07-06 15:24:56 +0000 | [diff] [blame] | 977 | if (K.isMetadata()) |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 978 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 979 | COFF::IMAGE_SCN_MEM_DISCARDABLE; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 980 | else if (K.isText()) |
| 981 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 982 | COFF::IMAGE_SCN_MEM_EXECUTE | |
Michael J. Spencer | 3931b54 | 2010-10-27 18:52:29 +0000 | [diff] [blame] | 983 | COFF::IMAGE_SCN_MEM_READ | |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 984 | COFF::IMAGE_SCN_CNT_CODE; |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 985 | else if (K.isBSS ()) |
| 986 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 987 | COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
| 988 | COFF::IMAGE_SCN_MEM_READ | |
| 989 | COFF::IMAGE_SCN_MEM_WRITE; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 990 | else if (K.isReadOnly()) |
| 991 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 992 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 993 | COFF::IMAGE_SCN_MEM_READ; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 994 | else if (K.isWriteable()) |
| 995 | Flags |= |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 996 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 997 | COFF::IMAGE_SCN_MEM_READ | |
| 998 | COFF::IMAGE_SCN_MEM_WRITE; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 999 | |
| 1000 | return Flags; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | const MCSection *TargetLoweringObjectFileCOFF:: |
| 1004 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 1005 | Mangler *Mang, const TargetMachine &TM) const { |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 1006 | return getContext().getCOFFSection(GV->getSection(), |
| 1007 | getCOFFSectionFlags(Kind), |
| 1008 | Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) { |
| 1012 | if (Kind.isText()) |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 1013 | return ".text$"; |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 1014 | if (Kind.isBSS ()) |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 1015 | return ".bss$"; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 1016 | if (Kind.isWriteable()) |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 1017 | return ".data$"; |
| 1018 | return ".rdata$"; |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | const MCSection *TargetLoweringObjectFileCOFF:: |
| 1023 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
| 1024 | Mangler *Mang, const TargetMachine &TM) const { |
| 1025 | assert(!Kind.isThreadLocal() && "Doesn't support TLS"); |
| 1026 | |
| 1027 | // If this global is linkonce/weak and the target handles this by emitting it |
| 1028 | // into a 'uniqued' section name, create and return the section now. |
| 1029 | if (GV->isWeakForLinker()) { |
| 1030 | const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind); |
| 1031 | SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); |
Chris Lattner | 4c6741f | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 1032 | MCSymbol *Sym = Mang->getSymbol(GV); |
NAKAMURA Takumi | 3b3b0eb | 2010-10-19 03:24:42 +0000 | [diff] [blame] | 1033 | Name.append(Sym->getName().begin() + 1, Sym->getName().end()); |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 1034 | |
| 1035 | unsigned Characteristics = getCOFFSectionFlags(Kind); |
| 1036 | |
Daniel Dunbar | 9461058 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 1037 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 1038 | |
| 1039 | return getContext().getCOFFSection(Name.str(), Characteristics, |
Anton Korobeynikov | 657985e | 2010-10-08 21:50:04 +0000 | [diff] [blame] | 1040 | COFF::IMAGE_COMDAT_SELECT_ANY, Kind); |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | if (Kind.isText()) |
| 1044 | return getTextSection(); |
| 1045 | |
| 1046 | return getDataSection(); |
| 1047 | } |
| 1048 | |