< prev index next >

test/hotspot/jtreg/runtime/execstack/TestCheckJDK.java

Print this page
8209817: stack is executable when building with Clang on Linux
Reviewed-by: dholmes, martin, mikael, ihse
Contributed-by: Arthur Eubanks <aeubanks@google.com>


  31  * @build sun.hotspot.WhiteBox
  32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  33  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  35  *                   TestCheckJDK
  36  */
  37 
  38 import jdk.test.lib.Asserts;
  39 import sun.hotspot.WhiteBox;
  40 
  41 import java.nio.file.Files;
  42 import java.nio.file.Path;
  43 import java.nio.file.Paths;
  44 
  45 public class TestCheckJDK {
  46     static boolean testPassed = true;
  47     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  48 
  49     static void checkExecStack(Path file) {
  50         String filename = file.toString();
  51         if (filename.endsWith(".so")) {

  52             if (!WB.checkLibSpecifiesNoexecstack(filename)) {
  53                 System.out.println("Library does not have the noexecstack bit set: " + filename);
  54                 testPassed = false;
  55             }
  56         }
  57     }
  58 
  59     public static void main(String[] args) throws Throwable {
  60         String vmInstallDir = System.getProperty("java.home");
  61 
  62         Files.walk(Paths.get(vmInstallDir)).filter(Files::isRegularFile).forEach(TestCheckJDK::checkExecStack);
  63 
  64         Asserts.assertTrue(testPassed,
  65             "The tested VM contains libs that don't have the noexecstack " +
  66             "bit set. They must be linked with -z,noexecstack.");
  67     }
  68 }


  31  * @build sun.hotspot.WhiteBox
  32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  33  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  35  *                   TestCheckJDK
  36  */
  37 
  38 import jdk.test.lib.Asserts;
  39 import sun.hotspot.WhiteBox;
  40 
  41 import java.nio.file.Files;
  42 import java.nio.file.Path;
  43 import java.nio.file.Paths;
  44 
  45 public class TestCheckJDK {
  46     static boolean testPassed = true;
  47     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  48 
  49     static void checkExecStack(Path file) {
  50         String filename = file.toString();
  51         Path parent = file.getParent();
  52         if (parent.endsWith("bin") || filename.endsWith(".so")) {
  53             if (!WB.checkLibSpecifiesNoexecstack(filename)) {
  54                 System.out.println("Library does not have the noexecstack bit set: " + filename);
  55                 testPassed = false;
  56             }
  57         }
  58     }
  59 
  60     public static void main(String[] args) throws Throwable {
  61         String vmInstallDir = System.getProperty("java.home");
  62 
  63         Files.walk(Paths.get(vmInstallDir)).filter(Files::isRegularFile).forEach(TestCheckJDK::checkExecStack);
  64 
  65         Asserts.assertTrue(testPassed,
  66             "The tested VM contains libs that don't have the noexecstack " +
  67             "bit set. They must be linked with -z,noexecstack.");
  68     }
  69 }
< prev index next >