[Wisp-cvs] wisp/users/dig elf.py,1.31,1.32
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-14 01:19:59
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv1226 Modified Files: elf.py Log Message: first successful ELF32 relocatable object generated Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- elf.py 14 Apr 2003 00:59:32 -0000 1.31 +++ elf.py 14 Apr 2003 01:19:56 -0000 1.32 @@ -503,7 +503,7 @@ binary.place_symbol('#elf/flags', 0) # no flags for ia386 shentnames = ['.text', '.data'] - if want_symbols: + if want_symbols or want_relocatable: shentnames += ['.symstr', '.symtab'] sections['.symstr'] = Linkie('<') sections['.symstr'].emit_byte(0) @@ -512,14 +512,18 @@ sections['.symtab'].align(4) sections['.symtab'].emit_string('\0' * 16) if want_relocatable: - if text.note_count(): - shentnames.append('.rel.text') - sections['.rel.text'] = Linkie('<') - sections['.rel.text'].align(4) - if data.note_count(): - shentnames.append('.rel.data') - sections['.rel.data'] = Linkie('<') - sections['.rel.data'].align(4) + for s, sn in (text, '.text'), (data, '.data'): + if s.note_count(): + shentnames.append('.rel' + sn) + r = Linkie('<'); sections['.rel' + sn] = r + r.align(4) + for ofs, typ, arg in s.get_notes(): + if typ == 4: + emit_ELF32_reloc_entry(r, sections['.symtab'], + sections['.symstr'], ofs, + RELOC.I386.D32, arg) + else: + raise 'Unrepresentable relocation type', (ofs, typ, arg) shentnames.append('.shstrtab') sections['.shstrtab'] = Linkie('<') @@ -568,11 +572,22 @@ binary.place_symbol('#' + name + '/filesz', section.filesz()) binary.place_symbol('#' + name + '/sh_size', section.filesz()) binary.place_symbol('#' + name + '/sh_type', guess_ELF32_shtype(name)) - binary.place_symbol('#' + name + '/sh_info', 0) + if name[:5] == '.rela': + sh_info = shentnames.index(name[5:]) + 1 + elif name[:4] == '.rel': + sh_info = shentnames.index(name[4:]) + 1 + else: sh_info = 0 + binary.place_symbol('#' + name + '/sh_info', sh_info) if name == '.symtab': sh_link = shentnames.index('.symstr') + 1 + elif name[:4] == '.rel': # catches both .rela* and .rel* + sh_link = shentnames.index('.symtab') + 1 else: sh_link = SHN.UNDEF binary.place_symbol('#' + name + '/sh_link', sh_link) - binary.place_symbol('#' + name + '/sh_entsize', 0) + if name[:5] == '.rela': sh_entsize = 0xC + elif name[:4] == '.rel': sh_entsize = 0x8 + elif name == '.symtab': sh_entsize = 0x10 + else: sh_entsize = 0 + binary.place_symbol('#' + name + '/sh_entsize', sh_entsize) binary.place_symbol('#' + name + '/sh_flags', guess_ELF32_shflags(name)) # alignment has been processed already |