def main(): parser = argparse.ArgumentParser() parser.add_argument( '--mode', choices=['clang', 'cl'], required=True, help='Specifies the compiler argument convention to use.') parser.add_argument('args', nargs=argparse.REMAINDER) parsed_args = parser.parse_args() prefix = '-Xclang' if parsed_args.mode == 'cl' else '-Xanalyzer' cmd = parsed_args.args + analyzer_enable_flags + \ interleave_args(analyzer_option_flags, prefix) returncode, stderr = wrapper_utils.CaptureCommandStderr( wrapper_utils.CommandToRun(cmd)) sys.stderr.write(stderr) if returncode != 0: sys.stderr.write( """WARNING! The Clang static analyzer exited with error code %d. Please share the error details in crbug.com/695243 if this looks like a new regression.\n""" % (returncode)) returncode, stderr = wrapper_utils.CaptureCommandStderr( wrapper_utils.CommandToRun(parsed_args.args)) sys.stderr.write(stderr) return returncode
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--ar', required=True, help='The ar binary to run', metavar='PATH') parser.add_argument('--output', required=True, help='Output archive file', metavar='ARCHIVE') parser.add_argument('--plugin', help='Load plugin') parser.add_argument('operation', help='Operation on the archive') parser.add_argument('inputs', nargs='+', help='Input files') args = parser.parse_args() command = [args.ar, args.operation] if args.plugin is not None: command += ['--plugin', args.plugin] command.append(args.output) command += args.inputs # Remove the output file first. try: os.remove(args.output) except OSError as e: if e.errno != os.errno.ENOENT: raise # Now just run the ar command. return subprocess.call(wrapper_utils.CommandToRun(command))
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--strip', help='The strip binary to run', metavar='PATH') parser.add_argument('--unstripped-file', help='Executable file produced by linking command', metavar='FILE') parser.add_argument('--map-file', help=('Use --Wl,-Map to generate a map file. Will be ' 'gzipped if extension ends with .gz'), metavar='FILE') parser.add_argument('--dwp', help=('The dwp binary to run'), metavar='FILE') parser.add_argument('--output', required=True, help='Final output executable file', metavar='FILE') parser.add_argument('command', nargs='+', help='Linking command') args = parser.parse_args() # Work-around for gold being slow-by-default. http://crbug.com/632230 fast_env = dict(os.environ) fast_env['LC_ALL'] = 'C' result = wrapper_utils.RunLinkWithOptionalMapFile(args.command, env=fast_env, map_file=args.map_file) if result != 0: return result # If dwp is set, then package debug info for this exe. dwp_proc = None if args.dwp: exe_file = args.output if args.unstripped_file: exe_file = args.unstripped_file # Suppress output here because it doesn't seem to be useful. The most # common error is a segfault, which will happen if files are missing. with open(os.devnull, "w") as devnull: dwp_proc = subprocess.Popen(wrapper_utils.CommandToRun( [args.dwp, '-e', exe_file, '-o', exe_file + '.dwp']), stdout=devnull, stderr=subprocess.STDOUT) # Finally, strip the linked executable (if desired). if args.strip: result = subprocess.call( CommandToRun([args.strip, '-o', args.output, args.unstripped_file])) if dwp_proc: dwp_result = dwp_proc.wait() if dwp_result != 0: sys.stderr.write( 'dwp failed with error code {}\n'.format(dwp_result)) return dwp_result return result
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--strip', help='The strip binary to run', metavar='PATH') parser.add_argument('--unstripped-file', help='Executable file produced by linking command', metavar='FILE') parser.add_argument('--map-file', help=('Use --Wl,-Map to generate a map file. Will be ' 'gzipped if extension ends with .gz'), metavar='FILE') parser.add_argument('--dwp', help=('The dwp binary to run'), metavar='FILE') parser.add_argument('--output', required=True, help='Final output executable file', metavar='FILE') parser.add_argument('command', nargs='+', help='Linking command') args = parser.parse_args() generate_dwp = '--generate-dwp' in args.command if generate_dwp: args.command.remove('--generate-dwp') # Work-around for gold being slow-by-default. http://crbug.com/632230 fast_env = dict(os.environ) fast_env['LC_ALL'] = 'C' result = wrapper_utils.RunLinkWithOptionalMapFile(args.command, env=fast_env, map_file=args.map_file) if result != 0: return result # If dwp is set, then package debug info for this exe. dwp_proc = None if generate_dwp: if not args.dwp: parser.error('--generate-dwp requireds --dwp') exe_file = args.output if args.unstripped_file: exe_file = args.unstripped_file dwp_proc = subprocess.Popen( wrapper_utils.CommandToRun( [args.dwp, '-e', exe_file, '-o', args.output + '.dwp'])) # Finally, strip the linked executable (if desired). if args.strip: result = subprocess.call( CommandToRun([args.strip, '-o', args.output, args.unstripped_file])) if dwp_proc: dwp_result = dwp_proc.wait() if dwp_result != 0: return dwp_result return result
def CollectDynSym(args): """Replaces: nm --format=posix -g -D $sofile | cut -f1-2 -d' '""" toc = '' nm = subprocess.Popen(wrapper_utils.CommandToRun([ args.nm, '--format=posix', '-g', '-D', args.sofile]), stdout=subprocess.PIPE, bufsize=-1) for line in nm.stdout: toc += ' '.join(line.split(' ', 2)[:2]) + '\n' return nm.wait(), toc
def CollectSONAME(args): """Replaces: readelf -d $sofile | grep SONAME""" toc = '' readelf = subprocess.Popen(wrapper_utils.CommandToRun( [args.readelf, '-d', args.sofile]), stdout=subprocess.PIPE, bufsize=-1) for line in readelf.stdout: if 'SONAME' in line: toc += line return readelf.wait(), toc
def main(): parser = argparse.ArgumentParser() parser.add_argument('--mode', choices=['clang', 'cl'], required=True, help='Specifies the compiler argument convention to use.') parser.add_argument('args', nargs=argparse.REMAINDER) parsed_args = parser.parse_args() prefix = '-Xclang' if parsed_args.mode == 'cl' else '-Xanalyzer' cmd = parsed_args.args + analyzer_enable_flags + \ interleave_args(analyzer_option_flags, prefix) returncode, stderr = wrapper_utils.CaptureCommandStderr( wrapper_utils.CommandToRun(cmd)) sys.stderr.write(stderr.decode()) returncode, stderr = wrapper_utils.CaptureCommandStderr( wrapper_utils.CommandToRun(parsed_args.args)) sys.stderr.write(stderr.decode()) return returncode
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--ar', required=True, help='The ar binary to run', metavar='PATH') parser.add_argument('--output', required=True, help='Output archive file', metavar='ARCHIVE') parser.add_argument('--plugin', help='Load plugin') parser.add_argument('--resource-whitelist', help='Merge all resource whitelists into a single file.', metavar='PATH') parser.add_argument('operation', help='Operation on the archive') parser.add_argument('inputs', nargs='+', help='Input files') args = parser.parse_args() # Specifies the type of object file ar should examine. # The ar on linux ignores this option. object_mode = [] if sys.platform.startswith('aix'): # The @file feature is not avaliable on ar for AIX. # For linux (and other posix like systems), the @file_name # option reads the contents of file_name as command line arguments. # For AIX we must parse these (rsp files) manually. # Read rspfile. args.inputs = wrapper_utils.ResolveRspLinks(args.inputs) object_mode = ['-X64'] else: if args.resource_whitelist: whitelist_candidates = wrapper_utils.ResolveRspLinks(args.inputs) wrapper_utils.CombineResourceWhitelists( whitelist_candidates, args.resource_whitelist) command = [args.ar] + object_mode + [args.operation] if args.plugin is not None: command += ['--plugin', args.plugin] command.append(args.output) command += args.inputs # Remove the output file first. try: os.remove(args.output) except OSError as e: if e.errno != os.errno.ENOENT: raise # Now just run the ar command. return subprocess.call(wrapper_utils.CommandToRun(command))
def CollectSONAME(args): """Replaces: readelf -d $sofile | grep SONAME""" # TODO(crbug.com/1259067): Come up with a way to get this info without having # to bundle readelf in the toolchain package. toc = '' readelf = subprocess.Popen(wrapper_utils.CommandToRun( [args.readelf, '-d', args.sofile]), stdout=subprocess.PIPE, bufsize=-1, universal_newlines=True) for line in readelf.stdout: if 'SONAME' in line: toc += line return readelf.wait(), toc
def CollectSONAME(args): """Replaces: readelf -d $sofile | grep SONAME. Args: args: the args to pass to the subprocess Returns: A tuple of (return code, output) """ toc = '' readelf = subprocess.Popen(wrapper_utils.CommandToRun( [args.readelf, '-d', args.sofile]), stdout=subprocess.PIPE, bufsize=-1) for line in readelf.stdout: if 'SONAME' in line: toc += line return readelf.wait(), toc
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--ar', required=True, help='The ar binary to run', metavar='PATH') parser.add_argument('--output', required=True, help='Output archive file', metavar='ARCHIVE') parser.add_argument('--plugin', help='Load plugin') parser.add_argument( '--resource-whitelist', help='Merge all resource whitelists into a single file.', metavar='PATH') parser.add_argument('operation', help='Operation on the archive') parser.add_argument('inputs', nargs='+', help='Input files') args = parser.parse_args() if args.resource_whitelist: whitelist_candidates = wrapper_utils.ResolveRspLinks(args.inputs) wrapper_utils.CombineResourceWhitelists(whitelist_candidates, args.resource_whitelist) command = [args.ar, args.operation] if args.plugin is not None: command += ['--plugin', args.plugin] command.append(args.output) command += args.inputs # Remove the output file first. try: os.remove(args.output) except OSError as e: if e.errno != errno.ENOENT: raise # Now just run the ar command. return subprocess.call(wrapper_utils.CommandToRun(command))
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--clang-cc-path', help='Path to the clang compiler.', metavar='PATH') parser.add_argument('--clang-cxx-path', help='Path to the clang++ compiler', metavar='PATH') parser.add_argument('--analyzer', help='Path to the language-specific Clang analysis tool.', required=True, metavar='PATH') args, compile_args = parser.parse_known_args() # Check that only one of --clang-cc-path or --clang-cxx-path are set. assert ((args.clang_cc_path != None) != (args.clang_cxx_path != None)) is_cxx = args.clang_cxx_path != None env = os.environ env['CCC_ANALYZER_FORCE_ANALYZE_DEBUG_CODE'] = '0' env['CCC_ANALYZER_OUTPUT_FORMAT'] = 'text' clang_path = args.clang_cxx_path or args.clang_cc_path if is_cxx: env['CCC_CXX'] = clang_path env['CLANG_CXX'] = clang_path else: env['CCC_CC'] = clang_path env['CLANG'] = clang_path # TODO(kmarshall): Place the summarized output in a useful directory. temp_dir = tempfile.mkdtemp() try: env['CCC_ANALYZER_HTML'] = temp_dir returncode, stderr = wrapper_utils.CaptureCommandStderr( wrapper_utils.CommandToRun([args.analyzer] + compile_args), env) sys.stderr.write(stderr) return returncode finally: shutil.rmtree(temp_dir)
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--resource-whitelist', help='Generate a resource whitelist for this target.', metavar='PATH') parser.add_argument('command', nargs=argparse.REMAINDER, help='Compilation command') args = parser.parse_args() returncode, stderr = wrapper_utils.CaptureCommandStderr( wrapper_utils.CommandToRun(args.command)) used_resources = wrapper_utils.ExtractResourceIdsFromPragmaWarnings(stderr) sys.stderr.write(stderr) if args.resource_whitelist: with open(args.resource_whitelist, 'w') as f: if used_resources: f.write('\n'.join( str(resource) for resource in used_resources)) f.write('\n') return returncode
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--readelf', required=True, help='The readelf binary to run', metavar='PATH') parser.add_argument('--nm', required=True, help='The nm binary to run', metavar='PATH') parser.add_argument('--strip', help='The strip binary to run', metavar='PATH') parser.add_argument('--sofile', required=True, help='Shared object file produced by linking command', metavar='FILE') parser.add_argument('--tocfile', required=True, help='Output table-of-contents file', metavar='FILE') parser.add_argument('--map-file', help=('Use --Wl,-Map to generate a map file. Will be ' 'gzipped if extension ends with .gz'), metavar='FILE') parser.add_argument('--output', required=True, help='Final output shared object file', metavar='FILE') parser.add_argument('--resource-whitelist', help='Merge all resource whitelists into a single file.', metavar='PATH') parser.add_argument('command', nargs='+', help='Linking command') args = parser.parse_args() # Work-around for gold being slow-by-default. http://crbug.com/632230 fast_env = dict(os.environ) fast_env['LC_ALL'] = 'C' if args.resource_whitelist: whitelist_candidates = wrapper_utils.ResolveRspLinks(args.command) wrapper_utils.CombineResourceWhitelists( whitelist_candidates, args.resource_whitelist) # First, run the actual link. command = wrapper_utils.CommandToRun(args.command) result = wrapper_utils.RunLinkWithOptionalMapFile(command, env=fast_env, map_file=args.map_file) if result != 0: return result # Next, generate the contents of the TOC file. result, toc = CollectTOC(args) if result != 0: return result # If there is an existing TOC file with identical contents, leave it alone. # Otherwise, write out the TOC file. UpdateTOC(args.tocfile, toc) # Finally, strip the linked shared object file (if desired). if args.strip: result = subprocess.call(wrapper_utils.CommandToRun( [args.strip, '--strip-unneeded', '-o', args.output, args.sofile])) return result
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--readelf', required=True, help='The readelf binary to run', metavar='PATH') parser.add_argument('--nm', required=True, help='The nm binary to run', metavar='PATH') parser.add_argument('--strip', help='The strip binary to run', metavar='PATH') parser.add_argument('--sofile', required=True, help='Shared object file produced by linking command', metavar='FILE') parser.add_argument('--tocfile', required=True, help='Output table-of-contents file', metavar='FILE') parser.add_argument('--map-file', help=('Use --Wl,-Map to generate a map file. Will be ' 'gzipped if extension ends with .gz'), metavar='FILE') parser.add_argument('--output', required=True, help='Final output shared object file', metavar='FILE') parser.add_argument('command', nargs='+', help='Linking command') args = parser.parse_args() # Work-around for gold being slow-by-default. http://crbug.com/632230 fast_env = dict(os.environ) fast_env['LC_ALL'] = 'C' # Extract the --link-only argument, which goes for a ride through ldflags into # the command, but is meant to be intercepted by this wrapper script (not # passed to the linker). https://crbug.com/954311 tracks finding a better way # to plumb this argument. link_only = '--link-only' in args.command if link_only: args.command.remove('--link-only') # First, run the actual link. command = wrapper_utils.CommandToRun(args.command) result = wrapper_utils.RunLinkWithOptionalMapFile(command, env=fast_env, map_file=args.map_file) if result != 0: return result # If only linking, we are likely generating a partitioned .so that will be # split apart later. In that case: # # - The TOC file optimization isn't useful, because the partition libraries # must always be re-extracted if the combined library changes (and nothing # should be depending on the combined library's dynamic symbol table). # - Stripping isn't necessary, because the combined library is not used in # production or published. # # Both of these operations could still be done, they're needless work, and # tools would need to be updated to handle and/or not complain about # partitioned libraries. Instead, to keep Ninja happy, simply create dummy # files for the TOC and stripped lib. if link_only: with open(args.output, 'w'): pass with open(args.tocfile, 'w'): pass return 0 # Next, generate the contents of the TOC file. result, toc = CollectTOC(args) if result != 0: return result # If there is an existing TOC file with identical contents, leave it alone. # Otherwise, write out the TOC file. UpdateTOC(args.tocfile, toc) # Finally, strip the linked shared object file (if desired). if args.strip: result = subprocess.call( wrapper_utils.CommandToRun( [args.strip, '-o', args.output, args.sofile])) return result
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--readelf', required=True, help='The readelf binary to run', metavar='PATH') parser.add_argument('--nm', required=True, help='The nm binary to run', metavar='PATH') parser.add_argument('--strip', help='The strip binary to run', metavar='PATH') parser.add_argument('--dwp', help='The dwp binary to run', metavar='PATH') parser.add_argument('--sofile', required=True, help='Shared object file produced by linking command', metavar='FILE') parser.add_argument('--tocfile', required=True, help='Output table-of-contents file', metavar='FILE') parser.add_argument('--map-file', help=('Use --Wl,-Map to generate a map file. Will be ' 'gzipped if extension ends with .gz'), metavar='FILE') parser.add_argument('--output', required=True, help='Final output shared object file', metavar='FILE') parser.add_argument('command', nargs='+', help='Linking command') args = parser.parse_args() # Work-around for gold being slow-by-default. http://crbug.com/632230 fast_env = dict(os.environ) fast_env['LC_ALL'] = 'C' # Extract flags passed through ldflags but meant for this script. # https://crbug.com/954311 tracks finding a better way to plumb these. link_only = InterceptFlag('--link-only', args.command) collect_inputs_only = InterceptFlag('--collect-inputs-only', args.command) generate_dwp = InterceptFlag('--generate-dwp', args.command) # If only linking, we are likely generating a partitioned .so that will be # split apart later. In that case: # # - The TOC file optimization isn't useful, because the partition libraries # must always be re-extracted if the combined library changes (and nothing # should be depending on the combined library's dynamic symbol table). # - Stripping isn't necessary, because the combined library is not used in # production or published. # # Both of these operations could still be done, they're needless work, and # tools would need to be updated to handle and/or not complain about # partitioned libraries. Instead, to keep Ninja happy, simply create dummy # files for the TOC and stripped lib. if link_only or collect_inputs_only: open(args.output, 'w').close() open(args.tocfile, 'w').close() # Instead of linking, records all inputs to a file. This is used by # enable_resource_allowlist_generation in order to avoid needing to # link (which is slow) to build the resources whitelist. if collect_inputs_only: with open(args.sofile, 'w') as f: CollectInputs(f, args.command) if args.map_file: open(args.map_file, 'w').close() return 0 # First, run the actual link. command = wrapper_utils.CommandToRun(args.command) result = wrapper_utils.RunLinkWithOptionalMapFile(command, env=fast_env, map_file=args.map_file) if result != 0 or link_only: return result # If dwp is set, then package debug info for this SO. dwp_proc = None if generate_dwp: if not args.dwp: parser.error('--generate-dwp requireds --dwp') dwp_proc = subprocess.Popen( wrapper_utils.CommandToRun( [args.dwp, '-e', args.sofile, '-o', args.output + '.dwp'])) # Next, generate the contents of the TOC file. result, toc = CollectTOC(args) if result != 0: return result # If there is an existing TOC file with identical contents, leave it alone. # Otherwise, write out the TOC file. UpdateTOC(args.tocfile, toc) # Finally, strip the linked shared object file (if desired). if args.strip: result = subprocess.call( wrapper_utils.CommandToRun( [args.strip, '-o', args.output, args.sofile])) if dwp_proc: dwp_result = dwp_proc.wait() if dwp_result != 0: return dwp_result return result