LLVM 20.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 class  IFSSymbolType {
  NoType , Object , Func , TLS ,
  Unknown = 16
}
 
enum class  IFSEndiannessType { Little , Big , Unknown = 256 }
 
enum class  IFSBitWidthType { IFS32 , IFS64 , Unknown = 256 }
 

Functions

Expected< std::unique_ptr< IFSStub > > readELFFile (MemoryBufferRef Buf)
 Attempt to read a binary ELF file from a MemoryBuffer.
 
Error writeBinaryStub (StringRef FilePath, const IFSStub &Stub, bool WriteIfChanged=false)
 Attempt to write a binary ELF stub.
 
const VersionTuple IFSVersionCurrent (3, 0)
 
Expected< std::unique_ptr< IFSStub > > readIFSFromBuffer (StringRef Buf)
 Attempts to read an IFS interface file from a StringRef buffer.
 
Error writeIFSToOutputStream (raw_ostream &OS, const IFSStub &Stub)
 Attempts to write an IFS interface file to a raw_ostream.
 
Error overrideIFSTarget (IFSStub &Stub, std::optional< IFSArch > OverrideArch, std::optional< IFSEndiannessType > OverrideEndianness, std::optional< IFSBitWidthType > OverrideBitWidth, std::optional< std::string > OverrideTriple)
 Override the target platform inforation in the text stub.
 
Error validateIFSTarget (IFSStub &Stub, bool ParseTriple)
 Validate the target platform inforation in the text stub.
 
void stripIFSTarget (IFSStub &Stub, bool StripTriple, bool StripArch, bool StripEndianness, bool StripBitWidth)
 Strips target platform information from the text stub.
 
Error filterIFSSyms (IFSStub &Stub, bool StripUndefined, const std::vector< std::string > &Exclude={})
 
IFSTarget parseTriple (StringRef TripleStr)
 Parse llvm triple string into a IFSTarget struct.
 
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.
 
uint8_t convertIFSEndiannessToELF (IFSEndiannessType Endianness)
 This function convert endianness type from IFS enum to ELF format Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
 
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.
 
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.
 
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.
 
IFSSymbolType convertELFSymbolTypeToIFS (uint8_t SymbolType)
 This function extracts symbol type from a symbol's st_info member and maps it to an IFSSymbolType enum.
 
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.
 
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.
 
template<class ELFT >
static Error populateDynamic (DynamicEntries &Dyn, typename ELFT::DynRange DynTable)
 This function populates a DynamicEntries struct using an ELFT::DynRange.
 
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.
 
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.
 
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.
 
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.
 

Typedef Documentation

◆ IFSArch

Definition at line 24 of file IFSStub.h.

Enumeration Type Documentation

◆ IFSBitWidthType

enum class llvm::ifs::IFSBitWidthType
strong
Enumerator
IFS32 
IFS64 
Unknown 

Definition at line 44 of file IFSStub.h.

◆ IFSEndiannessType

enum class llvm::ifs::IFSEndiannessType
strong
Enumerator
Little 
Big 
Unknown 

Definition at line 36 of file IFSStub.h.

◆ IFSSymbolType

enum class llvm::ifs::IFSSymbolType
strong
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

◆ 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 98 of file IFSStub.cpp.

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

Referenced by buildStub().

◆ 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 109 of file IFSStub.cpp.

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

Referenced by buildStub().

◆ 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 120 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, 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, llvm_unreachable, 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 520 of file ELFObjHandler.cpp.

References convertELFSymbolTypeToIFS(), Func, 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 ( ,
 
)

Referenced by readIFSFromBuffer().

◆ 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 52 of file ELFObjHandler.cpp.

References llvm::ELF::EI_CLASS, llvm::ELF::EI_DATA, llvm::ELF::EI_MAG0, llvm::ELF::EI_MAG1, llvm::ELF::EI_MAG2, llvm::ELF::EI_MAG3, llvm::ELF::EI_OSABI, llvm::ELF::EI_VERSION, llvm::ELF::ELFCLASS32, llvm::ELF::ELFCLASS64, llvm::ELF::ELFDATA2LSB, llvm::ELF::ELFDATA2MSB, llvm::ELF::ElfMagic, llvm::ELF::ELFOSABI_NONE, llvm::ELF::ET_DYN, llvm::ELF::EV_CURRENT, llvm::little, and Machine.

◆ 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,
std::optional< IFSArch OverrideArch,
std::optional< IFSEndiannessType OverrideEndianness,
std::optional< IFSBitWidthType OverrideBitWidth,
std::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 447 of file ELFObjHandler.cpp.

References llvm::createError(), llvm::createStringError(), llvm::ifs::DynamicEntries::DynSymAddr, llvm::ifs::DynamicEntries::ElfHash, llvm::ifs::DynamicEntries::GnuHash, llvm::ifs::DynamicEntries::NeededLibNames, llvm::Offset, llvm::ifs::DynamicEntries::SONameOffset, llvm::ifs::DynamicEntries::StrSize, llvm::ifs::DynamicEntries::StrTabAddr, and llvm::Error::success().

◆ 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 547 of file ELFObjHandler.cpp.

References llvm::ELF::STB_GLOBAL, llvm::ELF::STB_WEAK, llvm::ELF::STV_DEFAULT, llvm::ELF::STV_PROTECTED, llvm::Error::success(), Sym, llvm::ifs::IFSStub::Symbols, llvm::Expected< T >::takeError(), and terminatedSubstr().

◆ 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 179 of file IFSHandler.cpp.

References llvm::ELF::convertArchNameToEMachine(), llvm::createStringError(), llvm::ELF::EM_NONE, IFSVersionCurrent(), and 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 429 of file ELFObjHandler.cpp.

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

Referenced by buildStub(), and populateSymbols().

◆ 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 712 of file ELFObjHandler.cpp.

References llvm::ifs::IFSTarget::Arch, assert(), llvm::ifs::IFSTarget::BitWidth, llvm::ifs::IFSTarget::Endianness, IFS32, Little, 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 657 of file ELFObjHandler.cpp.

References llvm::FileOutputBuffer::create(), llvm::createStringError(), llvm::MemoryBuffer::getFile(), llvm::invalid_argument, memcmp, 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 213 of file IFSHandler.cpp.

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