llvm/lld/ELF/Relocations.h

//===- Relocations.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_RELOCATIONS_H
#define LLD_ELF_RELOCATIONS_H

#include "lld/Common/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Object/ELFTypes.h"
#include <vector>

namespace lld::elf {
struct Ctx;
class Defined;
class Symbol;
class InputSection;
class InputSectionBase;
class OutputSection;
class SectionBase;

// Represents a relocation type, such as R_X86_64_PC32 or R_ARM_THM_CALL.
RelType;
JumpModType;

// List of target-independent relocation types. Relocations read
// from files are converted to these types so that the main code
// doesn't have to know about architecture-specific details.
enum RelExpr {};

// Architecture-neutral representation of relocation.
struct Relocation {};

// Manipulate jump instructions with these modifiers.  These are used to relax
// jump instruction opcodes at basic block boundaries and are particularly
// useful when basic block sections are enabled.
struct JumpInstrMod {};

// This function writes undefined symbol diagnostics to an internal buffer.
// Call reportUndefinedSymbols() after calling scanRelocations() to emit
// the diagnostics.
template <class ELFT> void scanRelocations(Ctx &ctx);
template <class ELFT> void checkNoCrossRefs(Ctx &ctx);
void reportUndefinedSymbols(Ctx &);
void postScanRelocations(Ctx &ctx);
void addGotEntry(Ctx &ctx, Symbol &sym);

void hexagonTLSSymbolUpdate(Ctx &ctx);
bool hexagonNeedsTLSSymbol(ArrayRef<OutputSection *> outputSections);

class ThunkSection;
class Thunk;
class InputSectionDescription;

class ThunkCreator {};

// Decode LEB128 without error checking. Only used by performance critical code
// like RelocsCrel.
inline uint64_t readLEB128(const uint8_t *&p, uint64_t leb) {}
inline uint64_t readULEB128(const uint8_t *&p) {}
inline int64_t readSLEB128(const uint8_t *&p) {}

// This class implements a CREL iterator that does not allocate extra memory.
template <bool is64> struct RelocsCrel {};

template <class RelTy> struct Relocs : ArrayRef<RelTy> {};

Relocs<llvm::object::Elf_Crel_Impl<is64>>;

// Return a int64_t to make sure we get the sign extension out of the way as
// early as possible.
template <class ELFT>
static inline int64_t getAddend(const typename ELFT::Rel &rel) {}
template <class ELFT>
static inline int64_t getAddend(const typename ELFT::Rela &rel) {}
template <class ELFT>
static inline int64_t getAddend(const typename ELFT::Crel &rel) {}

template <typename RelTy>
inline Relocs<RelTy> sortRels(Relocs<RelTy> rels,
                              SmallVector<RelTy, 0> &storage) {}

template <bool is64>
inline Relocs<llvm::object::Elf_Crel_Impl<is64>>
sortRels(Relocs<llvm::object::Elf_Crel_Impl<is64>> rels,
         SmallVector<llvm::object::Elf_Crel_Impl<is64>, 0> &storage) {}

// Returns true if Expr refers a GOT entry. Note that this function returns
// false for TLS variables even though they need GOT, because TLS variables uses
// GOT differently than the regular variables.
bool needsGot(RelExpr expr);
} // namespace lld::elf

#endif