Path: blob/main/contrib/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp
35295 views
//===-- XtensaMCObjectWriter.cpp - Xtensa ELF writer ----------------------===//1//2// The LLVM Compiler Infrastructure3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//910#include "MCTargetDesc/XtensaMCTargetDesc.h"11#include "llvm/ADT/STLExtras.h"12#include "llvm/BinaryFormat/ELF.h"13#include "llvm/MC/MCELFObjectWriter.h"14#include "llvm/MC/MCExpr.h"15#include "llvm/MC/MCFixup.h"16#include "llvm/MC/MCObjectWriter.h"17#include "llvm/MC/MCValue.h"18#include "llvm/Support/ErrorHandling.h"19#include <cassert>20#include <cstdint>2122using namespace llvm;2324namespace {25class XtensaObjectWriter : public MCELFObjectTargetWriter {26public:27XtensaObjectWriter(uint8_t OSABI);2829virtual ~XtensaObjectWriter();3031protected:32unsigned getRelocType(MCContext &Ctx, const MCValue &Target,33const MCFixup &Fixup, bool IsPCRel) const override;34bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,35unsigned Type) const override;36};37} // namespace3839XtensaObjectWriter::XtensaObjectWriter(uint8_t OSABI)40: MCELFObjectTargetWriter(false, OSABI, ELF::EM_XTENSA,41/*HasRelocationAddend=*/true) {}4243XtensaObjectWriter::~XtensaObjectWriter() {}4445unsigned XtensaObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,46const MCFixup &Fixup,47bool IsPCRel) const {4849switch ((unsigned)Fixup.getKind()) {50case FK_Data_4:51return ELF::R_XTENSA_32;52default:53return ELF::R_XTENSA_SLOT0_OP;54}55}5657std::unique_ptr<MCObjectTargetWriter>58llvm::createXtensaObjectWriter(uint8_t OSABI, bool IsLittleEndian) {59return std::make_unique<XtensaObjectWriter>(OSABI);60}6162bool XtensaObjectWriter::needsRelocateWithSymbol(const MCValue &,63const MCSymbol &,64unsigned Type) const {65return false;66}676869