[Wisp-cvs] wisp/users/dig makehello.py,1.15,1.16
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-01 09:07:32
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv3355 Modified Files: makehello.py Log Message: made make_executable able to generate symbolless ELF executables Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- makehello.py 24 Mar 2003 21:18:13 -0000 1.15 +++ makehello.py 1 Apr 2003 09:07:12 -0000 1.16 @@ -80,7 +80,9 @@ if 'x' in flags: p_flags |= PF.X return p_flags -def make_executable (text = None, data = None, memory_bottom = 0x08048000): +def make_executable (text = None, data = None, + memory_bottom = 0x08048000, + want_symbols = 1): # Will set given sections' origins. sections = {} @@ -94,17 +96,20 @@ binary.place_symbol('#elf/machine', EM.I386) binary.place_symbol('#elf/flags', 0) # no flags for ia386 - shentnames = ['.text', '.data', '.symstr', '.symtab', '.shstrtab'] + shentnames = ['.text', '.data'] + if want_symbols: shentnames += ['.symstr', '.symtab'] + shentnames.append('.shstrtab') sections['.shstrtab'] = Linkie('<') sections['.shstrtab'].emit_byte(0) - sections['.symstr'] = Linkie('<') - sections['.symstr'].emit_byte(0) + if want_symbols: + sections['.symstr'] = Linkie('<') + sections['.symstr'].emit_byte(0) - sections['.symtab'] = Linkie('<') - sections['.symtab'].align(4) - sections['.symtab'].emit_string('\0' * 16) + sections['.symtab'] = Linkie('<') + sections['.symtab'].align(4) + sections['.symtab'].emit_string('\0' * 16) phentnames = [] for name in shentnames: @@ -158,19 +163,20 @@ # alignment has been processed already binary.place_symbol('!' + name) binary.paste(-1, section) - for symbol, value in section.get_symbols(): - if symbol[0] != '&': continue # only process memory references - symbol = symbol[1:] # but not their prefixen - symstr = sections['.symstr'] - symstr.place_symbol('#.symstr/strings/' + symbol) - sections['.symstr'].emit_string(symbol) - sections['.symstr'].emit_byte(0) - sections['.symtab'].emit_tetra_sum(['#.symstr/strings/' + symbol]) - sections['.symtab'].emit_tetra_sum(['&' + name]) - sections['.symtab'].emit_tetra(0) - sections['.symtab'].emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) - sections['.symtab'].emit_byte(0) - sections['.symtab'].emit_wyde(shentnames.index(name) + 1) + if want_symbols: + for symbol, value in section.get_symbols(): + if symbol[0] != '&': continue # only process memory references + symbol = symbol[1:] # but not their prefixen + symstr = sections['.symstr'] + symstr.place_symbol('#.symstr/strings/' + symbol) + sections['.symstr'].emit_string(symbol) + sections['.symstr'].emit_byte(0) + sections['.symtab'].emit_tetra_sum(['#.symstr/strings/' + symbol]) + sections['.symtab'].emit_tetra_sum(['&' + name]) + sections['.symtab'].emit_tetra(0) + sections['.symtab'].emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) + sections['.symtab'].emit_byte(0) + sections['.symtab'].emit_wyde(shentnames.index(name) + 1) memory_boundary += section.memsz() memory_boundary = (memory_boundary + 0xFFF) & ~0xFFF @@ -182,9 +188,18 @@ binary.link() return binary +print 'With symbols' hello = make_executable(text = code, data = data) hello.dump() f = open('hello', 'w') hello.get_file().tofile(f) +f.close() + +print 'Without symbols' +hellowosym = make_executable(text = code, data = data, want_symbols = 0) +hellowosym.dump() + +f = open('hellowosym', 'w') +hellowosym.get_file().tofile(f) f.close() |