Bug 1537725 - Use the default stack alignment in windows x86 for libdav1d. r=TD-Linux a=pascalc
authorAlex Chronopoulos <achronop@gmail.com>
Tue, 26 Mar 2019 09:45:21 +0000
changeset 525876 47e581a4ae655bcaf935c674c9b2c6475c04469e
parent 525875 039c28632803b8bf6070f3ee4a23b88794aa9023
child 525877 f3907c8d89f9b811d3fc50d961bfa6f376353be0
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTD-Linux, pascalc
bugs1537725
milestone67.0
Bug 1537725 - Use the default stack alignment in windows x86 for libdav1d. r=TD-Linux a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D24785
media/libdav1d/asm/moz.build
media/libdav1d/asm/x86_32/win/config.asm
media/libdav1d/moz.build
--- a/media/libdav1d/asm/moz.build
+++ b/media/libdav1d/asm/moz.build
@@ -20,33 +20,36 @@ LOCAL_INCLUDES += [
 # see: third_party/dav1d/include/dav1d/common.h
 DEFINES['DAV1D_API'] = ''
 
 CFLAGS += [
     # find the config.h file.
     '-I%s/dist/include/dav1d/' % TOPOBJDIR,
 ]
 
-# Default stack aligment is 16 bytes.
-stack_alignment = 16
-
+stack_alignment = 0
 # Attaching config.asm file
 if CONFIG['CPU_ARCH'] == 'x86':
+    # Default stack alignment can be 4 bytes.
     if CONFIG['OS_TARGET'] == 'WINNT':
+        stack_alignment = 4
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_32/win/' % TOPSRCDIR]
     else:
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_32/' % TOPSRCDIR]
-        # Default stack aligment can be 4 bytes, change it to 16 bytes.
+        stack_alignment = 16
+        # Change stack alignment to 16 bytes.
         if CONFIG['CC_TYPE'] == 'clang':
             CFLAGS += ['-mstack-alignment=16']
         elif CONFIG['CC_TYPE'] == 'gcc':
             CFLAGS += ['-mpreferred-stack-boundary=4']
 
 
 if CONFIG['CPU_ARCH'] == 'x86_64':
+    # Default stack aligment is 16 bytes.
+    stack_alignment = 16
     if CONFIG['OS_TARGET'] == 'Darwin':
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/osx/' % TOPSRCDIR]
     elif CONFIG['OS_TARGET'] == 'WINNT':
         ASFLAGS += ['-I%s/media/libdav1d/asm/x86_64/' % TOPSRCDIR]
     elif CONFIG['OS_TARGET'] == 'Android':
         error('Platform %s is not expected' % CONFIG['OS_TARGET'])
     else:
         # The rest of the platforms are all Linux flavors
@@ -57,16 +60,18 @@ if CONFIG['CPU_ARCH'] == 'x86_64':
         # Change the default stack alignment (16) to 32 bytes.
         stack_alignment = 32
         if CONFIG['CC_TYPE'] == 'clang':
             CFLAGS += ['-mstack-alignment=32']
         elif CONFIG['CC_TYPE'] == 'gcc':
             CFLAGS += ['-mpreferred-stack-boundary=5']
 
 # Set the macro here instead of config.h
+if stack_alignment == 0:
+    error('Stack alignment cannot be zero.')
 DEFINES['STACK_ALIGNMENT'] = stack_alignment
 
 if CONFIG['CPU_ARCH'] in ('x86', 'x86_64'):
     SOURCES += [
         '../../../third_party/dav1d/src/x86/cpu.c',
     ]
 
     EXPORTS.dav1d += [
--- a/media/libdav1d/asm/x86_32/win/config.asm
+++ b/media/libdav1d/asm/x86_32/win/config.asm
@@ -4,10 +4,10 @@
 %define ARCH_X86_32 1
 
 %define ARCH_X86_64 0
 
 %define PIC 1
 
 %define PREFIX 1
 
-%define STACK_ALIGNMENT 16
+%define STACK_ALIGNMENT 4
 
--- a/media/libdav1d/moz.build
+++ b/media/libdav1d/moz.build
@@ -27,46 +27,56 @@ SOURCES += [f for f in entrypoint_source
 
 # Don't export DAV1D_API symbols from libxul
 # see: third_party/dav1d/include/dav1d/common.h
 DEFINES['DAV1D_API'] = ''
 
 if CONFIG['MOZ_DAV1D_ASM']:
     DIRS += ['asm']
 
+    # Store the stack alignment that will be used.
+    stack_alignment = 0
+
     # Default stack alignment can be 4 bytes on x86.
     if CONFIG['CPU_ARCH'] == 'x86':
-        # Update stack alignment to 16 bytes.
-        if CONFIG['CC_TYPE'] == 'clang':
-            CFLAGS += ['-mstack-alignment=16']
-            for ep in entrypoint_source_files:
-                SOURCES[ep].flags += ['-mstackrealign']
-        elif CONFIG['CC_TYPE'] == 'gcc':
-            CFLAGS += ['-mpreferred-stack-boundary=4']
-            for ep in entrypoint_source_files:
-                SOURCES[ep].flags += ['-mincoming-stack-boundary=2']
+        if CONFIG['OS_TARGET'] == 'WINNT':
+            # Allow the default to avoid crashes
+            stack_alignment = 4
+        else:
+            # Update stack alignment to 16 bytes.
+            stack_alignment = 16
+            if CONFIG['CC_TYPE'] == 'clang':
+                CFLAGS += ['-mstack-alignment=16']
+                for ep in entrypoint_source_files:
+                    SOURCES[ep].flags += ['-mstackrealign']
+            elif CONFIG['CC_TYPE'] == 'gcc':
+                CFLAGS += ['-mpreferred-stack-boundary=4']
+                for ep in entrypoint_source_files:
+                    SOURCES[ep].flags += ['-mincoming-stack-boundary=2']
 
-    # Expect stack alignment of 16 bytes.
-    stack_alignment = 16
 
     # The default stack alignment in x86_64 is 16 bytes. On all Linux flavors the
     # default is used due to crashes with 32 bytes stack alignment.
     if CONFIG['OS_TARGET'] == 'WINNT' and CONFIG['CPU_ARCH'] == 'x86_64':
         stack_alignment = 32
         # Update stack alignment to 32 bytes.
         if CONFIG['CC_TYPE'] == 'clang':
             CFLAGS += ['-mstack-alignment=32']
             for ep in entrypoint_source_files:
                 SOURCES[ep].flags += ['-mstackrealign']
         elif CONFIG['CC_TYPE'] == 'gcc':
             CFLAGS += ['-mpreferred-stack-boundary=5']
             for ep in entrypoint_source_files:
                 SOURCES[ep].flags += ['-mincoming-stack-boundary=4']
+    else:
+        stack_alignment = 16
 
     # Set the macro here instead of config.h
+    if stack_alignment == 0:
+        error('Stack alignment cannot be zero.')
     DEFINES['STACK_ALIGNMENT'] = stack_alignment
 
 if CONFIG['OS_TARGET'] == 'Linux':
     # For fuzzing, We only support building on Linux currently.
     include('/tools/fuzzing/libfuzzer-config.mozbuild')
     if CONFIG['FUZZING_INTERFACES']:
         TEST_DIRS += [
             'test/fuzztest'