Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
v420v committed Jul 2, 2023
1 parent ff55f63 commit 774596f
Show file tree
Hide file tree
Showing 8 changed files with 7,424 additions and 8,788 deletions.
55 changes: 26 additions & 29 deletions encoder/addr.v
Original file line number Diff line number Diff line change
Expand Up @@ -76,40 +76,37 @@ fn fix_same_section_relocations() {
}

pub fn (mut e Encoder) assign_addresses() {
for name, mut instrs in e.instrs {
if name !in user_defined_sections {
user_defined_sections[name] = &UserDefinedSection{}
for mut instr in e.instrs {
if instr.section !in user_defined_sections {
user_defined_sections[instr.section] = &UserDefinedSection{}
}
mut section := user_defined_sections[name] or {
mut section := user_defined_sections[instr.section] or {
panic('this should not happen')
}

for mut i in instrs {
match i.kind {
.section {
section.flags = section_flags(i.flags)
}
.global {
change_symbol_binding(*i, elf.stb_global)
}
.local {
change_symbol_binding(*i, elf.stb_local)
}
.hidden {
change_symbol_visibility(*i, elf.stv_hidden)
}
.internal {
change_symbol_visibility(*i, elf.stv_internal)
}
.protected {
change_symbol_visibility(*i, elf.stv_protected)
} else {}
match instr.kind {
.section {
section.flags = section_flags(instr.flags)
}

i.addr = section.addr
section.addr += i.code.len
section.code << i.code
.global {
change_symbol_binding(*instr, elf.stb_global)
}
.local {
change_symbol_binding(*instr, elf.stb_local)
}
.hidden {
change_symbol_visibility(*instr, elf.stv_hidden)
}
.internal {
change_symbol_visibility(*instr, elf.stv_internal)
}
.protected {
change_symbol_visibility(*instr, elf.stv_protected)
} else {}
}

instr.addr = section.addr
section.addr += instr.code.len
section.code << instr.code
}

fix_same_section_relocations()
Expand Down
Loading

0 comments on commit 774596f

Please sign in to comment.