Bug 1527471 - part 1 - preprocess aarch64 windows assembly xptcall files; r=dmajor, a=lizzard
authorNathan Froyd <froydnj@mozilla.com>
Thu, 14 Feb 2019 20:58:45 +0000
changeset 516095 37dca6044dcba5ce00e928ce363f63a0f2118542
parent 516094 d1f8173046a0e34410ae3b9574746a8d26c6102a
child 516096 8d7fe5194e9399f47dd1a3abe65722c6b03cf78d
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmajor, lizzard
bugs1527471
milestone66.0
Bug 1527471 - part 1 - preprocess aarch64 windows assembly xptcall files; r=dmajor, a=lizzard We need to preprocess these files so we can eventually add unwind information, for which we need to include C headers. Differential Revision: https://phabricator.services.mozilla.com/D19819
xpcom/reflect/xptcall/md/win32/moz.build
xpcom/reflect/xptcall/md/win32/preprocess.py
--- a/xpcom/reflect/xptcall/md/win32/moz.build
+++ b/xpcom/reflect/xptcall/md/win32/moz.build
@@ -35,18 +35,28 @@ elif CONFIG['CPU_ARCH'] == 'x86':
             'xptcstubs.cpp',
         ]
         SOURCES['xptcinvoke_asm_x86_msvc.asm'].flags += ['-safeseh']
 elif CONFIG['CPU_ARCH'] == 'aarch64':
     SOURCES += [
         'xptcinvoke_aarch64.cpp',
         'xptcstubs_aarch64.cpp',
     ]
-    SOURCES += [
+    asm_files = [
         'xptcinvoke_asm_aarch64.asm',
         'xptcstubs_asm_aarch64.asm',
     ]
 
+    # make gets confused if the srcdir and objdir files have the same name, so
+    # we generate different names for the objdir files
+    for src in asm_files:
+        obj = src.replace('_asm_aarch64', '')
+        GENERATED_FILES += [obj]
+        asm = GENERATED_FILES[obj]
+        asm.script = 'preprocess.py:preprocess'
+        asm.inputs = [src]
+        SOURCES += ['!%s' % obj]
+
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '../..',
 ]
new file mode 100644
--- /dev/null
+++ b/xpcom/reflect/xptcall/md/win32/preprocess.py
@@ -0,0 +1,38 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import sys
+import os
+import shlex
+import subprocess
+import tempfile
+import which
+import buildconfig
+
+
+def preprocess(out, asm_file):
+    cxx = shlex.split(buildconfig.substs['CXX'])
+    if not os.path.exists(cxx[0]):
+        cxx[0] = which.which(cxx[0])
+    cppflags = buildconfig.substs['OS_CPPFLAGS']
+
+    # subprocess.Popen(stdout=) only accepts actual file objects, which `out`,
+    # above, is not.  So fake a temporary file to write to.
+    (outhandle, tmpout) = tempfile.mkstemp(suffix='.cpp')
+
+    # #line directives will confuse armasm64, and /EP is the only way to
+    # preprocess without emitting #line directives.
+    command = cxx + ['/EP'] + cppflags + ['/TP', asm_file]
+    with open(tmpout, 'wb') as t:
+        result = subprocess.Popen(command, stdout=t).wait()
+        if result != 0:
+            sys.exit(result)
+
+    with open(tmpout, 'rb') as t:
+        out.write(t.read())
+
+    os.close(outhandle)
+    os.remove(tmpout)