Commit 8c50837f0b58ba5b2bcb1b424a2a4bfa01559fb2

Fangrui Song 2020-03-10T04:36:09

Improve read-write .eh_frame check (#546) llvm-objdump -h does not print BFD SEC_* constants like "READONLY", so the check will consider .eh_frame writable. clang 11 (since https://reviews.llvm.org/D73999) will error for mismatching section flags. Use readelf -S and check "WA" instead.

diff --git a/configure.ac b/configure.ac
index bf96297..3ca1f4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -262,17 +262,11 @@ fi
 if test "x$GCC" = "xyes"; then
   AC_CACHE_CHECK([whether .eh_frame section should be read-only],
       libffi_cv_ro_eh_frame, [
-  	libffi_cv_ro_eh_frame=no
+  	libffi_cv_ro_eh_frame=yes
   	echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
   	if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
-	    objdump -h conftest.o > conftest.dump 2>&1
-	    libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
-	    if test "x$libffi_eh_frame_line" != "x"; then
-	        libffi_test_line=`expr $libffi_eh_frame_line + 1`p
-	        sed -n $libffi_test_line conftest.dump > conftest.line
-	        if grep READONLY conftest.line > /dev/null; then
-	            libffi_cv_ro_eh_frame=yes
-	        fi
+	    if readelf -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
+	        libffi_cv_ro_eh_frame=no
 	    fi
   	fi
   	rm -f conftest.*