Bug 778414: ensure the linker supports @unwind sections in libffi. r=glandium
authorLandry Breuil <landry@openbsd.org>
Tue, 28 Aug 2012 23:00:40 +0200
changeset 105748 b0d9390b60c62917a4ddd1e77a95f7a8f55e7702
parent 105747 8803fd630316fbb08187ff9c5ed07853afa9abac
child 105749 c4c6016ac3787a09adf18fc04737f04ff351891b
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersglandium
bugs778414
milestone18.0a1
Bug 778414: ensure the linker supports @unwind sections in libffi. r=glandium This fixes clang builds on OpenBSD/amd64, since clang itself supports @unwind sections but OpenBSD's ld 2.15 doesn't. Previously the test yielded true, thus producing a broken libffi.
js/src/ctypes/libffi/configure
js/src/ctypes/libffi/configure.ac
js/src/ctypes/patches-libffi/06-bug-778414.patch
--- a/js/src/ctypes/libffi/configure
+++ b/js/src/ctypes/libffi/configure
@@ -12422,26 +12422,42 @@ case "$target" in
      *-apple-darwin1* | *-*-freebsd* | *-*-openbsd* | *-pc-solaris*)
 
 $as_echo "#define FFI_MMAP_EXEC_WRIT 1" >>confdefs.h
 
      ;;
 esac
 
 if test x$TARGET = xX86_64; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler supports unwind section type" >&5
-$as_echo_n "checking assembler supports unwind section type... " >&6; }
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking toolchain supports unwind section type" >&5
+$as_echo_n "checking toolchain supports unwind section type... " >&6; }
 if test "${libffi_cv_as_x86_64_unwind_section_type+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
 
-	libffi_cv_as_x86_64_unwind_section_type=yes
-	echo '.section .eh_frame,"a",@unwind' > conftest.s
-	if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
-	    libffi_cv_as_x86_64_unwind_section_type=no
+        cat  > conftest1.s << EOF
+.text
+.globl foo
+foo:
+jmp bar
+.section .eh_frame,"a",@unwind
+bar:
+EOF
+
+        cat > conftest2.c  << EOF
+extern void foo();
+int main(){foo();}
+EOF
+
+	libffi_cv_as_x86_64_unwind_section_type=no
+	# we ensure that we can compile _and_ link an assembly file containing an @unwind section
+	# since the compiler can support it and not the linker (ie old binutils)
+	if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
+           $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
+	    libffi_cv_as_x86_64_unwind_section_type=yes
 	fi
 
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libffi_cv_as_x86_64_unwind_section_type" >&5
 $as_echo "$libffi_cv_as_x86_64_unwind_section_type" >&6; }
     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
 
 $as_echo "#define HAVE_AS_X86_64_UNWIND_SECTION_TYPE 1" >>confdefs.h
--- a/js/src/ctypes/libffi/configure.ac
+++ b/js/src/ctypes/libffi/configure.ac
@@ -327,22 +327,38 @@ case "$target" in
      *-apple-darwin1* | *-*-freebsd* | *-*-openbsd* | *-pc-solaris*)
        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
                  [Cannot use malloc on this target, so, we revert to
                    alternative means])
      ;;
 esac
 
 if test x$TARGET = xX86_64; then
-    AC_CACHE_CHECK([assembler supports unwind section type],
+    AC_CACHE_CHECK([toolchain supports unwind section type],
 	libffi_cv_as_x86_64_unwind_section_type, [
-	libffi_cv_as_x86_64_unwind_section_type=yes
-	echo '.section .eh_frame,"a",@unwind' > conftest.s
-	if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
-	    libffi_cv_as_x86_64_unwind_section_type=no
+        cat  > conftest1.s << EOF
+.text
+.globl foo
+foo:
+jmp bar
+.section .eh_frame,"a",@unwind
+bar:
+EOF
+
+        cat > conftest2.c  << EOF
+extern void foo();
+int main(){foo();}
+EOF
+
+	libffi_cv_as_x86_64_unwind_section_type=no
+	# we ensure that we can compile _and_ link an assembly file containing an @unwind section
+	# since the compiler can support it and not the linker (ie old binutils)
+	if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
+           $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
+	    libffi_cv_as_x86_64_unwind_section_type=yes
 	fi
 	])
     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
 	AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
 		  [Define if your assembler supports unwind section type.])
     fi
 fi
 
new file mode 100644
--- /dev/null
+++ b/js/src/ctypes/patches-libffi/06-bug-778414.patch
@@ -0,0 +1,99 @@
+diff --git a/js/src/ctypes/libffi/configure b/js/src/ctypes/libffi/configure
+--- a/js/src/ctypes/libffi/configure
++++ b/js/src/ctypes/libffi/configure
+@@ -12422,26 +12422,42 @@ case "$target" in
+      *-apple-darwin1* | *-*-freebsd* | *-*-openbsd* | *-pc-solaris*)
+ 
+ $as_echo "#define FFI_MMAP_EXEC_WRIT 1" >>confdefs.h
+ 
+      ;;
+ esac
+ 
+ if test x$TARGET = xX86_64; then
+-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler supports unwind section type" >&5
+-$as_echo_n "checking assembler supports unwind section type... " >&6; }
++    { $as_echo "$as_me:${as_lineno-$LINENO}: checking toolchain supports unwind section type" >&5
++$as_echo_n "checking toolchain supports unwind section type... " >&6; }
+ if test "${libffi_cv_as_x86_64_unwind_section_type+set}" = set; then :
+   $as_echo_n "(cached) " >&6
+ else
+ 
+-	libffi_cv_as_x86_64_unwind_section_type=yes
+-	echo '.section .eh_frame,"a",@unwind' > conftest.s
+-	if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
+-	    libffi_cv_as_x86_64_unwind_section_type=no
++        cat  > conftest1.s << EOF
++.text
++.globl foo
++foo:
++jmp bar
++.section .eh_frame,"a",@unwind
++bar:
++EOF
++
++        cat > conftest2.c  << EOF
++extern void foo();
++int main(){foo();}
++EOF
++
++	libffi_cv_as_x86_64_unwind_section_type=no
++	# we ensure that we can compile _and_ link an assembly file containing an @unwind section
++	# since the compiler can support it and not the linker (ie old binutils)
++	if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
++           $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
++	    libffi_cv_as_x86_64_unwind_section_type=yes
+ 	fi
+ 
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libffi_cv_as_x86_64_unwind_section_type" >&5
+ $as_echo "$libffi_cv_as_x86_64_unwind_section_type" >&6; }
+     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
+ 
+ $as_echo "#define HAVE_AS_X86_64_UNWIND_SECTION_TYPE 1" >>confdefs.h
+diff --git a/js/src/ctypes/libffi/configure.ac b/js/src/ctypes/libffi/configure.ac
+--- a/js/src/ctypes/libffi/configure.ac
++++ b/js/src/ctypes/libffi/configure.ac
+@@ -327,22 +327,38 @@ case "$target" in
+      *-apple-darwin1* | *-*-freebsd* | *-*-openbsd* | *-pc-solaris*)
+        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
+                  [Cannot use malloc on this target, so, we revert to
+                    alternative means])
+      ;;
+ esac
+ 
+ if test x$TARGET = xX86_64; then
+-    AC_CACHE_CHECK([assembler supports unwind section type],
++    AC_CACHE_CHECK([toolchain supports unwind section type],
+ 	libffi_cv_as_x86_64_unwind_section_type, [
+-	libffi_cv_as_x86_64_unwind_section_type=yes
+-	echo '.section .eh_frame,"a",@unwind' > conftest.s
+-	if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
+-	    libffi_cv_as_x86_64_unwind_section_type=no
++        cat  > conftest1.s << EOF
++.text
++.globl foo
++foo:
++jmp bar
++.section .eh_frame,"a",@unwind
++bar:
++EOF
++
++        cat > conftest2.c  << EOF
++extern void foo();
++int main(){foo();}
++EOF
++
++	libffi_cv_as_x86_64_unwind_section_type=no
++	# we ensure that we can compile _and_ link an assembly file containing an @unwind section
++	# since the compiler can support it and not the linker (ie old binutils)
++	if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
++           $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
++	    libffi_cv_as_x86_64_unwind_section_type=yes
+ 	fi
+ 	])
+     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
+ 	AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
+ 		  [Define if your assembler supports unwind section type.])
+     fi
+ fi
+