8209817: stack is executable when building with Clang on Linux
authormartin
Wed, 19 Sep 2018 10:51:06 -0700
changeset 51805 eb2adb0a9b09
parent 51804 eef954e29714
child 51806 1ecc914fb707
8209817: stack is executable when building with Clang on Linux Reviewed-by: dholmes, martin, mikael, ihse Contributed-by: Arthur Eubanks <aeubanks@google.com>
make/autoconf/flags-ldflags.m4
make/autoconf/toolchain.m4
test/hotspot/jtreg/runtime/execstack/TestCheckJDK.java
--- a/make/autoconf/flags-ldflags.m4	Wed Sep 19 19:12:20 2018 +0200
+++ b/make/autoconf/flags-ldflags.m4	Wed Sep 19 10:51:06 2018 -0700
@@ -74,10 +74,8 @@
     # Add -z defs, to forbid undefined symbols in object files.
     BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,defs"
 
-    BASIC_LDFLAGS_JVM_ONLY="-Wl,-z,noexecstack -Wl,-O1 -Wl,-z,relro"
+    BASIC_LDFLAGS_JVM_ONLY="-Wl,-O1 -Wl,-z,relro"
 
-    BASIC_LDFLAGS_JDK_LIB_ONLY="-Wl,-z,noexecstack"
-    LIBJSIG_NOEXECSTACK_LDFLAGS="-Wl,-z,noexecstack"
 
   elif test "x$TOOLCHAIN_TYPE" = xclang; then
     BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \
@@ -103,6 +101,12 @@
     BASIC_LDFLAGS_JVM_ONLY="-opt:icf,8 -subsystem:windows"
   fi
 
+  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
+    if test -n "$HAS_NOEXECSTACK"; then
+      BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,noexecstack"
+    fi
+  fi
+
   # Setup OS-dependent LDFLAGS
   if test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xgcc; then
     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
--- a/make/autoconf/toolchain.m4	Wed Sep 19 19:12:20 2018 +0200
+++ b/make/autoconf/toolchain.m4	Wed Sep 19 10:51:06 2018 -0700
@@ -1023,6 +1023,12 @@
     # This is later checked when setting flags.
   fi
 
+  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
+    # Check if linker has -z noexecstack.
+    HAS_NOEXECSTACK=`$CC -Wl,--help 2>/dev/null | $GREP 'z noexecstack'`
+    # This is later checked when setting flags.
+  fi
+
   # Setup hotspot lecagy names for toolchains
   HOTSPOT_TOOLCHAIN_TYPE=$TOOLCHAIN_TYPE
   if test "x$TOOLCHAIN_TYPE" = xclang; then
--- a/test/hotspot/jtreg/runtime/execstack/TestCheckJDK.java	Wed Sep 19 19:12:20 2018 +0200
+++ b/test/hotspot/jtreg/runtime/execstack/TestCheckJDK.java	Wed Sep 19 10:51:06 2018 -0700
@@ -48,7 +48,8 @@
 
     static void checkExecStack(Path file) {
         String filename = file.toString();
-        if (filename.endsWith(".so")) {
+        Path parent = file.getParent();
+        if (parent.endsWith("bin") || filename.endsWith(".so")) {
             if (!WB.checkLibSpecifiesNoexecstack(filename)) {
                 System.out.println("Library does not have the noexecstack bit set: " + filename);
                 testPassed = false;