4 #//===----------------------------------------------------------------------===//
6 #// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 #// See https://llvm.org/LICENSE.txt for license information.
8 #// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 #//===----------------------------------------------------------------------===//
17 use lib
"$FindBin::Bin/lib";
21 our $VERSION = "0.002";
29 if($target_arch eq "mic") {
30 $tool = "x86_64-k1om-linux-readelf";
34 execute
( [ $tool, "-l", "-W", $file ], -stdout
=> \
@output );
35 @stack = grep( $_ =~ m{\A\s*(?:GNU_)?STACK\s+}, @output );
37 # Interpret missed "STACK" line as error.
38 runtime_error
( "$file: No stack segment found; looks like stack would be executable." );
41 runtime_error
( "$file: More than one stack segment found.", "readelf output:", @output, "(eof)" );
43 # Typical stack lines are:
44 # Linux* OS IA-32 architecture:
45 # GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
46 # Linux* OS Intel(R) 64:
47 # GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x8
48 if ( $stack[ 0 ] !~ m{\A\s*(?:GNU_)?STACK(?:\s+0x[0-9a-f]+){5}\s
+([R
][W
][E
])\s
+0x
[0-9a
-f
]+\s
*\z
} ) {
49 runtime_error
( "$file: Cannot parse stack segment line:", ">>> $stack[ 0 ]" );
52 if ( $attrs =~ m{E} ) {
53 runtime_error
( "$file: Stack is executable" );
58 "arch=s" => \
$target_arch,
61 foreach my $file ( @ARGV ) {
73 B<check-execstack.pl> -- Check whether stack is executable, issue an error if so.
77 B<check-execstack.pl> I<option>... I<file>...
81 The script checks whether stack of specified executable file, and issues error if stack is
82 executable. If stack is not executable, the script exits silently with zero exit code.
84 The script runs C<readelf> utility to get information about specified executable file. So, the
85 script fails if C<readelf> is not available. Effectively it means the script works only on Linux* OS
86 (and, probably, Intel(R) Many Integrated Core Architecture).
92 =item Standard Options
100 Print full help message and exit.
104 Print short help message and exit.
108 Print very short usage message and exit.
112 Do print informational messages.
116 Print program version and exit.
120 Work quiet, do not print informational messages.
132 A name of executable or shared object to check. Multiple files may be specified.
138 Check libomp.so library:
140 $ check-execstack.pl libomp.so