Nick Lewycky | c1f9694 | 2013-03-09 09:31:44 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===// |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file assembles .s files and emits ELF .o object files. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCELFStreamer.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallString.h" |
| 15 | #include "llvm/ADT/SmallVector.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 16 | #include "llvm/BinaryFormat/ELF.h" |
David Peixotto | 7266731 | 2013-11-25 19:11:13 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCAsmBackend.h" |
Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCAsmInfo.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCAssembler.h" |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCCodeEmitter.h" |
Rafael Espindola | 81a6274 | 2012-01-07 23:18:39 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCContext.h" |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCExpr.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCFixup.h" |
| 24 | #include "llvm/MC/MCFragment.h" |
Rafael Espindola | e308c0c | 2014-01-23 22:49:25 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCObjectFileInfo.h" |
Reid Kleckner | 0801d12 | 2016-06-22 23:25:26 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCObjectWriter.h" |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCSection.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCSectionELF.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCStreamer.h" |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCSymbol.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCSymbolELF.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Casting.h" |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Rafael Espindola | cd584a8 | 2015-03-19 01:50:16 +0000 | [diff] [blame] | 34 | #include "llvm/Support/TargetRegistry.h" |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 36 | #include <cassert> |
| 37 | #include <cstdint> |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 38 | |
| 39 | using namespace llvm; |
| 40 | |
Lang Hames | 02d3305 | 2017-10-11 01:57:21 +0000 | [diff] [blame] | 41 | MCELFStreamer::MCELFStreamer(MCContext &Context, |
| 42 | std::unique_ptr<MCAsmBackend> TAB, |
Peter Collingbourne | f7b81db | 2018-05-18 18:26:45 +0000 | [diff] [blame] | 43 | std::unique_ptr<MCObjectWriter> OW, |
Lang Hames | 2241ffa | 2017-10-11 23:34:47 +0000 | [diff] [blame] | 44 | std::unique_ptr<MCCodeEmitter> Emitter) |
Peter Collingbourne | f7b81db | 2018-05-18 18:26:45 +0000 | [diff] [blame] | 45 | : MCObjectStreamer(Context, std::move(TAB), std::move(OW), |
| 46 | std::move(Emitter)) {} |
Lang Hames | 02d3305 | 2017-10-11 01:57:21 +0000 | [diff] [blame] | 47 | |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 48 | bool MCELFStreamer::isBundleLocked() const { |
Rafael Espindola | 983bec6 | 2015-05-27 21:04:14 +0000 | [diff] [blame] | 49 | return getCurrentSectionOnly()->isBundleLocked(); |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 52 | void MCELFStreamer::mergeFragment(MCDataFragment *DF, |
Pete Cooper | e0d4037 | 2015-06-17 22:01:28 +0000 | [diff] [blame] | 53 | MCDataFragment *EF) { |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 54 | MCAssembler &Assembler = getAssembler(); |
| 55 | |
| 56 | if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) { |
| 57 | uint64_t FSize = EF->getContents().size(); |
| 58 | |
| 59 | if (FSize > Assembler.getBundleAlignSize()) |
| 60 | report_fatal_error("Fragment can't be larger than a bundle size"); |
| 61 | |
| 62 | uint64_t RequiredBundlePadding = computeBundlePadding( |
| 63 | Assembler, EF, DF->getContents().size(), FSize); |
| 64 | |
| 65 | if (RequiredBundlePadding > UINT8_MAX) |
| 66 | report_fatal_error("Padding cannot exceed 255 bytes"); |
| 67 | |
| 68 | if (RequiredBundlePadding > 0) { |
| 69 | SmallString<256> Code; |
| 70 | raw_svector_ostream VecOS(Code); |
Peter Collingbourne | 147db3e | 2018-05-21 18:11:35 +0000 | [diff] [blame] | 71 | EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding)); |
| 72 | Assembler.writeFragmentPadding(VecOS, *EF, FSize); |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 73 | |
| 74 | DF->getContents().append(Code.begin(), Code.end()); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | flushPendingLabels(DF, DF->getContents().size()); |
| 79 | |
| 80 | for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) { |
| 81 | EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() + |
| 82 | DF->getContents().size()); |
| 83 | DF->getFixups().push_back(EF->getFixups()[i]); |
| 84 | } |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 85 | if (DF->getSubtargetInfo() == nullptr && EF->getSubtargetInfo()) |
| 86 | DF->setHasInstructions(*EF->getSubtargetInfo()); |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 87 | DF->getContents().append(EF->getContents().begin(), EF->getContents().end()); |
| 88 | } |
| 89 | |
Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 90 | void MCELFStreamer::InitSections(bool NoExecStack) { |
Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 91 | MCContext &Ctx = getContext(); |
| 92 | SwitchSection(Ctx.getObjectFileInfo()->getTextSection()); |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 93 | emitCodeAlignment(4); |
Rafael Espindola | 247f951 | 2014-01-24 02:18:40 +0000 | [diff] [blame] | 94 | |
Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 95 | if (NoExecStack) |
| 96 | SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx)); |
Rafael Espindola | f667d92 | 2010-09-15 21:48:40 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 99 | void MCELFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 100 | auto *Symbol = cast<MCSymbolELF>(S); |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 101 | MCObjectStreamer::emitLabel(Symbol, Loc); |
Rafael Espindola | 75d65b9 | 2010-09-25 05:42:19 +0000 | [diff] [blame] | 102 | |
Rafael Espindola | 84d0318 | 2010-11-11 19:04:55 +0000 | [diff] [blame] | 103 | const MCSectionELF &Section = |
Rafael Espindola | e3a20f5 | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 104 | static_cast<const MCSectionELF &>(*getCurrentSectionOnly()); |
Rafael Espindola | 0e7e34e | 2011-01-23 04:43:11 +0000 | [diff] [blame] | 105 | if (Section.getFlags() & ELF::SHF_TLS) |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 106 | Symbol->setType(ELF::STT_TLS); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Fangrui Song | 0bc77a0 | 2020-02-13 13:26:21 -0800 | [diff] [blame] | 109 | void MCELFStreamer::emitLabelAtPos(MCSymbol *S, SMLoc Loc, MCFragment *F, |
James Y Knight | bf142fc | 2019-11-10 16:12:29 -0500 | [diff] [blame] | 110 | uint64_t Offset) { |
Weiming Zhao | 74a7fa0 | 2017-04-03 21:50:04 +0000 | [diff] [blame] | 111 | auto *Symbol = cast<MCSymbolELF>(S); |
Fangrui Song | 0bc77a0 | 2020-02-13 13:26:21 -0800 | [diff] [blame] | 112 | MCObjectStreamer::emitLabelAtPos(Symbol, Loc, F, Offset); |
Weiming Zhao | 74a7fa0 | 2017-04-03 21:50:04 +0000 | [diff] [blame] | 113 | |
| 114 | const MCSectionELF &Section = |
| 115 | static_cast<const MCSectionELF &>(*getCurrentSectionOnly()); |
| 116 | if (Section.getFlags() & ELF::SHF_TLS) |
| 117 | Symbol->setType(ELF::STT_TLS); |
| 118 | } |
| 119 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 120 | void MCELFStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) { |
David Peixotto | 7266731 | 2013-11-25 19:11:13 +0000 | [diff] [blame] | 121 | // Let the target do whatever target specific stuff it needs to do. |
| 122 | getAssembler().getBackend().handleAssemblerFlag(Flag); |
| 123 | // Do any generic stuff we need to do. |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 124 | switch (Flag) { |
Jim Grosbach | 5a2c68d | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 125 | case MCAF_SyntaxUnified: return; // no-op here. |
Evan Cheng | 481ebb0 | 2011-07-27 00:38:12 +0000 | [diff] [blame] | 126 | case MCAF_Code16: return; // Change parsing mode; no-op here. |
| 127 | case MCAF_Code32: return; // Change parsing mode; no-op here. |
| 128 | case MCAF_Code64: return; // Change parsing mode; no-op here. |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 129 | case MCAF_SubsectionsViaSymbols: |
| 130 | getAssembler().setSubsectionsViaSymbols(true); |
| 131 | return; |
| 132 | } |
| 133 | |
Craig Topper | a2886c2 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 134 | llvm_unreachable("invalid assembler flag!"); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 137 | // If bundle alignment is used and there are any instructions in the section, it |
Derek Schuff | 2a1678a | 2015-04-21 00:14:25 +0000 | [diff] [blame] | 138 | // needs to be aligned to at least the bundle size. |
Rafael Espindola | cd62518 | 2015-05-25 18:34:26 +0000 | [diff] [blame] | 139 | static void setSectionAlignmentForBundling(const MCAssembler &Assembler, |
Rafael Espindola | e6e287d | 2015-05-26 14:42:52 +0000 | [diff] [blame] | 140 | MCSection *Section) { |
| 141 | if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() && |
| 142 | Section->getAlignment() < Assembler.getBundleAlignSize()) |
Guillaume Chatelet | 18f805a | 2019-09-27 12:54:21 +0000 | [diff] [blame] | 143 | Section->setAlignment(Align(Assembler.getBundleAlignSize())); |
Derek Schuff | 2a1678a | 2015-04-21 00:14:25 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 146 | void MCELFStreamer::ChangeSection(MCSection *Section, |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 147 | const MCExpr *Subsection) { |
Rafael Espindola | 983bec6 | 2015-05-27 21:04:14 +0000 | [diff] [blame] | 148 | MCSection *CurSection = getCurrentSectionOnly(); |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 149 | if (CurSection && isBundleLocked()) |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 150 | report_fatal_error("Unterminated .bundle_lock when changing a section"); |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 151 | |
| 152 | MCAssembler &Asm = getAssembler(); |
Derek Schuff | 2a1678a | 2015-04-21 00:14:25 +0000 | [diff] [blame] | 153 | // Ensure the previous section gets aligned if necessary. |
| 154 | setSectionAlignmentForBundling(Asm, CurSection); |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 155 | auto *SectionELF = static_cast<const MCSectionELF *>(Section); |
| 156 | const MCSymbol *Grp = SectionELF->getGroup(); |
Rafael Espindola | 7d0ba34 | 2010-11-14 04:17:37 +0000 | [diff] [blame] | 157 | if (Grp) |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 158 | Asm.registerSymbol(*Grp); |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 159 | |
David Blaikie | 618d342 | 2017-03-16 00:43:19 +0000 | [diff] [blame] | 160 | changeSectionImpl(Section, Subsection); |
Rafael Espindola | 13a79bb | 2017-02-02 21:26:06 +0000 | [diff] [blame] | 161 | Asm.registerSymbol(*Section->getBeginSymbol()); |
Rafael Espindola | 7d0ba34 | 2010-11-14 04:17:37 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 164 | void MCELFStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 165 | getAssembler().registerSymbol(*Symbol); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 166 | const MCExpr *Value = MCSymbolRefExpr::create( |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 167 | Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext()); |
Rafael Espindola | 1614597 | 2010-11-01 14:28:48 +0000 | [diff] [blame] | 168 | Alias->setVariableValue(Value); |
| 169 | } |
| 170 | |
Peter Collingbourne | adac407 | 2013-04-10 16:52:15 +0000 | [diff] [blame] | 171 | // When GNU as encounters more than one .type declaration for an object it seems |
| 172 | // to use a mechanism similar to the one below to decide which type is actually |
| 173 | // used in the object file. The greater of T1 and T2 is selected based on the |
| 174 | // following ordering: |
| 175 | // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else |
| 176 | // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user |
| 177 | // provided type). |
| 178 | static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) { |
Benjamin Kramer | 867bfc5 | 2015-03-07 17:41:00 +0000 | [diff] [blame] | 179 | for (unsigned Type : {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC, |
| 180 | ELF::STT_GNU_IFUNC, ELF::STT_TLS}) { |
| 181 | if (T1 == Type) |
Peter Collingbourne | adac407 | 2013-04-10 16:52:15 +0000 | [diff] [blame] | 182 | return T2; |
Benjamin Kramer | 867bfc5 | 2015-03-07 17:41:00 +0000 | [diff] [blame] | 183 | if (T2 == Type) |
Peter Collingbourne | adac407 | 2013-04-10 16:52:15 +0000 | [diff] [blame] | 184 | return T1; |
| 185 | } |
| 186 | |
| 187 | return T2; |
| 188 | } |
| 189 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 190 | bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 191 | auto *Symbol = cast<MCSymbolELF>(S); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 192 | |
| 193 | // Adding a symbol attribute always introduces the symbol, note that an |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 194 | // important side effect of calling registerSymbol here is to register |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 195 | // the symbol with the assembler. |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 196 | getAssembler().registerSymbol(*Symbol); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 197 | |
| 198 | // The implementation of symbol attributes is designed to match 'as', but it |
| 199 | // leaves much to desired. It doesn't really make sense to arbitrarily add and |
| 200 | // remove flags, but 'as' allows this (in particular, see .desc). |
| 201 | // |
| 202 | // In the future it might be worth trying to make these operations more well |
| 203 | // defined. |
| 204 | switch (Attribute) { |
Vedant Kumar | 13ef84f | 2019-01-25 18:30:22 +0000 | [diff] [blame] | 205 | case MCSA_Cold: |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 206 | case MCSA_LazyReference: |
| 207 | case MCSA_Reference: |
Kevin Enderby | 8be1441 | 2010-11-19 18:39:33 +0000 | [diff] [blame] | 208 | case MCSA_SymbolResolver: |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 209 | case MCSA_PrivateExtern: |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 210 | case MCSA_WeakDefinition: |
Eli Friedman | b20b524 | 2010-08-16 19:15:06 +0000 | [diff] [blame] | 211 | case MCSA_WeakDefAutoPrivate: |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 212 | case MCSA_Invalid: |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 213 | case MCSA_IndirectSymbol: |
Saleem Abdulrasool | 4208b61 | 2013-08-09 01:52:03 +0000 | [diff] [blame] | 214 | return false; |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 215 | |
Jim Grosbach | b7b750d | 2012-09-13 23:11:31 +0000 | [diff] [blame] | 216 | case MCSA_NoDeadStrip: |
Rafael Espindola | eba9022 | 2010-11-14 01:34:31 +0000 | [diff] [blame] | 217 | // Ignore for now. |
| 218 | break; |
| 219 | |
Rafael Espindola | 5fa925e | 2015-01-23 04:44:35 +0000 | [diff] [blame] | 220 | case MCSA_ELF_TypeGnuUniqueObject: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 221 | Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT)); |
| 222 | Symbol->setBinding(ELF::STB_GNU_UNIQUE); |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 223 | Symbol->setExternal(true); |
Rafael Espindola | 5fa925e | 2015-01-23 04:44:35 +0000 | [diff] [blame] | 224 | break; |
| 225 | |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 226 | case MCSA_Global: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 227 | Symbol->setBinding(ELF::STB_GLOBAL); |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 228 | Symbol->setExternal(true); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 229 | break; |
| 230 | |
Benjamin Kramer | 5af02b0 | 2010-09-02 17:18:32 +0000 | [diff] [blame] | 231 | case MCSA_WeakReference: |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 232 | case MCSA_Weak: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 233 | Symbol->setBinding(ELF::STB_WEAK); |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 234 | Symbol->setExternal(true); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 235 | break; |
| 236 | |
| 237 | case MCSA_Local: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 238 | Symbol->setBinding(ELF::STB_LOCAL); |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 239 | Symbol->setExternal(false); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 240 | break; |
| 241 | |
| 242 | case MCSA_ELF_TypeFunction: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 243 | Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC)); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 244 | break; |
| 245 | |
Roman Divacky | 735cb8b | 2011-12-12 17:34:04 +0000 | [diff] [blame] | 246 | case MCSA_ELF_TypeIndFunction: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 247 | Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC)); |
Roman Divacky | 735cb8b | 2011-12-12 17:34:04 +0000 | [diff] [blame] | 248 | break; |
| 249 | |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 250 | case MCSA_ELF_TypeObject: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 251 | Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT)); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 252 | break; |
| 253 | |
| 254 | case MCSA_ELF_TypeTLS: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 255 | Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS)); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 256 | break; |
| 257 | |
| 258 | case MCSA_ELF_TypeCommon: |
Peter Collingbourne | adac407 | 2013-04-10 16:52:15 +0000 | [diff] [blame] | 259 | // TODO: Emit these as a common symbol. |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 260 | Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT)); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 261 | break; |
| 262 | |
| 263 | case MCSA_ELF_TypeNoType: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 264 | Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE)); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 265 | break; |
| 266 | |
| 267 | case MCSA_Protected: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 268 | Symbol->setVisibility(ELF::STV_PROTECTED); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 269 | break; |
| 270 | |
| 271 | case MCSA_Hidden: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 272 | Symbol->setVisibility(ELF::STV_HIDDEN); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 273 | break; |
| 274 | |
| 275 | case MCSA_Internal: |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 276 | Symbol->setVisibility(ELF::STV_INTERNAL); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 277 | break; |
Lang Hames | 1b640e0 | 2016-03-15 01:43:05 +0000 | [diff] [blame] | 278 | |
| 279 | case MCSA_AltEntry: |
Lang Hames | f9033bb | 2016-04-11 18:33:45 +0000 | [diff] [blame] | 280 | llvm_unreachable("ELF doesn't support the .alt_entry attribute"); |
Xiangling Liao | 3b808fb | 2019-09-26 19:38:32 +0000 | [diff] [blame] | 281 | |
| 282 | case MCSA_LGlobal: |
| 283 | llvm_unreachable("ELF doesn't support the .lglobl attribute"); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 284 | } |
Saleem Abdulrasool | 4208b61 | 2013-08-09 01:52:03 +0000 | [diff] [blame] | 285 | |
| 286 | return true; |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 289 | void MCELFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size, |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 290 | unsigned ByteAlignment) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 291 | auto *Symbol = cast<MCSymbolELF>(S); |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 292 | getAssembler().registerSymbol(*Symbol); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 293 | |
Rafael Espindola | f6dcd2a | 2015-06-03 21:18:03 +0000 | [diff] [blame] | 294 | if (!Symbol->isBindingSet()) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 295 | Symbol->setBinding(ELF::STB_GLOBAL); |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 296 | Symbol->setExternal(true); |
Rafael Espindola | f0591c1 | 2010-09-21 00:24:38 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 299 | Symbol->setType(ELF::STT_OBJECT); |
Rafael Espindola | a7d0bed | 2010-11-14 21:11:16 +0000 | [diff] [blame] | 300 | |
Rafael Espindola | f8794ff | 2015-06-04 00:47:43 +0000 | [diff] [blame] | 301 | if (Symbol->getBinding() == ELF::STB_LOCAL) { |
Rafael Espindola | e7fe1a4 | 2015-11-03 18:50:51 +0000 | [diff] [blame] | 302 | MCSection &Section = *getAssembler().getContext().getELFSection( |
| 303 | ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); |
| 304 | MCSectionSubPair P = getCurrentSection(); |
| 305 | SwitchSection(&Section); |
| 306 | |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 307 | emitValueToAlignment(ByteAlignment, 0, 1, 0); |
| 308 | emitLabel(Symbol); |
Fangrui Song | 549b436 | 2020-02-15 08:52:56 -0800 | [diff] [blame^] | 309 | emitZeros(Size); |
Rafael Espindola | e7fe1a4 | 2015-11-03 18:50:51 +0000 | [diff] [blame] | 310 | |
Rafael Espindola | e7fe1a4 | 2015-11-03 18:50:51 +0000 | [diff] [blame] | 311 | SwitchSection(P.first, P.second); |
Rafael Espindola | f0591c1 | 2010-09-21 00:24:38 +0000 | [diff] [blame] | 312 | } else { |
Colin LeMahieu | 1c8c213 | 2015-06-06 20:12:40 +0000 | [diff] [blame] | 313 | if(Symbol->declareCommon(Size, ByteAlignment)) |
| 314 | report_fatal_error("Symbol: " + Symbol->getName() + |
| 315 | " redeclared as different type"); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 318 | cast<MCSymbolELF>(Symbol) |
| 319 | ->setSize(MCConstantExpr::create(Size, getContext())); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Dan Gohman | 734c59d | 2016-12-01 23:39:08 +0000 | [diff] [blame] | 322 | void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) { |
| 323 | cast<MCSymbolELF>(Symbol)->setSize(Value); |
Logan Chien | 59ff070 | 2012-12-07 15:50:40 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Rafael Espindola | 47b4d6b | 2018-03-09 18:42:25 +0000 | [diff] [blame] | 326 | void MCELFStreamer::emitELFSymverDirective(StringRef AliasName, |
Rafael Espindola | 81e911c | 2018-03-09 03:13:37 +0000 | [diff] [blame] | 327 | const MCSymbol *Aliasee) { |
Rafael Espindola | 47b4d6b | 2018-03-09 18:42:25 +0000 | [diff] [blame] | 328 | getAssembler().Symvers.push_back({AliasName, Aliasee}); |
Rafael Espindola | 81e911c | 2018-03-09 03:13:37 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 331 | void MCELFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size, |
Benjamin Kramer | 6397051 | 2011-09-01 23:04:27 +0000 | [diff] [blame] | 332 | unsigned ByteAlignment) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 333 | auto *Symbol = cast<MCSymbolELF>(S); |
Jason W Kim | 4c1386a | 2010-12-16 03:12:17 +0000 | [diff] [blame] | 334 | // FIXME: Should this be caught and done earlier? |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 335 | getAssembler().registerSymbol(*Symbol); |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 336 | Symbol->setBinding(ELF::STB_LOCAL); |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 337 | Symbol->setExternal(false); |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 338 | emitCommonSymbol(Symbol, Size, ByteAlignment); |
Jason W Kim | 4c1386a | 2010-12-16 03:12:17 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 341 | void MCELFStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, |
Craig Topper | 3c76c52 | 2015-09-20 23:35:59 +0000 | [diff] [blame] | 342 | SMLoc Loc) { |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 343 | if (isBundleLocked()) |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 344 | report_fatal_error("Emitting values inside a locked bundle is forbidden"); |
David Meyer | 44ec69e | 2012-02-15 15:09:06 +0000 | [diff] [blame] | 345 | fixSymbolsInTLSFixups(Value); |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 346 | MCObjectStreamer::emitValueImpl(Value, Size, Loc); |
David Meyer | 44ec69e | 2012-02-15 15:09:06 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 349 | void MCELFStreamer::emitValueToAlignment(unsigned ByteAlignment, |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 350 | int64_t Value, |
| 351 | unsigned ValueSize, |
| 352 | unsigned MaxBytesToEmit) { |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 353 | if (isBundleLocked()) |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 354 | report_fatal_error("Emitting values inside a locked bundle is forbidden"); |
Fangrui Song | 6d2d589 | 2020-02-14 19:21:58 -0800 | [diff] [blame] | 355 | MCObjectStreamer::emitValueToAlignment(ByteAlignment, Value, |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 356 | ValueSize, MaxBytesToEmit); |
| 357 | } |
| 358 | |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 359 | void MCELFStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From, |
| 360 | const MCSymbolRefExpr *To, |
| 361 | uint64_t Count) { |
| 362 | getAssembler().CGProfile.push_back({From, To, Count}); |
| 363 | } |
| 364 | |
Fangrui Song | 549b436 | 2020-02-15 08:52:56 -0800 | [diff] [blame^] | 365 | void MCELFStreamer::emitIdent(StringRef IdentString) { |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 366 | MCSection *Comment = getAssembler().getContext().getELFSection( |
Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 367 | ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, ""); |
Rafael Espindola | 5645bad | 2013-10-16 01:05:45 +0000 | [diff] [blame] | 368 | PushSection(); |
| 369 | SwitchSection(Comment); |
| 370 | if (!SeenIdent) { |
Fangrui Song | 7749710 | 2020-02-14 22:40:47 -0800 | [diff] [blame] | 371 | emitIntValue(0, 1); |
Rafael Espindola | 5645bad | 2013-10-16 01:05:45 +0000 | [diff] [blame] | 372 | SeenIdent = true; |
| 373 | } |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 374 | emitBytes(IdentString); |
Fangrui Song | 7749710 | 2020-02-14 22:40:47 -0800 | [diff] [blame] | 375 | emitIntValue(0, 1); |
Rafael Espindola | 5645bad | 2013-10-16 01:05:45 +0000 | [diff] [blame] | 376 | PopSection(); |
| 377 | } |
| 378 | |
| 379 | void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) { |
Rafael Espindola | 4e70ac7 | 2010-11-24 02:19:40 +0000 | [diff] [blame] | 380 | switch (expr->getKind()) { |
Tim Northover | e0e3aef | 2013-01-31 12:12:40 +0000 | [diff] [blame] | 381 | case MCExpr::Target: |
| 382 | cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler()); |
| 383 | break; |
Rafael Espindola | 4e70ac7 | 2010-11-24 02:19:40 +0000 | [diff] [blame] | 384 | case MCExpr::Constant: |
| 385 | break; |
| 386 | |
| 387 | case MCExpr::Binary: { |
| 388 | const MCBinaryExpr *be = cast<MCBinaryExpr>(expr); |
| 389 | fixSymbolsInTLSFixups(be->getLHS()); |
| 390 | fixSymbolsInTLSFixups(be->getRHS()); |
| 391 | break; |
| 392 | } |
| 393 | |
| 394 | case MCExpr::SymbolRef: { |
| 395 | const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr); |
Rafael Espindola | e98d483 | 2010-11-24 18:51:21 +0000 | [diff] [blame] | 396 | switch (symRef.getKind()) { |
| 397 | default: |
Rafael Espindola | 4e70ac7 | 2010-11-24 02:19:40 +0000 | [diff] [blame] | 398 | return; |
Joerg Sonnenberger | 07de07e | 2011-03-17 00:35:10 +0000 | [diff] [blame] | 399 | case MCSymbolRefExpr::VK_GOTTPOFF: |
| 400 | case MCSymbolRefExpr::VK_INDNTPOFF: |
Rafael Espindola | e98d483 | 2010-11-24 18:51:21 +0000 | [diff] [blame] | 401 | case MCSymbolRefExpr::VK_NTPOFF: |
| 402 | case MCSymbolRefExpr::VK_GOTNTPOFF: |
Fangrui Song | 656afe3 | 2019-05-29 02:02:59 +0000 | [diff] [blame] | 403 | case MCSymbolRefExpr::VK_TLSCALL: |
| 404 | case MCSymbolRefExpr::VK_TLSDESC: |
Rafael Espindola | e98d483 | 2010-11-24 18:51:21 +0000 | [diff] [blame] | 405 | case MCSymbolRefExpr::VK_TLSGD: |
Joerg Sonnenberger | 07de07e | 2011-03-17 00:35:10 +0000 | [diff] [blame] | 406 | case MCSymbolRefExpr::VK_TLSLD: |
Rafael Espindola | e98d483 | 2010-11-24 18:51:21 +0000 | [diff] [blame] | 407 | case MCSymbolRefExpr::VK_TLSLDM: |
| 408 | case MCSymbolRefExpr::VK_TPOFF: |
Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 409 | case MCSymbolRefExpr::VK_TPREL: |
Rafael Espindola | e98d483 | 2010-11-24 18:51:21 +0000 | [diff] [blame] | 410 | case MCSymbolRefExpr::VK_DTPOFF: |
Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 411 | case MCSymbolRefExpr::VK_DTPREL: |
Ulrich Weigand | f11efe7 | 2013-07-01 23:33:29 +0000 | [diff] [blame] | 412 | case MCSymbolRefExpr::VK_PPC_DTPMOD: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 413 | case MCSymbolRefExpr::VK_PPC_TPREL_LO: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 414 | case MCSymbolRefExpr::VK_PPC_TPREL_HI: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 415 | case MCSymbolRefExpr::VK_PPC_TPREL_HA: |
Sean Fertile | cac28ae | 2018-06-15 19:47:16 +0000 | [diff] [blame] | 416 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGH: |
| 417 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHA: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 418 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER: |
| 419 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA: |
| 420 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST: |
| 421 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 422 | case MCSymbolRefExpr::VK_PPC_DTPREL_LO: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 423 | case MCSymbolRefExpr::VK_PPC_DTPREL_HI: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 424 | case MCSymbolRefExpr::VK_PPC_DTPREL_HA: |
Sean Fertile | cac28ae | 2018-06-15 19:47:16 +0000 | [diff] [blame] | 425 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGH: |
| 426 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHA: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 427 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER: |
| 428 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA: |
| 429 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST: |
| 430 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA: |
| 431 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 432 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 433 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 434 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 435 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL: |
| 436 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO: |
| 437 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI: |
| 438 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA: |
Bill Schmidt | 441907d | 2013-02-26 16:41:03 +0000 | [diff] [blame] | 439 | case MCSymbolRefExpr::VK_PPC_TLS: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 440 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 441 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 442 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 443 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA: |
Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 444 | case MCSymbolRefExpr::VK_PPC_TLSGD: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 445 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 446 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO: |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 447 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI: |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 448 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA: |
Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 449 | case MCSymbolRefExpr::VK_PPC_TLSLD: |
Rafael Espindola | e98d483 | 2010-11-24 18:51:21 +0000 | [diff] [blame] | 450 | break; |
| 451 | } |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 452 | getAssembler().registerSymbol(symRef.getSymbol()); |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 453 | cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS); |
Rafael Espindola | 4e70ac7 | 2010-11-24 02:19:40 +0000 | [diff] [blame] | 454 | break; |
| 455 | } |
| 456 | |
| 457 | case MCExpr::Unary: |
| 458 | fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr()); |
| 459 | break; |
| 460 | } |
| 461 | } |
| 462 | |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 463 | void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) { |
| 464 | const MCSymbol *S = &SRE->getSymbol(); |
| 465 | if (S->isTemporary()) { |
| 466 | if (!S->isInSection()) { |
| 467 | getContext().reportError( |
| 468 | SRE->getLoc(), Twine("Reference to undefined temporary symbol ") + |
| 469 | "`" + S->getName() + "`"); |
| 470 | return; |
| 471 | } |
| 472 | S = S->getSection().getBeginSymbol(); |
| 473 | S->setUsedInReloc(); |
| 474 | SRE = |
| 475 | MCSymbolRefExpr::create(S, SRE->getKind(), getContext(), SRE->getLoc()); |
| 476 | return; |
| 477 | } |
| 478 | // Not a temporary, referece it as a weak undefined. |
| 479 | bool Created; |
| 480 | getAssembler().registerSymbol(*S, &Created); |
| 481 | if (Created) { |
| 482 | cast<MCSymbolELF>(S)->setBinding(ELF::STB_WEAK); |
| 483 | cast<MCSymbolELF>(S)->setExternal(true); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | void MCELFStreamer::finalizeCGProfile() { |
| 488 | for (MCAssembler::CGProfileEntry &E : getAssembler().CGProfile) { |
| 489 | finalizeCGProfileEntry(E.From); |
| 490 | finalizeCGProfileEntry(E.To); |
| 491 | } |
| 492 | } |
| 493 | |
David Woodhouse | 6f3c73f | 2014-01-28 23:12:49 +0000 | [diff] [blame] | 494 | void MCELFStreamer::EmitInstToFragment(const MCInst &Inst, |
| 495 | const MCSubtargetInfo &STI) { |
| 496 | this->MCObjectStreamer::EmitInstToFragment(Inst, STI); |
Eli Bendersky | 4d9ada0 | 2013-01-08 00:22:56 +0000 | [diff] [blame] | 497 | MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment()); |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 498 | |
Rafael Espindola | 3fa6fc1 | 2010-12-02 05:44:06 +0000 | [diff] [blame] | 499 | for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i) |
| 500 | fixSymbolsInTLSFixups(F.getFixups()[i].getValue()); |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 503 | // A fragment can only have one Subtarget, and when bundling is enabled we |
| 504 | // sometimes need to use the same fragment. We give an error if there |
| 505 | // are conflicting Subtargets. |
| 506 | static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI, |
| 507 | const MCSubtargetInfo *NewSTI) { |
| 508 | if (OldSTI && NewSTI && OldSTI != NewSTI) |
| 509 | report_fatal_error("A Bundle can only have one Subtarget."); |
| 510 | } |
| 511 | |
David Woodhouse | 6f3c73f | 2014-01-28 23:12:49 +0000 | [diff] [blame] | 512 | void MCELFStreamer::EmitInstToData(const MCInst &Inst, |
| 513 | const MCSubtargetInfo &STI) { |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 514 | MCAssembler &Assembler = getAssembler(); |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 515 | SmallVector<MCFixup, 4> Fixups; |
| 516 | SmallString<256> Code; |
| 517 | raw_svector_ostream VecOS(Code); |
Jim Grosbach | 91df21f | 2015-05-15 19:13:16 +0000 | [diff] [blame] | 518 | Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI); |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 519 | |
Rafael Espindola | 4e70ac7 | 2010-11-24 02:19:40 +0000 | [diff] [blame] | 520 | for (unsigned i = 0, e = Fixups.size(); i != e; ++i) |
| 521 | fixSymbolsInTLSFixups(Fixups[i].getValue()); |
| 522 | |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 523 | // There are several possibilities here: |
| 524 | // |
| 525 | // If bundling is disabled, append the encoded instruction to the current data |
| 526 | // fragment (or create a new such fragment if the current fragment is not a |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 527 | // data fragment, or the Subtarget has changed). |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 528 | // |
| 529 | // If bundling is enabled: |
Eli Bendersky | cf6009b | 2013-01-15 23:22:09 +0000 | [diff] [blame] | 530 | // - If we're not in a bundle-locked group, emit the instruction into a |
| 531 | // fragment of its own. If there are no fixups registered for the |
| 532 | // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a |
| 533 | // MCDataFragment. |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 534 | // - If we're in a bundle-locked group, append the instruction to the current |
| 535 | // data fragment because we want all the instructions in a group to get into |
| 536 | // the same fragment. Be careful not to do that for the first instruction in |
| 537 | // the group, though. |
| 538 | MCDataFragment *DF; |
| 539 | |
| 540 | if (Assembler.isBundlingEnabled()) { |
Rafael Espindola | 983bec6 | 2015-05-27 21:04:14 +0000 | [diff] [blame] | 541 | MCSection &Sec = *getCurrentSectionOnly(); |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 542 | if (Assembler.getRelaxAll() && isBundleLocked()) { |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 543 | // If the -mc-relax-all flag is used and we are bundle-locked, we re-use |
| 544 | // the current bundle group. |
| 545 | DF = BundleGroups.back(); |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 546 | CheckBundleSubtargets(DF->getSubtargetInfo(), &STI); |
| 547 | } |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 548 | else if (Assembler.getRelaxAll() && !isBundleLocked()) |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 549 | // When not in a bundle-locked group and the -mc-relax-all flag is used, |
| 550 | // we create a new temporary fragment which will be later merged into |
| 551 | // the current fragment. |
| 552 | DF = new MCDataFragment(); |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 553 | else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst()) { |
Derek Schuff | 8878bcc9 | 2013-02-15 22:50:52 +0000 | [diff] [blame] | 554 | // If we are bundle-locked, we re-use the current fragment. |
| 555 | // The bundle-locking directive ensures this is a new data fragment. |
| 556 | DF = cast<MCDataFragment>(getCurrentFragment()); |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 557 | CheckBundleSubtargets(DF->getSubtargetInfo(), &STI); |
| 558 | } |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 559 | else if (!isBundleLocked() && Fixups.size() == 0) { |
Eli Bendersky | cf6009b | 2013-01-15 23:22:09 +0000 | [diff] [blame] | 560 | // Optimize memory usage by emitting the instruction to a |
| 561 | // MCCompactEncodedInstFragment when not in a bundle-locked group and |
| 562 | // there are no fixups registered. |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 563 | MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment(); |
| 564 | insert(CEIF); |
Eli Bendersky | cf6009b | 2013-01-15 23:22:09 +0000 | [diff] [blame] | 565 | CEIF->getContents().append(Code.begin(), Code.end()); |
Peter Smith | 1503fc0 | 2018-06-15 09:48:18 +0000 | [diff] [blame] | 566 | CEIF->setHasInstructions(STI); |
Eli Bendersky | cf6009b | 2013-01-15 23:22:09 +0000 | [diff] [blame] | 567 | return; |
Derek Schuff | 8878bcc9 | 2013-02-15 22:50:52 +0000 | [diff] [blame] | 568 | } else { |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 569 | DF = new MCDataFragment(); |
| 570 | insert(DF); |
Derek Schuff | 05fb735 | 2014-10-15 17:10:04 +0000 | [diff] [blame] | 571 | } |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 572 | if (Sec.getBundleLockState() == MCSection::BundleLockedAlignToEnd) { |
Derek Schuff | 05fb735 | 2014-10-15 17:10:04 +0000 | [diff] [blame] | 573 | // If this fragment is for a group marked "align_to_end", set a flag |
| 574 | // in the fragment. This can happen after the fragment has already been |
| 575 | // created if there are nested bundle_align groups and an inner one |
| 576 | // is the one marked align_to_end. |
| 577 | DF->setAlignToBundleEnd(true); |
Eli Bendersky | 802b628 | 2013-01-07 21:51:08 +0000 | [diff] [blame] | 578 | } |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 579 | |
| 580 | // We're now emitting an instruction in a bundle group, so this flag has |
| 581 | // to be turned off. |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 582 | Sec.setBundleGroupBeforeFirstInst(false); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 583 | } else { |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 584 | DF = getOrCreateDataFragment(&STI); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 587 | // Add the fixups and data. |
| 588 | for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { |
| 589 | Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size()); |
Eli Bendersky | a31a894 | 2012-12-07 19:13:57 +0000 | [diff] [blame] | 590 | DF->getFixups().push_back(Fixups[i]); |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 591 | } |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 592 | DF->setHasInstructions(STI); |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 593 | DF->getContents().append(Code.begin(), Code.end()); |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 594 | |
| 595 | if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) { |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 596 | if (!isBundleLocked()) { |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 597 | mergeFragment(getOrCreateDataFragment(&STI), DF); |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 598 | delete DF; |
| 599 | } |
| 600 | } |
Benjamin Kramer | 1f60124 | 2010-08-27 10:40:51 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Fangrui Song | 549b436 | 2020-02-15 08:52:56 -0800 | [diff] [blame^] | 603 | void MCELFStreamer::emitBundleAlignMode(unsigned AlignPow2) { |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 604 | assert(AlignPow2 <= 30 && "Invalid bundle alignment"); |
| 605 | MCAssembler &Assembler = getAssembler(); |
Derek Schuff | 05fb735 | 2014-10-15 17:10:04 +0000 | [diff] [blame] | 606 | if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 || |
| 607 | Assembler.getBundleAlignSize() == 1U << AlignPow2)) |
| 608 | Assembler.setBundleAlignSize(1U << AlignPow2); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 609 | else |
Derek Schuff | 05fb735 | 2014-10-15 17:10:04 +0000 | [diff] [blame] | 610 | report_fatal_error(".bundle_align_mode cannot be changed once set"); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Fangrui Song | 549b436 | 2020-02-15 08:52:56 -0800 | [diff] [blame^] | 613 | void MCELFStreamer::emitBundleLock(bool AlignToEnd) { |
Rafael Espindola | 983bec6 | 2015-05-27 21:04:14 +0000 | [diff] [blame] | 614 | MCSection &Sec = *getCurrentSectionOnly(); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 615 | |
| 616 | // Sanity checks |
| 617 | // |
| 618 | if (!getAssembler().isBundlingEnabled()) |
| 619 | report_fatal_error(".bundle_lock forbidden when bundling is disabled"); |
Derek Schuff | 05fb735 | 2014-10-15 17:10:04 +0000 | [diff] [blame] | 620 | |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 621 | if (!isBundleLocked()) |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 622 | Sec.setBundleGroupBeforeFirstInst(true); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 623 | |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 624 | if (getAssembler().getRelaxAll() && !isBundleLocked()) { |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 625 | // TODO: drop the lock state and set directly in the fragment |
| 626 | MCDataFragment *DF = new MCDataFragment(); |
| 627 | BundleGroups.push_back(DF); |
| 628 | } |
| 629 | |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 630 | Sec.setBundleLockState(AlignToEnd ? MCSection::BundleLockedAlignToEnd |
| 631 | : MCSection::BundleLocked); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Fangrui Song | 549b436 | 2020-02-15 08:52:56 -0800 | [diff] [blame^] | 634 | void MCELFStreamer::emitBundleUnlock() { |
Rafael Espindola | 983bec6 | 2015-05-27 21:04:14 +0000 | [diff] [blame] | 635 | MCSection &Sec = *getCurrentSectionOnly(); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 636 | |
| 637 | // Sanity checks |
| 638 | if (!getAssembler().isBundlingEnabled()) |
| 639 | report_fatal_error(".bundle_unlock forbidden when bundling is disabled"); |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 640 | else if (!isBundleLocked()) |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 641 | report_fatal_error(".bundle_unlock without matching lock"); |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 642 | else if (Sec.isBundleGroupBeforeFirstInst()) |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 643 | report_fatal_error("Empty bundle-locked group is forbidden"); |
| 644 | |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 645 | // When the -mc-relax-all flag is used, we emit instructions to fragments |
Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 646 | // stored on a stack. When the bundle unlock is emitted, we pop a fragment |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 647 | // from the stack a merge it to the one below. |
| 648 | if (getAssembler().getRelaxAll()) { |
| 649 | assert(!BundleGroups.empty() && "There are no bundle groups"); |
| 650 | MCDataFragment *DF = BundleGroups.back(); |
| 651 | |
| 652 | // FIXME: Use BundleGroups to track the lock state instead. |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 653 | Sec.setBundleLockState(MCSection::NotBundleLocked); |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 654 | |
Rafael Espindola | c1cd944 | 2015-05-25 14:57:35 +0000 | [diff] [blame] | 655 | // FIXME: Use more separate fragments for nested groups. |
| 656 | if (!isBundleLocked()) { |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 657 | mergeFragment(getOrCreateDataFragment(DF->getSubtargetInfo()), DF); |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 658 | BundleGroups.pop_back(); |
| 659 | delete DF; |
| 660 | } |
| 661 | |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 662 | if (Sec.getBundleLockState() != MCSection::BundleLockedAlignToEnd) |
Petr Hosek | 9e0c890 | 2015-04-12 23:42:25 +0000 | [diff] [blame] | 663 | getOrCreateDataFragment()->setAlignToBundleEnd(false); |
| 664 | } else |
Rafael Espindola | b028cc8 | 2015-05-25 15:04:26 +0000 | [diff] [blame] | 665 | Sec.setBundleLockState(MCSection::NotBundleLocked); |
Eli Bendersky | f483ff9 | 2012-12-20 19:05:53 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 668 | void MCELFStreamer::FinishImpl() { |
Derek Schuff | 2a1678a | 2015-04-21 00:14:25 +0000 | [diff] [blame] | 669 | // Ensure the last section gets aligned if necessary. |
Rafael Espindola | 983bec6 | 2015-05-27 21:04:14 +0000 | [diff] [blame] | 670 | MCSection *CurSection = getCurrentSectionOnly(); |
Rafael Espindola | e6e287d | 2015-05-26 14:42:52 +0000 | [diff] [blame] | 671 | setSectionAlignmentForBundling(getAssembler(), CurSection); |
Derek Schuff | 2a1678a | 2015-04-21 00:14:25 +0000 | [diff] [blame] | 672 | |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 673 | finalizeCGProfile(); |
Rafael Espindola | 7f4ccce | 2014-05-12 13:30:10 +0000 | [diff] [blame] | 674 | EmitFrames(nullptr); |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 675 | |
Rafael Espindola | 0708209 | 2012-01-07 03:13:18 +0000 | [diff] [blame] | 676 | this->MCObjectStreamer::FinishImpl(); |
Matt Fleming | 6c1ad48 | 2010-08-16 18:57:57 +0000 | [diff] [blame] | 677 | } |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 678 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 679 | void MCELFStreamer::emitThumbFunc(MCSymbol *Func) { |
Tim Northover | 5cc3dc8 | 2012-12-07 16:50:23 +0000 | [diff] [blame] | 680 | llvm_unreachable("Generic ELF doesn't support this directive"); |
| 681 | } |
| 682 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 683 | void MCELFStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { |
Logan Chien | 59ff070 | 2012-12-07 15:50:40 +0000 | [diff] [blame] | 684 | llvm_unreachable("ELF doesn't support this directive"); |
| 685 | } |
| 686 | |
Fangrui Song | a55daa1 | 2020-02-14 18:16:24 -0800 | [diff] [blame] | 687 | void MCELFStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, |
Francis Visoiu Mistrih | 4d5b107 | 2018-07-02 17:29:43 +0000 | [diff] [blame] | 688 | uint64_t Size, unsigned ByteAlignment, |
| 689 | SMLoc Loc) { |
Logan Chien | 59ff070 | 2012-12-07 15:50:40 +0000 | [diff] [blame] | 690 | llvm_unreachable("ELF doesn't support this directive"); |
| 691 | } |
| 692 | |
Fangrui Song | 549b436 | 2020-02-15 08:52:56 -0800 | [diff] [blame^] | 693 | void MCELFStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, |
Logan Chien | 59ff070 | 2012-12-07 15:50:40 +0000 | [diff] [blame] | 694 | uint64_t Size, unsigned ByteAlignment) { |
| 695 | llvm_unreachable("ELF doesn't support this directive"); |
| 696 | } |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 697 | |
Lang Hames | 02d3305 | 2017-10-11 01:57:21 +0000 | [diff] [blame] | 698 | MCStreamer *llvm::createELFStreamer(MCContext &Context, |
| 699 | std::unique_ptr<MCAsmBackend> &&MAB, |
Peter Collingbourne | f7b81db | 2018-05-18 18:26:45 +0000 | [diff] [blame] | 700 | std::unique_ptr<MCObjectWriter> &&OW, |
Lang Hames | 2241ffa | 2017-10-11 23:34:47 +0000 | [diff] [blame] | 701 | std::unique_ptr<MCCodeEmitter> &&CE, |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 702 | bool RelaxAll) { |
Lang Hames | 2241ffa | 2017-10-11 23:34:47 +0000 | [diff] [blame] | 703 | MCELFStreamer *S = |
Peter Collingbourne | f7b81db | 2018-05-18 18:26:45 +0000 | [diff] [blame] | 704 | new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE)); |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 705 | if (RelaxAll) |
| 706 | S->getAssembler().setRelaxAll(true); |
| 707 | return S; |
| 708 | } |