6#include "tpde/AssemblerElf.hpp"
15 static const TargetInfo TARGET_INFO;
17 class SectionWriter :
public Base::SectionWriterBase<SectionWriter> {
19 void align(
size_t align)
noexcept;
22 enum class UnresolvedEntryKind : u8 {
29 void add_unresolved_entry(Label label,
32 UnresolvedEntryKind kind)
noexcept {
33 AssemblerElfBase::reloc_sec(sec, label,
static_cast<u8
>(kind), off);
36 void handle_fixup(
const TempSymbolInfo &info,
37 const TempSymbolFixup &fixup)
noexcept;
41 AssemblerElfX64::handle_fixup(
const TempSymbolInfo &info,
42 const TempSymbolFixup &fixup)
noexcept {
44 assert(info.section == fixup.section &&
"multi-text section not supported");
45 u8 *dst_ptr = get_section(fixup.section).data.data() + fixup.off;
47 switch (
static_cast<UnresolvedEntryKind
>(fixup.kind)) {
48 case UnresolvedEntryKind::JMP_OR_MEM_DISP: {
50 u32 value = (info.off - fixup.off) - 4;
51 std::memcpy(dst_ptr, &value,
sizeof(u32));
54 case UnresolvedEntryKind::JUMP_TABLE: {
55 const auto table_off = *
reinterpret_cast<u32 *
>(dst_ptr);
56 const auto diff = (i32)info.off - (i32)table_off;
57 std::memcpy(dst_ptr, &diff,
sizeof(u32));
63inline void AssemblerElfX64::SectionWriter::align(
size_t align)
noexcept {
64 u32 old_off = offset();
65 SectionWriterBase::align(align);
67 if (u32 cur_off = offset(); cur_off > old_off) {
68 fe64_NOP(cur_ptr() - (cur_off - old_off), cur_off - old_off);
AssemblerElf contains the architecture-independent logic to emit ELF object files (currently linux-sp...
The x86_64-specific implementation for the AssemblerElf.