Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Wrapper for invoking the BFD loader | 6 """Wrapper for invoking the BFD loader |
| 7 | 7 |
| 8 A simple script to invoke the bfd loader instead of gold, removing | 8 A simple script to invoke the bfd loader instead of gold. |
| 9 threading command line options that the bfd loader doesn't support. | 9 This script is in a filename "ld" so it can be invoked from gcc |
| 10 Because this script is invoked from gcc via the -B flag, it needs | 10 via the -B flag. |
| 11 to be in a file named "ld". | |
| 12 """ | 11 """ |
| 13 | 12 # TODO(bradchen): Delete this script when Gold supports linker scripts properly. |
| 14 import os | 13 import os |
| 15 import subprocess | 14 import subprocess |
| 16 import sys | 15 import sys |
| 17 | 16 |
| 18 # TODO(bradchen): Delete this script when Gold supports -Ttext properly. | 17 def PathTo(fname): |
| 19 # It should be fixed by this patch: | 18 if fname[0] == os.pathsep: |
| 20 # http://sourceware.org/ml/binutils/2011-07/msg00206.html | 19 return fname |
| 20 for p in os.environ["PATH"].split(os.pathsep): | |
| 21 fpath = os.path.join(p, fname) | |
| 22 if os.path.exists(fpath): | |
| 23 return fpath | |
| 24 return fname | |
| 25 | |
| 26 def FindLDBFD(): | |
| 27 cxx = os.getenv("CXX") | |
| 28 if not cxx: | |
| 29 cxx = "gcc" | |
|
Lei Zhang
2011/09/07 22:54:15
nit: this should be g++
| |
| 30 popen = subprocess.Popen(cxx + " -print-prog-name=ld", | |
| 31 shell=True, | |
| 32 stdout=subprocess.PIPE, | |
| 33 stdin=subprocess.PIPE) | |
| 34 (ld, error) = popen.communicate() | |
| 35 if popen.wait() != 0: | |
| 36 print "Could not find ld:" + error | |
| 37 return "ld" | |
| 38 ld = ld.strip() | |
| 39 ld_bfd = PathTo(ld + ".bfd") | |
| 40 if os.access(ld_bfd, os.X_OK): | |
| 41 return ld_bfd | |
| 42 return ld | |
|
Lei Zhang
2011/09/07 22:54:15
Have you considered trying /usr/bin/ld.bfd if |ld_
| |
| 43 | |
| 21 def main(): | 44 def main(): |
| 22 LD_BFD = "/usr/bin/ld.bfd" | 45 args = [FindLDBFD()] + sys.argv[1:] |
| 23 if not (os.path.exists(LD_BFD) and os.access(LD_BFD, os.X_OK)): | 46 print("tools/ld_bfd/ld: exec " + ' '.join(args)) |
| 24 # Can't find the BFD loader, so invoke the unmodified argv | |
| 25 args = sys.argv | |
| 26 args[0] = "ld" | |
| 27 print "ld_bfd/ld: using ld" | |
| 28 sys.exit(subprocess.call(args)) | |
| 29 # found the BFD loader, so use it | |
| 30 args = list() | |
| 31 args.append("/usr/bin/ld.bfd") | |
| 32 for arg in sys.argv[1:]: | |
| 33 if arg == "-Wl,--threads" or arg == "--threads": | |
| 34 continue | |
| 35 if arg == "-Wl,--thread-count=4" or arg == "--thread-count=4": | |
| 36 continue | |
| 37 if arg == "--icf=none": | |
| 38 continue | |
| 39 args.append(arg) | |
| 40 print("ld_bfd/ld: exec ", args) | |
| 41 sys.exit(subprocess.call(args)) | 47 sys.exit(subprocess.call(args)) |
| 42 | 48 |
| 43 if __name__ == "__main__": | 49 if __name__ == "__main__": |
| 44 main() | 50 main() |
| OLD | NEW |