summaryrefslogtreecommitdiffstats
path: root/scripts/relocate_sdk.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/relocate_sdk.py')
-rwxr-xr-xscripts/relocate_sdk.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index 8a728720ba..9e01c09cb0 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -49,6 +49,34 @@ def get_arch():
49 elif ei_class == 2: 49 elif ei_class == 2:
50 return 64 50 return 64
51 51
52def get_dl_arch(dl_path):
53 try:
54 with open(dl_path, "r+b") as f:
55 e_ident =f.read(16)
56 except IOError:
57 exctype, ioex = sys.exc_info()[:2]
58 if ioex.errno == errno.ETXTBSY:
59 print("Could not open %s. File used by another process.\nPlease "\
60 "make sure you exit all processes that might use any SDK "\
61 "binaries." % e)
62 else:
63 print("Could not open %s: %s(%d)" % (e, ioex.strerror, ioex.errno))
64 sys.exit(-1)
65
66 ei_mag0,ei_mag1_3,ei_class,ei_data,ei_version = struct.unpack("<B3sBBB9x", e_ident)
67
68 if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0:
69 print("ERROR: unknow %s" % dl_path)
70 sys.exit(-1)
71
72 if ei_class == 1:
73 arch = 32
74 elif ei_class == 2:
75 arch = 64
76
77 return arch
78
79
52def parse_elf_header(): 80def parse_elf_header():
53 global e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\ 81 global e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\
54 e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum, e_shstrndx 82 e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum, e_shstrndx
@@ -223,6 +251,8 @@ else:
223 251
224executables_list = sys.argv[3:] 252executables_list = sys.argv[3:]
225 253
254dl_arch = get_dl_arch(new_dl_path)
255
226errors = False 256errors = False
227for e in executables_list: 257for e in executables_list:
228 perms = os.stat(e)[stat.ST_MODE] 258 perms = os.stat(e)[stat.ST_MODE]
@@ -247,7 +277,7 @@ for e in executables_list:
247 old_size = os.path.getsize(e) 277 old_size = os.path.getsize(e)
248 if old_size >= 64: 278 if old_size >= 64:
249 arch = get_arch() 279 arch = get_arch()
250 if arch: 280 if arch and arch == dl_arch:
251 parse_elf_header() 281 parse_elf_header()
252 if not change_interpreter(e): 282 if not change_interpreter(e):
253 errors = True 283 errors = True