LLVM API Documentation
00001 //===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file assembles .s files and emits ELF .o object files. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/MC/MCELFStreamer.h" 00015 #include "llvm/ADT/STLExtras.h" 00016 #include "llvm/ADT/SmallPtrSet.h" 00017 #include "llvm/MC/MCAsmBackend.h" 00018 #include "llvm/MC/MCAssembler.h" 00019 #include "llvm/MC/MCCodeEmitter.h" 00020 #include "llvm/MC/MCContext.h" 00021 #include "llvm/MC/MCELF.h" 00022 #include "llvm/MC/MCELFSymbolFlags.h" 00023 #include "llvm/MC/MCExpr.h" 00024 #include "llvm/MC/MCInst.h" 00025 #include "llvm/MC/MCObjectFileInfo.h" 00026 #include "llvm/MC/MCObjectStreamer.h" 00027 #include "llvm/MC/MCSection.h" 00028 #include "llvm/MC/MCSectionELF.h" 00029 #include "llvm/MC/MCSymbol.h" 00030 #include "llvm/MC/MCValue.h" 00031 #include "llvm/Support/Debug.h" 00032 #include "llvm/Support/ELF.h" 00033 #include "llvm/Support/ErrorHandling.h" 00034 #include "llvm/Support/raw_ostream.h" 00035 00036 using namespace llvm; 00037 00038 MCELFStreamer::~MCELFStreamer() { 00039 } 00040 00041 void MCELFStreamer::InitSections() { 00042 // This emulates the same behavior of GNU as. This makes it easier 00043 // to compare the output as the major sections are in the same order. 00044 SwitchSection(getContext().getObjectFileInfo()->getTextSection()); 00045 EmitCodeAlignment(4); 00046 00047 SwitchSection(getContext().getObjectFileInfo()->getDataSection()); 00048 EmitCodeAlignment(4); 00049 00050 SwitchSection(getContext().getObjectFileInfo()->getBSSSection()); 00051 EmitCodeAlignment(4); 00052 00053 SwitchSection(getContext().getObjectFileInfo()->getTextSection()); 00054 } 00055 00056 void MCELFStreamer::EmitLabel(MCSymbol *Symbol) { 00057 assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); 00058 00059 MCObjectStreamer::EmitLabel(Symbol); 00060 00061 const MCSectionELF &Section = 00062 static_cast<const MCSectionELF&>(Symbol->getSection()); 00063 MCSymbolData &SD = getAssembler().getSymbolData(*Symbol); 00064 if (Section.getFlags() & ELF::SHF_TLS) 00065 MCELF::SetType(SD, ELF::STT_TLS); 00066 } 00067 00068 void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) { 00069 // Let the target do whatever target specific stuff it needs to do. 00070 getAssembler().getBackend().handleAssemblerFlag(Flag); 00071 // Do any generic stuff we need to do. 00072 switch (Flag) { 00073 case MCAF_SyntaxUnified: return; // no-op here. 00074 case MCAF_Code16: return; // Change parsing mode; no-op here. 00075 case MCAF_Code32: return; // Change parsing mode; no-op here. 00076 case MCAF_Code64: return; // Change parsing mode; no-op here. 00077 case MCAF_SubsectionsViaSymbols: 00078 getAssembler().setSubsectionsViaSymbols(true); 00079 return; 00080 } 00081 00082 llvm_unreachable("invalid assembler flag!"); 00083 } 00084 00085 void MCELFStreamer::ChangeSection(const MCSection *Section, 00086 const MCExpr *Subsection) { 00087 MCSectionData *CurSection = getCurrentSectionData(); 00088 if (CurSection && CurSection->isBundleLocked()) 00089 report_fatal_error("Unterminated .bundle_lock when changing a section"); 00090 const MCSymbol *Grp = static_cast<const MCSectionELF *>(Section)->getGroup(); 00091 if (Grp) 00092 getAssembler().getOrCreateSymbolData(*Grp); 00093 this->MCObjectStreamer::ChangeSection(Section, Subsection); 00094 } 00095 00096 void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { 00097 getAssembler().getOrCreateSymbolData(*Symbol); 00098 const MCExpr *Value = MCSymbolRefExpr::Create( 00099 Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext()); 00100 Alias->setVariableValue(Value); 00101 } 00102 00103 // When GNU as encounters more than one .type declaration for an object it seems 00104 // to use a mechanism similar to the one below to decide which type is actually 00105 // used in the object file. The greater of T1 and T2 is selected based on the 00106 // following ordering: 00107 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else 00108 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user 00109 // provided type). 00110 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) { 00111 unsigned TypeOrdering[] = {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC, 00112 ELF::STT_GNU_IFUNC, ELF::STT_TLS}; 00113 for (unsigned i = 0; i != array_lengthof(TypeOrdering); ++i) { 00114 if (T1 == TypeOrdering[i]) 00115 return T2; 00116 if (T2 == TypeOrdering[i]) 00117 return T1; 00118 } 00119 00120 return T2; 00121 } 00122 00123 bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, 00124 MCSymbolAttr Attribute) { 00125 // Indirect symbols are handled differently, to match how 'as' handles 00126 // them. This makes writing matching .o files easier. 00127 if (Attribute == MCSA_IndirectSymbol) { 00128 // Note that we intentionally cannot use the symbol data here; this is 00129 // important for matching the string table that 'as' generates. 00130 IndirectSymbolData ISD; 00131 ISD.Symbol = Symbol; 00132 ISD.SectionData = getCurrentSectionData(); 00133 getAssembler().getIndirectSymbols().push_back(ISD); 00134 return true; 00135 } 00136 00137 // Adding a symbol attribute always introduces the symbol, note that an 00138 // important side effect of calling getOrCreateSymbolData here is to register 00139 // the symbol with the assembler. 00140 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); 00141 00142 // The implementation of symbol attributes is designed to match 'as', but it 00143 // leaves much to desired. It doesn't really make sense to arbitrarily add and 00144 // remove flags, but 'as' allows this (in particular, see .desc). 00145 // 00146 // In the future it might be worth trying to make these operations more well 00147 // defined. 00148 switch (Attribute) { 00149 case MCSA_LazyReference: 00150 case MCSA_Reference: 00151 case MCSA_SymbolResolver: 00152 case MCSA_PrivateExtern: 00153 case MCSA_WeakDefinition: 00154 case MCSA_WeakDefAutoPrivate: 00155 case MCSA_Invalid: 00156 case MCSA_IndirectSymbol: 00157 return false; 00158 00159 case MCSA_NoDeadStrip: 00160 case MCSA_ELF_TypeGnuUniqueObject: 00161 // Ignore for now. 00162 break; 00163 00164 case MCSA_Global: 00165 MCELF::SetBinding(SD, ELF::STB_GLOBAL); 00166 SD.setExternal(true); 00167 BindingExplicitlySet.insert(Symbol); 00168 break; 00169 00170 case MCSA_WeakReference: 00171 case MCSA_Weak: 00172 MCELF::SetBinding(SD, ELF::STB_WEAK); 00173 SD.setExternal(true); 00174 BindingExplicitlySet.insert(Symbol); 00175 break; 00176 00177 case MCSA_Local: 00178 MCELF::SetBinding(SD, ELF::STB_LOCAL); 00179 SD.setExternal(false); 00180 BindingExplicitlySet.insert(Symbol); 00181 break; 00182 00183 case MCSA_ELF_TypeFunction: 00184 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), 00185 ELF::STT_FUNC)); 00186 break; 00187 00188 case MCSA_ELF_TypeIndFunction: 00189 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), 00190 ELF::STT_GNU_IFUNC)); 00191 break; 00192 00193 case MCSA_ELF_TypeObject: 00194 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), 00195 ELF::STT_OBJECT)); 00196 break; 00197 00198 case MCSA_ELF_TypeTLS: 00199 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), 00200 ELF::STT_TLS)); 00201 break; 00202 00203 case MCSA_ELF_TypeCommon: 00204 // TODO: Emit these as a common symbol. 00205 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), 00206 ELF::STT_OBJECT)); 00207 break; 00208 00209 case MCSA_ELF_TypeNoType: 00210 MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), 00211 ELF::STT_NOTYPE)); 00212 break; 00213 00214 case MCSA_Protected: 00215 MCELF::SetVisibility(SD, ELF::STV_PROTECTED); 00216 break; 00217 00218 case MCSA_Hidden: 00219 MCELF::SetVisibility(SD, ELF::STV_HIDDEN); 00220 break; 00221 00222 case MCSA_Internal: 00223 MCELF::SetVisibility(SD, ELF::STV_INTERNAL); 00224 break; 00225 } 00226 00227 return true; 00228 } 00229 00230 void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, 00231 unsigned ByteAlignment) { 00232 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); 00233 00234 if (!BindingExplicitlySet.count(Symbol)) { 00235 MCELF::SetBinding(SD, ELF::STB_GLOBAL); 00236 SD.setExternal(true); 00237 } 00238 00239 MCELF::SetType(SD, ELF::STT_OBJECT); 00240 00241 if (MCELF::GetBinding(SD) == ELF_STB_Local) { 00242 const MCSection *Section = getAssembler().getContext().getELFSection(".bss", 00243 ELF::SHT_NOBITS, 00244 ELF::SHF_WRITE | 00245 ELF::SHF_ALLOC, 00246 SectionKind::getBSS()); 00247 00248 AssignSection(Symbol, Section); 00249 00250 struct LocalCommon L = {&SD, Size, ByteAlignment}; 00251 LocalCommons.push_back(L); 00252 } else { 00253 SD.setCommon(Size, ByteAlignment); 00254 } 00255 00256 SD.setSize(MCConstantExpr::Create(Size, getContext())); 00257 } 00258 00259 void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) { 00260 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); 00261 SD.setSize(Value); 00262 } 00263 00264 void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, 00265 unsigned ByteAlignment) { 00266 // FIXME: Should this be caught and done earlier? 00267 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); 00268 MCELF::SetBinding(SD, ELF::STB_LOCAL); 00269 SD.setExternal(false); 00270 BindingExplicitlySet.insert(Symbol); 00271 EmitCommonSymbol(Symbol, Size, ByteAlignment); 00272 } 00273 00274 void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, 00275 const SMLoc &Loc) { 00276 if (getCurrentSectionData()->isBundleLocked()) 00277 report_fatal_error("Emitting values inside a locked bundle is forbidden"); 00278 fixSymbolsInTLSFixups(Value); 00279 MCObjectStreamer::EmitValueImpl(Value, Size, Loc); 00280 } 00281 00282 void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment, 00283 int64_t Value, 00284 unsigned ValueSize, 00285 unsigned MaxBytesToEmit) { 00286 if (getCurrentSectionData()->isBundleLocked()) 00287 report_fatal_error("Emitting values inside a locked bundle is forbidden"); 00288 MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value, 00289 ValueSize, MaxBytesToEmit); 00290 } 00291 00292 // Add a symbol for the file name of this module. They start after the 00293 // null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol 00294 // with the same name may appear. 00295 void MCELFStreamer::EmitFileDirective(StringRef Filename) { 00296 getAssembler().addFileName(Filename); 00297 } 00298 00299 void MCELFStreamer::EmitIdent(StringRef IdentString) { 00300 const MCSection *Comment = getAssembler().getContext().getELFSection( 00301 ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 00302 SectionKind::getReadOnly(), 1, ""); 00303 PushSection(); 00304 SwitchSection(Comment); 00305 if (!SeenIdent) { 00306 EmitIntValue(0, 1); 00307 SeenIdent = true; 00308 } 00309 EmitBytes(IdentString); 00310 EmitIntValue(0, 1); 00311 PopSection(); 00312 } 00313 00314 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) { 00315 switch (expr->getKind()) { 00316 case MCExpr::Target: 00317 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler()); 00318 break; 00319 case MCExpr::Constant: 00320 break; 00321 00322 case MCExpr::Binary: { 00323 const MCBinaryExpr *be = cast<MCBinaryExpr>(expr); 00324 fixSymbolsInTLSFixups(be->getLHS()); 00325 fixSymbolsInTLSFixups(be->getRHS()); 00326 break; 00327 } 00328 00329 case MCExpr::SymbolRef: { 00330 const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr); 00331 switch (symRef.getKind()) { 00332 default: 00333 return; 00334 case MCSymbolRefExpr::VK_GOTTPOFF: 00335 case MCSymbolRefExpr::VK_INDNTPOFF: 00336 case MCSymbolRefExpr::VK_NTPOFF: 00337 case MCSymbolRefExpr::VK_GOTNTPOFF: 00338 case MCSymbolRefExpr::VK_TLSGD: 00339 case MCSymbolRefExpr::VK_TLSLD: 00340 case MCSymbolRefExpr::VK_TLSLDM: 00341 case MCSymbolRefExpr::VK_TPOFF: 00342 case MCSymbolRefExpr::VK_DTPOFF: 00343 case MCSymbolRefExpr::VK_Mips_TLSGD: 00344 case MCSymbolRefExpr::VK_Mips_GOTTPREL: 00345 case MCSymbolRefExpr::VK_Mips_TPREL_HI: 00346 case MCSymbolRefExpr::VK_Mips_TPREL_LO: 00347 case MCSymbolRefExpr::VK_PPC_DTPMOD: 00348 case MCSymbolRefExpr::VK_PPC_TPREL: 00349 case MCSymbolRefExpr::VK_PPC_TPREL_LO: 00350 case MCSymbolRefExpr::VK_PPC_TPREL_HI: 00351 case MCSymbolRefExpr::VK_PPC_TPREL_HA: 00352 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER: 00353 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA: 00354 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST: 00355 case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA: 00356 case MCSymbolRefExpr::VK_PPC_DTPREL: 00357 case MCSymbolRefExpr::VK_PPC_DTPREL_LO: 00358 case MCSymbolRefExpr::VK_PPC_DTPREL_HI: 00359 case MCSymbolRefExpr::VK_PPC_DTPREL_HA: 00360 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER: 00361 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA: 00362 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST: 00363 case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA: 00364 case MCSymbolRefExpr::VK_PPC_GOT_TPREL: 00365 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO: 00366 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI: 00367 case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA: 00368 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL: 00369 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO: 00370 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI: 00371 case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA: 00372 case MCSymbolRefExpr::VK_PPC_TLS: 00373 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD: 00374 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO: 00375 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI: 00376 case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA: 00377 case MCSymbolRefExpr::VK_PPC_TLSGD: 00378 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD: 00379 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO: 00380 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI: 00381 case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA: 00382 case MCSymbolRefExpr::VK_PPC_TLSLD: 00383 break; 00384 } 00385 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(symRef.getSymbol()); 00386 MCELF::SetType(SD, ELF::STT_TLS); 00387 break; 00388 } 00389 00390 case MCExpr::Unary: 00391 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr()); 00392 break; 00393 } 00394 } 00395 00396 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst, 00397 const MCSubtargetInfo &STI) { 00398 this->MCObjectStreamer::EmitInstToFragment(Inst, STI); 00399 MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment()); 00400 00401 for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i) 00402 fixSymbolsInTLSFixups(F.getFixups()[i].getValue()); 00403 } 00404 00405 void MCELFStreamer::EmitInstToData(const MCInst &Inst, 00406 const MCSubtargetInfo &STI) { 00407 MCAssembler &Assembler = getAssembler(); 00408 SmallVector<MCFixup, 4> Fixups; 00409 SmallString<256> Code; 00410 raw_svector_ostream VecOS(Code); 00411 Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups, STI); 00412 VecOS.flush(); 00413 00414 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) 00415 fixSymbolsInTLSFixups(Fixups[i].getValue()); 00416 00417 // There are several possibilities here: 00418 // 00419 // If bundling is disabled, append the encoded instruction to the current data 00420 // fragment (or create a new such fragment if the current fragment is not a 00421 // data fragment). 00422 // 00423 // If bundling is enabled: 00424 // - If we're not in a bundle-locked group, emit the instruction into a 00425 // fragment of its own. If there are no fixups registered for the 00426 // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a 00427 // MCDataFragment. 00428 // - If we're in a bundle-locked group, append the instruction to the current 00429 // data fragment because we want all the instructions in a group to get into 00430 // the same fragment. Be careful not to do that for the first instruction in 00431 // the group, though. 00432 MCDataFragment *DF; 00433 00434 if (Assembler.isBundlingEnabled()) { 00435 MCSectionData *SD = getCurrentSectionData(); 00436 if (SD->isBundleLocked() && !SD->isBundleGroupBeforeFirstInst()) 00437 // If we are bundle-locked, we re-use the current fragment. 00438 // The bundle-locking directive ensures this is a new data fragment. 00439 DF = cast<MCDataFragment>(getCurrentFragment()); 00440 else if (!SD->isBundleLocked() && Fixups.size() == 0) { 00441 // Optimize memory usage by emitting the instruction to a 00442 // MCCompactEncodedInstFragment when not in a bundle-locked group and 00443 // there are no fixups registered. 00444 MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment(); 00445 insert(CEIF); 00446 CEIF->getContents().append(Code.begin(), Code.end()); 00447 return; 00448 } else { 00449 DF = new MCDataFragment(); 00450 insert(DF); 00451 if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) { 00452 // If this is a new fragment created for a bundle-locked group, and the 00453 // group was marked as "align_to_end", set a flag in the fragment. 00454 DF->setAlignToBundleEnd(true); 00455 } 00456 } 00457 00458 // We're now emitting an instruction in a bundle group, so this flag has 00459 // to be turned off. 00460 SD->setBundleGroupBeforeFirstInst(false); 00461 } else { 00462 DF = getOrCreateDataFragment(); 00463 } 00464 00465 // Add the fixups and data. 00466 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { 00467 Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size()); 00468 DF->getFixups().push_back(Fixups[i]); 00469 } 00470 DF->setHasInstructions(true); 00471 DF->getContents().append(Code.begin(), Code.end()); 00472 } 00473 00474 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) { 00475 assert(AlignPow2 <= 30 && "Invalid bundle alignment"); 00476 MCAssembler &Assembler = getAssembler(); 00477 if (Assembler.getBundleAlignSize() == 0 && AlignPow2 > 0) 00478 Assembler.setBundleAlignSize(1 << AlignPow2); 00479 else 00480 report_fatal_error(".bundle_align_mode should be only set once per file"); 00481 } 00482 00483 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) { 00484 MCSectionData *SD = getCurrentSectionData(); 00485 00486 // Sanity checks 00487 // 00488 if (!getAssembler().isBundlingEnabled()) 00489 report_fatal_error(".bundle_lock forbidden when bundling is disabled"); 00490 else if (SD->isBundleLocked()) 00491 report_fatal_error("Nesting of .bundle_lock is forbidden"); 00492 00493 SD->setBundleLockState(AlignToEnd ? MCSectionData::BundleLockedAlignToEnd : 00494 MCSectionData::BundleLocked); 00495 SD->setBundleGroupBeforeFirstInst(true); 00496 } 00497 00498 void MCELFStreamer::EmitBundleUnlock() { 00499 MCSectionData *SD = getCurrentSectionData(); 00500 00501 // Sanity checks 00502 if (!getAssembler().isBundlingEnabled()) 00503 report_fatal_error(".bundle_unlock forbidden when bundling is disabled"); 00504 else if (!SD->isBundleLocked()) 00505 report_fatal_error(".bundle_unlock without matching lock"); 00506 else if (SD->isBundleGroupBeforeFirstInst()) 00507 report_fatal_error("Empty bundle-locked group is forbidden"); 00508 00509 SD->setBundleLockState(MCSectionData::NotBundleLocked); 00510 } 00511 00512 void MCELFStreamer::Flush() { 00513 for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(), 00514 e = LocalCommons.end(); 00515 i != e; ++i) { 00516 MCSymbolData *SD = i->SD; 00517 uint64_t Size = i->Size; 00518 unsigned ByteAlignment = i->ByteAlignment; 00519 const MCSymbol &Symbol = SD->getSymbol(); 00520 const MCSection &Section = Symbol.getSection(); 00521 00522 MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section); 00523 new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData); 00524 00525 MCFragment *F = new MCFillFragment(0, 0, Size, &SectData); 00526 SD->setFragment(F); 00527 00528 // Update the maximum alignment of the section if necessary. 00529 if (ByteAlignment > SectData.getAlignment()) 00530 SectData.setAlignment(ByteAlignment); 00531 } 00532 00533 LocalCommons.clear(); 00534 } 00535 00536 void MCELFStreamer::FinishImpl() { 00537 EmitFrames(nullptr); 00538 00539 Flush(); 00540 00541 this->MCObjectStreamer::FinishImpl(); 00542 } 00543 00544 MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB, 00545 raw_ostream &OS, MCCodeEmitter *CE, 00546 bool RelaxAll, bool NoExecStack) { 00547 MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE); 00548 if (RelaxAll) 00549 S->getAssembler().setRelaxAll(true); 00550 if (NoExecStack) 00551 S->getAssembler().setNoExecStack(true); 00552 return S; 00553 } 00554 00555 void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) { 00556 llvm_unreachable("Generic ELF doesn't support this directive"); 00557 } 00558 00559 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { 00560 llvm_unreachable("ELF doesn't support this directive"); 00561 } 00562 00563 void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) { 00564 llvm_unreachable("ELF doesn't support this directive"); 00565 } 00566 00567 void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) { 00568 llvm_unreachable("ELF doesn't support this directive"); 00569 } 00570 00571 void MCELFStreamer::EmitCOFFSymbolType(int Type) { 00572 llvm_unreachable("ELF doesn't support this directive"); 00573 } 00574 00575 void MCELFStreamer::EndCOFFSymbolDef() { 00576 llvm_unreachable("ELF doesn't support this directive"); 00577 } 00578 00579 void MCELFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol, 00580 uint64_t Size, unsigned ByteAlignment) { 00581 llvm_unreachable("ELF doesn't support this directive"); 00582 } 00583 00584 void MCELFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, 00585 uint64_t Size, unsigned ByteAlignment) { 00586 llvm_unreachable("ELF doesn't support this directive"); 00587 }