LLVM  15.0.0git
Namespaces | Functions | Variables
ELFObject.cpp File Reference
#include "ELFObject.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/Path.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <unordered_set>
#include <utility>
#include <vector>
Include dependency graph for ELFObject.cpp:

Go to the source code of this file.

Namespaces

 llvm
 This is an optimization pass for GlobalISel generic memory operations.
 
 llvm::objcopy
 
 llvm::objcopy::elf
 

Functions

static bool addressOverflows32bit (uint64_t Addr)
 
template<class T >
static T checkedGetHex (StringRef S)
 
template<class T , class Iterator >
static Iterator toHexStr (T X, Iterator It, size_t Len)
 
static Error checkRecord (const IHexRecord &R)
 
static Error checkChars (StringRef Line)
 
static uint64_t sectionPhysicalAddr (const SectionBase *Sec)
 
static bool isDataGnuCompressed (ArrayRef< uint8_t > Data)
 
template<class ELFT >
static std::tuple< uint64_t, uint64_tgetDecompressedSizeAndAlignment (ArrayRef< uint8_t > Data)
 
static bool isValidReservedSectionIndex (uint16_t Index, uint16_t Machine)
 
template<class ELFT >
static void setAddend (Elf_Rel_Impl< ELFT, false > &, uint64_t)
 
template<class ELFT >
static void setAddend (Elf_Rel_Impl< ELFT, true > &Rela, uint64_t Addend)
 
template<class RelRange , class T >
static void writeRel (const RelRange &Relocations, T *Buf, bool IsMips64EL)
 
static bool sectionWithinSegment (const SectionBase &Sec, const Segment &Seg)
 
static bool segmentOverlapsSegment (const Segment &Child, const Segment &Parent)
 
static bool compareSegmentsByOffset (const Segment *A, const Segment *B)
 
template<class ELFT >
static void getAddend (uint64_t &, const Elf_Rel_Impl< ELFT, false > &)
 
template<class ELFT >
static void getAddend (uint64_t &ToSet, const Elf_Rel_Impl< ELFT, true > &Rela)
 
template<class T >
static Error initRelocations (RelocationSection *Relocs, T RelRange)
 
static void orderSegments (std::vector< Segment * > &Segments)
 
static uint64_t layoutSegments (std::vector< Segment * > &Segments, uint64_t Offset)
 
template<class Range >
static uint64_t layoutSections (Range Sections, uint64_t Offset)
 
static uint64_t layoutSectionsForOnlyKeepDebug (Object &Obj, uint64_t Off)
 
static uint64_t layoutSegmentsForOnlyKeepDebug (std::vector< Segment * > &Segments, uint64_t HdrEnd)
 
static Error removeUnneededSections (Object &Obj)
 

Variables

static constexpr std::array< uint8_t, 4 > ZlibGnuMagic = {{'Z', 'L', 'I', 'B'}}
 

Function Documentation

◆ addressOverflows32bit()

static bool addressOverflows32bit ( uint64_t  Addr)
static

Definition at line 177 of file ELFObject.cpp.

References Addr.

Referenced by llvm::objcopy::elf::IHexWriter::finalize().

◆ checkChars()

static Error checkChars ( StringRef  Line)
static

◆ checkedGetHex()

template<class T >
static T checkedGetHex ( StringRef  S)
static

Definition at line 182 of file ELFObject.cpp.

References assert(), Fail, and S.

◆ checkRecord()

static Error checkRecord ( const IHexRecord R)
static

◆ compareSegmentsByOffset()

static bool compareSegmentsByOffset ( const Segment A,
const Segment B 
)
static

Definition at line 1225 of file ELFObject.cpp.

References B.

Referenced by layoutSegments(), and orderSegments().

◆ getAddend() [1/2]

template<class ELFT >
static void getAddend ( uint64_t ,
const Elf_Rel_Impl< ELFT, false > &   
)
static

Definition at line 1614 of file ELFObject.cpp.

Referenced by initRelocations(), and loadObj().

◆ getAddend() [2/2]

template<class ELFT >
static void getAddend ( uint64_t ToSet,
const Elf_Rel_Impl< ELFT, true > &  Rela 
)
static

Definition at line 1617 of file ELFObject.cpp.

◆ getDecompressedSizeAndAlignment()

template<class ELFT >
static std::tuple<uint64_t, uint64_t> getDecompressedSizeAndAlignment ( ArrayRef< uint8_t >  Data)
static

◆ initRelocations()

template<class T >
static Error initRelocations ( RelocationSection Relocs,
T  RelRange 
)
static

◆ isDataGnuCompressed()

static bool isDataGnuCompressed ( ArrayRef< uint8_t >  Data)
static

◆ isValidReservedSectionIndex()

static bool isValidReservedSectionIndex ( uint16_t  Index,
uint16_t  Machine 
)
static

◆ layoutSections()

template<class Range >
static uint64_t layoutSections ( Range  Sections,
uint64_t  Offset 
)
static

◆ layoutSectionsForOnlyKeepDebug()

static uint64_t layoutSectionsForOnlyKeepDebug ( Object Obj,
uint64_t  Off 
)
static

◆ layoutSegments()

static uint64_t layoutSegments ( std::vector< Segment * > &  Segments,
uint64_t  Offset 
)
static

◆ layoutSegmentsForOnlyKeepDebug()

static uint64_t layoutSegmentsForOnlyKeepDebug ( std::vector< Segment * > &  Segments,
uint64_t  HdrEnd 
)
static

◆ orderSegments()

static void orderSegments ( std::vector< Segment * > &  Segments)
static

Definition at line 2260 of file ELFObject.cpp.

References compareSegmentsByOffset(), and llvm::stable_sort().

◆ removeUnneededSections()

static Error removeUnneededSections ( Object Obj)
static

◆ sectionPhysicalAddr()

static uint64_t sectionPhysicalAddr ( const SectionBase Sec)
static

◆ sectionWithinSegment()

static bool sectionWithinSegment ( const SectionBase Sec,
const Segment Seg 
)
static

◆ segmentOverlapsSegment()

static bool segmentOverlapsSegment ( const Segment Child,
const Segment Parent 
)
static

◆ setAddend() [1/2]

template<class ELFT >
static void setAddend ( Elf_Rel_Impl< ELFT, false > &  ,
uint64_t   
)
static

Definition at line 943 of file ELFObject.cpp.

Referenced by writeRel().

◆ setAddend() [2/2]

template<class ELFT >
static void setAddend ( Elf_Rel_Impl< ELFT, true > &  Rela,
uint64_t  Addend 
)
static

Definition at line 946 of file ELFObject.cpp.

◆ toHexStr()

template<class T , class Iterator >
static Iterator toHexStr ( T  X,
Iterator  It,
size_t  Len 
)
static

Definition at line 193 of file ELFObject.cpp.

References assert(), I, Mod, and X.

Referenced by llvm::objcopy::elf::IHexRecord::getLine().

◆ writeRel()

template<class RelRange , class T >
static void writeRel ( const RelRange &  Relocations,
T Buf,
bool  IsMips64EL 
)
static

Definition at line 951 of file ELFObject.cpp.

References setAddend().

Referenced by llvm::objcopy::elf::ELFSectionWriter< ELFT >::visit().

Variable Documentation

◆ ZlibGnuMagic

constexpr std::array<uint8_t, 4> ZlibGnuMagic = {{'Z', 'L', 'I', 'B'}}
staticconstexpr