Exemplo n.º 1
0
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('--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

  # Finally, strip the linked executable (if desired).
  if args.strip:
    result = subprocess.call(CommandToRun([
        args.strip, '--strip-unneeded', '-o', args.output, args.unstripped_file
        ]))

  return result
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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