LLVM 24.0.0git
LoongArchELFStreamer.cpp
Go to the documentation of this file.
1//===-- LoongArchELFStreamer.cpp - LoongArch ELF Target Streamer Methods --===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides LoongArch specific target streamer methods.
10//
11//===----------------------------------------------------------------------===//
12
14#include "LoongArchAsmBackend.h"
15#include "LoongArchBaseInfo.h"
17#include "llvm/MC/MCAssembler.h"
20#include "llvm/MC/MCSection.h"
21
22using namespace llvm;
23
24// This part is for ELF object output.
34
38
43
45 auto &S = getStreamer();
46 S.ensureHeadroom(4);
48 S.appendContents(4, 0);
49}
50
52 auto &S = getStreamer();
53 S.ensureHeadroom(8);
55 S.appendContents(8, 0);
56}
57
62
63 // Figure out the e_flags.
64 //
65 // Bitness is already represented with the EI_CLASS byte in the current spec,
66 // so here we only record the base ABI modifier. Also set the object file ABI
67 // version to v1, as upstream LLVM cannot handle the previous stack-machine-
68 // based relocs from day one.
69 //
70 // Refer to LoongArch ELF psABI v2.01 for details.
71 unsigned EFlags = W.getELFHeaderEFlags();
73 switch (ABI) {
77 break;
81 break;
85 break;
87 llvm_unreachable("Improperly initialized target ABI");
88 }
89 W.setELFHeaderEFlags(EFlags);
90}
91
93 const MCSubtargetInfo &STI,
94 unsigned MaxBytesToEmit) {
95 // Save the Align fragment.
96 auto *AlignFrag = getCurrentFragment();
97 MCELFStreamer::emitCodeAlignment(Alignment, STI, MaxBytesToEmit);
98
99 // Pre-mark the Align fragment as linker-relaxable.
101 AlignFrag->setLinkerRelaxable();
102}
103
104namespace llvm {
106 std::unique_ptr<MCAsmBackend> MAB,
107 std::unique_ptr<MCObjectWriter> MOW,
108 std::unique_ptr<MCCodeEmitter> MCE) {
110 C, std::move(MAB), std::move(MOW), std::move(MCE));
111 return S;
112}
113} // end namespace llvm
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static bool shouldRelaxAlign(const MCFragment &F)
Check whether an alignment fragment needs linker relaxation.
void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit) override
Emit nops until the byte alignment ByteAlignment is reached.
void emitDTPRel32Value(const MCExpr *) override
void emitDTPRel64Value(const MCExpr *) override
LoongArchTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
LoongArchABI::ABI getTargetABI() const
void setTargetABI(LoongArchABI::ABI ABI)
MCAsmBackend & getBackend() const
Context object for machine code objects.
Definition MCContext.h:83
ELFObjectWriter & getWriter()
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
MCAssembler & getAssembler()
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
Streaming machine code generation interface.
Definition MCStreamer.h:222
MCFragment * getCurrentFragment() const
Definition MCStreamer.h:449
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
virtual void finish()
MCStreamer & Streamer
Definition MCStreamer.h:97
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ EF_LOONGARCH_OBJABI_V1
Definition ELF.h:1083
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
Definition ELF.h:1077
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
Definition ELF.h:1078
@ EF_LOONGARCH_ABI_SOFT_FLOAT
Definition ELF.h:1076
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
This is an optimization pass for GlobalISel generic memory operations.
MCELFStreamer * createLoongArchELFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > MOW, std::unique_ptr< MCCodeEmitter > MCE)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39