Skip to content

Commit 3a54b40

Browse files
committed
fix search name condition
1 parent f1fd105 commit 3a54b40

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

lib/caotral/binary/elf.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ def [](idx) = @sections[idx]
2424
def find_by_name(section_name) = @sections.find { |s| section_name == s.section_name }
2525
def select_by_name(section_name) = @sections.select { |s| section_name == s.section_name }
2626
def index(section_name) = @sections.index { |s| section_name == s.section_name }
27-
def select_by_names(section_names)
28-
@sections.select do |section|
29-
next true if section.section_name.nil?
30-
section_names.any? do |name|
31-
re = Regexp === name
32-
re ? section.section_name.match(name) : section.section_name == name
33-
end
34-
end
35-
end
27+
def select_by_names(section_names) = @sections.select { |section| section_names.any? { |name| name === section.section_name.to_s } }
3628
end
3729
end
3830
end

lib/caotral/linker/writer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def write_order_sections
117117
def write_section_index(section_name) = @write_sections.index { it.section_name == section_name }
118118
def ref_index(section)
119119
section_name = section.section_name
120-
ref = @elf_obj.select_by_names(section_name.split(".").filter { |sn| !sn.empty? && sn != "rel" && sn != "rela" }).first
120+
ref = @elf_obj.select_by_names(section_name.split(".").filter { |sn| !sn.empty? && sn != "rel" && sn != "rela" }.map { "." + it }).first
121121
write_section_index(ref.section_name)
122122
end
123123
end

test/caotral/linker/writer_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_write
1616
written_output = Caotral::Linker::Writer.write!(elf_obj: @elf_obj, output: "write.o", debug: false)
1717
read_written_elf = Caotral::Binary::ELF::Reader.read!(input: written_output, debug: false)
1818
assert_equal @elf_obj.header.shoffset, read_written_elf.header.shoffset
19-
assert_equal 6, read_written_elf.sections.size
19+
assert_equal 5, read_written_elf.sections.size
2020
assert_equal 0x401000, read_written_elf.header.entry
2121
end
2222

0 commit comments

Comments
 (0)