Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / runtime / tools / check-execstack.pl
blob7a710072f972461eaca2eb947185f9144a0f9827
1 #!/usr/bin/env perl
4 #//===----------------------------------------------------------------------===//
5 #//
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
9 #//
10 #//===----------------------------------------------------------------------===//
13 use strict;
14 use warnings;
16 use FindBin;
17 use lib "$FindBin::Bin/lib";
19 use tools;
21 our $VERSION = "0.002";
22 my $target_arch;
24 sub execstack($) {
25 my ( $file ) = @_;
26 my @output;
27 my @stack;
28 my $tool;
29 if($target_arch eq "mic") {
30 $tool = "x86_64-k1om-linux-readelf";
31 } else {
32 $tool = "readelf";
34 execute( [ $tool, "-l", "-W", $file ], -stdout => \@output );
35 @stack = grep( $_ =~ m{\A\s*(?:GNU_)?STACK\s+}, @output );
36 if ( not @stack ) {
37 # Interpret missed "STACK" line as error.
38 runtime_error( "$file: No stack segment found; looks like stack would be executable." );
39 }; # if
40 if ( @stack > 1 ) {
41 runtime_error( "$file: More than one stack segment found.", "readelf output:", @output, "(eof)" );
42 }; # if
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 ]" );
50 }; # if
51 my $attrs = $1;
52 if ( $attrs =~ m{E} ) {
53 runtime_error( "$file: Stack is executable" );
54 }; # if
55 }; # sub execstack
57 get_options(
58 "arch=s" => \$target_arch,
61 foreach my $file ( @ARGV ) {
62 execstack( $file );
63 }; # foreach $file
65 exit( 0 );
67 __END__
69 =pod
71 =head1 NAME
73 B<check-execstack.pl> -- Check whether stack is executable, issue an error if so.
75 =head1 SYNOPSIS
77 B<check-execstack.pl> I<option>... I<file>...
79 =head1 DESCRIPTION
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).
88 =head1 OPTIONS
90 =over
92 =item Standard Options
94 =over
96 =item B<--doc>
98 =item B<--manual>
100 Print full help message and exit.
102 =item B<--help>
104 Print short help message and exit.
106 =item B<--usage>
108 Print very short usage message and exit.
110 =item B<--verbose>
112 Do print informational messages.
114 =item B<--version>
116 Print program version and exit.
118 =item B<--quiet>
120 Work quiet, do not print informational messages.
122 =back
124 =back
126 =head1 ARGUMENTS
128 =over
130 =item I<file>
132 A name of executable or shared object to check. Multiple files may be specified.
134 =back
136 =head1 EXAMPLES
138 Check libomp.so library:
140 $ check-execstack.pl libomp.so
142 =cut
144 # end of file #