| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 """Runs 'ld -shared' and generates a .TOC file that's untouched when unchanged. | 6 """Runs 'ld -shared' and generates a .TOC file that's untouched when unchanged. |
| 7 | 7 |
| 8 This script exists to avoid using complex shell commands in | 8 This script exists to avoid using complex shell commands in |
| 9 gcc_toolchain.gni's tool("solink"), in case the host running the compiler | 9 gcc_toolchain.gni's tool("solink"), in case the host running the compiler |
| 10 does not have a POSIX-like shell (e.g. Windows). | 10 does not have a POSIX-like shell (e.g. Windows). |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 help='The strip binary to run', | 71 help='The strip binary to run', |
| 72 metavar='PATH') | 72 metavar='PATH') |
| 73 parser.add_argument('--sofile', | 73 parser.add_argument('--sofile', |
| 74 required=True, | 74 required=True, |
| 75 help='Shared object file produced by linking command', | 75 help='Shared object file produced by linking command', |
| 76 metavar='FILE') | 76 metavar='FILE') |
| 77 parser.add_argument('--tocfile', | 77 parser.add_argument('--tocfile', |
| 78 required=True, | 78 required=True, |
| 79 help='Output table-of-contents file', | 79 help='Output table-of-contents file', |
| 80 metavar='FILE') | 80 metavar='FILE') |
| 81 parser.add_argument('--map-file', |
| 82 help=('Use --Wl,-Map to generate a map file. Will be ' |
| 83 'gzipped if extension ends with .gz'), |
| 84 metavar='FILE') |
| 81 parser.add_argument('--output', | 85 parser.add_argument('--output', |
| 82 required=True, | 86 required=True, |
| 83 help='Final output shared object file', | 87 help='Final output shared object file', |
| 84 metavar='FILE') | 88 metavar='FILE') |
| 85 parser.add_argument('--resource-whitelist', | 89 parser.add_argument('--resource-whitelist', |
| 86 help='Merge all resource whitelists into a single file.', | 90 help='Merge all resource whitelists into a single file.', |
| 87 metavar='PATH') | 91 metavar='PATH') |
| 88 parser.add_argument('command', nargs='+', | 92 parser.add_argument('command', nargs='+', |
| 89 help='Linking command') | 93 help='Linking command') |
| 90 args = parser.parse_args() | 94 args = parser.parse_args() |
| 91 | 95 |
| 92 # Work-around for gold being slow-by-default. http://crbug.com/632230 | 96 # Work-around for gold being slow-by-default. http://crbug.com/632230 |
| 93 fast_env = dict(os.environ) | 97 fast_env = dict(os.environ) |
| 94 fast_env['LC_ALL'] = 'C' | 98 fast_env['LC_ALL'] = 'C' |
| 95 | 99 |
| 96 if args.resource_whitelist: | 100 if args.resource_whitelist: |
| 97 whitelist_candidates = wrapper_utils.ResolveRspLinks(args.command) | 101 whitelist_candidates = wrapper_utils.ResolveRspLinks(args.command) |
| 98 wrapper_utils.CombineResourceWhitelists( | 102 wrapper_utils.CombineResourceWhitelists( |
| 99 whitelist_candidates, args.resource_whitelist) | 103 whitelist_candidates, args.resource_whitelist) |
| 100 | 104 |
| 101 # First, run the actual link. | 105 # First, run the actual link. |
| 102 result = subprocess.call( | 106 command = wrapper_utils.CommandToRun(args.command) |
| 103 wrapper_utils.CommandToRun(args.command), env=fast_env) | 107 result = wrapper_utils.RunLinkWithOptionalMapFile(command, env=fast_env, |
| 108 map_file=args.map_file) |
| 109 |
| 104 if result != 0: | 110 if result != 0: |
| 105 return result | 111 return result |
| 106 | 112 |
| 107 # Next, generate the contents of the TOC file. | 113 # Next, generate the contents of the TOC file. |
| 108 result, toc = CollectTOC(args) | 114 result, toc = CollectTOC(args) |
| 109 if result != 0: | 115 if result != 0: |
| 110 return result | 116 return result |
| 111 | 117 |
| 112 # If there is an existing TOC file with identical contents, leave it alone. | 118 # If there is an existing TOC file with identical contents, leave it alone. |
| 113 # Otherwise, write out the TOC file. | 119 # Otherwise, write out the TOC file. |
| 114 UpdateTOC(args.tocfile, toc) | 120 UpdateTOC(args.tocfile, toc) |
| 115 | 121 |
| 116 # Finally, strip the linked shared object file (if desired). | 122 # Finally, strip the linked shared object file (if desired). |
| 117 if args.strip: | 123 if args.strip: |
| 118 result = subprocess.call(wrapper_utils.CommandToRun( | 124 result = subprocess.call(wrapper_utils.CommandToRun( |
| 119 [args.strip, '--strip-unneeded', '-o', args.output, args.sofile])) | 125 [args.strip, '--strip-unneeded', '-o', args.output, args.sofile])) |
| 120 | 126 |
| 121 return result | 127 return result |
| 122 | 128 |
| 123 | 129 |
| 124 if __name__ == "__main__": | 130 if __name__ == "__main__": |
| 125 sys.exit(main()) | 131 sys.exit(main()) |
| OLD | NEW |