Path: blob/main/contrib/llvm-project/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
35294 views
//===-- LoongArchELFStreamer.cpp - LoongArch ELF Target Streamer Methods --===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file provides LoongArch specific target streamer methods.9//10//===----------------------------------------------------------------------===//1112#include "LoongArchELFStreamer.h"13#include "LoongArchAsmBackend.h"14#include "LoongArchBaseInfo.h"15#include "llvm/BinaryFormat/ELF.h"16#include "llvm/MC/MCAssembler.h"17#include "llvm/MC/MCCodeEmitter.h"18#include "llvm/MC/MCObjectWriter.h"1920using namespace llvm;2122// This part is for ELF object output.23LoongArchTargetELFStreamer::LoongArchTargetELFStreamer(24MCStreamer &S, const MCSubtargetInfo &STI)25: LoongArchTargetStreamer(S) {26auto &MAB = static_cast<LoongArchAsmBackend &>(27getStreamer().getAssembler().getBackend());28setTargetABI(LoongArchABI::computeTargetABI(29STI.getTargetTriple(), STI.getFeatureBits(),30MAB.getTargetOptions().getABIName()));31}3233MCELFStreamer &LoongArchTargetELFStreamer::getStreamer() {34return static_cast<MCELFStreamer &>(Streamer);35}3637void LoongArchTargetELFStreamer::finish() {38LoongArchTargetStreamer::finish();39ELFObjectWriter &W = getStreamer().getWriter();40LoongArchABI::ABI ABI = getTargetABI();4142// Figure out the e_flags.43//44// Bitness is already represented with the EI_CLASS byte in the current spec,45// so here we only record the base ABI modifier. Also set the object file ABI46// version to v1, as upstream LLVM cannot handle the previous stack-machine-47// based relocs from day one.48//49// Refer to LoongArch ELF psABI v2.01 for details.50unsigned EFlags = W.getELFHeaderEFlags();51EFlags |= ELF::EF_LOONGARCH_OBJABI_V1;52switch (ABI) {53case LoongArchABI::ABI_ILP32S:54case LoongArchABI::ABI_LP64S:55EFlags |= ELF::EF_LOONGARCH_ABI_SOFT_FLOAT;56break;57case LoongArchABI::ABI_ILP32F:58case LoongArchABI::ABI_LP64F:59EFlags |= ELF::EF_LOONGARCH_ABI_SINGLE_FLOAT;60break;61case LoongArchABI::ABI_ILP32D:62case LoongArchABI::ABI_LP64D:63EFlags |= ELF::EF_LOONGARCH_ABI_DOUBLE_FLOAT;64break;65case LoongArchABI::ABI_Unknown:66llvm_unreachable("Improperly initialized target ABI");67}68W.setELFHeaderEFlags(EFlags);69}7071namespace {72class LoongArchELFStreamer : public MCELFStreamer {73public:74LoongArchELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,75std::unique_ptr<MCObjectWriter> MOW,76std::unique_ptr<MCCodeEmitter> MCE)77: MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}78};79} // end namespace8081namespace llvm {82MCELFStreamer *createLoongArchELFStreamer(MCContext &C,83std::unique_ptr<MCAsmBackend> MAB,84std::unique_ptr<MCObjectWriter> MOW,85std::unique_ptr<MCCodeEmitter> MCE) {86LoongArchELFStreamer *S = new LoongArchELFStreamer(87C, std::move(MAB), std::move(MOW), std::move(MCE));88return S;89}90} // end namespace llvm919293