comparison python/ppci/linker.py @ 348:442fb043d149

Added log option to zcc
author Windel Bouwman
date Sat, 08 Mar 2014 15:32:33 +0100
parents b4882ff0ed06
children 2b02bd286fe9
comparison
equal deleted inserted replaced
346:3bb7dcfe5529 348:442fb043d149
1 1 import logging
2 import struct 2 import struct
3 from .objectfile import ObjectFile 3 from .objectfile import ObjectFile
4 from . import CompilerError 4 from . import CompilerError
5 5
6 def align(x, m): 6 def align(x, m):
90 90
91 91
92 class Linker: 92 class Linker:
93 """ Merges the sections of several object files and 93 """ Merges the sections of several object files and
94 performs relocation """ 94 performs relocation """
95 def __init__(self):
96 self.logger = logging.getLogger('Linker')
97
95 def link(self, objs, layout={}): 98 def link(self, objs, layout={}):
96 # Create new object file to store output: 99 # Create new object file to store output:
97 self.dst = ObjectFile() 100 self.dst = ObjectFile()
98 101
99 # Create sections with address: 102 # Create sections with address:
111 out_s.add_data(bytes([0])) 114 out_s.add_data(bytes([0]))
112 115
113 # Add new section: 116 # Add new section:
114 offsets[in_s.name] = out_s.Size 117 offsets[in_s.name] = out_s.Size
115 out_s.add_data(in_s.data) 118 out_s.add_data(in_s.data)
116 119 self.logger.debug('{} {}({})'.format(offsets[in_s.name], iobj, in_s.name))
117 120
118 # Merge symbols: 121 # Merge symbols:
119 for sym in iobj.symbols.values(): 122 for sym in iobj.symbols.values():
120 out_s = self.dst.get_section(sym.section) 123 out_s = self.dst.get_section(sym.section)
121 value = offsets[sym.section] + out_s.address + sym.value 124 value = offsets[sym.section] + out_s.address + sym.value