llvm/lld/ELF/Target.h

//===- Target.h -------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLD_ELF_TARGET_H
#define LLD_ELF_TARGET_H

#include "Config.h"
#include "InputSection.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFTypes.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MathExtras.h"
#include <array>

namespace lld {
std::string toString(elf::RelType type);

namespace elf {
class Defined;
class InputFile;
class Symbol;

class TargetInfo {};

TargetInfo *getAArch64TargetInfo(Ctx &);
TargetInfo *getAMDGPUTargetInfo(Ctx &);
TargetInfo *getARMTargetInfo(Ctx &);
TargetInfo *getAVRTargetInfo(Ctx &);
TargetInfo *getHexagonTargetInfo(Ctx &);
TargetInfo *getLoongArchTargetInfo(Ctx &);
TargetInfo *getMSP430TargetInfo(Ctx &);
TargetInfo *getMipsTargetInfo(Ctx &);
TargetInfo *getPPC64TargetInfo(Ctx &);
TargetInfo *getPPCTargetInfo(Ctx &);
TargetInfo *getRISCVTargetInfo(Ctx &);
TargetInfo *getSPARCV9TargetInfo(Ctx &);
TargetInfo *getSystemZTargetInfo(Ctx &);
TargetInfo *getX86TargetInfo(Ctx &);
TargetInfo *getX86_64TargetInfo(Ctx &);

struct ErrorPlace {};

// Returns input section and corresponding source string for the given location.
ErrorPlace getErrorPlace(Ctx &ctx, const uint8_t *loc);

static inline std::string getErrorLocation(const uint8_t *loc) {}

void processArmCmseSymbols(Ctx &);

void writePPC32GlinkSection(uint8_t *buf, size_t numEntries);

unsigned getPPCDFormOp(unsigned secondaryOp);
unsigned getPPCDSFormOp(unsigned secondaryOp);

// In the PowerPC64 Elf V2 abi a function can have 2 entry points.  The first
// is a global entry point (GEP) which typically is used to initialize the TOC
// pointer in general purpose register 2.  The second is a local entry
// point (LEP) which bypasses the TOC pointer initialization code. The
// offset between GEP and LEP is encoded in a function's st_other flags.
// This function will return the offset (in bytes) from the global entry-point
// to the local entry-point.
unsigned getPPC64GlobalEntryToLocalEntryOffset(uint8_t stOther);

// Write a prefixed instruction, which is a 4-byte prefix followed by a 4-byte
// instruction (regardless of endianness). Therefore, the prefix is always in
// lower memory than the instruction.
void writePrefixedInstruction(uint8_t *loc, uint64_t insn);

void addPPC64SaveRestore();
uint64_t getPPC64TocBase();
uint64_t getAArch64Page(uint64_t expr);
bool isAArch64BTILandingPad(Symbol &s, int64_t a);
template <typename ELFT> void writeARMCmseImportLib();
uint64_t getLoongArchPageDelta(uint64_t dest, uint64_t pc, RelType type);
void riscvFinalizeRelax(int passes);
void mergeRISCVAttributesSections(Ctx &);
void addArmInputSectionMappingSymbols();
void addArmSyntheticSectionMappingSymbol(Defined *);
void sortArmMappingSymbols();
void convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf);
void createTaggedSymbols(const SmallVector<ELFFileBase *, 0> &files);
void initSymbolAnchors();

TargetInfo *getTarget(Ctx &);

template <class ELFT> bool isMipsPIC(const Defined *sym);

void reportRangeError(Ctx &, uint8_t *loc, const Relocation &rel,
                      const Twine &v, int64_t min, uint64_t max);
void reportRangeError(Ctx &ctx, uint8_t *loc, int64_t v, int n,
                      const Symbol &sym, const Twine &msg);

// Make sure that V can be represented as an N bit signed integer.
inline void checkInt(uint8_t *loc, int64_t v, int n, const Relocation &rel) {}

// Make sure that V can be represented as an N bit unsigned integer.
inline void checkUInt(uint8_t *loc, uint64_t v, int n, const Relocation &rel) {}

// Make sure that V can be represented as an N bit signed or unsigned integer.
inline void checkIntUInt(uint8_t *loc, uint64_t v, int n,
                         const Relocation &rel) {}

inline void checkAlignment(uint8_t *loc, uint64_t v, int n,
                           const Relocation &rel) {}

// Endianness-aware read/write.
inline uint16_t read16(const void *p) {}

inline uint32_t read32(const void *p) {}

inline uint64_t read64(const void *p) {}

inline void write16(void *p, uint16_t v) {}

inline void write32(void *p, uint32_t v) {}

inline void write64(void *p, uint64_t v) {}

// Overwrite a ULEB128 value and keep the original length.
inline uint64_t overwriteULEB128(uint8_t *bufLoc, uint64_t val) {}
} // namespace elf
} // namespace lld

#ifdef __clang__
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
#define invokeELFT(f, ...)

#endif