119 u8 cie_return_addr_register;
121 std::span<const u8> cie_instrs;
123 u8 cie_code_alignment_factor;
125 u8 cie_data_alignment_factor;
134 const TargetInfo &target_info;
136 util::BumpAllocator<> section_allocator;
137 util::SmallVector<util::BumpAllocUniquePtr<DataSection>, 16> sections;
139 Assembler(
const TargetInfo &target_info) noexcept
140 : target_info(target_info) {}
141 virtual ~Assembler();
144 virtual void reset()
noexcept;
149 DataSection &get_section(SecRef ref)
noexcept {
151 return *sections[ref.id()];
154 const DataSection &get_section(SecRef ref)
const noexcept {
156 return *sections[ref.id()];
166 SecRef sec, SymRef sym, u32 type, u32 offset, i64 addend)
noexcept {
167 assert(i32(addend) == addend &&
"non-32-bit addends are unsupported");
168 get_section(sec).relocs.emplace_back(offset, sym, type, addend);
171 void reloc_pc32(SecRef sec, SymRef sym, u32 offset, i64 addend)
noexcept {
172 reloc_sec(sec, sym, target_info.reloc_pc32, offset, addend);
175 void reloc_abs(SecRef sec, SymRef sym, u32 offset, i64 addend)
noexcept {
176 reloc_sec(sec, sym, target_info.reloc_abs64, offset, addend);
181 virtual void finalize() noexcept {}
183 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.