configure: Don't assume a 16 byte aligned stack on BSDs on i386

Message ID 20180316193710.54472-1-martin@martin.st
State Committed
Commit ea2f72a2c14c67a3b35dac6426d1e3c0fae33fd5
Headers show
Series
  • configure: Don't assume a 16 byte aligned stack on BSDs on i386
Related show

Commit Message

Martin Storsjö March 16, 2018, 7:37 p.m.
With GCC, request it to maintain 16 byte alignment, and the existing
entry points already align it via attribute_align_arg.

With clang, do the same as for mingw; disable the aligned stack
and let the assembly functions that require it do the alignment
instead.
---
 configure | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Comments

Luca Barbato March 17, 2018, 7:26 a.m. | #1
On 16/03/2018 20:37, Martin Storsjö wrote:
> With GCC, request it to maintain 16 byte alignment, and the existing
> entry points already align it via attribute_align_arg.
> 
> With clang, do the same as for mingw; disable the aligned stack
> and let the assembly functions that require it do the alignment
> instead.
> ---
>   configure | 22 ++++++++++++++++++++--
>   1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 95e6006440..78a2065208 100755
> --- a/configure
> +++ b/configure
> @@ -4957,16 +4957,34 @@ elif enabled gcc; then
>       check_cflags -Werror=format-security
>       check_cflags -fdiagnostics-color=auto
>       enabled extra_warnings || check_disable_warning -Wno-maybe-uninitialized
> +    if enabled x86_32; then
> +        case $target_os in
> +        *bsd*)
> +            # BSDs don't guarantee a 16 byte aligned stack, but we can
> +            # request GCC to try to maintain 16 byte alignment throughout
> +            # function calls. Library entry points that might call assembly
> +            # functions align the stack. (The parameter means 2^4 bytes.)
> +            check_cflags -mpreferred-stack-boundary=4
> +            ;;
> +        esac
> +    fi
>   elif enabled llvm_gcc; then
>       check_cflags -mllvm -stack-alignment=16
>   elif enabled clang; then
> -    if [ "$target_os" = "mingw32" -o "$target_os" = "win32" ] && enabled x86_32; then
> +    if enabled x86_32; then
>           # Clang doesn't support maintaining alignment without assuming the
>           # same alignment in every function. If 16 byte alignment would be
>           # enabled, one would also have to either add attribute_align_arg on
>           # every single entry point into the libraries or enable -mstackrealign
>           # (doing stack realignment in every single function).
> -        disable aligned_stack
> +        case $target_os in
> +        mingw32|win32|*bsd*)
> +            disable aligned_stack
> +            ;;
> +        *)
> +            check_cflags -mllvm -stack-alignment=16
> +            ;;
> +        esac
>       else
>           check_cflags -mllvm -stack-alignment=16
>       fi
> 

Ok.

Patch

diff --git a/configure b/configure
index 95e6006440..78a2065208 100755
--- a/configure
+++ b/configure
@@ -4957,16 +4957,34 @@  elif enabled gcc; then
     check_cflags -Werror=format-security
     check_cflags -fdiagnostics-color=auto
     enabled extra_warnings || check_disable_warning -Wno-maybe-uninitialized
+    if enabled x86_32; then
+        case $target_os in
+        *bsd*)
+            # BSDs don't guarantee a 16 byte aligned stack, but we can
+            # request GCC to try to maintain 16 byte alignment throughout
+            # function calls. Library entry points that might call assembly
+            # functions align the stack. (The parameter means 2^4 bytes.)
+            check_cflags -mpreferred-stack-boundary=4
+            ;;
+        esac
+    fi
 elif enabled llvm_gcc; then
     check_cflags -mllvm -stack-alignment=16
 elif enabled clang; then
-    if [ "$target_os" = "mingw32" -o "$target_os" = "win32" ] && enabled x86_32; then
+    if enabled x86_32; then
         # Clang doesn't support maintaining alignment without assuming the
         # same alignment in every function. If 16 byte alignment would be
         # enabled, one would also have to either add attribute_align_arg on
         # every single entry point into the libraries or enable -mstackrealign
         # (doing stack realignment in every single function).
-        disable aligned_stack
+        case $target_os in
+        mingw32|win32|*bsd*)
+            disable aligned_stack
+            ;;
+        *)
+            check_cflags -mllvm -stack-alignment=16
+            ;;
+        esac
     else
         check_cflags -mllvm -stack-alignment=16
     fi