bug 1299959 - use GENERATED_FILES for libffi's preprocessed assembly files. r=chmanchester
authorTed Mielczarek <ted@mielczarek.org>
Thu, 14 Sep 2017 06:42:53 -0400
changeset 386764 80acc252947941171929d39a03f3e4c6b14f1064
parent 386763 e7a617e26b9696c2656a09bc711649549f3e0875
child 386765 f605961878cc80936b242290ef1674e82dac97fe
push id96306
push usertmielczarek@mozilla.com
push dateTue, 17 Oct 2017 23:50:40 +0000
treeherdermozilla-inbound@80acc2529479 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1299959
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1299959 - use GENERATED_FILES for libffi's preprocessed assembly files. r=chmanchester libffi has assembly files on Windows that need to be preprocessed. Previously this was handled by using a wrapper shell script as the assembler. This patch handles them in GENERATED_FILES with a Python script that performs an equivalent transformation. MozReview-Commit-ID: 3w0HNpUb8TA
config/external/ffi/Makefile.in
config/external/ffi/moz.build
config/external/ffi/preprocess_libffi_asm.py
deleted file mode 100644
--- a/config/external/ffi/Makefile.in
+++ /dev/null
@@ -1,12 +0,0 @@
-# -*- Mode: python; c-basic-offset: 4; 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/.
-
-# libffi's assembly files want to be pre-processed, so we still use the libffi
-# wrapper to combine the preprocessor and assembler stages.
-# Bug 1299959 is on file to find a better way to do this in moz.build.
-ifdef _MSC_VER
-AS = $(topsrcdir)/js/src/ctypes/libffi/msvcc.sh
-endif
--- a/config/external/ffi/moz.build
+++ b/config/external/ffi/moz.build
@@ -80,23 +80,42 @@ else:
             ASFLAGS += ['-no-integrated-as']
     elif CONFIG['FFI_TARGET'] == 'AARCH64':
         ffi_srcs = ('sysv.S', 'ffi.c')
     elif CONFIG['FFI_TARGET'] == 'X86':
         ffi_srcs = ('ffi.c', 'sysv.S', 'win32.S')
     elif CONFIG['FFI_TARGET'] == 'X86_64':
         ffi_srcs = ('ffi64.c', 'unix64.S', 'ffi.c', 'sysv.S')
     elif CONFIG['FFI_TARGET'] == 'X86_WIN32':
+        ffi_srcs = ['ffi.c']
         # MinGW Build for 32 bit
         if CONFIG['CC_TYPE'] == 'gcc':
             DEFINES['SYMBOL_UNDERSCORE'] = True
-        ffi_srcs = ('ffi.c', 'win32.S')
+            ffi_srcs += ['win32.S']
+        else:
+            # libffi asm needs to be preprocessed for MSVC
+            GENERATED_FILES += ['win32.asm']
+            asm = GENERATED_FILES['win32.asm']
+            asm.inputs = ['/js/src/ctypes/libffi/src/x86/win32.S']
+            asm.script = 'preprocess_libffi_asm.py'
+            asm.flags = ['$(DEFINES)', '$(LOCAL_INCLUDES)']
+            SOURCES += ['!win32.asm']
+            ASFLAGS += ['-safeseh']
     elif CONFIG['FFI_TARGET'] == 'X86_WIN64':
-        ffi_srcs = ('ffi.c', 'win64.S')
-        ASFLAGS += ['-m64']
+        ffi_srcs = ['ffi.c']
+        if CONFIG['CC_TYPE'] == 'gcc':
+            ffi_srcs += ['win64.S']
+        else:
+            # libffi asm needs to be preprocessed for MSVC
+            GENERATED_FILES += ['win64.asm']
+            asm = GENERATED_FILES['win64.asm']
+            asm.inputs = ['/js/src/ctypes/libffi/src/x86/win64.S']
+            asm.script = 'preprocess_libffi_asm.py'
+            asm.flags = ['$(DEFINES)', '$(LOCAL_INCLUDES)']
+            SOURCES += ['!win64.asm']
     elif CONFIG['FFI_TARGET'] == 'X86_DARWIN':
         DEFINES['FFI_MMAP_EXEC_WRIT'] = True
         if CONFIG['OS_TEST'] != 'x86_64':
             ffi_srcs = ('ffi.c', 'darwin.S', 'ffi64.c', 'darwin64.S',
                         'win32.S')
             DEFINES['SYMBOL_UNDERSCORE'] = True
         else:
             ffi_srcs = ('ffi.c', 'darwin.S', 'ffi64.c', 'darwin64.S')
new file mode 100644
--- /dev/null
+++ b/config/external/ffi/preprocess_libffi_asm.py
@@ -0,0 +1,26 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Souce Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distibuted with this
+# file, You can obtain one at http://mozilla.og/MPL/2.0/.
+
+import buildconfig
+import mozpack.path as mozpath
+import os
+import re
+import shlex
+import subprocess
+
+def main(output, input_asm, defines, includes):
+    defines = shlex.split(defines)
+    includes = shlex.split(includes)
+    # CPP uses -E which generates #line directives. -EP suppresses them.
+    cpp = buildconfig.substs['CPP'] + ['-EP']
+    input_asm = mozpath.relpath(input_asm, os.getcwd())
+    args = cpp + defines + includes + [input_asm]
+    print(' '.join(args))
+    preprocessed = subprocess.check_output(args)
+    r = re.compile('F[dpa][^ ]*')
+    for line in preprocessed.splitlines():
+        output.write(r.sub('', line))
+        output.write('\n')