Allow 64-bit code to be stored as ELF64.

Previously all unsandboxed 64-bit code was assumed to use ILP32 and
be stored in ELF32 format using the x32 ABI.

BUG=swiftshader:9

Change-Id: I2476a09d1f0af60b1ac6f8807ee9ed37d54a99d4
Reviewed-on: https://chromium-review.googlesource.com/385277
Reviewed-by: Jim Stichnoth <stichnot@chromium.org>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/IceClFlags.def b/src/IceClFlags.def
index bb9a181..3c03813 100644
--- a/src/IceClFlags.def
+++ b/src/IceClFlags.def
@@ -229,6 +229,13 @@
                    "Low-level integrated assembly ('.s') file"),               \
         clEnumValEnd))                                                         \
                                                                                \
+  X(ApplicationBinaryInterface, Ice::ABI, dev_opt_flag, "abi",                 \
+    cl::desc("ABI type"), cl::init(Ice::ABI_PNaCl),                            \
+    cl::values(                                                                \
+        clEnumValN(Ice::ABI_PNaCl, "pnacl", "x32 for unsandboxed 64-bit x86"), \
+        clEnumValN(Ice::ABI_Platform, "platform", "Native executable ABI"),    \
+        clEnumValEnd))                                                         \
+                                                                               \
   X(ParseParallel, bool, dev_opt_flag, "parse-parallel",                       \
     cl::desc("Parse function blocks in parallel"), cl::init(true))             \
                                                                                \
diff --git a/src/IceDefs.h b/src/IceDefs.h
index bffbd2d..45c20d3 100644
--- a/src/IceDefs.h
+++ b/src/IceDefs.h
@@ -372,6 +372,11 @@
   FT_Iasm /// "Integrated assembler" .byte-style .s file
 };
 
+enum ABI {
+  ABI_PNaCl,   /// x32 for unsandboxed 64-bit x86
+  ABI_Platform /// Native executable ABI
+};
+
 using Ostream = llvm::raw_ostream;
 using Fdstream = llvm::raw_fd_ostream;
 
diff --git a/src/IceELFObjectWriter.cpp b/src/IceELFObjectWriter.cpp
index bb3e0ed..2b32e23 100644
--- a/src/IceELFObjectWriter.cpp
+++ b/src/IceELFObjectWriter.cpp
@@ -49,8 +49,9 @@
     return false;
   }
 
-  if (!Flags.getUseSandboxing()) {
-    // Unsandboxed code is always ELF32 (pexes are ILP32.)
+  if (Flags.getApplicationBinaryInterface() == ABI_PNaCl &&
+      !Flags.getUseSandboxing()) {
+    // Unsandboxed PNaCl code is always ELF32 (pexes are ILP32.)
     return false;
   }