Subzero: Add a --elf arg to szbuild.py and crosstest.py.

This also implicitly applies to szbuild_spec2k.py.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/892803002
diff --git a/pydir/crosstest.py b/pydir/crosstest.py
index 3fb205b..a197bd3 100755
--- a/pydir/crosstest.py
+++ b/pydir/crosstest.py
@@ -65,6 +65,9 @@
                            'from the same bitcode as the subzero object. ' +
                            'If 0, then compile it straight from source.' +
                            ' Default %(default)d.')
+    argparser.add_argument('--elf', dest='elf',
+                           action='store_true',
+                           help='Directly generate ELF output')
     args = argparser.parse_args()
 
     nacl_root = FindBaseNaCl()
@@ -105,13 +108,15 @@
                   '--target=' + args.target,
                   '--prefix=' + args.prefix,
                   '-allow-uninitialized-globals',
-                  '-o=' + asm_sz,
-                  bitcode])
-        shellcmd(['llvm-mc',
-                  '-arch=' + arch_map[args.target],
-                  '-filetype=obj',
-                  '-o=' + obj_sz,
-                  asm_sz])
+                  '-o=' + (obj_sz if args.elf else asm_sz),
+                  bitcode] +
+                 (['-elf-writer'] if args.elf else []))
+        if not args.elf:
+            shellcmd(['llvm-mc',
+                      '-arch=' + arch_map[args.target],
+                      '-filetype=obj',
+                      '-o=' + obj_sz,
+                      asm_sz])
         objs.append(obj_sz)
         # Each original bitcode file needs to be translated by the
         # LLVM toolchain and have its object file linked in.  There
diff --git a/pydir/szbuild.py b/pydir/szbuild.py
index b9e6485..7fcb924 100755
--- a/pydir/szbuild.py
+++ b/pydir/szbuild.py
@@ -80,6 +80,9 @@
                            help='Optimization level ' +
                                 '(m1 and -1 are equivalent).' +
                                 ' Default %(default)s.')
+    argparser.add_argument('--elf', dest='elf',
+                           action='store_true',
+                           help='Directly generate ELF output')
     argparser.add_argument('--verbose', '-v', dest='verbose',
                            action='store_true',
                            help='Display some extra debugging output')
@@ -202,16 +205,18 @@
         shellcmd([llvm2ice,
                   '-O' + opt_level,
                   '-bitcode-format=pnacl',
-                  '-o', asm_sz] +
+                  '-o', obj_sz if args.elf else asm_sz] +
                  (['-externalize',
                    '-ffunction-sections',
                    '-fdata-sections'] if hybrid else []) +
+                 (['-elf-writer'] if args.elf else []) +
                  args.sz_args +
                  [pexe],
                  echo=args.verbose)
-        shellcmd((
-            'llvm-mc -arch=x86 -filetype=obj -o {obj} {asm}'
-            ).format(asm=asm_sz, obj=obj_sz), echo=args.verbose)
+        if not args.elf:
+            shellcmd((
+                'llvm-mc -arch=x86 -filetype=obj -o {obj} {asm}'
+                ).format(asm=asm_sz, obj=obj_sz), echo=args.verbose)
         shellcmd((
             'objcopy --redefine-sym _start=_user_start {obj}'
             ).format(obj=obj_sz), echo=args.verbose)