121 u8 cie_return_addr_register;
123 std::span<const u8> cie_instrs;
125 u8 cie_code_alignment_factor;
127 u8 cie_data_alignment_factor;
136 const TargetInfo &target_info;
138 util::BumpAllocator<> section_allocator;
139 util::SmallVector<util::BumpAllocUniquePtr<DataSection>, 16> sections;
141 Assembler(
const TargetInfo &target_info) noexcept
142 : target_info(target_info) {}
143 virtual ~Assembler();
146 virtual void reset()
noexcept;
151 DataSection &get_section(SecRef ref)
noexcept {
153 return *sections[ref.id()];
156 const DataSection &get_section(SecRef ref)
const noexcept {
158 return *sections[ref.id()];
168 SecRef sec, SymRef sym, u32 type, u32 offset, i64 addend)
noexcept {
169 assert(i32(addend) == addend &&
"non-32-bit addends are unsupported");
170 get_section(sec).relocs.emplace_back(offset, sym, type, addend);
173 void reloc_pc32(SecRef sec, SymRef sym, u32 offset, i64 addend)
noexcept {
174 reloc_sec(sec, sym, target_info.reloc_pc32, offset, addend);
177 void reloc_abs(SecRef sec, SymRef sym, u32 offset, i64 addend)
noexcept {
178 reloc_sec(sec, sym, target_info.reloc_abs64, offset, addend);
183 virtual void finalize() noexcept {}
185 virtual std::vector<u8> build_object_file() noexcept = 0;
void reloc_sec(SecRef sec, SymRef sym, u32 type, u32 offset, i64 addend) noexcept
Add relocation. Type is file-format and target-specific.