Anton Korobeynikov | ab663a0 | 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" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SmallString.h" |
| 17 | #include "llvm/ADT/StringExtras.h" |
| 18 | #include "llvm/ADT/Triple.h" |
| 19 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Constants.h" |
| 21 | #include "llvm/IR/DataLayout.h" |
| 22 | #include "llvm/IR/DerivedTypes.h" |
| 23 | #include "llvm/IR/Function.h" |
| 24 | #include "llvm/IR/GlobalVariable.h" |
Rafael Espindola | 894843c | 2014-01-07 21:19:40 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Mangler.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 26 | #include "llvm/IR/Module.h" |
Peter Collingbourne | 94d7786 | 2015-11-03 23:40:03 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCAsmInfo.h" |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCContext.h" |
| 29 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 87cffa9 | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCSectionCOFF.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCSectionELF.h" |
| 32 | #include "llvm/MC/MCSectionMachO.h" |
Rafael Espindola | a83b177 | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCStreamer.h" |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 34 | #include "llvm/MC/MCSymbolELF.h" |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 35 | #include "llvm/MC/MCValue.h" |
Reid Kleckner | 1f13d47 | 2015-09-03 16:41:50 +0000 | [diff] [blame] | 36 | #include "llvm/Support/COFF.h" |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 37 | #include "llvm/Support/Dwarf.h" |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 38 | #include "llvm/Support/ELF.h" |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 39 | #include "llvm/Support/ErrorHandling.h" |
| 40 | #include "llvm/Support/raw_ostream.h" |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetLowering.h" |
Chandler Carruth | 442f784 | 2014-03-04 10:07:28 +0000 | [diff] [blame] | 42 | #include "llvm/Target/TargetMachine.h" |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 43 | #include "llvm/Target/TargetSubtargetInfo.h" |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 44 | using namespace llvm; |
Anton Korobeynikov | 31a9212 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 45 | using namespace dwarf; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 46 | |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | // ELF |
| 49 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 50 | |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 51 | MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol( |
| 52 | const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, |
| 53 | MachineModuleInfo *MMI) const { |
Rafael Espindola | ce83fc3 | 2011-04-27 23:17:57 +0000 | [diff] [blame] | 54 | unsigned Encoding = getPersonalityEncoding(); |
Logan Chien | c002981 | 2014-05-30 16:48:56 +0000 | [diff] [blame] | 55 | if ((Encoding & 0x80) == dwarf::DW_EH_PE_indirect) |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 56 | return getContext().getOrCreateSymbol(StringRef("DW.ref.") + |
Rafael Espindola | a3ad4e6 | 2014-02-19 20:30:41 +0000 | [diff] [blame] | 57 | TM.getSymbol(GV, Mang)->getName()); |
Logan Chien | c002981 | 2014-05-30 16:48:56 +0000 | [diff] [blame] | 58 | if ((Encoding & 0x70) == dwarf::DW_EH_PE_absptr) |
| 59 | return TM.getSymbol(GV, Mang); |
| 60 | report_fatal_error("We do not support this DWARF encoding yet!"); |
Rafael Espindola | a83b177 | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 63 | void TargetLoweringObjectFileELF::emitPersonalityValue( |
| 64 | MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) const { |
Rafael Espindola | 51d2d7a | 2011-06-13 03:09:13 +0000 | [diff] [blame] | 65 | SmallString<64> NameData("DW.ref."); |
| 66 | NameData += Sym->getName(); |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 67 | MCSymbolELF *Label = |
| 68 | cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData)); |
Rafael Espindola | 3989776 | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 69 | Streamer.EmitSymbolAttribute(Label, MCSA_Hidden); |
| 70 | Streamer.EmitSymbolAttribute(Label, MCSA_Weak); |
Rafael Espindola | 51d2d7a | 2011-06-13 03:09:13 +0000 | [diff] [blame] | 71 | StringRef Prefix = ".data."; |
| 72 | NameData.insert(NameData.begin(), Prefix.begin(), Prefix.end()); |
Rafael Espindola | 3989776 | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 73 | unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP; |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 74 | MCSection *Sec = getContext().getELFSection(NameData, ELF::SHT_PROGBITS, |
| 75 | Flags, 0, Label->getName()); |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 76 | unsigned Size = DL.getPointerSize(); |
Rafael Espindola | 3989776 | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 77 | Streamer.SwitchSection(Sec); |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 78 | Streamer.EmitValueToAlignment(DL.getPointerABIAlignment()); |
Rafael Espindola | 3989776 | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 79 | Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 80 | const MCExpr *E = MCConstantExpr::create(Size, getContext()); |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 81 | Streamer.emitELFSize(Label, E); |
Rafael Espindola | 3989776 | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 82 | Streamer.EmitLabel(Label); |
Rafael Espindola | a83b177 | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 83 | |
Rafael Espindola | 3989776 | 2011-04-27 21:29:52 +0000 | [diff] [blame] | 84 | Streamer.EmitSymbolValue(Sym, Size); |
Rafael Espindola | a83b177 | 2011-04-16 03:51:21 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Rafael Espindola | 15b2669 | 2014-02-09 14:50:44 +0000 | [diff] [blame] | 87 | const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference( |
| 88 | const GlobalValue *GV, unsigned Encoding, Mangler &Mang, |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 89 | const TargetMachine &TM, MachineModuleInfo *MMI, |
| 90 | MCStreamer &Streamer) const { |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 91 | |
| 92 | if (Encoding & dwarf::DW_EH_PE_indirect) { |
| 93 | MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>(); |
| 94 | |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 95 | MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang, TM); |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 96 | |
| 97 | // Add information about the stub reference to ELFMMI so that the stub |
| 98 | // gets emitted by the asmprinter. |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 99 | MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 100 | if (!StubSym.getPointer()) { |
Rafael Espindola | a3ad4e6 | 2014-02-19 20:30:41 +0000 | [diff] [blame] | 101 | MCSymbol *Sym = TM.getSymbol(GV, Mang); |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 102 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
| 103 | } |
| 104 | |
| 105 | return TargetLoweringObjectFile:: |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 106 | getTTypeReference(MCSymbolRefExpr::create(SSym, getContext()), |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 107 | Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); |
| 108 | } |
| 109 | |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 110 | return TargetLoweringObjectFile:: |
| 111 | getTTypeGlobalReference(GV, Encoding, Mang, TM, MMI, Streamer); |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 114 | static SectionKind |
| 115 | getELFKindForNamedSection(StringRef Name, SectionKind K) { |
Rafael Espindola | 0d018b1 | 2011-05-24 03:10:31 +0000 | [diff] [blame] | 116 | // N.B.: The defaults used in here are no the same ones used in MC. |
| 117 | // We follow gcc, MC follows gas. For example, given ".section .eh_frame", |
| 118 | // both gas and MC will produce a section with no flags. Given |
Bill Wendling | d163405 | 2012-07-19 00:04:14 +0000 | [diff] [blame] | 119 | // section(".eh_frame") gcc will produce: |
| 120 | // |
| 121 | // .section .eh_frame,"a",@progbits |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 122 | if (Name.empty() || Name[0] != '.') return K; |
| 123 | |
| 124 | // Some lame default implementation based on some magic section names. |
| 125 | if (Name == ".bss" || |
| 126 | Name.startswith(".bss.") || |
| 127 | Name.startswith(".gnu.linkonce.b.") || |
| 128 | Name.startswith(".llvm.linkonce.b.") || |
| 129 | Name == ".sbss" || |
| 130 | Name.startswith(".sbss.") || |
| 131 | Name.startswith(".gnu.linkonce.sb.") || |
| 132 | Name.startswith(".llvm.linkonce.sb.")) |
| 133 | return SectionKind::getBSS(); |
| 134 | |
| 135 | if (Name == ".tdata" || |
| 136 | Name.startswith(".tdata.") || |
| 137 | Name.startswith(".gnu.linkonce.td.") || |
| 138 | Name.startswith(".llvm.linkonce.td.")) |
| 139 | return SectionKind::getThreadData(); |
| 140 | |
| 141 | if (Name == ".tbss" || |
| 142 | Name.startswith(".tbss.") || |
| 143 | Name.startswith(".gnu.linkonce.tb.") || |
| 144 | Name.startswith(".llvm.linkonce.tb.")) |
| 145 | return SectionKind::getThreadBSS(); |
| 146 | |
| 147 | return K; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | static unsigned getELFSectionType(StringRef Name, SectionKind K) { |
| 152 | |
| 153 | if (Name == ".init_array") |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 154 | return ELF::SHT_INIT_ARRAY; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 155 | |
| 156 | if (Name == ".fini_array") |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 157 | return ELF::SHT_FINI_ARRAY; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 158 | |
| 159 | if (Name == ".preinit_array") |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 160 | return ELF::SHT_PREINIT_ARRAY; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 161 | |
| 162 | if (K.isBSS() || K.isThreadBSS()) |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 163 | return ELF::SHT_NOBITS; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 164 | |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 165 | return ELF::SHT_PROGBITS; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 168 | static unsigned getELFSectionFlags(SectionKind K) { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 169 | unsigned Flags = 0; |
| 170 | |
| 171 | if (!K.isMetadata()) |
Rafael Espindola | 0e7e34e | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 172 | Flags |= ELF::SHF_ALLOC; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 173 | |
| 174 | if (K.isText()) |
Rafael Espindola | 0e7e34e | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 175 | Flags |= ELF::SHF_EXECINSTR; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 176 | |
Rafael Espindola | c85e0d8 | 2011-06-07 23:26:45 +0000 | [diff] [blame] | 177 | if (K.isWriteable()) |
Rafael Espindola | 0e7e34e | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 178 | Flags |= ELF::SHF_WRITE; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 179 | |
| 180 | if (K.isThreadLocal()) |
Rafael Espindola | 0e7e34e | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 181 | Flags |= ELF::SHF_TLS; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 182 | |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 183 | if (K.isMergeableCString() || K.isMergeableConst()) |
Rafael Espindola | 0e7e34e | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 184 | Flags |= ELF::SHF_MERGE; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 185 | |
| 186 | if (K.isMergeableCString()) |
Rafael Espindola | 0e7e34e | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 187 | Flags |= ELF::SHF_STRINGS; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 188 | |
| 189 | return Flags; |
| 190 | } |
| 191 | |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 192 | static const Comdat *getELFComdat(const GlobalValue *GV) { |
| 193 | const Comdat *C = GV->getComdat(); |
| 194 | if (!C) |
| 195 | return nullptr; |
| 196 | |
| 197 | if (C->getSelectionKind() != Comdat::Any) |
| 198 | report_fatal_error("ELF COMDATs only support SelectionKind::Any, '" + |
| 199 | C->getName() + "' cannot be lowered."); |
| 200 | |
| 201 | return C; |
| 202 | } |
| 203 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 204 | MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal( |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 205 | const GlobalValue *GV, SectionKind Kind, Mangler &Mang, |
| 206 | const TargetMachine &TM) const { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 207 | StringRef SectionName = GV->getSection(); |
| 208 | |
| 209 | // Infer section flags from the section name if we can. |
| 210 | Kind = getELFKindForNamedSection(SectionName, Kind); |
| 211 | |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 212 | StringRef Group = ""; |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 213 | unsigned Flags = getELFSectionFlags(Kind); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 214 | if (const Comdat *C = getELFComdat(GV)) { |
| 215 | Group = C->getName(); |
| 216 | Flags |= ELF::SHF_GROUP; |
| 217 | } |
Chris Lattner | 80c3459 | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 218 | return getContext().getELFSection(SectionName, |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 219 | getELFSectionType(SectionName, Kind), Flags, |
Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 220 | /*EntrySize=*/0, Group); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Rafael Espindola | 25d2c20 | 2015-02-11 14:44:17 +0000 | [diff] [blame] | 223 | /// Return the section prefix name used by options FunctionsSections and |
| 224 | /// DataSections. |
David Majnemer | 102ff69 | 2014-06-24 16:01:53 +0000 | [diff] [blame] | 225 | static StringRef getSectionPrefixForGlobal(SectionKind Kind) { |
Rafael Espindola | 25d2c20 | 2015-02-11 14:44:17 +0000 | [diff] [blame] | 226 | if (Kind.isText()) |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 227 | return ".text"; |
Rafael Espindola | 25d2c20 | 2015-02-11 14:44:17 +0000 | [diff] [blame] | 228 | if (Kind.isReadOnly()) |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 229 | return ".rodata"; |
Rafael Espindola | 25d2c20 | 2015-02-11 14:44:17 +0000 | [diff] [blame] | 230 | if (Kind.isBSS()) |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 231 | return ".bss"; |
Rafael Espindola | 25d2c20 | 2015-02-11 14:44:17 +0000 | [diff] [blame] | 232 | if (Kind.isThreadData()) |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 233 | return ".tdata"; |
Rafael Espindola | 25d2c20 | 2015-02-11 14:44:17 +0000 | [diff] [blame] | 234 | if (Kind.isThreadBSS()) |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 235 | return ".tbss"; |
Rafael Espindola | 449711c | 2015-11-18 06:02:15 +0000 | [diff] [blame] | 236 | if (Kind.isData()) |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 237 | return ".data"; |
Chris Lattner | 5b212a3 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 238 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 239 | return ".data.rel.ro"; |
Chris Lattner | 5b212a3 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 242 | static MCSectionELF * |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 243 | selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV, |
| 244 | SectionKind Kind, Mangler &Mang, |
| 245 | const TargetMachine &TM, bool EmitUniqueSection, |
| 246 | unsigned Flags, unsigned *NextUniqueID) { |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 247 | unsigned EntrySize = 0; |
| 248 | if (Kind.isMergeableCString()) { |
| 249 | if (Kind.isMergeable2ByteCString()) { |
| 250 | EntrySize = 2; |
| 251 | } else if (Kind.isMergeable4ByteCString()) { |
| 252 | EntrySize = 4; |
| 253 | } else { |
| 254 | EntrySize = 1; |
| 255 | assert(Kind.isMergeable1ByteCString() && "unknown string width"); |
| 256 | } |
| 257 | } else if (Kind.isMergeableConst()) { |
| 258 | if (Kind.isMergeableConst4()) { |
| 259 | EntrySize = 4; |
| 260 | } else if (Kind.isMergeableConst8()) { |
| 261 | EntrySize = 8; |
| 262 | } else { |
| 263 | assert(Kind.isMergeableConst16() && "unknown data width"); |
| 264 | EntrySize = 16; |
| 265 | } |
| 266 | } |
| 267 | |
Rafael Espindola | 9075f77 | 2015-02-20 23:28:28 +0000 | [diff] [blame] | 268 | StringRef Group = ""; |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 269 | if (const Comdat *C = getELFComdat(GV)) { |
Rafael Espindola | 9075f77 | 2015-02-20 23:28:28 +0000 | [diff] [blame] | 270 | Flags |= ELF::SHF_GROUP; |
| 271 | Group = C->getName(); |
| 272 | } |
| 273 | |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 274 | bool UniqueSectionNames = TM.getUniqueSectionNames(); |
| 275 | SmallString<128> Name; |
Rafael Espindola | a05b3b7 | 2015-01-28 17:54:19 +0000 | [diff] [blame] | 276 | if (Kind.isMergeableCString()) { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 277 | // We also need alignment here. |
| 278 | // FIXME: this is getting the alignment of the character, not the |
| 279 | // alignment of the global! |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 280 | unsigned Align = GV->getParent()->getDataLayout().getPreferredAlignment( |
| 281 | cast<GlobalVariable>(GV)); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 282 | |
Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 283 | std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + "."; |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 284 | Name = SizeSpec + utostr(Align); |
| 285 | } else if (Kind.isMergeableConst()) { |
| 286 | Name = ".rodata.cst"; |
| 287 | Name += utostr(EntrySize); |
| 288 | } else { |
| 289 | Name = getSectionPrefixForGlobal(Kind); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Rafael Espindola | 8bc9ccc | 2015-02-25 00:52:15 +0000 | [diff] [blame] | 292 | if (EmitUniqueSection && UniqueSectionNames) { |
| 293 | Name.push_back('.'); |
| 294 | TM.getNameWithPrefix(Name, GV, Mang, true); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 295 | } |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 296 | unsigned UniqueID = ~0; |
| 297 | if (EmitUniqueSection && !UniqueSectionNames) { |
| 298 | UniqueID = *NextUniqueID; |
| 299 | (*NextUniqueID)++; |
| 300 | } |
Rafael Espindola | 4491d0d | 2015-02-26 23:55:11 +0000 | [diff] [blame] | 301 | return Ctx.getELFSection(Name, getELFSectionType(Name, Kind), Flags, |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 302 | EntrySize, Group, UniqueID); |
Rafael Espindola | 4491d0d | 2015-02-26 23:55:11 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 305 | MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal( |
Rafael Espindola | 4491d0d | 2015-02-26 23:55:11 +0000 | [diff] [blame] | 306 | const GlobalValue *GV, SectionKind Kind, Mangler &Mang, |
| 307 | const TargetMachine &TM) const { |
| 308 | unsigned Flags = getELFSectionFlags(Kind); |
| 309 | |
| 310 | // If we have -ffunction-section or -fdata-section then we should emit the |
| 311 | // global value to a uniqued section specifically for it. |
| 312 | bool EmitUniqueSection = false; |
| 313 | if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) { |
| 314 | if (Kind.isText()) |
| 315 | EmitUniqueSection = TM.getFunctionSections(); |
| 316 | else |
| 317 | EmitUniqueSection = TM.getDataSections(); |
| 318 | } |
| 319 | EmitUniqueSection |= GV->hasComdat(); |
| 320 | |
| 321 | return selectELFSectionForGlobal(getContext(), GV, Kind, Mang, TM, |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 322 | EmitUniqueSection, Flags, &NextUniqueID); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 325 | MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable( |
Rafael Espindola | 29786d4 | 2015-02-12 17:16:46 +0000 | [diff] [blame] | 326 | const Function &F, Mangler &Mang, const TargetMachine &TM) const { |
| 327 | // If the function can be removed, produce a unique section so that |
| 328 | // the table doesn't prevent the removal. |
| 329 | const Comdat *C = F.getComdat(); |
| 330 | bool EmitUniqueSection = TM.getFunctionSections() || C; |
| 331 | if (!EmitUniqueSection) |
| 332 | return ReadOnlySection; |
| 333 | |
Rafael Espindola | 4491d0d | 2015-02-26 23:55:11 +0000 | [diff] [blame] | 334 | return selectELFSectionForGlobal(getContext(), &F, SectionKind::getReadOnly(), |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 335 | Mang, TM, EmitUniqueSection, ELF::SHF_ALLOC, |
| 336 | &NextUniqueID); |
Rafael Espindola | 29786d4 | 2015-02-12 17:16:46 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Rafael Espindola | df19519 | 2015-02-17 23:34:51 +0000 | [diff] [blame] | 339 | bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection( |
| 340 | bool UsesLabelDifference, const Function &F) const { |
| 341 | // We can always create relative relocations, so use another section |
| 342 | // that can be marked non-executable. |
| 343 | return false; |
| 344 | } |
| 345 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 346 | /// Given a mergeable constant with the specified size and relocation |
| 347 | /// information, return a section that it should be placed in. |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 348 | MCSection *TargetLoweringObjectFileELF::getSectionForConstant( |
| 349 | const DataLayout &DL, SectionKind Kind, const Constant *C) const { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 350 | if (Kind.isMergeableConst4() && MergeableConst4Section) |
| 351 | return MergeableConst4Section; |
| 352 | if (Kind.isMergeableConst8() && MergeableConst8Section) |
| 353 | return MergeableConst8Section; |
| 354 | if (Kind.isMergeableConst16() && MergeableConst16Section) |
| 355 | return MergeableConst16Section; |
| 356 | if (Kind.isReadOnly()) |
| 357 | return ReadOnlySection; |
| 358 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 359 | assert(Kind.isReadOnlyWithRel() && "Unknown section kind"); |
| 360 | return DataRelROSection; |
| 361 | } |
| 362 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 363 | static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray, |
| 364 | bool IsCtor, unsigned Priority, |
| 365 | const MCSymbol *KeySym) { |
Rafael Espindola | c4b4253 | 2014-09-04 23:03:58 +0000 | [diff] [blame] | 366 | std::string Name; |
| 367 | unsigned Type; |
| 368 | unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE; |
Rafael Espindola | c4b4253 | 2014-09-04 23:03:58 +0000 | [diff] [blame] | 369 | StringRef COMDAT = KeySym ? KeySym->getName() : ""; |
| 370 | |
| 371 | if (KeySym) |
| 372 | Flags |= ELF::SHF_GROUP; |
Anton Korobeynikov | 7722a2d | 2012-01-25 22:24:19 +0000 | [diff] [blame] | 373 | |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 374 | if (UseInitArray) { |
Rafael Espindola | 7c7d7b9 | 2014-09-05 00:02:50 +0000 | [diff] [blame] | 375 | if (IsCtor) { |
| 376 | Type = ELF::SHT_INIT_ARRAY; |
| 377 | Name = ".init_array"; |
| 378 | } else { |
| 379 | Type = ELF::SHT_FINI_ARRAY; |
| 380 | Name = ".fini_array"; |
| 381 | } |
Rafael Espindola | c4b4253 | 2014-09-04 23:03:58 +0000 | [diff] [blame] | 382 | if (Priority != 65535) { |
| 383 | Name += '.'; |
| 384 | Name += utostr(Priority); |
| 385 | } |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 386 | } else { |
Rafael Espindola | c4b4253 | 2014-09-04 23:03:58 +0000 | [diff] [blame] | 387 | // The default scheme is .ctor / .dtor, so we have to invert the priority |
| 388 | // numbering. |
Rafael Espindola | 7c7d7b9 | 2014-09-05 00:02:50 +0000 | [diff] [blame] | 389 | if (IsCtor) |
| 390 | Name = ".ctors"; |
| 391 | else |
| 392 | Name = ".dtors"; |
Rafael Espindola | c4b4253 | 2014-09-04 23:03:58 +0000 | [diff] [blame] | 393 | if (Priority != 65535) { |
| 394 | Name += '.'; |
| 395 | Name += utostr(65535 - Priority); |
| 396 | } |
| 397 | Type = ELF::SHT_PROGBITS; |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 398 | } |
Rafael Espindola | c4b4253 | 2014-09-04 23:03:58 +0000 | [diff] [blame] | 399 | |
Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 400 | return Ctx.getELFSection(Name, Type, Flags, 0, COMDAT); |
Rafael Espindola | 7c7d7b9 | 2014-09-05 00:02:50 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 403 | MCSection *TargetLoweringObjectFileELF::getStaticCtorSection( |
Rafael Espindola | 7c7d7b9 | 2014-09-05 00:02:50 +0000 | [diff] [blame] | 404 | unsigned Priority, const MCSymbol *KeySym) const { |
| 405 | return getStaticStructorSection(getContext(), UseInitArray, true, Priority, |
| 406 | KeySym); |
Anton Korobeynikov | 7722a2d | 2012-01-25 22:24:19 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 409 | MCSection *TargetLoweringObjectFileELF::getStaticDtorSection( |
Rafael Espindola | 0766ae0 | 2014-06-06 19:26:12 +0000 | [diff] [blame] | 410 | unsigned Priority, const MCSymbol *KeySym) const { |
Rafael Espindola | 7c7d7b9 | 2014-09-05 00:02:50 +0000 | [diff] [blame] | 411 | return getStaticStructorSection(getContext(), UseInitArray, false, Priority, |
| 412 | KeySym); |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void |
| 416 | TargetLoweringObjectFileELF::InitializeELF(bool UseInitArray_) { |
| 417 | UseInitArray = UseInitArray_; |
| 418 | if (!UseInitArray) |
| 419 | return; |
| 420 | |
Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 421 | StaticCtorSection = getContext().getELFSection( |
| 422 | ".init_array", ELF::SHT_INIT_ARRAY, ELF::SHF_WRITE | ELF::SHF_ALLOC); |
| 423 | StaticDtorSection = getContext().getELFSection( |
| 424 | ".fini_array", ELF::SHT_FINI_ARRAY, ELF::SHF_WRITE | ELF::SHF_ALLOC); |
Anton Korobeynikov | 7722a2d | 2012-01-25 22:24:19 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 427 | //===----------------------------------------------------------------------===// |
| 428 | // MachO |
| 429 | //===----------------------------------------------------------------------===// |
| 430 | |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 431 | TargetLoweringObjectFileMachO::TargetLoweringObjectFileMachO() |
| 432 | : TargetLoweringObjectFile() { |
| 433 | SupportIndirectSymViaGOTPCRel = true; |
| 434 | } |
| 435 | |
Daniel Dunbar | 9585612 | 2013-01-18 19:37:00 +0000 | [diff] [blame] | 436 | /// emitModuleFlags - Perform code emission for module flags. |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 437 | void TargetLoweringObjectFileMachO:: |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 438 | emitModuleFlags(MCStreamer &Streamer, |
| 439 | ArrayRef<Module::ModuleFlagEntry> ModuleFlags, |
Rafael Espindola | fa0f728 | 2014-02-08 14:53:28 +0000 | [diff] [blame] | 440 | Mangler &Mang, const TargetMachine &TM) const { |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 441 | unsigned VersionVal = 0; |
Bill Wendling | f1b14b7 | 2012-04-24 11:03:50 +0000 | [diff] [blame] | 442 | unsigned ImageInfoFlags = 0; |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 443 | MDNode *LinkerOptions = nullptr; |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 444 | StringRef SectionVal; |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 445 | |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 446 | for (ArrayRef<Module::ModuleFlagEntry>::iterator |
| 447 | i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) { |
| 448 | const Module::ModuleFlagEntry &MFE = *i; |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 449 | |
| 450 | // Ignore flags with 'Require' behavior. |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 451 | if (MFE.Behavior == Module::Require) |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 452 | continue; |
| 453 | |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 454 | StringRef Key = MFE.Key->getString(); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 455 | Metadata *Val = MFE.Val; |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 456 | |
Daniel Dunbar | 9585612 | 2013-01-18 19:37:00 +0000 | [diff] [blame] | 457 | if (Key == "Objective-C Image Info Version") { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 458 | VersionVal = mdconst::extract<ConstantInt>(Val)->getZExtValue(); |
Daniel Dunbar | 9585612 | 2013-01-18 19:37:00 +0000 | [diff] [blame] | 459 | } else if (Key == "Objective-C Garbage Collection" || |
| 460 | Key == "Objective-C GC Only" || |
Manman Ren | c98ec0e | 2014-11-21 19:24:55 +0000 | [diff] [blame] | 461 | Key == "Objective-C Is Simulated" || |
| 462 | Key == "Objective-C Image Swift Version") { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 463 | ImageInfoFlags |= mdconst::extract<ConstantInt>(Val)->getZExtValue(); |
Daniel Dunbar | 9585612 | 2013-01-18 19:37:00 +0000 | [diff] [blame] | 464 | } else if (Key == "Objective-C Image Info Section") { |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 465 | SectionVal = cast<MDString>(Val)->getString(); |
Daniel Dunbar | 9585612 | 2013-01-18 19:37:00 +0000 | [diff] [blame] | 466 | } else if (Key == "Linker Options") { |
| 467 | LinkerOptions = cast<MDNode>(Val); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | // Emit the linker options if present. |
| 472 | if (LinkerOptions) { |
| 473 | for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { |
| 474 | MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i)); |
| 475 | SmallVector<std::string, 4> StrOptions; |
| 476 | |
| 477 | // Convert to strings. |
| 478 | for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { |
| 479 | MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii)); |
| 480 | StrOptions.push_back(MDOption->getString()); |
| 481 | } |
| 482 | |
| 483 | Streamer.EmitLinkerOptions(StrOptions); |
| 484 | } |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 487 | // The section is mandatory. If we don't have it, then we don't have GC info. |
| 488 | if (SectionVal.empty()) return; |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 489 | |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 490 | StringRef Segment, Section; |
| 491 | unsigned TAA = 0, StubSize = 0; |
| 492 | bool TAAParsed; |
| 493 | std::string ErrorCode = |
| 494 | MCSectionMachO::ParseSectionSpecifier(SectionVal, Segment, Section, |
| 495 | TAA, TAAParsed, StubSize); |
Bill Wendling | a0009ee | 2012-02-15 22:47:53 +0000 | [diff] [blame] | 496 | if (!ErrorCode.empty()) |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 497 | // If invalid, report the error with report_fatal_error. |
Bill Wendling | a0009ee | 2012-02-15 22:47:53 +0000 | [diff] [blame] | 498 | report_fatal_error("Invalid section specifier '" + Section + "': " + |
| 499 | ErrorCode + "."); |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 500 | |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 501 | // Get the section. |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 502 | MCSectionMachO *S = getContext().getMachOSection( |
Rafael Espindola | 449711c | 2015-11-18 06:02:15 +0000 | [diff] [blame] | 503 | Segment, Section, TAA, StubSize, SectionKind::getData()); |
Bill Wendling | 734909a | 2012-02-15 22:36:15 +0000 | [diff] [blame] | 504 | Streamer.SwitchSection(S); |
| 505 | Streamer.EmitLabel(getContext(). |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 506 | getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO"))); |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 507 | Streamer.EmitIntValue(VersionVal, 4); |
Bill Wendling | f1b14b7 | 2012-04-24 11:03:50 +0000 | [diff] [blame] | 508 | Streamer.EmitIntValue(ImageInfoFlags, 4); |
Bill Wendling | 06df772 | 2012-02-14 21:28:13 +0000 | [diff] [blame] | 509 | Streamer.AddBlankLine(); |
| 510 | } |
| 511 | |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 512 | static void checkMachOComdat(const GlobalValue *GV) { |
| 513 | const Comdat *C = GV->getComdat(); |
| 514 | if (!C) |
| 515 | return; |
| 516 | |
| 517 | report_fatal_error("MachO doesn't support COMDATs, '" + C->getName() + |
| 518 | "' cannot be lowered."); |
| 519 | } |
| 520 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 521 | MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal( |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 522 | const GlobalValue *GV, SectionKind Kind, Mangler &Mang, |
| 523 | const TargetMachine &TM) const { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 524 | // Parse the section specifier and create it if valid. |
| 525 | StringRef Segment, Section; |
Stuart Hastings | 12d5312 | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 526 | unsigned TAA = 0, StubSize = 0; |
| 527 | bool TAAParsed; |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 528 | |
| 529 | checkMachOComdat(GV); |
| 530 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 531 | std::string ErrorCode = |
| 532 | MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section, |
Stuart Hastings | 12d5312 | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 533 | TAA, TAAParsed, StubSize); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 534 | if (!ErrorCode.empty()) { |
Chris Lattner | 2104b8d | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 535 | // If invalid, report the error with report_fatal_error. |
Benjamin Kramer | 1f97a5a | 2011-11-15 16:27:03 +0000 | [diff] [blame] | 536 | report_fatal_error("Global variable '" + GV->getName() + |
| 537 | "' has an invalid section specifier '" + |
| 538 | GV->getSection() + "': " + ErrorCode + "."); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | // Get the section. |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 542 | MCSectionMachO *S = |
| 543 | getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 544 | |
Stuart Hastings | b4863a4 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 545 | // If TAA wasn't set by ParseSectionSpecifier() above, |
| 546 | // use the value returned by getMachOSection() as a default. |
Stuart Hastings | 12d5312 | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 547 | if (!TAAParsed) |
Stuart Hastings | b4863a4 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 548 | TAA = S->getTypeAndAttributes(); |
| 549 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 550 | // Okay, now that we got the section, verify that the TAA & StubSize agree. |
| 551 | // If the user declared multiple globals with different section flags, we need |
| 552 | // to reject it here. |
| 553 | if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) { |
Chris Lattner | 2104b8d | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 554 | // If invalid, report the error with report_fatal_error. |
Benjamin Kramer | 1f97a5a | 2011-11-15 16:27:03 +0000 | [diff] [blame] | 555 | report_fatal_error("Global variable '" + GV->getName() + |
| 556 | "' section type or attributes does not match previous" |
| 557 | " section specifier"); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | return S; |
| 561 | } |
| 562 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 563 | MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal( |
| 564 | const GlobalValue *GV, SectionKind Kind, Mangler &Mang, |
| 565 | const TargetMachine &TM) const { |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 566 | checkMachOComdat(GV); |
Bill Wendling | 25b61db | 2013-11-17 10:53:13 +0000 | [diff] [blame] | 567 | |
| 568 | // Handle thread local data. |
| 569 | if (Kind.isThreadBSS()) return TLSBSSSection; |
| 570 | if (Kind.isThreadData()) return TLSDataSection; |
| 571 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 572 | if (Kind.isText()) |
Arnold Schwaighofer | c31c2de | 2013-08-08 21:04:16 +0000 | [diff] [blame] | 573 | return GV->isWeakForLinker() ? TextCoalSection : TextSection; |
| 574 | |
| 575 | // If this is weak/linkonce, put this in a coalescable section, either in text |
| 576 | // or data depending on if it is writable. |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 577 | if (GV->isWeakForLinker()) { |
| 578 | if (Kind.isReadOnly()) |
Arnold Schwaighofer | c31c2de | 2013-08-08 21:04:16 +0000 | [diff] [blame] | 579 | return ConstTextCoalSection; |
| 580 | return DataCoalSection; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | // FIXME: Alignment check should be handled by section classifier. |
Chris Lattner | ef2f804 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 584 | if (Kind.isMergeable1ByteCString() && |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 585 | GV->getParent()->getDataLayout().getPreferredAlignment( |
| 586 | cast<GlobalVariable>(GV)) < 32) |
Chris Lattner | ef2f804 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 587 | return CStringSection; |
Michael J. Spencer | fbdab0d | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 588 | |
Chris Lattner | ef2f804 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 589 | // Do not put 16-bit arrays in the UString section if they have an |
| 590 | // externally visible label, this runs into issues with certain linker |
| 591 | // versions. |
| 592 | if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() && |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 593 | GV->getParent()->getDataLayout().getPreferredAlignment( |
| 594 | cast<GlobalVariable>(GV)) < 32) |
Chris Lattner | ef2f804 | 2010-03-07 04:28:09 +0000 | [diff] [blame] | 595 | return UStringSection; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 596 | |
Rafael Espindola | b43d51d | 2014-08-28 20:13:31 +0000 | [diff] [blame] | 597 | // With MachO only variables whose corresponding symbol starts with 'l' or |
| 598 | // 'L' can be merged, so we only try merging GVs with private linkage. |
| 599 | if (GV->hasPrivateLinkage() && Kind.isMergeableConst()) { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 600 | if (Kind.isMergeableConst4()) |
| 601 | return FourByteConstantSection; |
| 602 | if (Kind.isMergeableConst8()) |
| 603 | return EightByteConstantSection; |
Rafael Espindola | 1f3de49 | 2014-02-13 23:16:11 +0000 | [diff] [blame] | 604 | if (Kind.isMergeableConst16()) |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 605 | return SixteenByteConstantSection; |
| 606 | } |
| 607 | |
| 608 | // Otherwise, if it is readonly, but not something we can specially optimize, |
| 609 | // just drop it in .const. |
| 610 | if (Kind.isReadOnly()) |
| 611 | return ReadOnlySection; |
| 612 | |
| 613 | // If this is marked const, put it into a const section. But if the dynamic |
| 614 | // linker needs to write to it, put it in the data segment. |
| 615 | if (Kind.isReadOnlyWithRel()) |
| 616 | return ConstDataSection; |
| 617 | |
| 618 | // Put zero initialized globals with strong external linkage in the |
| 619 | // DATA, __common section with the .zerofill directive. |
| 620 | if (Kind.isBSSExtern()) |
| 621 | return DataCommonSection; |
| 622 | |
| 623 | // Put zero initialized globals with local linkage in __DATA,__bss directive |
| 624 | // with the .zerofill directive (aka .lcomm). |
| 625 | if (Kind.isBSSLocal()) |
| 626 | return DataBSSSection; |
Michael J. Spencer | fbdab0d | 2010-10-27 18:52:20 +0000 | [diff] [blame] | 627 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 628 | // Otherwise, just drop the variable in the normal data section. |
| 629 | return DataSection; |
| 630 | } |
| 631 | |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 632 | MCSection *TargetLoweringObjectFileMachO::getSectionForConstant( |
| 633 | const DataLayout &DL, SectionKind Kind, const Constant *C) const { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 634 | // If this constant requires a relocation, we have to put it in the data |
| 635 | // segment, not in the text segment. |
Rafael Espindola | 449711c | 2015-11-18 06:02:15 +0000 | [diff] [blame] | 636 | if (Kind.isData() || Kind.isReadOnlyWithRel()) |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 637 | return ConstDataSection; |
| 638 | |
| 639 | if (Kind.isMergeableConst4()) |
| 640 | return FourByteConstantSection; |
| 641 | if (Kind.isMergeableConst8()) |
| 642 | return EightByteConstantSection; |
Rafael Espindola | 1f3de49 | 2014-02-13 23:16:11 +0000 | [diff] [blame] | 643 | if (Kind.isMergeableConst16()) |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 644 | return SixteenByteConstantSection; |
| 645 | return ReadOnlySection; // .const |
| 646 | } |
| 647 | |
Rafael Espindola | 15b2669 | 2014-02-09 14:50:44 +0000 | [diff] [blame] | 648 | const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference( |
| 649 | const GlobalValue *GV, unsigned Encoding, Mangler &Mang, |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 650 | const TargetMachine &TM, MachineModuleInfo *MMI, |
| 651 | MCStreamer &Streamer) const { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 652 | // The mach-o version of this method defaults to returning a stub reference. |
| 653 | |
Anton Korobeynikov | 31a9212 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 654 | if (Encoding & DW_EH_PE_indirect) { |
| 655 | MachineModuleInfoMachO &MachOMMI = |
| 656 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 657 | |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 658 | MCSymbol *SSym = |
| 659 | getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM); |
Anton Korobeynikov | 31a9212 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 660 | |
| 661 | // Add information about the stub reference to MachOMMI so that the stub |
| 662 | // gets emitted by the asmprinter. |
Bill Wendling | 57e3aaa | 2011-10-24 23:05:43 +0000 | [diff] [blame] | 663 | MachineModuleInfoImpl::StubValueTy &StubSym = |
| 664 | GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) : |
| 665 | MachOMMI.getGVStubEntry(SSym); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 666 | if (!StubSym.getPointer()) { |
Rafael Espindola | a3ad4e6 | 2014-02-19 20:30:41 +0000 | [diff] [blame] | 667 | MCSymbol *Sym = TM.getSymbol(GV, Mang); |
Chris Lattner | 2ea586b | 2010-03-15 20:37:38 +0000 | [diff] [blame] | 668 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
Anton Korobeynikov | 31a9212 | 2010-02-21 20:28:15 +0000 | [diff] [blame] | 669 | } |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 670 | |
| 671 | return TargetLoweringObjectFile:: |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 672 | getTTypeReference(MCSymbolRefExpr::create(SSym, getContext()), |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 673 | Encoding & ~dwarf::DW_EH_PE_indirect, Streamer); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 676 | return TargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding, Mang, |
| 677 | TM, MMI, Streamer); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 680 | MCSymbol *TargetLoweringObjectFileMachO::getCFIPersonalitySymbol( |
| 681 | const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, |
| 682 | MachineModuleInfo *MMI) const { |
Rafael Espindola | 0870434 | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 683 | // The mach-o version of this method defaults to returning a stub reference. |
| 684 | MachineModuleInfoMachO &MachOMMI = |
| 685 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 686 | |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 687 | MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM); |
Rafael Espindola | 0870434 | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 688 | |
| 689 | // Add information about the stub reference to MachOMMI so that the stub |
| 690 | // gets emitted by the asmprinter. |
Bill Wendling | e4cc332 | 2011-11-29 01:43:20 +0000 | [diff] [blame] | 691 | MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 692 | if (!StubSym.getPointer()) { |
Rafael Espindola | a3ad4e6 | 2014-02-19 20:30:41 +0000 | [diff] [blame] | 693 | MCSymbol *Sym = TM.getSymbol(GV, Mang); |
Rafael Espindola | 0870434 | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 694 | StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); |
| 695 | } |
| 696 | |
| 697 | return SSym; |
| 698 | } |
| 699 | |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 700 | const MCExpr *TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel( |
| 701 | const MCSymbol *Sym, const MCValue &MV, int64_t Offset, |
| 702 | MachineModuleInfo *MMI, MCStreamer &Streamer) const { |
Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 703 | // Although MachO 32-bit targets do not explicitly have a GOTPCREL relocation |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 704 | // as 64-bit do, we replace the GOT equivalent by accessing the final symbol |
| 705 | // through a non_lazy_ptr stub instead. One advantage is that it allows the |
| 706 | // computation of deltas to final external symbols. Example: |
| 707 | // |
| 708 | // _extgotequiv: |
| 709 | // .long _extfoo |
| 710 | // |
| 711 | // _delta: |
| 712 | // .long _extgotequiv-_delta |
| 713 | // |
| 714 | // is transformed to: |
| 715 | // |
| 716 | // _delta: |
| 717 | // .long L_extfoo$non_lazy_ptr-(_delta+0) |
| 718 | // |
| 719 | // .section __IMPORT,__pointers,non_lazy_symbol_pointers |
| 720 | // L_extfoo$non_lazy_ptr: |
| 721 | // .indirect_symbol _extfoo |
| 722 | // .long 0 |
| 723 | // |
| 724 | MachineModuleInfoMachO &MachOMMI = |
| 725 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 726 | MCContext &Ctx = getContext(); |
| 727 | |
| 728 | // The offset must consider the original displacement from the base symbol |
| 729 | // since 32-bit targets don't have a GOTPCREL to fold the PC displacement. |
| 730 | Offset = -MV.getConstant(); |
| 731 | const MCSymbol *BaseSym = &MV.getSymB()->getSymbol(); |
| 732 | |
| 733 | // Access the final symbol via sym$non_lazy_ptr and generate the appropriated |
| 734 | // non_lazy_ptr stubs. |
| 735 | SmallString<128> Name; |
| 736 | StringRef Suffix = "$non_lazy_ptr"; |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 737 | Name += MMI->getModule()->getDataLayout().getPrivateGlobalPrefix(); |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 738 | Name += Sym->getName(); |
| 739 | Name += Suffix; |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 740 | MCSymbol *Stub = Ctx.getOrCreateSymbol(Name); |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 741 | |
| 742 | MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub); |
| 743 | if (!StubSym.getPointer()) |
| 744 | StubSym = MachineModuleInfoImpl:: |
| 745 | StubValueTy(const_cast<MCSymbol *>(Sym), true /* access indirectly */); |
| 746 | |
| 747 | const MCExpr *BSymExpr = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 748 | MCSymbolRefExpr::create(BaseSym, MCSymbolRefExpr::VK_None, Ctx); |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 749 | const MCExpr *LHS = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 750 | MCSymbolRefExpr::create(Stub, MCSymbolRefExpr::VK_None, Ctx); |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 751 | |
| 752 | if (!Offset) |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 753 | return MCBinaryExpr::createSub(LHS, BSymExpr, Ctx); |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 754 | |
| 755 | const MCExpr *RHS = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 756 | MCBinaryExpr::createAdd(BSymExpr, MCConstantExpr::create(Offset, Ctx), Ctx); |
| 757 | return MCBinaryExpr::createSub(LHS, RHS, Ctx); |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Peter Collingbourne | 94d7786 | 2015-11-03 23:40:03 +0000 | [diff] [blame] | 760 | static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo, |
| 761 | const MCSection &Section) { |
| 762 | if (!AsmInfo.isSectionAtomizableBySymbols(Section)) |
| 763 | return true; |
| 764 | |
| 765 | // If it is not dead stripped, it is safe to use private labels. |
| 766 | const MCSectionMachO &SMO = cast<MCSectionMachO>(Section); |
| 767 | if (SMO.hasAttribute(MachO::S_ATTR_NO_DEAD_STRIP)) |
| 768 | return true; |
| 769 | |
| 770 | return false; |
| 771 | } |
| 772 | |
| 773 | void TargetLoweringObjectFileMachO::getNameWithPrefix( |
| 774 | SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang, |
| 775 | const TargetMachine &TM) const { |
| 776 | SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM); |
| 777 | const MCSection *TheSection = SectionForGlobal(GV, GVKind, Mang, TM); |
| 778 | bool CannotUsePrivateLabel = |
| 779 | !canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection); |
| 780 | Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel); |
| 781 | } |
| 782 | |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 783 | //===----------------------------------------------------------------------===// |
| 784 | // COFF |
| 785 | //===----------------------------------------------------------------------===// |
| 786 | |
Chris Lattner | 87cffa9 | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 787 | static unsigned |
| 788 | getCOFFSectionFlags(SectionKind K) { |
| 789 | unsigned Flags = 0; |
| 790 | |
Anton Korobeynikov | e415230 | 2010-07-06 15:24:56 +0000 | [diff] [blame] | 791 | if (K.isMetadata()) |
Chris Lattner | 0284493 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 792 | Flags |= |
Daniel Dunbar | 329d202 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 793 | COFF::IMAGE_SCN_MEM_DISCARDABLE; |
Chris Lattner | 87cffa9 | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 794 | else if (K.isText()) |
| 795 | Flags |= |
Daniel Dunbar | 329d202 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 796 | COFF::IMAGE_SCN_MEM_EXECUTE | |
Michael J. Spencer | 0f83d96 | 2010-10-27 18:52:29 +0000 | [diff] [blame] | 797 | COFF::IMAGE_SCN_MEM_READ | |
Daniel Dunbar | 329d202 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 798 | COFF::IMAGE_SCN_CNT_CODE; |
David Majnemer | b8dbebb | 2014-09-20 07:31:46 +0000 | [diff] [blame] | 799 | else if (K.isBSS()) |
Chris Lattner | 0284493 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 800 | Flags |= |
Daniel Dunbar | 329d202 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 801 | COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
| 802 | COFF::IMAGE_SCN_MEM_READ | |
| 803 | COFF::IMAGE_SCN_MEM_WRITE; |
Anton Korobeynikov | c6b4017 | 2012-02-11 17:26:53 +0000 | [diff] [blame] | 804 | else if (K.isThreadLocal()) |
| 805 | Flags |= |
| 806 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 807 | COFF::IMAGE_SCN_MEM_READ | |
| 808 | COFF::IMAGE_SCN_MEM_WRITE; |
David Majnemer | b8dbebb | 2014-09-20 07:31:46 +0000 | [diff] [blame] | 809 | else if (K.isReadOnly() || K.isReadOnlyWithRel()) |
Chris Lattner | 87cffa9 | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 810 | Flags |= |
Daniel Dunbar | 329d202 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 811 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 812 | COFF::IMAGE_SCN_MEM_READ; |
Chris Lattner | 87cffa9 | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 813 | else if (K.isWriteable()) |
| 814 | Flags |= |
Daniel Dunbar | 329d202 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 815 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 816 | COFF::IMAGE_SCN_MEM_READ | |
| 817 | COFF::IMAGE_SCN_MEM_WRITE; |
Chris Lattner | 87cffa9 | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 818 | |
| 819 | return Flags; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Benjamin Kramer | 6cbe670 | 2014-07-07 14:47:51 +0000 | [diff] [blame] | 822 | static const GlobalValue *getComdatGVForCOFF(const GlobalValue *GV) { |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 823 | const Comdat *C = GV->getComdat(); |
| 824 | assert(C && "expected GV to have a Comdat!"); |
| 825 | |
| 826 | StringRef ComdatGVName = C->getName(); |
| 827 | const GlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName); |
| 828 | if (!ComdatGV) |
| 829 | report_fatal_error("Associative COMDAT symbol '" + ComdatGVName + |
| 830 | "' does not exist."); |
| 831 | |
| 832 | if (ComdatGV->getComdat() != C) |
| 833 | report_fatal_error("Associative COMDAT symbol '" + ComdatGVName + |
Hans Wennborg | c0f0c51 | 2014-09-19 01:14:56 +0000 | [diff] [blame] | 834 | "' is not a key for its COMDAT."); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 835 | |
| 836 | return ComdatGV; |
| 837 | } |
| 838 | |
| 839 | static int getSelectionForCOFF(const GlobalValue *GV) { |
| 840 | if (const Comdat *C = GV->getComdat()) { |
| 841 | const GlobalValue *ComdatKey = getComdatGVForCOFF(GV); |
| 842 | if (const auto *GA = dyn_cast<GlobalAlias>(ComdatKey)) |
| 843 | ComdatKey = GA->getBaseObject(); |
| 844 | if (ComdatKey == GV) { |
| 845 | switch (C->getSelectionKind()) { |
| 846 | case Comdat::Any: |
| 847 | return COFF::IMAGE_COMDAT_SELECT_ANY; |
| 848 | case Comdat::ExactMatch: |
| 849 | return COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH; |
| 850 | case Comdat::Largest: |
| 851 | return COFF::IMAGE_COMDAT_SELECT_LARGEST; |
| 852 | case Comdat::NoDuplicates: |
| 853 | return COFF::IMAGE_COMDAT_SELECT_NODUPLICATES; |
| 854 | case Comdat::SameSize: |
| 855 | return COFF::IMAGE_COMDAT_SELECT_SAME_SIZE; |
| 856 | } |
| 857 | } else { |
| 858 | return COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE; |
| 859 | } |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 860 | } |
| 861 | return 0; |
| 862 | } |
| 863 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 864 | MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal( |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 865 | const GlobalValue *GV, SectionKind Kind, Mangler &Mang, |
| 866 | const TargetMachine &TM) const { |
Michael J. Spencer | f1aef75 | 2012-11-13 22:04:09 +0000 | [diff] [blame] | 867 | int Selection = 0; |
| 868 | unsigned Characteristics = getCOFFSectionFlags(Kind); |
Rafael Espindola | 2d30ae2 | 2013-11-27 01:18:37 +0000 | [diff] [blame] | 869 | StringRef Name = GV->getSection(); |
| 870 | StringRef COMDATSymName = ""; |
Rafael Espindola | 12ca34f | 2015-01-19 15:16:06 +0000 | [diff] [blame] | 871 | if (GV->hasComdat()) { |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 872 | Selection = getSelectionForCOFF(GV); |
| 873 | const GlobalValue *ComdatGV; |
| 874 | if (Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) |
| 875 | ComdatGV = getComdatGVForCOFF(GV); |
| 876 | else |
| 877 | ComdatGV = GV; |
| 878 | |
| 879 | if (!ComdatGV->hasPrivateLinkage()) { |
| 880 | MCSymbol *Sym = TM.getSymbol(ComdatGV, Mang); |
| 881 | COMDATSymName = Sym->getName(); |
| 882 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
| 883 | } else { |
| 884 | Selection = 0; |
| 885 | } |
Michael J. Spencer | f1aef75 | 2012-11-13 22:04:09 +0000 | [diff] [blame] | 886 | } |
| 887 | return getContext().getCOFFSection(Name, |
| 888 | Characteristics, |
Nico Rieck | a37acf7 | 2013-07-06 12:13:10 +0000 | [diff] [blame] | 889 | Kind, |
Rafael Espindola | 2d30ae2 | 2013-11-27 01:18:37 +0000 | [diff] [blame] | 890 | COMDATSymName, |
Nico Rieck | a37acf7 | 2013-07-06 12:13:10 +0000 | [diff] [blame] | 891 | Selection); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Rafael Espindola | 2d30ae2 | 2013-11-27 01:18:37 +0000 | [diff] [blame] | 894 | static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) { |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 895 | if (Kind.isText()) |
Rafael Espindola | 2d30ae2 | 2013-11-27 01:18:37 +0000 | [diff] [blame] | 896 | return ".text"; |
David Majnemer | a9bdb32 | 2014-04-08 22:33:40 +0000 | [diff] [blame] | 897 | if (Kind.isBSS()) |
Rafael Espindola | 2d30ae2 | 2013-11-27 01:18:37 +0000 | [diff] [blame] | 898 | return ".bss"; |
| 899 | if (Kind.isThreadLocal()) |
Rafael Espindola | 3c8e147 | 2013-11-27 15:52:11 +0000 | [diff] [blame] | 900 | return ".tls$"; |
David Majnemer | 597be2d | 2014-09-22 20:39:23 +0000 | [diff] [blame] | 901 | if (Kind.isReadOnly() || Kind.isReadOnlyWithRel()) |
| 902 | return ".rdata"; |
| 903 | return ".data"; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 906 | MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal( |
| 907 | const GlobalValue *GV, SectionKind Kind, Mangler &Mang, |
| 908 | const TargetMachine &TM) const { |
David Majnemer | 9338984 | 2014-03-23 17:47:39 +0000 | [diff] [blame] | 909 | // If we have -ffunction-sections then we should emit the global value to a |
| 910 | // uniqued section specifically for it. |
David Majnemer | 273bff4 | 2014-03-25 06:14:26 +0000 | [diff] [blame] | 911 | bool EmitUniquedSection; |
| 912 | if (Kind.isText()) |
| 913 | EmitUniquedSection = TM.getFunctionSections(); |
| 914 | else |
| 915 | EmitUniquedSection = TM.getDataSections(); |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 916 | |
Rafael Espindola | 12ca34f | 2015-01-19 15:16:06 +0000 | [diff] [blame] | 917 | if ((EmitUniquedSection && !Kind.isCommon()) || GV->hasComdat()) { |
Rafael Espindola | 2d30ae2 | 2013-11-27 01:18:37 +0000 | [diff] [blame] | 918 | const char *Name = getCOFFSectionNameForUniqueGlobal(Kind); |
Chris Lattner | 0284493 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 919 | unsigned Characteristics = getCOFFSectionFlags(Kind); |
| 920 | |
Daniel Dunbar | 329d202 | 2010-07-01 20:07:24 +0000 | [diff] [blame] | 921 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 922 | int Selection = getSelectionForCOFF(GV); |
| 923 | if (!Selection) |
| 924 | Selection = COFF::IMAGE_COMDAT_SELECT_NODUPLICATES; |
| 925 | const GlobalValue *ComdatGV; |
| 926 | if (GV->hasComdat()) |
| 927 | ComdatGV = getComdatGVForCOFF(GV); |
| 928 | else |
| 929 | ComdatGV = GV; |
| 930 | |
| 931 | if (!ComdatGV->hasPrivateLinkage()) { |
| 932 | MCSymbol *Sym = TM.getSymbol(ComdatGV, Mang); |
| 933 | StringRef COMDATSymName = Sym->getName(); |
| 934 | return getContext().getCOFFSection(Name, Characteristics, Kind, |
| 935 | COMDATSymName, Selection); |
David Majnemer | 7db449a | 2015-03-17 23:54:51 +0000 | [diff] [blame] | 936 | } else { |
| 937 | SmallString<256> TmpData; |
Peter Collingbourne | 94d7786 | 2015-11-03 23:40:03 +0000 | [diff] [blame] | 938 | Mang.getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true); |
David Majnemer | 7db449a | 2015-03-17 23:54:51 +0000 | [diff] [blame] | 939 | return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData, |
| 940 | Selection); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 941 | } |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | if (Kind.isText()) |
David Majnemer | 3d96acb | 2013-08-13 01:23:53 +0000 | [diff] [blame] | 945 | return TextSection; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 946 | |
Anton Korobeynikov | c6b4017 | 2012-02-11 17:26:53 +0000 | [diff] [blame] | 947 | if (Kind.isThreadLocal()) |
David Majnemer | 3d96acb | 2013-08-13 01:23:53 +0000 | [diff] [blame] | 948 | return TLSDataSection; |
Anton Korobeynikov | c6b4017 | 2012-02-11 17:26:53 +0000 | [diff] [blame] | 949 | |
David Majnemer | 597be2d | 2014-09-22 20:39:23 +0000 | [diff] [blame] | 950 | if (Kind.isReadOnly() || Kind.isReadOnlyWithRel()) |
David Majnemer | f76d6b3 | 2013-08-08 01:50:52 +0000 | [diff] [blame] | 951 | return ReadOnlySection; |
| 952 | |
David Majnemer | a9bdb32 | 2014-04-08 22:33:40 +0000 | [diff] [blame] | 953 | // Note: we claim that common symbols are put in BSSSection, but they are |
| 954 | // really emitted with the magic .comm directive, which creates a symbol table |
| 955 | // entry but not a section. |
| 956 | if (Kind.isBSS() || Kind.isCommon()) |
David Majnemer | 3d96acb | 2013-08-13 01:23:53 +0000 | [diff] [blame] | 957 | return BSSSection; |
| 958 | |
| 959 | return DataSection; |
Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 960 | } |
| 961 | |
David Majnemer | 7db449a | 2015-03-17 23:54:51 +0000 | [diff] [blame] | 962 | void TargetLoweringObjectFileCOFF::getNameWithPrefix( |
Peter Collingbourne | 94d7786 | 2015-11-03 23:40:03 +0000 | [diff] [blame] | 963 | SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang, |
| 964 | const TargetMachine &TM) const { |
| 965 | bool CannotUsePrivateLabel = false; |
David Majnemer | 7db449a | 2015-03-17 23:54:51 +0000 | [diff] [blame] | 966 | if (GV->hasPrivateLinkage() && |
| 967 | ((isa<Function>(GV) && TM.getFunctionSections()) || |
| 968 | (isa<GlobalVariable>(GV) && TM.getDataSections()))) |
| 969 | CannotUsePrivateLabel = true; |
| 970 | |
| 971 | Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel); |
| 972 | } |
| 973 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 974 | MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable( |
Rafael Espindola | ab447e4 | 2015-03-11 19:58:37 +0000 | [diff] [blame] | 975 | const Function &F, Mangler &Mang, const TargetMachine &TM) const { |
| 976 | // If the function can be removed, produce a unique section so that |
| 977 | // the table doesn't prevent the removal. |
| 978 | const Comdat *C = F.getComdat(); |
| 979 | bool EmitUniqueSection = TM.getFunctionSections() || C; |
| 980 | if (!EmitUniqueSection) |
| 981 | return ReadOnlySection; |
| 982 | |
| 983 | // FIXME: we should produce a symbol for F instead. |
| 984 | if (F.hasPrivateLinkage()) |
| 985 | return ReadOnlySection; |
| 986 | |
| 987 | MCSymbol *Sym = TM.getSymbol(&F, Mang); |
| 988 | StringRef COMDATSymName = Sym->getName(); |
| 989 | |
| 990 | SectionKind Kind = SectionKind::getReadOnly(); |
| 991 | const char *Name = getCOFFSectionNameForUniqueGlobal(Kind); |
| 992 | unsigned Characteristics = getCOFFSectionFlags(Kind); |
| 993 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
| 994 | |
| 995 | return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName, |
| 996 | COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE); |
| 997 | } |
| 998 | |
Reid Kleckner | d973ca3 | 2013-04-25 19:34:41 +0000 | [diff] [blame] | 999 | void TargetLoweringObjectFileCOFF:: |
| 1000 | emitModuleFlags(MCStreamer &Streamer, |
| 1001 | ArrayRef<Module::ModuleFlagEntry> ModuleFlags, |
Rafael Espindola | fa0f728 | 2014-02-08 14:53:28 +0000 | [diff] [blame] | 1002 | Mangler &Mang, const TargetMachine &TM) const { |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 1003 | MDNode *LinkerOptions = nullptr; |
Reid Kleckner | d973ca3 | 2013-04-25 19:34:41 +0000 | [diff] [blame] | 1004 | |
| 1005 | // Look for the "Linker Options" flag, since it's the only one we support. |
| 1006 | for (ArrayRef<Module::ModuleFlagEntry>::iterator |
| 1007 | i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) { |
| 1008 | const Module::ModuleFlagEntry &MFE = *i; |
| 1009 | StringRef Key = MFE.Key->getString(); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1010 | Metadata *Val = MFE.Val; |
Reid Kleckner | d973ca3 | 2013-04-25 19:34:41 +0000 | [diff] [blame] | 1011 | if (Key == "Linker Options") { |
| 1012 | LinkerOptions = cast<MDNode>(Val); |
| 1013 | break; |
| 1014 | } |
| 1015 | } |
| 1016 | if (!LinkerOptions) |
| 1017 | return; |
| 1018 | |
| 1019 | // Emit the linker options to the linker .drectve section. According to the |
| 1020 | // spec, this section is a space-separated string containing flags for linker. |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 1021 | MCSection *Sec = getDrectveSection(); |
Reid Kleckner | d973ca3 | 2013-04-25 19:34:41 +0000 | [diff] [blame] | 1022 | Streamer.SwitchSection(Sec); |
| 1023 | for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { |
| 1024 | MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i)); |
| 1025 | for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { |
| 1026 | MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii)); |
Reid Kleckner | d973ca3 | 2013-04-25 19:34:41 +0000 | [diff] [blame] | 1027 | // Lead with a space for consistency with our dllexport implementation. |
Michael Kuperstein | fc3e626 | 2015-02-16 11:57:17 +0000 | [diff] [blame] | 1028 | std::string Directive(" "); |
| 1029 | Directive.append(MDOption->getString()); |
| 1030 | Streamer.EmitBytes(Directive); |
Reid Kleckner | d973ca3 | 2013-04-25 19:34:41 +0000 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | } |
Reid Kleckner | fceb76f | 2014-05-16 20:39:27 +0000 | [diff] [blame] | 1034 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 1035 | MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection( |
Rafael Espindola | 0766ae0 | 2014-06-06 19:26:12 +0000 | [diff] [blame] | 1036 | unsigned Priority, const MCSymbol *KeySym) const { |
Reid Kleckner | 7c4059e | 2014-09-04 17:42:03 +0000 | [diff] [blame] | 1037 | return getContext().getAssociativeCOFFSection( |
| 1038 | cast<MCSectionCOFF>(StaticCtorSection), KeySym); |
Reid Kleckner | fceb76f | 2014-05-16 20:39:27 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 1041 | MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection( |
Rafael Espindola | 0766ae0 | 2014-06-06 19:26:12 +0000 | [diff] [blame] | 1042 | unsigned Priority, const MCSymbol *KeySym) const { |
Reid Kleckner | 7c4059e | 2014-09-04 17:42:03 +0000 | [diff] [blame] | 1043 | return getContext().getAssociativeCOFFSection( |
| 1044 | cast<MCSectionCOFF>(StaticDtorSection), KeySym); |
Reid Kleckner | fceb76f | 2014-05-16 20:39:27 +0000 | [diff] [blame] | 1045 | } |
Peter Collingbourne | aef3659 | 2015-06-29 22:04:09 +0000 | [diff] [blame] | 1046 | |
| 1047 | void TargetLoweringObjectFileCOFF::emitLinkerFlagsForGlobal( |
| 1048 | raw_ostream &OS, const GlobalValue *GV, const Mangler &Mang) const { |
| 1049 | if (!GV->hasDLLExportStorageClass() || GV->isDeclaration()) |
| 1050 | return; |
| 1051 | |
| 1052 | const Triple &TT = getTargetTriple(); |
| 1053 | |
| 1054 | if (TT.isKnownWindowsMSVCEnvironment()) |
| 1055 | OS << " /EXPORT:"; |
| 1056 | else |
| 1057 | OS << " -export:"; |
| 1058 | |
| 1059 | if (TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment()) { |
| 1060 | std::string Flag; |
| 1061 | raw_string_ostream FlagOS(Flag); |
| 1062 | Mang.getNameWithPrefix(FlagOS, GV, false); |
| 1063 | FlagOS.flush(); |
Mehdi Amini | 5c0fa58 | 2015-07-16 06:04:17 +0000 | [diff] [blame] | 1064 | if (Flag[0] == GV->getParent()->getDataLayout().getGlobalPrefix()) |
Peter Collingbourne | aef3659 | 2015-06-29 22:04:09 +0000 | [diff] [blame] | 1065 | OS << Flag.substr(1); |
| 1066 | else |
| 1067 | OS << Flag; |
| 1068 | } else { |
| 1069 | Mang.getNameWithPrefix(OS, GV, false); |
| 1070 | } |
| 1071 | |
| 1072 | if (!GV->getValueType()->isFunctionTy()) { |
| 1073 | if (TT.isKnownWindowsMSVCEnvironment()) |
| 1074 | OS << ",DATA"; |
| 1075 | else |
| 1076 | OS << ",data"; |
| 1077 | } |
| 1078 | } |