LLVM  13.0.0git
Classes | Typedefs | Enumerations | Functions
llvm::elfabi Namespace Reference

Classes

struct  DynamicEntries
 
class  ELFStub
 
struct  ELFSymbol
 

Typedefs

typedef uint16_t ELFArch
 

Enumerations

enum  ELFTarget { ELFTarget::ELF32LE, ELFTarget::ELF32BE, ELFTarget::ELF64LE, ELFTarget::ELF64BE }
 
enum  ELFSymbolType {
  ELFSymbolType::NoType = ELF::STT_NOTYPE, ELFSymbolType::Object = ELF::STT_OBJECT, ELFSymbolType::Func = ELF::STT_FUNC, ELFSymbolType::TLS = ELF::STT_TLS,
  ELFSymbolType::Unknown = 16
}
 

Functions

Expected< std::unique_ptr< ELFStub > > readELFFile (MemoryBufferRef Buf)
 Attempt to read a binary ELF file from a MemoryBuffer. More...
 
Error writeBinaryStub (StringRef FilePath, const ELFStub &Stub, ELFTarget OutputFormat, bool WriteIfChanged=false)
 Attempt to write a binary ELF stub. More...
 
const VersionTuple TBEVersionCurrent (1, 0)
 
Expected< std::unique_ptr< ELFStub > > readTBEFromBuffer (StringRef Buf)
 Attempts to read an ELF interface file from a StringRef buffer. More...
 
Error writeTBEToOutputStream (raw_ostream &OS, const ELFStub &Stub)
 Attempts to write an ELF interface file to a raw_ostream. 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...
 
Error appendToError (Error Err, StringRef After)
 This function takes an error, and appends a string of text to the end of that error. More...
 
template<class ELFT >
static Error populateDynamic (DynamicEntries &Dyn, typename ELFT::DynRange DynTable)
 This function populates a DynamicEntries struct using an ELFT::DynRange. More...
 
static ELFSymbolType convertInfoToType (uint8_t Info)
 This function extracts symbol type from a symbol's st_info member and maps it to an ELFSymbolType enum. More...
 
template<class ELFT >
static ELFSymbol createELFSym (StringRef SymName, const typename ELFT::Sym &RawSym)
 This function creates an ELFSymbol and populates all members using information from a binary ELFT::Sym. More...
 
template<class ELFT >
static Error populateSymbols (ELFStub &TargetStub, const typename ELFT::SymRange DynSym, StringRef DynStr)
 This function populates an ELFStub with symbols using information read from an ELF binary. More...
 
template<class ELFT >
static Expected< std::unique_ptr< ELFStub > > buildStub (const ELFObjectFile< ELFT > &ElfObj)
 Returns a new ELFStub with all members populated from an ELFObjectFile. More...
 
template<class ELFT >
static Error writeELFBinaryToFile (StringRef FilePath, const ELFStub &Stub, bool WriteIfChanged)
 This function opens a file for writing and then writes a binary ELF stub to the file. More...
 

Typedef Documentation

◆ ELFArch

Definition at line 25 of file ELFStub.h.

Enumeration Type Documentation

◆ ELFSymbolType

Enumerator
NoType 
Object 
Func 
TLS 
Unknown 

Definition at line 27 of file ELFStub.h.

◆ ELFTarget

Enumerator
ELF32LE 
ELF32BE 
ELF64LE 
ELF64BE 

Definition at line 27 of file ELFObjHandler.h.

Function Documentation

◆ appendToError()

Error llvm::elfabi::appendToError ( Error  Err,
StringRef  After 
)

This function takes an error, and appends a string of text to the end of that error.

Since "appending" to an Error isn't supported behavior of an Error, this function technically creates a new error with the combined message and consumes the old error.

Parameters
ErrSource error.
AfterText to append at the end of Err's error message.

Definition at line 363 of file ELFObjHandler.cpp.

◆ buildStub()

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

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

Parameters
ElfObjSource ELFObjectFile.

Definition at line 530 of file ELFObjHandler.cpp.

References llvm::object::ELFFile< ELFT >::dynamicEntries(), llvm::object::ELFObjectFile< ELFT >::getELFFile(), llvm::object::ELFFile< ELFT >::program_headers(), and llvm::Expected< T >::takeError().

Referenced by readELFFile().

◆ convertInfoToType()

static ELFSymbolType llvm::elfabi::convertInfoToType ( uint8_t  Info)
static

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

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

Parameters
InfoBinary symbol st_info to extract symbol type from.

Definition at line 452 of file ELFObjHandler.cpp.

References Info, llvm::ELF::STT_FUNC, llvm::ELF::STT_NOTYPE, llvm::ELF::STT_OBJECT, llvm::ELF::STT_TLS, and llvm::pdb::Unknown.

Referenced by createELFSym().

◆ createELFSym()

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

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

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

Definition at line 474 of file ELFObjHandler.cpp.

References convertInfoToType(), llvm::ELF::STB_WEAK, and llvm::elfabi::ELFSymbol::Weak.

◆ initELFHeader()

template<class ELFT >
static void llvm::elfabi::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 53 of file ELFObjHandler.cpp.

◆ populateDynamic()

template<class ELFT >
static Error llvm::elfabi::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 sanity checks.

Parameters
DynTarget DynamicEntries struct to populate.
DynTableSource dynamic table.

Definition at line 379 of file ELFObjHandler.cpp.

References llvm::object::createError().

◆ populateSymbols()

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

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

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

Definition at line 501 of file ELFObjHandler.cpp.

◆ readELFFile()

Expected< std::unique_ptr< ELFStub > > llvm::elfabi::readELFFile ( MemoryBufferRef  Buf)

◆ readTBEFromBuffer()

Expected< std::unique_ptr< ELFStub > > llvm::elfabi::readTBEFromBuffer ( StringRef  Buf)

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

Definition at line 123 of file TBEHandler.cpp.

◆ TBEVersionCurrent()

const VersionTuple llvm::elfabi::TBEVersionCurrent ( ,
 
)

◆ terminatedSubstr()

static Expected<StringRef> llvm::elfabi::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 345 of file ELFObjHandler.cpp.

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

◆ writeBinaryStub()

Error llvm::elfabi::writeBinaryStub ( StringRef  FilePath,
const ELFStub Stub,
ELFTarget  OutputFormat,
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.
OutputFormatTarget ELFType to write binary as.
WriteIfChangedWhether or not to preserve timestamp if the output stays the same.

Definition at line 669 of file ELFObjHandler.cpp.

References llvm_unreachable, and WriteIfChanged.

◆ writeELFBinaryToFile()

template<class ELFT >
static Error llvm::elfabi::writeELFBinaryToFile ( StringRef  FilePath,
const ELFStub 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 ELFStub to generate a binary ELF stub from.

Definition at line 614 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.

◆ writeTBEToOutputStream()

Error llvm::elfabi::writeTBEToOutputStream ( raw_ostream OS,
const ELFStub Stub 
)

Attempts to write an ELF interface file to a raw_ostream.

Definition at line 138 of file TBEHandler.cpp.

References llvm::Error::success().