Implement simple if conditions
This commit is contained in:
@ -33,13 +33,6 @@ namespace elna::riscv
|
||||
// Create string table writer
|
||||
ELFIO::string_section_accessor stra(str_sec);
|
||||
|
||||
// Create read only data section
|
||||
ELFIO::section* ro_sec = writer.sections.add(".rodata");
|
||||
ro_sec->set_type(ELFIO::SHT_PROGBITS);
|
||||
ro_sec->set_flags(ELFIO::SHF_ALLOC);
|
||||
ro_sec->set_addr_align(0x4);
|
||||
ro_sec->set_data("%d\n");
|
||||
|
||||
// Create symbol table section
|
||||
ELFIO::section* sym_sec = writer.sections.add(".symtab");
|
||||
sym_sec->set_type(ELFIO::SHT_SYMTAB);
|
||||
@ -57,24 +50,38 @@ namespace elna::riscv
|
||||
rel_sec->set_link(sym_sec->get_index());
|
||||
rel_sec->set_flags(ELFIO::SHF_ALLOC);
|
||||
|
||||
// Create read only data section
|
||||
ELFIO::section* ro_sec = writer.sections.add(".rodata");
|
||||
ro_sec->set_type(ELFIO::SHT_PROGBITS);
|
||||
ro_sec->set_flags(ELFIO::SHF_ALLOC);
|
||||
ro_sec->set_addr_align(0x4);
|
||||
|
||||
// Create symbol relocation table writers
|
||||
ELFIO::symbol_section_accessor syma(writer, sym_sec);
|
||||
ELFIO::relocation_section_accessor rela(writer, rel_sec);
|
||||
ELFIO::Elf_Word digit_symbol = syma.add_symbol(stra, ".CL0", 0x00000000, strlen("%d\n") + 1,
|
||||
ELFIO::STB_LOCAL, ELFIO::STT_NOTYPE, 0, ro_sec->get_index());
|
||||
ELFIO::Elf_Word digit_symbol;
|
||||
|
||||
for (auto read_only_text : _visitor->read_only)
|
||||
{
|
||||
ro_sec->append_data(read_only_text.second.data(), read_only_text.second.size());
|
||||
|
||||
syma.add_symbol(stra, read_only_text.first.c_str(), 0x00000000,
|
||||
read_only_text.first.size() + 1, ELFIO::STB_LOCAL, ELFIO::STT_NOTYPE, 0, ro_sec->get_index());
|
||||
}
|
||||
ELFIO::Elf_Word printf_symbol = syma.add_symbol(stra, "printf", 0x00000000, 0,
|
||||
ELFIO::STB_GLOBAL, ELFIO::STT_NOTYPE, 0, ELFIO::SHN_UNDEF);
|
||||
|
||||
for (auto& reference : _visitor->references)
|
||||
{
|
||||
// The loop assumes that address_t::lower12i always follows address_t::high20.
|
||||
switch (reference.target)
|
||||
{
|
||||
case address_t::high20:
|
||||
digit_symbol = _visitor->read_only.lookup(reference.name) + 1;
|
||||
rela.add_entry(reference.offset, digit_symbol, 26 /* ELFIO::R_RISCV_HI20 */);
|
||||
rela.add_entry(reference.offset, digit_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
break;
|
||||
case address_t::lower12i:
|
||||
digit_symbol = _visitor->read_only.lookup(reference.name) + 1;
|
||||
rela.add_entry(reference.offset, digit_symbol, 27 /* ELFIO::R_RISCV_LO12_I */);
|
||||
rela.add_entry(reference.offset, digit_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user