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