blob: f11629d94e90c1fc4764145cd75834a56e402edb [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MCELFStreamer.h - MCStreamer ELF Object File Interface ---*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_MC_MCELFSTREAMER_H
10#define LLVM_MC_MCELFSTREAMER_H
11
12#include "llvm/ADT/SmallVector.h"
13#include "llvm/MC/MCDirectives.h"
14#include "llvm/MC/MCObjectStreamer.h"
15
16namespace llvm {
17
18class MCAsmBackend;
19class MCCodeEmitter;
20class MCExpr;
21class MCInst;
22
23class MCELFStreamer : public MCObjectStreamer {
24public:
25 MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
Andrew Scullcdfcccc2018-10-05 20:58:37 +010026 std::unique_ptr<MCObjectWriter> OW,
27 std::unique_ptr<MCCodeEmitter> Emitter);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010028
29 ~MCELFStreamer() override = default;
30
31 /// state management
32 void reset() override {
33 SeenIdent = false;
34 BundleGroups.clear();
35 MCObjectStreamer::reset();
36 }
37
38 /// \name MCStreamer Interface
39 /// @{
40
41 void InitSections(bool NoExecStack) override;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020042 void changeSection(MCSection *Section, const MCExpr *Subsection) override;
43 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
44 void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F,
45 uint64_t Offset) override;
46 void emitAssemblerFlag(MCAssemblerFlag Flag) override;
47 void emitThumbFunc(MCSymbol *Func) override;
48 void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
49 bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
50 void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
51 void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010052 unsigned ByteAlignment) override;
53
54 void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
55 void emitELFSymverDirective(StringRef AliasName,
56 const MCSymbol *Aliasee) override;
57
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020058 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010059 unsigned ByteAlignment) override;
60
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020061 void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
Andrew Scullcdfcccc2018-10-05 20:58:37 +010062 uint64_t Size = 0, unsigned ByteAlignment = 0,
63 SMLoc L = SMLoc()) override;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020064 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010065 unsigned ByteAlignment = 0) override;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020066 void emitValueImpl(const MCExpr *Value, unsigned Size,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010067 SMLoc Loc = SMLoc()) override;
68
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020069 void emitIdent(StringRef IdentString) override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010070
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020071 void emitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010072
Andrew Scullcdfcccc2018-10-05 20:58:37 +010073 void emitCGProfileEntry(const MCSymbolRefExpr *From,
74 const MCSymbolRefExpr *To, uint64_t Count) override;
75
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020076 void finishImpl() override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010077
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020078 void emitBundleAlignMode(unsigned AlignPow2) override;
79 void emitBundleLock(bool AlignToEnd) override;
80 void emitBundleUnlock() override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010081
82private:
83 bool isBundleLocked() const;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020084 void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
85 void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010086
87 void fixSymbolsInTLSFixups(const MCExpr *expr);
Andrew Scullcdfcccc2018-10-05 20:58:37 +010088 void finalizeCGProfileEntry(const MCSymbolRefExpr *&S);
89 void finalizeCGProfile();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010090
Andrew Scullcdfcccc2018-10-05 20:58:37 +010091 /// Merge the content of the fragment \p EF into the fragment \p DF.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010092 void mergeFragment(MCDataFragment *, MCDataFragment *);
93
94 bool SeenIdent = false;
95
96 /// BundleGroups - The stack of fragments holding the bundle-locked
97 /// instructions.
98 SmallVector<MCDataFragment *, 4> BundleGroups;
99};
100
101MCELFStreamer *createARMELFStreamer(MCContext &Context,
102 std::unique_ptr<MCAsmBackend> TAB,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100103 std::unique_ptr<MCObjectWriter> OW,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100104 std::unique_ptr<MCCodeEmitter> Emitter,
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200105 bool RelaxAll, bool IsThumb, bool IsAndroid);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100106
107} // end namespace llvm
108
109#endif // LLVM_MC_MCELFSTREAMER_H