Path: blob/main/contrib/llvm-project/llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
35295 views
//===-- LanaiELFObjectWriter.cpp - Lanai ELF Writer -----------------------===//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//===----------------------------------------------------------------------===//78#include "MCTargetDesc/LanaiBaseInfo.h"9#include "MCTargetDesc/LanaiFixupKinds.h"10#include "llvm/BinaryFormat/ELF.h"11#include "llvm/MC/MCELFObjectWriter.h"12#include "llvm/MC/MCObjectWriter.h"13#include "llvm/Support/ErrorHandling.h"1415using namespace llvm;1617namespace {1819class LanaiELFObjectWriter : public MCELFObjectTargetWriter {20public:21explicit LanaiELFObjectWriter(uint8_t OSABI);2223~LanaiELFObjectWriter() override = default;2425protected:26unsigned getRelocType(MCContext &Ctx, const MCValue &Target,27const MCFixup &Fixup, bool IsPCRel) const override;28bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,29unsigned Type) const override;30};3132} // end anonymous namespace3334LanaiELFObjectWriter::LanaiELFObjectWriter(uint8_t OSABI)35: MCELFObjectTargetWriter(/*Is64Bit_=*/false, OSABI, ELF::EM_LANAI,36/*HasRelocationAddend_=*/true) {}3738unsigned LanaiELFObjectWriter::getRelocType(MCContext & /*Ctx*/,39const MCValue & /*Target*/,40const MCFixup &Fixup,41bool /*IsPCRel*/) const {42unsigned Type;43unsigned Kind = static_cast<unsigned>(Fixup.getKind());44switch (Kind) {45case Lanai::FIXUP_LANAI_21:46Type = ELF::R_LANAI_21;47break;48case Lanai::FIXUP_LANAI_21_F:49Type = ELF::R_LANAI_21_F;50break;51case Lanai::FIXUP_LANAI_25:52Type = ELF::R_LANAI_25;53break;54case Lanai::FIXUP_LANAI_32:55case FK_Data_4:56Type = ELF::R_LANAI_32;57break;58case Lanai::FIXUP_LANAI_HI16:59Type = ELF::R_LANAI_HI16;60break;61case Lanai::FIXUP_LANAI_LO16:62Type = ELF::R_LANAI_LO16;63break;64case Lanai::FIXUP_LANAI_NONE:65Type = ELF::R_LANAI_NONE;66break;6768default:69llvm_unreachable("Invalid fixup kind!");70}71return Type;72}7374bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCValue &,75const MCSymbol &,76unsigned Type) const {77switch (Type) {78case ELF::R_LANAI_21:79case ELF::R_LANAI_21_F:80case ELF::R_LANAI_25:81case ELF::R_LANAI_32:82case ELF::R_LANAI_HI16:83return true;84default:85return false;86}87}8889std::unique_ptr<MCObjectTargetWriter>90llvm::createLanaiELFObjectWriter(uint8_t OSABI) {91return std::make_unique<LanaiELFObjectWriter>(OSABI);92}939495