Chromium Code Reviews| Index: chrome/nacl/nacl_helper_bootstrap_munge_phdr.py |
| diff --git a/chrome/nacl/nacl_helper_bootstrap_munge_phdr.py b/chrome/nacl/nacl_helper_bootstrap_munge_phdr.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..66f39fdf8afa27cc4be8052f0e63bb79a6bf7c89 |
| --- /dev/null |
| +++ b/chrome/nacl/nacl_helper_bootstrap_munge_phdr.py |
| @@ -0,0 +1,39 @@ |
| +#!/usr/bin/python |
| +# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +# |
| +# This takes three command-line arguments: |
| +# MUNGE-PHDR-PROGRAM file name of program built from |
| +# nacl_helper_bootstrap_munge_phdr.c |
| +# INFILE raw linked ELF file name |
| +# OUTFILE output file name |
| +# |
| +# We just run the MUNGE-PHDR-PROGRAM on a copy of INFILE. |
| +# That modifies the file in place. Then we move it to OUTFILE. |
| +# |
| +# We only have this wrapper script because nacl_helper_bootstrap_munge_phdr.c |
| +# wants to modify a file in place (and it would be a much longer and more |
| +# fragile program if it created a fresh ELF output file instead). |
| + |
| +import optparse |
|
Mark Seaborn
2011/08/30 20:12:25
Not used.
|
| +import shutil |
| +import subprocess |
| +import sys |
| + |
| + |
| +def Main(argv): |
| + if len(argv) != 4: |
| + print 'Usage: %s MUNGE-PHDR-PROGRAM INFILE OUTFILE' % argv[0] |
| + sys.exit(1) |
| + [prog, munger, infile, outfile] = argv |
| + tmpfile = outfile + '.tmp' |
| + shutil.copy(infile, tmpfile) |
| + result = subprocess.call([munger, tmpfile, '1']) |
|
Mark Seaborn
2011/08/30 20:12:25
Nit: Maybe do:
segment_num = '1'
result = subproce
|
| + if result != 0: |
|
Mark Seaborn
2011/08/30 20:12:25
You can use subprocess.check_call(). Then you don
|
| + print '%s failed with %d' % (munger, result) |
| + sys.exit(result) |
| + shutil.move(tmpfile, outfile) |
| + |
| +if __name__ == '__main__': |
| + Main(sys.argv) |
|
Mark Seaborn
2011/08/30 20:12:25
FWIW, I think it's preferable to do "Main(sys.argv
|