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 {};

void setAArch64TargetInfo(Ctx &);
void setAMDGPUTargetInfo(Ctx &);
void setARMTargetInfo(Ctx &);
void setAVRTargetInfo(Ctx &);
void setHexagonTargetInfo(Ctx &);
void setLoongArchTargetInfo(Ctx &);
void setMSP430TargetInfo(Ctx &);
void setMipsTargetInfo(Ctx &);
void setPPC64TargetInfo(Ctx &);
void setPPCTargetInfo(Ctx &);
void setRISCVTargetInfo(Ctx &);
void setSPARCV9TargetInfo(Ctx &);
void setSystemZTargetInfo(Ctx &);
void setX86TargetInfo(Ctx &);
void setX86_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 getErrorLoc(Ctx &ctx, const uint8_t *loc) {}

void processArmCmseSymbols(Ctx &);

template <class ELFT> uint32_t calcMipsEFlags(Ctx &);
uint8_t getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag,
                         llvm::StringRef fileName);
bool isMipsN32Abi(Ctx &, const InputFile &f);
bool isMicroMips(Ctx &);
bool isMipsR6(Ctx &);

void writePPC32GlinkSection(Ctx &, 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 writePrefixedInst(Ctx &, uint8_t *loc, uint64_t insn);

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

void setTarget(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