2 # -*- coding: utf-8 -*-
3 # kate: space-indent on; indent-width 2; mixedindent off; indent-mode python;
5 # Copyright (C) 2009 Amand 'alrj' Tihon <amand.tihon@alrj.org>
7 # This file is part of bold, the Byte Optimized Linker.
9 # You can redistribute this file and/or modify it under the terms of the
10 # GNU Lesser General Public License as published by the Free Software
11 # Foundation, version 2.1.
13 #from bold.constants import *
14 #from bold.elf import Elf64, Elf64_Phdr, TextSegment, DataSegment, Dynamic, Interpreter
16 __author__ = "Amand Tihon <amand.tihon@alrj.org>"
20 from Bold.linker import BoldLinker
21 from Bold.errors import *
22 from optparse import OptionParser
25 class BoldOptionParser(OptionParser):
26 """Bold option parser."""
28 _usage_message = "%prog [options] file..."
29 _version_message = "%%prog version %s" % __version__
30 _description_message = """A limited ELF linker for x86_64. It is
31 intended to create very small executables with the least possible overhead."""
34 OptionParser.__init__(self, usage=self._usage_message,
35 version=self._version_message, description=self._description_message,
36 add_help_option=True, prog="bold")
38 self.set_defaults(entry="_start", outfile="a.out")
40 self.add_option("-e", "--entry", action="store", dest="entry",
41 metavar="SYMBOL", help="Set the entry point (default: _start)")
42 self.add_option("-l", "--library", action="append", dest="shlibs",
43 metavar="LIBNAME", help="Search for library LIBNAME")
44 self.add_option("-o", "--output", action="store", dest="outfile",
45 metavar="FILE", help="Set output file name (default: a.out)")
49 parser = BoldOptionParser()
50 options, args = parser.parse_args()
55 for shlib in options.shlibs:
57 linker.add_shlib(shlib)
58 except LibNotFound, e:
63 print >>sys.stderr, "No input files"
68 linker.add_object(infile)
69 except UnsupportedObject, e:
76 linker.entry_point = options.entry
80 except UndefinedSymbol, e:
83 except RedefinedSymbol, e:
87 # Remove the file if it was present
89 os.unlink(options.outfile)
91 if e.errno == 2: # No such file
95 o = open(options.outfile, "wb")
104 os.chmod(options.outfile, 0755)
106 print >>sys.stderr, e
112 if __name__ == "__main__":
117 print >>sys.stderr, "Unhandled error:", e