# HG changeset patch # User martin # Date 1537379466 25200 # Node ID eb2adb0a9b093e61b7bc4eb2458707d660059293 # Parent eef954e2971424e4a9cecd6919ed7c1c931f78aa 8209817: stack is executable when building with Clang on Linux Reviewed-by: dholmes, martin, mikael, ihse Contributed-by: Arthur Eubanks diff -r eef954e29714 -r eb2adb0a9b09 make/autoconf/flags-ldflags.m4 --- 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 diff -r eef954e29714 -r eb2adb0a9b09 make/autoconf/toolchain.m4 --- 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 diff -r eef954e29714 -r eb2adb0a9b09 test/hotspot/jtreg/runtime/execstack/TestCheckJDK.java --- 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;