brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · e2b1c56 Raw
69 lines · cpp
1//===-- XtensaMCObjectWriter.cpp - Xtensa ELF writer ----------------------===//2//3//                     The LLVM Compiler Infrastructure4//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-exception8//9//===----------------------------------------------------------------------===//10 11#include "MCTargetDesc/XtensaMCAsmInfo.h"12#include "MCTargetDesc/XtensaMCTargetDesc.h"13#include "llvm/ADT/STLExtras.h"14#include "llvm/BinaryFormat/ELF.h"15#include "llvm/MC/MCELFObjectWriter.h"16#include "llvm/MC/MCExpr.h"17#include "llvm/MC/MCFixup.h"18#include "llvm/MC/MCObjectWriter.h"19#include "llvm/MC/MCValue.h"20#include "llvm/Support/ErrorHandling.h"21#include <cassert>22#include <cstdint>23 24using namespace llvm;25 26namespace {27class XtensaObjectWriter : public MCELFObjectTargetWriter {28public:29  XtensaObjectWriter(uint8_t OSABI);30 31  virtual ~XtensaObjectWriter();32 33protected:34  unsigned getRelocType(const MCFixup &, const MCValue &,35                        bool IsPCRel) const override;36  bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;37};38} // namespace39 40XtensaObjectWriter::XtensaObjectWriter(uint8_t OSABI)41    : MCELFObjectTargetWriter(false, OSABI, ELF::EM_XTENSA,42                              /*HasRelocationAddend=*/true) {}43 44XtensaObjectWriter::~XtensaObjectWriter() {}45 46unsigned XtensaObjectWriter::getRelocType(const MCFixup &Fixup,47                                          const MCValue &Target,48                                          bool IsPCRel) const {49  uint8_t Specifier = Target.getSpecifier();50 51  switch ((unsigned)Fixup.getKind()) {52  case FK_Data_4:53    return Specifier == Xtensa::S_TPOFF ? ELF::R_XTENSA_TLS_TPOFF54                                        : ELF::R_XTENSA_32;55  default:56    return ELF::R_XTENSA_SLOT0_OP;57  }58}59 60std::unique_ptr<MCObjectTargetWriter>61llvm::createXtensaObjectWriter(uint8_t OSABI, bool IsLittleEndian) {62  return std::make_unique<XtensaObjectWriter>(OSABI);63}64 65bool XtensaObjectWriter::needsRelocateWithSymbol(const MCValue &,66                                                 unsigned Type) const {67  return false;68}69