bug 1299959 - use GENERATED_FILES for libffi's preprocessed assembly files. r=chmanchester draft
authorTed Mielczarek <ted@mielczarek.org>
Thu, 14 Sep 2017 06:42:53 -0400
changeset 680028 284a3825cdaf2957507d60276a772f88f8c96488
parent 678462 20d9ad08dd36fe5230ad0ccf6cb3e4865d7851cf
child 735738 77142e4f6257fc4ea3b961e0b44efaefedeb53f8
push id84370
push userbmo:ted@mielczarek.org
push dateFri, 13 Oct 2017 10:49:05 +0000
reviewerschmanchester
bugs1299959
milestone58.0a1
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')