Skip to content

Commit cd8446b

Browse files
committed
set table for section type
1 parent 6661898 commit cd8446b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/caotral/assembler/writer.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
module Caotral
44
class Assembler
55
class Writer
6+
SECTION_TYPE_BY_NAME = {
7+
nil => :null,
8+
".symtab" => :symtab,
9+
".shstrtab" => :strtab,
10+
".strtab" => :strtab,
11+
".text" => :progbits,
12+
}.freeze
13+
614
def self.write!(elf_obj:, output:, debug: false) = new(elf_obj:, output:, debug:).write
715
def initialize(elf_obj:, output:, debug: false)
816
@elf_obj = elf_obj
@@ -68,21 +76,21 @@ def write(output: @output)
6876
end
6977
output
7078
end
79+
private_constant :SECTION_TYPE_BY_NAME
7180

7281
private
7382
def decide(section)
74-
type_num = _type(section.section_name)
75-
type = Caotral::Binary::ELF::SectionHeader::SHT_BY_VALUE[type_num]
83+
type = SECTION_TYPE_BY_NAME[section.section_name]
7684
[
77-
type_num,
85+
_type(type),
7886
_flag(type),
7987
_addralign(type, section.section_name),
8088
_info(type),
8189
_entsize(type),
8290
]
8391
end
8492

85-
def _type(section_name) = Caotral::Binary::ELF::SectionHeader::SHT[type_name(section_name)]
93+
def _type(type_name) = Caotral::Binary::ELF::SectionHeader::SHT[type_name]
8694

8795
def _flag(section_type)
8896
case section_type
@@ -121,13 +129,6 @@ def _entsize(section_type)
121129
0
122130
end
123131
end
124-
125-
def type_name(section_name)
126-
name = section_name.nil? ? :null : section_name[1..].to_sym
127-
name = :progbits if name == :text
128-
name = :strtab if name == :shstrtab
129-
name
130-
end
131132
end
132133
end
133134
end

0 commit comments

Comments
 (0)