1//===-- XtensaMCObjectWriter.cpp - Xtensa ELF writer ----------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6// See https://llvm.org/LICENSE.txt for license information. 7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8// 9//===----------------------------------------------------------------------===// 10 11#include "MCTargetDesc/XtensaMCTargetDesc.h" 12#include "llvm/ADT/STLExtras.h" 13#include "llvm/BinaryFormat/ELF.h" 14#include "llvm/MC/MCELFObjectWriter.h" 15#include "llvm/MC/MCExpr.h" 16#include "llvm/MC/MCFixup.h" 17#include "llvm/MC/MCObjectWriter.h" 18#include "llvm/MC/MCValue.h" 19#include "llvm/Support/ErrorHandling.h" 20#include <cassert> 21#include <cstdint> 22 23using namespace llvm; 24 25namespace { 26class XtensaObjectWriter : public MCELFObjectTargetWriter { 27public: 28 XtensaObjectWriter(uint8_t OSABI); 29 30 virtual ~XtensaObjectWriter(); 31 32protected: 33 unsigned getRelocType(MCContext &Ctx, const MCValue &Target, 34 const MCFixup &Fixup, bool IsPCRel) const override; 35 bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym, 36 unsigned Type) const override; 37}; 38} // namespace 39 40XtensaObjectWriter::XtensaObjectWriter(uint8_t OSABI) 41 : MCELFObjectTargetWriter(false, OSABI, ELF::EM_XTENSA, 42 /*HasRelocationAddend=*/true) {} 43 44XtensaObjectWriter::~XtensaObjectWriter() {} 45 46unsigned XtensaObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target, 47 const MCFixup &Fixup, 48 bool IsPCRel) const { 49 50 switch ((unsigned)Fixup.getKind()) { 51 case FK_Data_4: 52 return ELF::R_XTENSA_32; 53 default: 54 return ELF::R_XTENSA_SLOT0_OP; 55 } 56} 57 58std::unique_ptr<MCObjectTargetWriter> 59llvm::createXtensaObjectWriter(uint8_t OSABI, bool IsLittleEndian) { 60 return std::make_unique<XtensaObjectWriter>(OSABI); 61} 62 63bool XtensaObjectWriter::needsRelocateWithSymbol(const MCValue &, 64 const MCSymbol &, 65 unsigned Type) const { 66 return false; 67} 68