llvm-project/openmp/runtime/tools/check-depends.pl

507 lines
15 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
#
#//===----------------------------------------------------------------------===//
#//
#// The LLVM Compiler Infrastructure
#//
#// This file is dual licensed under the MIT and the University of Illinois Open
#// Source Licenses. See LICENSE.txt for details.
#//
#//===----------------------------------------------------------------------===//
#
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib";
use tools;
our $VERSION = "0.005";
my $target_os;
my $target_arch;
# --------------------------------------------------------------------------------------------------
# Ouput parse error.
# $tool -- Name of tool.
# @bulk -- Output of the tool.
# $n -- Number of line caused parse error.
sub parse_error($\@$) {
my ( $tool, $bulk, $n ) = @_;
my @bulk;
for ( my $i = 0; $i < @$bulk; ++ $i ) {
push( @bulk, ( $i == $n ? ">>> " : " " ) . $bulk->[ $i ] );
}; # for $i
runtime_error( "Fail to parse $tool output:", @bulk, "(eof)" );
}; # sub parse_error
# --------------------------------------------------------------------------------------------------
# Linux* OS version of get_deps() parses output of ldd:
#
# $ ldd libname.so
# libc.so.6 => /lib64/libc.so.6 (0x00002b60fedd8000)
# libdl.so.2 => /lib64/libdl.so.2 (0x00002b60ff12b000)
# libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b60ff32f000)
# /lib64/ld-linux-x86-64.so.2 (0x0000003879400000)
#
# Note: ldd printd all the dependencies, direct and indirect. (For example, if specified library
# requires libdl.so, and libdl.so requires /lib/ld-linux.so, ldd prints both libdl.so and
# /lib/ld-linux.so). If you do not want indirect dependencies, look at readelf tool.
#
sub get_deps_ldd($) {
my $lib = shift ( @_ );
my $tool = "ldd";
my @bulk;
my @deps;
execute( [ $tool, $lib ], -stdout => \@bulk );
debug( @bulk, "(eof)" );
foreach my $i ( 0 .. @bulk - 1 ) {
my $line = $bulk[ $i ];
if ( $line !~ m{^\s*(?:([_a-z0-9.+-/]*)\s+=>\s+)?([_a-z0-9.+-/]*)\s+\(0x[0-9a-z]*\)$}i ) {
parse_error( $tool, @bulk, $i );
}; # if
my $dep = ( defined( $1 ) ? $1 : $2 );
push( @deps, $dep );
}; # foreach $i
return @deps;
}; # sub get_deps_ldd
# --------------------------------------------------------------------------------------------------
# Another Linux* OS version of get_deps() parses output of readelf:
#
# $ readelf -d exports/lin_32e/lib/libomp.so
#
# Dynamic segment at offset 0x87008 contains 24 entries:
# Tag Type Name/Value
# 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
# 0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
# 0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
# 0x000000000000000e (SONAME) Library soname: [libomp.so]
# 0x000000000000000d (FINI) 0x51caa
# 0x0000000000000004 (HASH) 0x158
# 0x0000000000000005 (STRTAB) 0x9350
# ...
#
# Note: In contrast to ldd, readlef shows only direct dependencies.
#
sub get_deps_readelf($) {
my $file = shift ( @_ );
my $tool;
my @bulk;
my @deps;
if($target_arch eq "mic") {
$tool = "x86_64-k1om-linux-readelf";
} else {
$tool = "readelf";
}
# Force the readelf call to be in English. For example, when readelf
# is called on a french localization, it will find "Librairie partagees"
# instead of shared library
$ENV{ LANG } = "C";
execute( [ $tool, "-d", $file ], -stdout => \@bulk );
debug( @bulk, "(eof)" );
my $i = 0;
# Parse header.
( $i < @bulk and $bulk[ $i ] =~ m{^\s*$} )
or parse_error( $tool, @bulk, $i );
++ $i;
if ( $i == @bulk - 1 and $bulk[ $i ] =~ m{^There is no dynamic section in this file\.\s*$} ) {
# This is not dynamic executable => no dependencies.
return @deps;
}; # if
( $i < @bulk and $bulk[ $i ] =~ m{^Dynamic (?:segment|section) at offset 0x[0-9a-f]+ contains \d+ entries:\s*$} )
or parse_error( $tool, @bulk, $i );
++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^\s*Tag\s+Type\s+Name/Value\s*$} )
or parse_error( $tool, @bulk, $i );
++ $i;
# Parse body.
while ( $i < @bulk ) {
my $line = $bulk[ $i ];
if ( $line !~ m{^\s*0x[0-9a-f]+\s+\(([_A-Z0-9]+)\)\s+(.*)\s*$}i ) {
parse_error( $tool, @bulk, $i );
}; # if
my ( $type, $value ) = ( $1, $2 );
if ( $type eq "NEEDED" ) {
if ( $value !~ m{\AShared library: \[(.*)\]\z} ) {
parse_error( $tool, @bulk, $i );
}; # if
my $dep = $1;
push( @deps, $dep );
}; # if
++ $i;
}; # foreach $i
return @deps;
}; # sub get_deps_readelf
# --------------------------------------------------------------------------------------------------
# OS X* version of get_deps() parses output of otool:
#
# $ otool -L libname.dylib
# exports/mac_32/lib.thin/libomp.dylib:
# libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
# /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.3)
#
sub get_deps_otool($) {
my $file = shift ( @_ );
my $name = get_file( $file );
my $tool = "otool";
my @bulk;
my @deps;
if ( $target_arch eq "32e" ) {
# On older (Tiger) systems otool does not recognize 64-bit binaries, so try to locate
# otool64.
my $path = which( "otool64" );
if ( defined ( $path ) ) {
$tool = "otool64";
}; # if
}; # if
execute( [ $tool, "-L", $file ], -stdout => \@bulk );
debug( @bulk, "(eof)" );
my $i = 0;
# Parse the first one or two lines separately.
( $i < @bulk and $bulk[ $i ] =~ m{^\Q$file\E:$} )
or parse_error( $tool, @bulk, $i );
++ $i;
if ( $name =~ m{\.dylib\z} ) {
# Added "@rpath/" enables dynamic load of the library designated at link time.
$name = '@rpath/' . $name;
# In case of dynamic library otool print the library itself as a dependent library.
( $i < @bulk and $bulk[ $i ] =~ m{^\s+\Q$name\E\s+\(compatibility version.*\)$} )
or parse_error( $tool, @bulk, $i );
++ $i;
}; # if
# Then parse the rest.
while ( $i < @bulk ) {
my $line = $bulk[ $i ];
if ( $line !~ m/^\s*(.*)\s+\(compatibility version\s.*\)$/ ) {
parse_error( $tool, @bulk, $i );
}; # if
my ( $dep ) = ( $1 );
push( @deps, $dep );
++ $i;
}; # while
return @deps;
}; # sub get_deps_otool
# --------------------------------------------------------------------------------------------------
# Windows* OS version of get_deps() parses output of link:
#
# > link -dump -dependents libname.dll
# Microsoft (R) COFF/PE Dumper Version 8.00.40310.39
# Copyright (C) Microsoft Corporation. All rights reserved.
# Dump of file S:\Projects.OMP\users\omalyshe\omp\libomp\exports\win_64\lib\libompmd.dll
# File Type: DLL
# Image has the following dependencies:
# KERNEL32.dll
# Summary
# C000 .data
# 6000 .pdata
# 18000 .rdata
# ...
#
# > link -dump -directives libname.lib
# Microsoft (R) COFF/PE Dumper Version 8.00.40310.39
# Copyright (C) Microsoft Corporation. All rights reserved.
# Dump of file S:\Projects.OMP\users\omalyshe\omp\libomp\exports\win_32e\lib\libimp5mt.lib
# File Type: LIBRARY
# Linker Directives
# -----------------
# -defaultlib:"uuid.lib"
# -defaultlib:"uuid.lib"
# .....
# Summary
# 3250 .bss
# 3FBC .data
# 34 .data1
# ....
sub get_deps_link($) {
my ( $lib ) = @_;
my $tool = "link";
my @bulk;
my @deps;
my $ext = lc( get_ext( $lib ) );
if ( $ext !~ m{\A\.(?:lib|dll|exe)\z}i ) {
runtime_error( "Incorrect file is specified: `$lib'; only `lib', `dll' or `exe' file expected" );
}; # if
execute(
[ $tool, "/dump", ( $ext eq ".lib" ? "/directives" : "/dependents" ), $lib ],
-stdout => \@bulk
);
debug( @bulk, "(eof)" );
my $i = 0;
( $i < @bulk and $bulk[ $i ] =~ m{^Microsoft \(R\) COFF\/PE Dumper Version.*$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^Copyright \(C\) Microsoft Corporation\..*$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^\s*$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^\s*$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^Dump of file\s\Q$lib\E$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^\s*$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^File Type:\s(.*)$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
( $i < @bulk and $bulk[ $i ] =~ m{^\s*$} ) or parse_error( $tool, @bulk, $i ); ++ $i;
if ( $ext eq ".lib" ) {
my %deps;
while ( $i < @bulk ) {
my $line = $bulk[ $i ];
if ( 0 ) {
} elsif ( $line =~ m{^\s*[-/]defaultlib\:(.*)\s*$}i ) {
my $dep = $1;
# Normalize library name:
$dep = lc( $1 ); # Convert to lower case.
$dep =~ s{\A"(.*)"\z}{$1}; # Drop surrounding quotes (if any).
$dep =~ s{\.lib\z}{}; # Drop .lib suffix (if any).
$deps{ $dep } = 1;
} elsif ( $line =~ m{^\s*Linker Directives\s*$} ) {
} elsif ( $line =~ m{^\s*-+\s*$} ) {
} elsif ( $line =~ m{^\s*/alternatename\:.*$} ) {
} elsif ( $line =~ m{^\s*$} ) {
I apologise in advance for the size of this check-in. At Intel we do understand that this is not friendly, and are working to change our internal code-development to make it easier to make development features available more frequently and in finer (more functional) chunks. Unfortunately we haven't got that in place yet, and unpicking this into multiple separate check-ins would be non-trivial, so please bear with me on this one. We should be better in the future. Apologies over, what do we have here? GGC 4.9 compatibility -------------------- * We have implemented the new entrypoints used by code compiled by GCC 4.9 to implement the same functionality in gcc 4.8. Therefore code compiled with gcc 4.9 that used to work will continue to do so. However, there are some other new entrypoints (associated with task cancellation) which are not implemented. Therefore user code compiled by gcc 4.9 that uses these new features will not link against the LLVM runtime. (It remains unclear how to handle those entrypoints, since the GCC interface has potentially unpleasant performance implications for join barriers even when cancellation is not used) --- new parallel entry points --- new entry points that aren't OpenMP 4.0 related These are implemented fully :- GOMP_parallel_loop_dynamic() GOMP_parallel_loop_guided() GOMP_parallel_loop_runtime() GOMP_parallel_loop_static() GOMP_parallel_sections() GOMP_parallel() --- cancellation entry points --- Currently, these only give a runtime error if OMP_CANCELLATION is true because our plain barriers don't check for cancellation while waiting GOMP_barrier_cancel() GOMP_cancel() GOMP_cancellation_point() GOMP_loop_end_cancel() GOMP_sections_end_cancel() --- taskgroup entry points --- These are implemented fully. GOMP_taskgroup_start() GOMP_taskgroup_end() --- target entry points --- These are empty (as they are in libgomp) GOMP_target() GOMP_target_data() GOMP_target_end_data() GOMP_target_update() GOMP_teams() Improvements in Barriers and Fork/Join -------------------------------------- * Barrier and fork/join code is now in its own file (which makes it easier to understand and modify). * Wait/release code is now templated and in its own file; suspend/resume code is also templated * There's a new, hierarchical, barrier, which exploits the cache-hierarchy of the Intel(r) Xeon Phi(tm) coprocessor to improve fork/join and barrier performance. ***BEWARE*** the new source files have *not* been added to the legacy Cmake build system. If you want to use that fixes wil be required. Statistics Collection Code -------------------------- * New code has been added to collect application statistics (if this is enabled at library compile time; by default it is not). The statistics code itself is generally useful, the lightweight timing code uses the X86 rdtsc instruction, so will require changes for other architectures. The intent of this code is not for users to tune their codes but rather 1) For timing code-paths inside the runtime 2) For gathering general properties of OpenMP codes to focus attention on which OpenMP features are most used. Nested Hot Teams ---------------- * The runtime now maintains more state to reduce the overhead of creating and destroying inner parallel teams. This improves the performance of code that repeatedly uses nested parallelism with the same resource allocation. Set the new KMP_HOT_TEAMS_MAX_LEVEL envirable to a depth to enable this (and, of course, OMP_NESTED=true to enable nested parallelism at all). Improved Intel(r) VTune(Tm) Amplifier support --------------------------------------------- * The runtime provides additional information to Vtune via the itt_notify interface to allow it to display better OpenMP specific analyses of load-imbalance. Support for OpenMP Composite Statements --------------------------------------- * Implement new entrypoints required by some of the OpenMP 4.1 composite statements. Improved ifdefs --------------- * More separation of concepts ("Does this platform do X?") from platforms ("Are we compiling for platform Y?"), which should simplify future porting. ScaleMP* contribution --------------------- Stack padding to improve the performance in their environment where cross-node coherency is managed at the page level. Redesign of wait and release code --------------------------------- The code is simplified and performance improved. Bug Fixes --------- *Fixes for Windows multiple processor groups. *Fix Fortran module build on Linux: offload attribute added. *Fix entry names for distribute-parallel-loop construct to be consistent with the compiler codegen. *Fix an inconsistent error message for KMP_PLACE_THREADS environment variable. llvm-svn: 219214
2014-10-08 00:25:50 +08:00
} elsif ( $line =~ m{^\s*/FAILIFMISMATCH\:.*$} ) {
# This directive is produced only by _MSC_VER=1600
} elsif ( $line =~ m{^\s*Summary\s*$} ) {
last;
} else {
parse_error( $tool, @bulk, $i );
}; # if
++ $i;
} # while
@deps = keys( %deps );
} else {
( $i < @bulk and $bulk[ $i ] =~ m{\s*Image has the following dependencies\:$} )
or parse_error( $tool, @bulk, $i );
++ $i;
while ( $i < @bulk ) {
my $line = $bulk[ $i ];
if ( 0 ) {
} elsif ( $line =~ m{^\s*$} ) {
# Ignore empty lines.
} elsif ( $line =~ m{^\s*(.*\.dll)$}i ) {
my $dep = lc( $1 );
push( @deps, $dep );
} elsif ( $line =~ m{^\s*Summary$} ) {
last;
} else {
parse_error( $tool, @bulk, $i );
}; # if
++ $i;
}; # while
}; # if
return @deps;
}; # sub get_deps_link
# --------------------------------------------------------------------------------------------------
# Main.
# --------------------------------------------------------------------------------------------------
# Parse command line.
my $expected;
my $bare;
Getopt::Long::Configure( "permute" );
get_options(
"os=s" => \$target_os,
"arch=s" => \$target_arch,
"bare" => \$bare,
"expected=s" => \$expected,
);
my @expected;
if ( defined( $expected ) ) {
if ( $expected ne "none" ) {
@expected = sort( split( ",", $expected ) );
if ( $target_os eq "win" ) {
@expected = map( lc( $_ ), @expected );
}; # if
}; # if
}; # if
if ( @ARGV < 1 ) {
cmdline_error( "Specify a library name to check for dependencies" );
}; # if
if ( @ARGV > 1 ) {
cmdline_error( "Too many arguments" );
}; # if
my $lib = shift( @ARGV );
if ( not -e $lib ){
runtime_error( "Specified file does not exist: \"$lib\"" );
}; # if
# Select appropriate get_deps implementation.
if ( 0 ) {
} elsif ( $target_os eq "lin" ) {
*get_deps = \*get_deps_readelf;
} elsif ( $target_os eq "mac" ) {
*get_deps = \*get_deps_otool;
} elsif ( $target_os eq "win" ) {
*get_deps = \*get_deps_link;
} else {
runtime_error( "OS \"$target_os\" not supported" );
}; # if
# Do the work.
my @deps = sort( get_deps( $lib ) );
if ( $bare ) {
print( map( "$_\n", @deps ) );
} else {
info( "Dependencies:", @deps ? map( " $_", @deps ) : "(none)" );
}; # if
if ( defined( $expected ) ) {
my %deps = map( ( $_ => 1 ), @deps );
foreach my $dep ( @expected ) {
delete( $deps{ $dep } );
}; # foreach
my @unexpected = sort( keys( %deps ) );
if ( @unexpected ) {
runtime_error( "Unexpected dependencies:", map( " $_", @unexpected ) );
}; # if
}; # if
exit( 0 );
__END__
=pod
=head1 NAME
B<check-depends.pl> -- Check dependencies for a specified library.
=head1 SYNOPSIS
B<check-depends.pl> I<OPTIONS>... I<library>
=head1 DESCRIPTION
C<check-depends.pl> finds direct dependencies for a specified library. List of actual dependencies
is sorted alphabetically and printed. If list of expected dependencies is specified, the scripts
checks the library has only allowed dependencies. In case of not expected depndencies the script
issues error message and exits with non-zero code.
Linux* OS and OS X*: The script finds dependencies only for dymamic libraries. Windows* OS: The script
finds dependencies for either static or dymamic libraries.
The script uses external tools. On Linux* OS, it runs F<readelf>, on OS X* -- F<otool> (or F<otool64>),
on Windows* OS -- F<link>.
On Windows* OS dependencies are printed in lower case, case of expected dependencies ignored.
=head1 OPTIONS
=over
=item B<--bare>
Do not use fancy formatting; produce plain, bare output: just a list of libraries,
a library per line.
=item B<--expected=>I<list>
I<list> is comma-separated list of expected dependencies (or C<none>).
If C<--expected> option specified, C<check-depends.pl> checks the specified library
has only expected dependencies.
=item B<--os=>I<str>
Specify target OS (tool to use) manually.
Useful for cross-build, when host OS is not the same as target OS.
I<str> should be either C<lin>, C<mac>, or C<win>.
=back
=head2 Standard Options
=over
=item B<--help>
Print short help message and exit.
=item B<--doc>
=item B<--manual>
Print full documentation and exit.
=item B<--quiet>
Do not output informational messages.
=item B<--version>
Print version and exit.
=back
=head1 ARGUMENTS
=over
=item I<library>
A name of library to find or check dependencies.
=back
=head1 EXAMPLES
Just print library dependencies (Windows* OS):
> check-depends.pl exports/win_32/lib/libompmd.dll
check-depends.pl: (i) Dependencies:
check-depends.pl: (i) kernel32.dll
Print library dependencies, use bare output (Linux* OS):
$ check-depends.pl --bare exports/lin_32e/lib/libomp_db.so
libc.so.6
libdl.so.2
libpthread.so.0
Check the library does not have any dependencies (OS X*):
$ check-depends.pl --expected=none exports/mac_32/lib/libomp.dylib
check-depends.pl: (i) Dependencies:
check-depends.pl: (i) /usr/lib/libSystem.B.dylib
check-depends.pl: (x) Unexpected dependencies:
check-depends.pl: (x) /usr/lib/libSystem.B.dylib
$ echo $?
2
=cut
# end of file #