[Wisp-cvs] wisp/users/dig elf.py,1.34,1.35
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-14 01:57:55
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv20413 Modified Files: elf.py Log Message: converted emit_ELF32_symtab_entry into the ELF32_symtab class Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- elf.py 14 Apr 2003 01:38:44 -0000 1.34 +++ elf.py 14 Apr 2003 01:57:52 -0000 1.35 @@ -408,28 +408,33 @@ this.emit_byte(0) return ofs -# Returns index of the entry added. -def emit_ELF32_symtab_entry (symtab, symstr, pname, - value = None, section = SHN.ABS): - ofs = symstr.emit_entry(pname[1:]) - # No explicit alignment. .symtab doesn't bear padding; if - # you get it out of align, you're out of luck anyway. - i = symtab.memsz() / 16 - symtab.emit_tetra(ofs) - if value == None: symtab.emit_tetra_sum([pname]) - else: symtab.emit_tetra(value) - symtab.emit_tetra(0) # st_size - symtab.emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) - symtab.emit_byte(0) # st_other; reserved - symtab.emit_wyde(section) - return i +class ELF32_symtab (Linkie): + def __init__ (this, byte_order, strtab): + Linkie.__init__(this, byte_order) + this._strtab = strtab + this.align(4) + this.emit_string('\0' * 16) + this._index = 0 # for pre-increment + # Returns index of the entry added. + def emit_entry (this, pname, value = None, section = SHN.ABS): + ofs = this._strtab.emit_entry(pname[1:]) + # No explicit alignment. .symtab doesn't bear padding; if + # you get it out of align, you're out of luck anyway. + this.emit_tetra(ofs) + if value == None: this.emit_tetra_sum([pname]) + else: this.emit_tetra(value) + this.emit_tetra(0) # st_size + this.emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) + this.emit_byte(0) # st_other; reserved + this.emit_wyde(section) + this._index += 1 + return this._index # Note: all entries in a single relocation section # must either have or not have explicit addends. -def emit_ELF32_reloc_entry (rel, symtab, symstr, offset, type, pname, +def emit_ELF32_reloc_entry (rel, symtab, offset, type, pname, addend = None): - i = emit_ELF32_symtab_entry(symtab, symstr, pname, - value = 0, section = SHN.UNDEF) + i = symtab.emit_entry(pname, value = 0, section = SHN.UNDEF) # No explicit alignment. .rel* don't bear padding; if # you get it out of align, you're out of luck anyway. rel.emit_tetra(offset) @@ -516,9 +521,7 @@ if want_symbols or want_relocatable: shentnames += ['.symstr', '.symtab'] sections['.symstr'] = ELF32_strtab('<') - sections['.symtab'] = Linkie('<') - sections['.symtab'].align(4) - sections['.symtab'].emit_string('\0' * 16) + sections['.symtab'] = ELF32_symtab('<', sections['.symstr']) if want_relocatable: for s, sn in (text, '.text'), (data, '.data'): if s.note_count(): @@ -527,8 +530,7 @@ r.align(4) for ofs, typ, arg in s.get_notes(): if typ == 4: - emit_ELF32_reloc_entry(r, sections['.symtab'], - sections['.symstr'], ofs, + emit_ELF32_reloc_entry(r, sections['.symtab'], ofs, RELOC.I386.D32, arg) else: raise 'Unrepresentable relocation type', (ofs, typ, arg) @@ -603,8 +605,7 @@ symstr = sections['.symstr'] for symbol, value in section.get_symbols(): if symbol[0] == '&': # only process memory references - emit_ELF32_symtab_entry(symtab, symstr, symbol, value, - shentnames.index(name) + 1) + symtab.emit_entry(symbol, value, shentnames.index(name) + 1) memory_boundary += section.memsz() memory_boundary = (memory_boundary + 0xFFF) & ~0xFFF |