<commit_before>//===- lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp -------------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "Atoms.h"
#include "MipsCtorsOrderPass.h"
#include "MipsLinkingContext.h"
#include "MipsRelocationPass.h"
#include "MipsTargetHandler.h"

using namespace lld;
using namespace lld::elf;

std::unique_ptr<ELFLinkingContext>
elf::createMipsLinkingContext(llvm::Triple triple) {
  if (triple.getArch() == llvm::Triple::mips ||
      triple.getArch() == llvm::Triple::mipsel ||
      triple.getArch() == llvm::Triple::mips64 ||
      triple.getArch() == llvm::Triple::mips64el)
    return llvm::make_unique<MipsLinkingContext>(triple);
  return nullptr;
}

static std::unique_ptr<TargetHandler> createTarget(llvm::Triple triple,
                                                   MipsLinkingContext &ctx) {
  switch (triple.getArch()) {
  case llvm::Triple::mips:
    return llvm::make_unique<MipsTargetHandler<ELF32BE>>(ctx);
  case llvm::Triple::mipsel:
    return llvm::make_unique<MipsTargetHandler<ELF32LE>>(ctx);
  case llvm::Triple::mips64:
    return llvm::make_unique<MipsTargetHandler<ELF64BE>>(ctx);
  case llvm::Triple::mips64el:
    return llvm::make_unique<MipsTargetHandler<ELF64LE>>(ctx);
  default:
    llvm_unreachable("Unhandled arch");
  }
}

MipsLinkingContext::MipsLinkingContext(llvm::Triple triple)
    : ELFLinkingContext(triple, createTarget(triple, *this)) {}

uint64_t MipsLinkingContext::getBaseAddress() const {
  if (_baseAddress != 0 || getOutputELFType() != llvm::ELF::ET_EXEC)
    return _baseAddress;
  switch (getAbi()) {
    case MipsAbi::O32:
      return 0x0400000;
    case MipsAbi::N32:
      return 0x10000000;
    case MipsAbi::N64:
      return 0x120000000;
  }
}

StringRef MipsLinkingContext::entrySymbolName() const {
  if (_outputELFType == elf::ET_EXEC && _entrySymbolName.empty())
    return "__start";
  return _entrySymbolName;
}

StringRef MipsLinkingContext::getDefaultInterpreter() const {
  switch (getAbi()) {
    case MipsAbi::O32:
      return "/lib/ld.so.1";
    case MipsAbi::N32:
      return "/lib32/ld.so.1";
    case MipsAbi::N64:
      return "/lib64/ld.so.1";
  }
}

void MipsLinkingContext::addPasses(PassManager &pm) {
  auto pass = createMipsRelocationPass(*this);
  if (pass)
    pm.add(std::move(pass));
  ELFLinkingContext::addPasses(pm);
  pm.add(llvm::make_unique<elf::MipsCtorsOrderPass>());
}
<commit_msg>ELF: Fix "not all control paths return a value" warning.<commit_after>//===- lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp -------------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "Atoms.h"
#include "MipsCtorsOrderPass.h"
#include "MipsLinkingContext.h"
#include "MipsRelocationPass.h"
#include "MipsTargetHandler.h"

using namespace lld;
using namespace lld::elf;

std::unique_ptr<ELFLinkingContext>
elf::createMipsLinkingContext(llvm::Triple triple) {
  if (triple.getArch() == llvm::Triple::mips ||
      triple.getArch() == llvm::Triple::mipsel ||
      triple.getArch() == llvm::Triple::mips64 ||
      triple.getArch() == llvm::Triple::mips64el)
    return llvm::make_unique<MipsLinkingContext>(triple);
  return nullptr;
}

static std::unique_ptr<TargetHandler> createTarget(llvm::Triple triple,
                                                   MipsLinkingContext &ctx) {
  switch (triple.getArch()) {
  case llvm::Triple::mips:
    return llvm::make_unique<MipsTargetHandler<ELF32BE>>(ctx);
  case llvm::Triple::mipsel:
    return llvm::make_unique<MipsTargetHandler<ELF32LE>>(ctx);
  case llvm::Triple::mips64:
    return llvm::make_unique<MipsTargetHandler<ELF64BE>>(ctx);
  case llvm::Triple::mips64el:
    return llvm::make_unique<MipsTargetHandler<ELF64LE>>(ctx);
  default:
    llvm_unreachable("Unhandled arch");
  }
}

MipsLinkingContext::MipsLinkingContext(llvm::Triple triple)
    : ELFLinkingContext(triple, createTarget(triple, *this)) {}

uint64_t MipsLinkingContext::getBaseAddress() const {
  if (_baseAddress != 0 || getOutputELFType() != llvm::ELF::ET_EXEC)
    return _baseAddress;
  switch (getAbi()) {
  case MipsAbi::O32:
    return 0x0400000;
  case MipsAbi::N32:
    return 0x10000000;
  case MipsAbi::N64:
    return 0x120000000;
  default:
    llvm_unreachable("unknown MIPS ABI flag");
  }
}

StringRef MipsLinkingContext::entrySymbolName() const {
  if (_outputELFType == elf::ET_EXEC && _entrySymbolName.empty())
    return "__start";
  return _entrySymbolName;
}

StringRef MipsLinkingContext::getDefaultInterpreter() const {
  switch (getAbi()) {
  case MipsAbi::O32:
    return "/lib/ld.so.1";
  case MipsAbi::N32:
    return "/lib32/ld.so.1";
  case MipsAbi::N64:
    return "/lib64/ld.so.1";
  default:
    llvm_unreachable("unknown MIPS ABI flag");
  }
}

void MipsLinkingContext::addPasses(PassManager &pm) {
  auto pass = createMipsRelocationPass(*this);
  if (pass)
    pm.add(std::move(pass));
  ELFLinkingContext::addPasses(pm);
  pm.add(llvm::make_unique<elf::MipsCtorsOrderPass>());
}

{'fraction_non_alphanumeric': 0.17293093871505277, 'fraction_numerical': 0.024069616737641176, 'mean_word_length': 3.6369098712446353, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4732802', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1855, 'n_words': 315}