Skip to content

Commit

Permalink
elf: smaller .nointerp files
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyg committed Nov 19, 2020
1 parent 091efcb commit cf6e3cf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions metasm/exe_format/elf_encode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ def arch_386_preencode_reloc

# encodes the .dynamic section, creates .hash/.gnu.hash/.rel/.rela/.dynsym/.strtab/.init,*_array as needed
def encode_segments_dynamic
return if @header.shnum == 0 # .nointerp
if not strtab = @sections.find { |s| s.type == 'STRTAB' and s.flags.include? 'ALLOC' }
strtab = Section.new
strtab.name = '.dynstr'
Expand Down Expand Up @@ -924,7 +925,7 @@ def encode_elf

# ensure last PT_LOAD is writeable (used for bss)
seg = loadsegs.last
if not seg or not seg.flags.include? 'W'
if (not seg or not seg.flags.include? 'W') and @header.shnum != 0
seg = Segment.new
seg.type = 'LOAD'
seg.flags = ['R', 'W']
Expand Down Expand Up @@ -956,7 +957,7 @@ def encode_elf
first_seg.filesz = new_label('segfilsz')
end

if first_seg and not @segments.find { |seg_| seg_.type == 'PHDR' }
if first_seg and not @segments.find { |seg_| seg_.type == 'PHDR' } and @header.shnum != 0
phdr = Segment.new
phdr.type = 'PHDR'
phdr.flags = first_seg.flags
Expand Down

0 comments on commit cf6e3cf

Please sign in to comment.