<commit_before>//===- lib/ReaderWriter/ELF/Mips/MipsELFWriters.h -------------------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_WRITERS_H
#define LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_WRITERS_H

#include "MipsLinkingContext.h"
#include "OutputELFWriter.h"

namespace lld {
namespace elf {

template <class ELFT> class MipsTargetLayout;

template <typename ELFT> class MipsELFWriter {
public:
  MipsELFWriter(MipsLinkingContext &context,
                MipsTargetLayout<ELFT> &targetLayout)
      : _mipsLinkingContext(context), _mipsTargetLayout(targetLayout) {}

  bool setELFHeader(ELFHeader<ELFT> &elfHeader) {
    elfHeader.e_version(1);
    elfHeader.e_ident(llvm::ELF::EI_VERSION, llvm::ELF::EV_CURRENT);
    elfHeader.e_ident(llvm::ELF::EI_OSABI, llvm::ELF::ELFOSABI_NONE);
    if (_mipsTargetLayout.findOutputSection(".got.plt"))
      elfHeader.e_ident(llvm::ELF::EI_ABIVERSION, 1);
    else
      elfHeader.e_ident(llvm::ELF::EI_ABIVERSION, 0);

    // FIXME (simon): Read elf flags from all inputs, check compatibility,
    // merge them and write result here.
    uint32_t flags = llvm::ELF::EF_MIPS_NOREORDER | llvm::ELF::EF_MIPS_ABI_O32 |
                     llvm::ELF::EF_MIPS_CPIC | llvm::ELF::EF_MIPS_ARCH_32R2;
    if (_mipsLinkingContext.getOutputELFType() == llvm::ELF::ET_DYN)
      flags |= EF_MIPS_PIC;
    elfHeader.e_flags(flags);
    return true;
  }

  void finalizeMipsRuntimeAtomValues() {
    if (_mipsLinkingContext.isDynamic()) {
      auto gotSection = _mipsTargetLayout.findOutputSection(".got");
      auto got = gotSection ? gotSection->virtualAddr() : 0;
      auto gp = gotSection ? got + _mipsTargetLayout.getGPOffset() : 0;

      auto gotAtomIter =
          _mipsTargetLayout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
      assert(gotAtomIter != _mipsTargetLayout.absoluteAtoms().end());
      (*gotAtomIter)->_virtualAddr = got;

      auto gpAtomIter = _mipsTargetLayout.findAbsoluteAtom("_gp");
      assert(gpAtomIter != _mipsTargetLayout.absoluteAtoms().end());
      (*gpAtomIter)->_virtualAddr = gp;

      AtomLayout *gpAtom = _mipsTargetLayout.getGP();
      assert(gpAtom != nullptr);
      gpAtom->_virtualAddr = gp;
    }
  }

  bool hasGlobalGOTEntry(const Atom *a) const {
    return _mipsTargetLayout.getGOTSection().hasGlobalGOTEntry(a);
  }

private:
  MipsLinkingContext &_mipsLinkingContext;
  MipsTargetLayout<ELFT> &_mipsTargetLayout;
};<commit_msg>[Mips] Change unused return type from 'bool' to 'void'.<commit_after>//===- lib/ReaderWriter/ELF/Mips/MipsELFWriters.h -------------------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_WRITERS_H
#define LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_WRITERS_H

#include "MipsLinkingContext.h"
#include "OutputELFWriter.h"

namespace lld {
namespace elf {

template <class ELFT> class MipsTargetLayout;

template <typename ELFT> class MipsELFWriter {
public:
  MipsELFWriter(MipsLinkingContext &context,
                MipsTargetLayout<ELFT> &targetLayout)
      : _mipsLinkingContext(context), _mipsTargetLayout(targetLayout) {}

  void setELFHeader(ELFHeader<ELFT> &elfHeader) {
    elfHeader.e_version(1);
    elfHeader.e_ident(llvm::ELF::EI_VERSION, llvm::ELF::EV_CURRENT);
    elfHeader.e_ident(llvm::ELF::EI_OSABI, llvm::ELF::ELFOSABI_NONE);
    if (_mipsTargetLayout.findOutputSection(".got.plt"))
      elfHeader.e_ident(llvm::ELF::EI_ABIVERSION, 1);
    else
      elfHeader.e_ident(llvm::ELF::EI_ABIVERSION, 0);

    // FIXME (simon): Read elf flags from all inputs, check compatibility,
    // merge them and write result here.
    uint32_t flags = llvm::ELF::EF_MIPS_NOREORDER | llvm::ELF::EF_MIPS_ABI_O32 |
                     llvm::ELF::EF_MIPS_CPIC | llvm::ELF::EF_MIPS_ARCH_32R2;
    if (_mipsLinkingContext.getOutputELFType() == llvm::ELF::ET_DYN)
      flags |= EF_MIPS_PIC;
    elfHeader.e_flags(flags);
  }

  void finalizeMipsRuntimeAtomValues() {
    if (_mipsLinkingContext.isDynamic()) {
      auto gotSection = _mipsTargetLayout.findOutputSection(".got");
      auto got = gotSection ? gotSection->virtualAddr() : 0;
      auto gp = gotSection ? got + _mipsTargetLayout.getGPOffset() : 0;

      auto gotAtomIter =
          _mipsTargetLayout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
      assert(gotAtomIter != _mipsTargetLayout.absoluteAtoms().end());
      (*gotAtomIter)->_virtualAddr = got;

      auto gpAtomIter = _mipsTargetLayout.findAbsoluteAtom("_gp");
      assert(gpAtomIter != _mipsTargetLayout.absoluteAtoms().end());
      (*gpAtomIter)->_virtualAddr = gp;

      AtomLayout *gpAtom = _mipsTargetLayout.getGP();
      assert(gpAtom != nullptr);
      gpAtom->_virtualAddr = gp;
    }
  }

  bool hasGlobalGOTEntry(const Atom *a) const {
    return _mipsTargetLayout.getGOTSection().hasGlobalGOTEntry(a);
  }

private:
  MipsLinkingContext &_mipsLinkingContext;
  MipsTargetLayout<ELFT> &_mipsTargetLayout;
};
{'fraction_non_alphanumeric': 0.15287334945136694, 'fraction_numerical': 0.004463455458434071, 'mean_word_length': 3.4154351395730704, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6529143', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1835, 'n_words': 298}