[Wisp-cvs] wisp/users/dig linkie.py,1.25,1.26
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-14 21:46:47
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv23275 Modified Files: linkie.py Log Message: added support for MS RVAs Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- linkie.py 14 Apr 2003 21:30:20 -0000 1.25 +++ linkie.py 14 Apr 2003 21:46:42 -0000 1.26 @@ -19,6 +19,7 @@ this._locals = [] # label no -> address this._unresolved_locals = [] # order is irrelevant this._origin = 0 # the base address of this linkie + this._origin_secondary = 0 # support MS-style RVAs (%foo symbols) if byte_order == '<': this.emit_wyde = this.emit_lewyde this.emit_tetra = this.emit_letetra @@ -84,7 +85,7 @@ else: # forwards this._unresolved_locals.append((a, size, len(this._binary))) elif type(a) == StringType: # global reference - if not a[0] in '#&!': + if not a[0] in '#&!%': raise 'unprefixed symbol being referred to', a this.notify_linker(this.memsz(), size, a) else: raise 'Invalid addend', a @@ -146,14 +147,14 @@ """place_symbol(symbol, value = None) => value Places a globally visible symbol in the linkie. Takes care of adding the base address if the symbol - starts in '&'. + starts in '&' or '%'. Does NOT check uniqueness. None signifies the current offset.""" if type(symbol) <> StringType: raise 'Not a string', symbol if not symbol[0] in '#&!': raise 'unprefixed symbol being placed', symbol if value == None: value = len(this._binary) + this._skipped - if symbol[0] == '&': value += this._origin + if symbol[0] in '&%': value += this._origin this._symbols.append((symbol, value)) return value def align (this, boundary): @@ -173,8 +174,8 @@ def set_origin (this, origin): """set_origin(origin) Sets the base address of the linkie to the specified value. - Recalculates the &foo symbols. Does NOT influence already - resolved references to changing labels, so be careful + Recalculates the &foo symbols. Does NOT influence + already resolved references to changing labels, so be careful if using after partial linkage.""" if (origin % this._alignment) != 0: raise 'New base address violates alignment', \ @@ -182,9 +183,24 @@ delta = origin - this._origin for i in range(len(this._symbols)): symbol, value = this._symbols[i] - if symbol[0] == '&': + if symbol[0] in '&': this._symbols[i] = symbol, value + delta this._origin = origin + def set_secondary_origin (this, origin): + """set_secondary_origin(origin) + Sets the secondary base address of the linkie to the specified + value. Recalculates the %foo symbols. Does NOT influence + already resolved references to changing labels, so be careful + if using after partial linkage.""" + if (origin % this._alignment) != 0: + raise 'New base address violates alignment', \ + (boundary, this._origin) + delta = origin - this._origin_secondary + for i in range(len(this._symbols)): + symbol, value = this._symbols[i] + if symbol[0] in '%': + this._symbols[i] = symbol, value + delta + this._origin_secondary = origin def get_file (this): """get_file() -> array of chars @@ -254,12 +270,7 @@ this._binary.extend(that._binary) this._skipped = that._skipped for sym, val in that._symbols: - if sym[0] in '#&!': - this._symbols.append((sym, val)) - else: - # FIXME: backwards compatibility - print 'WARNING: unprefixed symbol', sym - this._symbols.append((sym, val + delta)) + this._symbols.append((sym, val)) for ofs, typ, arg in that._linker_notes: this._linker_notes.append((ofs + delta, typ, arg)) return delta @@ -292,9 +303,9 @@ for sym, val in that._symbols: if sym[0] == '!': this._symbols.append((sym, val + thatofs)) - elif sym[0] in '#': + elif sym[0] == '#': this._symbols.append((sym, val)) - elif sym[0] in '&': + elif sym[0] in '&%': if not skip_addr: this._symbols.append((sym, val)) else: raise 'unprefixed symbol', sym @@ -334,6 +345,7 @@ rnotes = {}; othernotes = [] for sym, val in this._symbols: if sym[0] == '&': val -= this._origin + if sym[0] == '%': val -= this._origin_secondary if sym[0] != '#' and 0 <= val < this.memsz(): if rsymbols.has_key(val): rsymbols[val].append(sym) else: rsymbols[val] = [sym] |