# -*- coding: utf-8 -*-
-
# kate: space-indent on; indent-width 2; mixedindent off; indent-mode python;
# Copyright (C) 2009 Amand 'alrj' Tihon <amand.tihon@alrj.org>
# This file is part of bold, the Byte Optimized Linker.
#
# You can redistribute this file and/or modify it under the terms of the
-# GNU Lesser General Public License as published by the Free Software
-# Foundation, version 2.1.
+# GNU General Public License as published by the Free Software Foundation,
+# either version 3 of the License or (at your option) any later version.
from BinArray import BinArray
def nested_property(c):
return property(**c())
+
#--------------------------------------------------------------------------
# Elf
#--------------------------------------------------------------------------
self.local_symbols = {}
self.global_symbols = {}
self.undefined_symbols = []
+ self.common_symbols = []
if path:
self.filename = path
continue
if symbol.st_shndx == SHN_ABS:
continue
+ if symbol.st_shndx == SHN_COMMON:
+ if symbol.name:
+ sym = (symbol.name, symbol.st_size, symbol.st_value)
+ self.common_symbols.append(sym)
+ continue
if symbol.st_shndx == SHN_UNDEF:
if symbol.name:
self.undefined_symbols.append(symbol.name)
target = sh.target.content
for reloc in sh.content.relatab:
- if reloc.symbol.st_shndx == SHN_UNDEF:
- # This is an extern symbol, find it in all_global_symbols
+ if reloc.symbol.st_shndx in [SHN_UNDEF, SHN_COMMON]:
+ # This is an extern or common symbol, find it in all_global_symbols
sym_address = all_global_symbols[reloc.symbol.name]
else:
# source == in which section it is defined
elif reloc.r_type == R_X86_64_32:
format = "<I" # Direct 32 bit zero extended
target_value = sym_address + reloc.r_addend
+ elif reloc.r_type == R_X86_64_32S:
+ format = "<i" # Direct 32 bit sign extended
+ target_value = sym_address + reloc.r_addend
elif reloc.r_type == R_X86_64_PC16:
format = "<h" # 16 bit sign extended pc relative
target_value = sym_address + reloc.r_addend - pc_address