1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
--- a/src/mklibs
+++ b/src/mklibs
@@ -57,18 +57,18 @@ debuglevel = DEBUG_NORMAL
def debug(level, *msg):
if debuglevel >= level:
- print string.join(msg)
+ print(' '.join(msg))
# return a list of lines of output of the command
def command(command, *args):
- debug(DEBUG_SPAM, "calling", command, string.join(args))
+ debug(DEBUG_SPAM, "calling", command, ' '.join(args))
pipe = os.popen(command + ' ' + ' '.join(args), 'r')
output = pipe.read().strip()
status = pipe.close()
if status is not None and os.WEXITSTATUS(status) != 0:
- print "Command failed with status", os.WEXITSTATUS(status), ":", \
- command, string.join(args)
- print "With output:", output
+ print("Command failed with status", os.WEXITSTATUS(status), ":", \
+ command, ' '.join(args))
+ print("With output:", output)
sys.exit(1)
return [i for i in output.split('\n') if i]
@@ -204,7 +204,7 @@ class ProvidedSymbol(Symbol):
# Return a set of symbols provided by a library
def provided_symbols(obj):
if not os.access(obj, os.F_OK):
- raise Exception("Cannot find lib" + obj)
+ raise Exception("Cannot find lib " + obj)
library = extract_soname(obj)
output = command("mklibs-readelf", "--print-symbols-provided", obj)
@@ -297,27 +297,27 @@ def usage(was_err):
outfd = sys.stderr
else:
outfd = sys.stdout
- print >> outfd, "Usage: mklibs [OPTION]... -d DEST FILE ..."
- print >> outfd, "Make a set of minimal libraries for FILE(s) in DEST."
- print >> outfd, ""
- print >> outfd, " -d, --dest-dir DIRECTORY create libraries in DIRECTORY"
- print >> outfd, " -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path), ")"
- print >> outfd, " -L DIRECTORY[:DIRECTORY]... add DIRECTORY(s) to the library search path"
- print >> outfd, " -l LIBRARY add LIBRARY always"
- print >> outfd, " --ldlib LDLIB use LDLIB for the dynamic linker"
- print >> outfd, " --libc-extras-dir DIRECTORY look for libc extra files in DIRECTORY"
- print >> outfd, " --target TARGET prepend TARGET- to the gcc and binutils calls"
- print >> outfd, " --root ROOT search in ROOT for library rpaths"
- print >> outfd, " --sysroot ROOT prepend ROOT to all paths for libraries"
- print >> outfd, " --gcc-options OPTIONS pass OPTIONS to gcc"
- print >> outfd, " --libdir DIR use DIR (e.g. lib64) in place of lib in default paths"
- print >> outfd, " -v, --verbose explain what is being done"
- print >> outfd, " -h, --help display this help and exit"
+ print("Usage: mklibs [OPTION]... -d DEST FILE ...", file=outfd)
+ print("Make a set of minimal libraries for FILE(s) in DEST.", file=outfd)
+ print("", file=outfd)
+ print(" -d, --dest-dir DIRECTORY create libraries in DIRECTORY", file=outfd)
+ print(" -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path), ")", file=outfd)
+ print(" -L DIRECTORY[:DIRECTORY]... add DIRECTORY(s) to the library search path", file=outfd)
+ print(" -l LIBRARY add LIBRARY always", file=outfd)
+ print(" --ldlib LDLIB use LDLIB for the dynamic linker", file=outfd)
+ print(" --libc-extras-dir DIRECTORY look for libc extra files in DIRECTORY", file=outfd)
+ print(" --target TARGET prepend TARGET- to the gcc and binutils calls", file=outfd)
+ print(" --root ROOT search in ROOT for library rpaths", file=outfd)
+ print(" --sysroot ROOT prepend ROOT to all paths for libraries", file=outfd)
+ print(" --gcc-options OPTIONS pass OPTIONS to gcc", file=outfd)
+ print(" --libdir DIR use DIR (e.g. lib64) in place of lib in default paths", file=outfd)
+ print(" -v, --verbose explain what is being done", file=outfd)
+ print(" -h, --help display this help and exit", file=outfd)
sys.exit(was_err)
def version(vers):
- print "mklibs: version ",vers
- print ""
+ print("mklibs: version ",vers)
+ print("")
#################### main ####################
## Usage: ./mklibs.py [OPTION]... -d DEST FILE ...
@@ -368,8 +368,8 @@ script_pattern = re.compile("^#!\s*/")
try:
optlist, proglist = getopt.getopt(sys.argv[1:], opts, longopts)
-except getopt.GetoptError, msg:
- print >> sys.stderr, msg
+except getopt.GetoptError as msg:
+ print(msg, file=sys.stderr)
usage(1)
for opt, arg in optlist:
@@ -377,7 +377,7 @@ for opt, arg in optlist:
if debuglevel < DEBUG_SPAM:
debuglevel = debuglevel + 1
elif opt == "-L":
- lib_path.extend(string.split(arg, ":"))
+ lib_path.extend(arg.split(":"))
elif opt in ("-d", "--dest-dir"):
dest_path = arg
elif opt in ("-D", "--no-default-lib"):
@@ -396,17 +396,17 @@ for opt, arg in optlist:
elif opt in ("-l",):
force_libs.append(arg)
elif opt == "--gcc-options":
- gcc_options.extend(string.split(arg, " "))
+ gcc_options.extend(arg.split(" "))
elif opt == "--libdir":
libdir = arg
elif opt in ("--help", "-h"):
- usage(0)
+ usage(0)
sys.exit(0)
elif opt in ("--version", "-V"):
version(vers)
sys.exit(0)
else:
- print "WARNING: unknown option: " + opt + "\targ: " + arg
+ print("WARNING: unknown option: " + opt + "\targ: " + arg)
if include_default_lib_path == "yes":
lib_path.extend([a.replace("/lib/", "/" + libdir + "/") for a in default_lib_path])
@@ -424,22 +424,22 @@ if ldlib == "LDLIB":
objects = {} # map from inode to filename
for prog in proglist:
inode = os.stat(prog)[ST_INO]
- if objects.has_key(inode):
+ if inode in objects:
debug(DEBUG_SPAM, prog, "is a hardlink to", objects[inode])
elif so_pattern.match(prog):
debug(DEBUG_SPAM, prog, "is a library")
- elif script_pattern.match(open(prog).read(256)):
+ elif script_pattern.match(open(prog, 'r', encoding='iso-8859-1').read(256)):
debug(DEBUG_SPAM, prog, "is a script")
else:
objects[inode] = prog
if not ldlib:
- for obj in objects.values():
+ for obj in list(objects.values()):
output = command("mklibs-readelf", "--print-interp", obj)
if output:
ldlib = output.pop()
- if ldlib:
- break
+ if ldlib:
+ break
if not ldlib:
sys.exit("E: Dynamic linker not found, aborting.")
@@ -454,10 +454,10 @@ for obj in sorted(objects.values()):
for rpath_elem in rpath_val:
if not rpath_elem in lib_rpath:
if debuglevel >= DEBUG_VERBOSE:
- print "Adding rpath " + rpath_elem + " for " + obj
+ print("Adding rpath " + rpath_elem + " for " + obj)
lib_rpath.append(rpath_elem)
else:
- print "warning: " + obj + " may need rpath, but --root not specified"
+ print("warning: " + obj + " may need rpath, but --root not specified")
lib_path.extend(lib_rpath)
@@ -465,12 +465,12 @@ passnr = 1
available_libs = []
previous_pass_unresolved = set()
while 1:
- debug(DEBUG_NORMAL, "I: library reduction pass", `passnr`)
+ debug(DEBUG_NORMAL, "I: library reduction pass", repr(passnr))
if debuglevel >= DEBUG_VERBOSE:
- print "Objects:",
- for obj in sorted([x[string.rfind(x, '/') + 1:] for x in objects.values()]):
- print obj,
- print
+ print("Objects:", end=' ')
+ for obj in sorted([x[x.rfind('/') + 1:] for x in list(objects.values())]):
+ print(obj, end=' ')
+ print()
passnr = passnr + 1
# Gather all already reduced libraries and treat them as objects as well
@@ -479,7 +479,7 @@ while 1:
obj = dest_path + "/" + lib
small_libs.append(obj)
inode = os.stat(obj)[ST_INO]
- if objects.has_key(inode):
+ if inode in objects:
debug(DEBUG_SPAM, obj, "is hardlink to", objects[inode])
else:
objects[inode] = obj
@@ -509,7 +509,7 @@ while 1:
present_symbols = {}
checked_libs = small_libs
checked_libs.extend(available_libs)
- checked_libs.append(ldlib)
+ checked_libs.append(sysroot + "/" + ldlib)
for lib in checked_libs:
for symbol in provided_symbols(lib):
debug(DEBUG_SPAM, "present_symbols adding %s" % symbol)
@@ -529,8 +529,8 @@ while 1:
unresolved.add(name)
num_unresolved = num_unresolved + 1
- debug (DEBUG_NORMAL, `len(needed_symbols)`, "symbols,",
- `num_unresolved`, "unresolved")
+ debug (DEBUG_NORMAL, repr(len(needed_symbols)), "symbols,",
+ repr(num_unresolved), "unresolved")
if num_unresolved == 0:
break
@@ -539,7 +539,7 @@ while 1:
# No progress in last pass. Verify all remaining symbols are weak.
for name in unresolved:
if not needed_symbols[name].weak:
- print "WARNING: Unresolvable symbol %s" % name
+ print("WARNING: Unresolvable symbol %s" % name)
break
previous_pass_unresolved = unresolved
@@ -641,9 +641,9 @@ while 1:
command(target + "gcc", *cmd)
## DEBUG
- debug(DEBUG_VERBOSE, so_file, "\t", `os.stat(so_file)[ST_SIZE]`)
+ debug(DEBUG_VERBOSE, so_file, "\t", repr(os.stat(so_file)[ST_SIZE]))
debug(DEBUG_VERBOSE, dest_path + "/" + so_file_name + "-so", "\t",
- `os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]`)
+ repr(os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]))
# Finalising libs and cleaning up
for lib in regexpfilter(os.listdir(dest_path), "(.*)-so$"):
@@ -680,4 +680,4 @@ if not os.access(dest_path + "/" + ld_fu
command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
ld_file, dest_path + "/" + ld_full_path)
-os.chmod(dest_path + "/" + ld_full_path, 0755)
+os.chmod(dest_path + "/" + ld_full_path, 0o755)
--- a/src/mklibs-copy
+++ b/src/mklibs-copy
@@ -51,9 +51,9 @@ def command(command, *args):
output = pipe.read().strip()
status = pipe.close()
if status is not None and os.WEXITSTATUS(status) != 0:
- print "Command failed with status", os.WEXITSTATUS(status), ":", \
- command, ' '.join(args)
- print "With output:", output
+ print("Command failed with status", os.WEXITSTATUS(status), ":", \
+ command, ' '.join(args))
+ print("With output:", output)
sys.exit(1)
return output.split('\n')
@@ -134,8 +134,8 @@ def multiarch(paths):
return paths
def version(vers):
- print "mklibs: version ",vers
- print ""
+ print("mklibs: version ",vers)
+ print("")
# Clean the environment
vers="0.12"
@@ -159,7 +159,7 @@ if include_default_lib_path:
objects = {} # map from inode to filename
for prog in proglist:
inode = os.stat(prog)[ST_INO]
- if objects.has_key(inode):
+ if inode in objects:
logger.debug("%s is a hardlink to %s", prog, objects[inode])
elif so_pattern.match(prog):
logger.debug("%s is a library", prog)
@@ -169,12 +169,12 @@ for prog in proglist:
logger.debug("%s is no ELF", prog)
if not ldlib:
- for obj in objects.values():
+ for obj in list(objects.values()):
output = command("mklibs-readelf", "-i", obj)
- for x in output:
+ for x in output:
ldlib = x
- if ldlib:
- break
+ if ldlib:
+ break
if not ldlib:
sys.exit("E: Dynamic linker not found, aborting.")
@@ -182,7 +182,7 @@ if not ldlib:
logger.info('Using %s as dynamic linker', ldlib)
# Check for rpaths
-for obj in objects.values():
+for obj in list(objects.values()):
rpath_val = rpath(obj)
if rpath_val:
if root:
@@ -208,18 +208,18 @@ while 1:
obj = dest_path + "/" + lib
small_libs.append(obj)
inode = os.stat(obj)[ST_INO]
- if objects.has_key(inode):
+ if inode in objects:
logger.debug("%s is hardlink to %s", obj, objects[inode])
else:
objects[inode] = obj
- for obj in objects.values():
+ for obj in list(objects.values()):
small_libs.append(obj)
- logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.itervalues()]))
+ logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.values()]))
libraries = set()
- for obj in objects.values():
+ for obj in list(objects.values()):
libraries.update(library_depends(obj))
if libraries == previous_pass_libraries:
@@ -272,4 +272,4 @@ if not os.access(dest_path + "/" + ld_fu
command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
ld_file, dest_path + "/" + ld_full_path)
-os.chmod(dest_path + "/" + ld_full_path, 0755)
+os.chmod(dest_path + "/" + ld_full_path, 0o755)
|