LLVM  15.0.0git
Classes | Typedefs | Enumerations | Functions
llvm::ifs Namespace Reference

Classes

struct  DynamicEntries
 
struct  IFSStub
 
struct  IFSStubTriple
 
struct  IFSSymbol
 
struct  IFSTarget
 

Typedefs

typedef uint16_t IFSArch
 

Enumerations

enum  IFSSymbolType {
  IFSSymbolType::NoType, IFSSymbolType::Object, IFSSymbolType::Func, IFSSymbolType::TLS,
  IFSSymbolType::Unknown = 16
}
 
enum  IFSEndiannessType { IFSEndiannessType::Little, IFSEndiannessType::Big, IFSEndiannessType::Unknown = 256 }
 
enum  IFSBitWidthType { IFSBitWidthType::IFS32, IFSBitWidthType::IFS64, IFSBitWidthType::Unknown = 256 }
 

Functions

Expected< std::unique_ptr< IFSStub > > readELFFile (MemoryBufferRef Buf)
 Attempt to read a binary ELF file from a MemoryBuffer. More...
 
Error writeBinaryStub (StringRef FilePath, const IFSStub &Stub, bool WriteIfChanged=false)
 Attempt to write a binary ELF stub. More...
 
const VersionTuple IFSVersionCurrent (3, 0)
 
Expected< std::unique_ptr< IFSStub > > readIFSFromBuffer (StringRef Buf)
 Attempts to read an IFS interface file from a StringRef buffer. More...
 
Error writeIFSToOutputStream (raw_ostream &OS, const IFSStub &Stub)
 Attempts to write an IFS interface file to a raw_ostream. More...
 
Error overrideIFSTarget (IFSStub &Stub, Optional< IFSArch > OverrideArch, Optional< IFSEndiannessType > OverrideEndianness, Optional< IFSBitWidthType > OverrideBitWidth, Optional< std::string > OverrideTriple)
 Override the target platform inforation in the text stub. More...
 
Error validateIFSTarget (IFSStub &Stub, bool ParseTriple)
 Validate the target platform inforation in the text stub. More...
 
void stripIFSTarget (IFSStub &Stub, bool StripTriple, bool StripArch, bool StripEndianness, bool StripBitWidth)
 Strips target platform information from the text stub. More...
 
Error filterIFSSyms (IFSStub &Stub, bool StripUndefined, const std::vector< std::string > &Exclude={})
 
IFSTarget parseTriple (StringRef TripleStr)
 Parse llvm triple string into a IFSTarget struct. More...
 
bool operator== (const IFSTarget &Lhs, const IFSTarget &Rhs)
 
bool operator!= (const IFSTarget &Lhs, const IFSTarget &Rhs)
 
uint8_t convertIFSBitWidthToELF (IFSBitWidthType BitWidth)
 This function convert bit width type from IFS enum to ELF format Currently, ELFCLASS32 and ELFCLASS64 are supported. More...
 
uint8_t convertIFSEndiannessToELF (IFSEndiannessType Endianness)
 This function convert endianness type from IFS enum to ELF format Currently, ELFDATA2LSB and ELFDATA2MSB are supported. More...
 
uint8_t convertIFSSymbolTypeToELF (IFSSymbolType SymbolType)
 This function convert symbol type from IFS enum to ELF format Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported. More...
 
IFSBitWidthType convertELFBitWidthToIFS (uint8_t BitWidth)
 This function extracts ELF bit width from e_ident[EI_CLASS] of an ELF file Currently, ELFCLASS32 and ELFCLASS64 are supported. More...
 
IFSEndiannessType convertELFEndiannessToIFS (uint8_t Endianness)
 This function extracts ELF endianness from e_ident[EI_DATA] of an ELF file Currently, ELFDATA2LSB and ELFDATA2MSB are supported. More...
 
IFSSymbolType convertELFSymbolTypeToIFS (uint8_t SymbolType)
 This function extracts symbol type from a symbol's st_info member and maps it to an IFSSymbolType enum. More...
 
template<class ELFT >
static void initELFHeader (typename ELFT::Ehdr &ElfHeader, uint16_t Machine)
 This initializes an ELF file header with information specific to a binary dynamic shared object. More...
 
static Expected< StringRefterminatedSubstr (StringRef Str, size_t Offset)
 This function behaves similarly to StringRef::substr(), but attempts to terminate the returned StringRef at the first null terminator. More...
 
template<class ELFT >
static Error populateDynamic (DynamicEntries &Dyn, typename ELFT::DynRange DynTable)
 This function populates a DynamicEntries struct using an ELFT::DynRange. More...
 
template<class ELFT >
static IFSSymbol createELFSym (StringRef SymName, const typename ELFT::Sym &RawSym)
 This function creates an IFSSymbol and populates all members using information from a binary ELFT::Sym. More...
 
template<class ELFT >
static Error populateSymbols (IFSStub &TargetStub, const typename ELFT::SymRange DynSym, StringRef DynStr)
 This function populates an IFSStub with symbols using information read from an ELF binary. More...
 
template<class ELFT >
static Expected< std::unique_ptr< IFSStub > > buildStub (const ELFObjectFile< ELFT > &ElfObj)
 Returns a new IFSStub with all members populated from an ELFObjectFile. More...
 
template<class ELFT >
static Error writeELFBinaryToFile (StringRef FilePath, const IFSStub &Stub, bool WriteIfChanged)
 This function opens a file for writing and then writes a binary ELF stub to the file. More...
 

Typedef Documentation

◆ IFSArch

Definition at line 24 of file IFSStub.h.

Enumeration Type Documentation

◆ IFSBitWidthType

Enumerator
IFS32 
IFS64 
Unknown 

Definition at line 44 of file IFSStub.h.

◆ IFSEndiannessType

Enumerator
Little 
Big 
Unknown 

Definition at line 36 of file IFSStub.h.

◆ IFSSymbolType

Enumerator
NoType 
Object 
Func 
TLS 
Unknown 

Definition at line 26 of file IFSStub.h.

Function Documentation

◆ buildStub()

template<class ELFT >
static Expected<std::unique_ptr<IFSStub> > llvm::ifs::buildStub ( const ELFObjectFile< ELFT > &  ElfObj)
static

Returns a new IFSStub with all members populated from an ELFObjectFile.

Parameters
ElfObjSource ELFObjectFile.

Definition at line 575 of file ELFObjHandler.cpp.

Referenced by readELFFile().

◆ convertELFBitWidthToIFS()

IFSBitWidthType llvm::ifs::convertELFBitWidthToIFS ( uint8_t  BitWidth)

This function extracts ELF bit width from e_ident[EI_CLASS] of an ELF file Currently, ELFCLASS32 and ELFCLASS64 are supported.

Other endianness types are mapped to IFSBitWidthType::Unknown.

Parameters
BitWidthe_ident[EI_CLASS] value to extract bit width from.

Definition at line 97 of file IFSStub.cpp.

References llvm::BitWidth, llvm::ELF::ELFCLASS32, llvm::ELF::ELFCLASS64, IFS32, IFS64, and Unknown.

◆ convertELFEndiannessToIFS()

IFSEndiannessType llvm::ifs::convertELFEndiannessToIFS ( uint8_t  Endianness)

This function extracts ELF endianness from e_ident[EI_DATA] of an ELF file Currently, ELFDATA2LSB and ELFDATA2MSB are supported.

Other endianness types are mapped to IFSEndiannessType::Unknown.

Parameters
Endiannesse_ident[EI_DATA] value to extract endianness type from.

Definition at line 108 of file IFSStub.cpp.

References Big, llvm::ELF::ELFDATA2LSB, llvm::ELF::ELFDATA2MSB, llvm::msgpack::Endianness, Little, and Unknown.

◆ convertELFSymbolTypeToIFS()

IFSSymbolType llvm::ifs::convertELFSymbolTypeToIFS ( uint8_t  SymbolType)

This function extracts symbol type from a symbol's st_info member and maps it to an IFSSymbolType enum.

Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported. Other symbol types are mapped to IFSSymbolType::Unknown.

Parameters
SymbolTypeBinary symbol st_info to extract symbol type from.

Definition at line 119 of file IFSStub.cpp.

References Func, NoType, Object, llvm::ELF::STT_FUNC, llvm::ELF::STT_NOTYPE, llvm::ELF::STT_OBJECT, llvm::ELF::STT_TLS, TLS, and Unknown.

Referenced by createELFSym().

◆ convertIFSBitWidthToELF()

uint8_t llvm::ifs::convertIFSBitWidthToELF ( IFSBitWidthType  BitWidth)

This function convert bit width type from IFS enum to ELF format Currently, ELFCLASS32 and ELFCLASS64 are supported.

Parameters
BitWidthIFS bit width type.

Definition at line 61 of file IFSStub.cpp.

References llvm::BitWidth, llvm::ELF::ELFCLASS32, llvm::ELF::ELFCLASS64, IFS32, IFS64, and llvm_unreachable.

◆ convertIFSEndiannessToELF()

uint8_t llvm::ifs::convertIFSEndiannessToELF ( IFSEndiannessType  Endianness)

This function convert endianness type from IFS enum to ELF format Currently, ELFDATA2LSB and ELFDATA2MSB are supported.

Parameters
EndiannessIFS endianness type.

Definition at line 72 of file IFSStub.cpp.

References Big, llvm::ELF::ELFDATA2LSB, llvm::ELF::ELFDATA2MSB, llvm::msgpack::Endianness, Little, and llvm_unreachable.

◆ convertIFSSymbolTypeToELF()

uint8_t llvm::ifs::convertIFSSymbolTypeToELF ( IFSSymbolType  SymbolType)

This function convert symbol type from IFS enum to ELF format Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.

Parameters
SymbolTypeIFS symbol type.

Definition at line 83 of file IFSStub.cpp.

References Func, NoType, Object, llvm::ELF::STT_FUNC, llvm::ELF::STT_NOTYPE, llvm::ELF::STT_OBJECT, llvm::ELF::STT_TLS, and TLS.

◆ createELFSym()

template<class ELFT >
static IFSSymbol llvm::ifs::createELFSym ( StringRef  SymName,
const typename ELFT::Sym &  RawSym 
)
static

This function creates an IFSSymbol and populates all members using information from a binary ELFT::Sym.

Parameters
SymNameThe desired name of the IFSSymbol.
RawSymELFT::Sym to extract symbol information from.

Definition at line 519 of file ELFObjHandler.cpp.

References convertELFSymbolTypeToIFS(), and llvm::ELF::STB_WEAK.

◆ filterIFSSyms()

Error llvm::ifs::filterIFSSyms ( IFSStub Stub,
bool  StripUndefined,
const std::vector< std::string > &  Exclude = {} 
)

◆ IFSVersionCurrent()

const VersionTuple llvm::ifs::IFSVersionCurrent ( ,
 
)

◆ initELFHeader()

template<class ELFT >
static void llvm::ifs::initELFHeader ( typename ELFT::Ehdr &  ElfHeader,
uint16_t  Machine 
)
static

This initializes an ELF file header with information specific to a binary dynamic shared object.

Offsets, indexes, links, etc. for section and program headers are just zero-initialized as they will be updated elsewhere.

Parameters
ElfHeaderTarget ELFT::Ehdr to populate.
MachineTarget architecture (e_machine from ELF specifications).

Definition at line 51 of file ELFObjHandler.cpp.

◆ operator!=()

bool llvm::ifs::operator!= ( const IFSTarget Lhs,
const IFSTarget Rhs 
)
inline

Definition at line 83 of file IFSStub.h.

◆ operator==()

bool llvm::ifs::operator== ( const IFSTarget Lhs,
const IFSTarget Rhs 
)
inline

◆ overrideIFSTarget()

Error llvm::ifs::overrideIFSTarget ( IFSStub Stub,
Optional< IFSArch OverrideArch,
Optional< IFSEndiannessType OverrideEndianness,
Optional< IFSBitWidthType OverrideBitWidth,
Optional< std::string >  OverrideTriple 
)

◆ parseTriple()

IFSTarget llvm::ifs::parseTriple ( StringRef  TripleStr)

◆ populateDynamic()

template<class ELFT >
static Error llvm::ifs::populateDynamic ( DynamicEntries Dyn,
typename ELFT::DynRange  DynTable 
)
static

This function populates a DynamicEntries struct using an ELFT::DynRange.

After populating the struct, the members are validated with some basic correctness checks.

Parameters
DynTarget DynamicEntries struct to populate.
DynTableSource dynamic table.

Definition at line 446 of file ELFObjHandler.cpp.

References llvm::object::createError().

◆ populateSymbols()

template<class ELFT >
static Error llvm::ifs::populateSymbols ( IFSStub TargetStub,
const typename ELFT::SymRange  DynSym,
StringRef  DynStr 
)
static

This function populates an IFSStub with symbols using information read from an ELF binary.

Parameters
TargetStubIFSStub to add symbols to.
DynSymRange of dynamic symbols to add to TargetStub.
DynStrStringRef to the dynamic string table.

Definition at line 546 of file ELFObjHandler.cpp.

◆ readELFFile()

Expected< std::unique_ptr< IFSStub > > llvm::ifs::readELFFile ( MemoryBufferRef  Buf)

◆ readIFSFromBuffer()

Expected< std::unique_ptr< IFSStub > > llvm::ifs::readIFSFromBuffer ( StringRef  Buf)

Attempts to read an IFS interface file from a StringRef buffer.

Definition at line 178 of file IFSHandler.cpp.

References usesTriple().

◆ stripIFSTarget()

void llvm::ifs::stripIFSTarget ( IFSStub Stub,
bool  StripTriple,
bool  StripArch,
bool  StripEndianness,
bool  StripBitWidth 
)

◆ terminatedSubstr()

static Expected<StringRef> llvm::ifs::terminatedSubstr ( StringRef  Str,
size_t  Offset 
)
static

This function behaves similarly to StringRef::substr(), but attempts to terminate the returned StringRef at the first null terminator.

If no null terminator is found, an error is returned.

Parameters
StrSource string to create a substring from.
OffsetThe start index of the desired substring.

Definition at line 428 of file ELFObjHandler.cpp.

References llvm::object::createError(), and llvm::StringRef::npos.

◆ validateIFSTarget()

Error llvm::ifs::validateIFSTarget ( IFSStub Stub,
bool  ParseTriple 
)

◆ writeBinaryStub()

Error llvm::ifs::writeBinaryStub ( StringRef  FilePath,
const IFSStub Stub,
bool  WriteIfChanged = false 
)

Attempt to write a binary ELF stub.

This function determines appropriate ELFType using the passed ELFTarget and then writes a binary ELF stub to a specified file path.

Parameters
FilePathFile path for writing the ELF binary.
StubSource ELFStub to generate a binary ELF stub from.
WriteIfChangedWhether or not to preserve timestamp if the output stays the same.

Definition at line 711 of file ELFObjHandler.cpp.

References llvm::ifs::IFSTarget::Arch, assert(), llvm::ifs::IFSTarget::BitWidth, llvm::ifs::IFSTarget::Endianness, llvm_unreachable, llvm::ifs::IFSStub::Target, and WriteIfChanged.

◆ writeELFBinaryToFile()

template<class ELFT >
static Error llvm::ifs::writeELFBinaryToFile ( StringRef  FilePath,
const IFSStub Stub,
bool  WriteIfChanged 
)
static

This function opens a file for writing and then writes a binary ELF stub to the file.

Parameters
FilePathFile path for writing the ELF binary.
StubSource InterFace Stub to generate a binary ELF stub from.

Definition at line 656 of file ELFObjHandler.cpp.

References Builder, llvm::FileOutputBuffer::create(), llvm::createStringError(), llvm::MemoryBuffer::getFile(), llvm::invalid_argument, memcmp, memcpy(), move, llvm::Error::success(), llvm::Expected< T >::takeError(), llvm::toString(), and WriteIfChanged.

◆ writeIFSToOutputStream()

Error llvm::ifs::writeIFSToOutputStream ( raw_ostream OS,
const IFSStub Stub 
)

Attempts to write an IFS interface file to a raw_ostream.

Definition at line 201 of file IFSHandler.cpp.

References llvm::ifs::IFSTarget::Arch, llvm::ELF::convertEMachineToArchName(), llvm::Error::success(), and llvm::ifs::IFSStub::Target.