5#include "tpde/FunctionWriter.hpp"
6#include "tpde/base.hpp"
12class FunctionWriterX64 :
public FunctionWriter<FunctionWriterX64> {
13 friend class FunctionWriter<FunctionWriterX64>;
15 static const TargetCIEInfo CIEInfo;
18 FunctionWriterX64() noexcept : FunctionWriter(CIEInfo) {}
20 void align(
size_t align)
noexcept {
22 FunctionWriter::align(align);
24 if (u32 cur_off =
offset(); cur_off > old_off) {
25 fe64_NOP(
cur_ptr() - (cur_off - old_off), cur_off - old_off);
30 void handle_fixups()
noexcept;
33inline void FunctionWriterX64::handle_fixups() noexcept {
35 u32 label_off = label_offset(fixup.label);
39 case LabelFixupKind::X64_JMP_OR_MEM_DISP: {
41 u32 value = (label_off - fixup_off) - 4;
42 std::memcpy(dst_ptr, &value,
sizeof(u32));
45 case LabelFixupKind::X64_JUMP_TABLE: {
46 const auto table_off = *
reinterpret_cast<u32 *
>(dst_ptr) -
label_skew;
47 const auto diff = (i32)label_off - (i32)table_off;
48 std::memcpy(dst_ptr, &diff,
sizeof(u32));
51 default: TPDE_UNREACHABLE(
"unexpected label fixup kind");
util::SmallVector< LabelFixup > label_fixups
Fixups for labels placed after their first use, processed at function end.
u8 *& cur_ptr() noexcept
Modifiable pointer to current writing position of the section.
u8 * begin_ptr() noexcept
Pointer to beginning of section data.
size_t offset() const noexcept
Get the current offset into the section.
u32 label_skew
Offset to subtract from all label offsets.