LLVM 19.0.0git
Macros | Functions
MipsELFObjectWriter.cpp File Reference
#include "MCTargetDesc/MipsFixupKinds.h"
#include "MCTargetDesc/MipsMCTargetDesc.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iterator>
#include <list>
#include <utility>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "mips-elf-object-writer"
 

Functions

template<class InputIt , class OutputIt1 , class OutputIt2 , class UnaryPredicate >
static std::pair< OutputIt1, OutputIt2 > copy_if_else (InputIt First, InputIt Last, OutputIt1 d1, OutputIt2 d2, UnaryPredicate Predicate)
 Copy elements in the range [First, Last) to d1 when the predicate is true or d2 when the predicate is false.
 
template<class InputIt , class UnaryPredicate , class Comparator >
static InputIt find_best (InputIt First, InputIt Last, UnaryPredicate Predicate, Comparator BetterThan)
 Find the best match in the range [First, Last).
 
static unsigned getMatchingLoType (const ELFRelocationEntry &Reloc)
 Determine the low relocation that matches the given relocation.
 
static FindBestPredicateResult isMatchingReloc (const MipsRelocationEntry &X, const ELFRelocationEntry &R, unsigned MatchingType)
 Determine whether a relocation (X) matches the one given in R.
 
static bool compareMatchingRelocs (const MipsRelocationEntry &Candidate, const MipsRelocationEntry &PreviousBest)
 Determine whether Candidate or PreviousBest is the better match.
 
template<class Container >
static void dumpRelocs (const char *Prefix, const Container &Relocs)
 Print all the relocations.
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "mips-elf-object-writer"

Definition at line 31 of file MipsELFObjectWriter.cpp.

Function Documentation

◆ compareMatchingRelocs()

static bool compareMatchingRelocs ( const MipsRelocationEntry &  Candidate,
const MipsRelocationEntry &  PreviousBest 
)
static

Determine whether Candidate or PreviousBest is the better match.

The return value is true if Candidate is the better match.

A matching relocation is a better match if:

  • It has a smaller addend.
  • It is not already involved in a match.

Definition at line 197 of file MipsELFObjectWriter.cpp.

◆ copy_if_else()

template<class InputIt , class OutputIt1 , class OutputIt2 , class UnaryPredicate >
static std::pair< OutputIt1, OutputIt2 > copy_if_else ( InputIt  First,
InputIt  Last,
OutputIt1  d1,
OutputIt2  d2,
UnaryPredicate  Predicate 
)
static

Copy elements in the range [First, Last) to d1 when the predicate is true or d2 when the predicate is false.

This is essentially both std::copy_if and std::remove_copy_if combined into a single pass.

Definition at line 85 of file MipsELFObjectWriter.cpp.

References llvm::First, I, and llvm::Last.

◆ dumpRelocs()

template<class Container >
static void dumpRelocs ( const char Prefix,
const Container &  Relocs 
)
static

Print all the relocations.

Definition at line 207 of file MipsELFObjectWriter.cpp.

References llvm::dbgs().

◆ find_best()

template<class InputIt , class UnaryPredicate , class Comparator >
static InputIt find_best ( InputIt  First,
InputIt  Last,
UnaryPredicate  Predicate,
Comparator  BetterThan 
)
static

Find the best match in the range [First, Last).

An element matches when Predicate(X) returns FindBest_Match or FindBest_PerfectMatch. A value of FindBest_PerfectMatch also terminates the search. BetterThan(A, B) is a comparator that returns true when A is a better match than B. The return value is the position of the best match.

This is similar to std::find_if but finds the best of multiple possible matches.

Definition at line 111 of file MipsELFObjectWriter.cpp.

References llvm::dbgs(), llvm::First, I, llvm::Last, and LLVM_DEBUG.

◆ getMatchingLoType()

static unsigned getMatchingLoType ( const ELFRelocationEntry Reloc)
static

Determine the low relocation that matches the given relocation.

If the relocation does not need a low relocation then the return value is ELF::R_MIPS_NONE.

The relocations that need a matching low part are R_(MIPS|MICROMIPS|MIPS16)_HI16 for all symbols and R_(MIPS|MICROMIPS|MIPS16)_GOT16 for local symbols only.

Definition at line 141 of file MipsELFObjectWriter.cpp.

References llvm::MCSymbolELF::getBinding(), llvm::ELFRelocationEntry::OriginalSymbol, llvm::ELF::STB_LOCAL, and llvm::ELFRelocationEntry::Type.

◆ isMatchingReloc()

static FindBestPredicateResult isMatchingReloc ( const MipsRelocationEntry &  X,
const ELFRelocationEntry R,
unsigned  MatchingType 
)
static

Determine whether a relocation (X) matches the one given in R.

A relocation matches if:

  • It's type matches that of a corresponding low part. This is provided in MatchingType for efficiency.
  • It's based on the same symbol.
  • It's offset of greater or equal to that of the one given in R. It should be noted that this rule assumes the programmer does not use offsets that exceed the alignment of the symbol. The carry-bit will be incorrect if this is not true.

A matching relocation is unbeatable if:

  • It is not already involved in a match.
  • It's offset is exactly that of the one given in R.

Definition at line 178 of file MipsELFObjectWriter.cpp.

References X.