]> git.alrj.org Git - bold.git/blobdiff - Bold/elf.py
Add support for SHN_COMMON.
[bold.git] / Bold / elf.py
index b439451a3abc102d19b33448d1784455d733074f..0ff4602bab1cd736cbb71dd1d51410e8f77b2e9d 100644 (file)
@@ -1,5 +1,4 @@
 # -*- 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>
@@ -7,8 +6,8 @@
 # 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
@@ -20,6 +19,7 @@ import struct
 def nested_property(c):
   return property(**c())
 
+
 #--------------------------------------------------------------------------
 #  Elf
 #--------------------------------------------------------------------------
@@ -40,6 +40,7 @@ class Elf64(object):
     self.local_symbols = {}
     self.global_symbols = {}
     self.undefined_symbols = []
+    self.common_symbols = []
 
     if path:
       self.filename = path
@@ -106,6 +107,11 @@ class Elf64(object):
             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)
@@ -132,8 +138,8 @@ class Elf64(object):
       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
@@ -152,6 +158,9 @@ class Elf64(object):
         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