Nyxstone
|
#include <ObjectWriterWrapper.h>
Public Member Functions | |
ObjectWriterWrapper (std::unique_ptr< llvm::MCObjectWriter > &&object_writer, llvm::raw_pwrite_stream &stream, llvm::MCContext &context, bool write_text_section_only, u64 start_address, std::string &extended_error, std::vector< Nyxstone::Instruction > *instructions) | |
Creates an ObjectWriterWrapper. | |
void | executePostLayoutBinding (llvm::MCAssembler &Asm, const llvm::MCAsmLayout &Layout) override |
Simple function wrapper calling the wrapped object wrapper function directly. | |
bool | resolve_relocation (llvm::MCAssembler &assembler, const llvm::MCAsmLayout &layout, const llvm::MCFragment *fragment, const llvm::MCFixup &fixup, llvm::MCValue target, uint64_t &fixed_value) |
Internal resolve for relocations. | |
void | recordRelocation (llvm::MCAssembler &Asm, const llvm::MCAsmLayout &Layout, const llvm::MCFragment *Fragment, const llvm::MCFixup &Fixup, llvm::MCValue Target, uint64_t &FixedValue) override |
Tries to resolve relocations (that are normally resolved at link time) instead of recording them. | |
uint64_t | writeObject (llvm::MCAssembler &Asm, const llvm::MCAsmLayout &Layout) override |
Write object to the stream and update the bytes of the instruction details. | |
Static Public Member Functions | |
static std::unique_ptr< llvm::MCObjectWriter > | createObjectWriterWrapper (std::unique_ptr< llvm::MCObjectWriter > &&object_writer, llvm::raw_pwrite_stream &stream, llvm::MCContext &context, bool write_text_section_only, u64 start_address, std::string &extended_error, std::vector< Nyxstone::Instruction > *instructions) |
Creates a UniquePtr holding the the ObjectWriterWrapper. | |
This class enables us to limit the final output byte stream to the relevant bytes (as opposed to the whole ELF object file) and grab final instruction bytes (after relaxation and fixups) (via 'writeObject()').
This class is also used to insert custom relocations and fixup validations. These are necessary when a relocation is normally performed at link time or when LLVM does not verify a fixup according to the specification, leading to wrong output for specific instruction/label combinations.
|
inline |
Creates an ObjectWriterWrapper.
The ObjectWriterWrapper is created using the wrapped MCObjectWriter, some additional llvm classes used for querying additional information from LLVM, and a (nullable) pointer to the instruction information.
object_writer | The object writer object to wrap, must implement the function used by this class. |
stream | Stream (used for the object_writer ) to write the .text section to if requested via write_text_section_only . |
write_text_section_only | If only the .text section should be written to stream . |
start_address | Absolute start address of the instructions |
extended_error | Accumulation for llvm errors, since Exceptions might not be supported by the linked LLVM. |
instructions | Instruction information for which the bytes should be corrected. |
|
static |
Creates a UniquePtr holding the the ObjectWriterWrapper.
object_writer | The object writer object to wrap, must implement the function used by this class. |
stream | Stream (used for the object_writer ) to write the .text section to if requested via write_text_section_only . |
write_text_section_only | If only the .text section should be written to stream . |
start_address | Absolute start address of the instructions |
extended_error | Accumulation for llvm errors, since Exceptions might not be supported by the linked LLVM. |
instructions | Instruction information for which the bytes should be corrected. |
|
override |
Tries to resolve relocations (that are normally resolved at link time) instead of recording them.
This function serves multiple purposes:
Normally, this function records relocations, which are resolved by the linker. Since we do not have a linking step, we must assume that any relocation which would be recorded is not yet correctly assembled. Thus, we try to resolve relocations ourself, although this must be implemented on a relocation basis, and we currently implement:
adrp
Any missing label in the assembly must be resolved by the linker and leads to this function being called, we use this fact to emit errors for missing labels.
bool nyxstone::ObjectWriterWrapper::resolve_relocation | ( | llvm::MCAssembler & | assembler, |
const llvm::MCAsmLayout & | layout, | ||
const llvm::MCFragment * | fragment, | ||
const llvm::MCFixup & | fixup, | ||
llvm::MCValue | target, | ||
uint64_t & | fixed_value ) |
Internal resolve for relocations.
Implements relocation for:
adrp