6 die("NOEXEC_CHECK not set") unless(exists($ENV{NOEXEC_CHECK}));
8 my @files = split(/ /, $ENV{NOEXEC_CHECK});
10 FILES: foreach my $file (@files) {
12 my @cmd = ('readelf', '-l', $file);
13 open($output, '-|', @cmd)
14 or die("$0: failed to run: '".join(' ', @cmd)."': $!\n");
19 # Find the offset of the Flags field
21 next unless(/^\s*Type\b/);
26 # Look for a Flg field on this line (32 bit)
27 $offset = index($_, 'Flg ');
30 # 64 bit is split over 2 lines. Look for a Flags field on the next
33 $offset = index($_, 'Flags ');
38 die("Unrecognised header: ".join("\n", @lines)) if(-1 == $offset);
42 # Find the GNU_STACK entry
44 next unless(/^\s*GNU_STACK\b/);
46 # Skip over input lines according to the header
47 for(my $i = 1; $i < $line; $i++) {
51 my $flags = substr($_, $offset, 3);
53 $flags =~ /^[ R][ W]([ E])$/ or die("Unrecognised flags: $flags");
56 print "***** $file has an executable stack *****\n";
63 die("Didn't find GNU_STACK entry");