Skip to content

Commit 878ab93

Browse files
committed
testcase to check for bad symbol name prefixes
This checks the main libs that would be directly or indirectly linked against the users executable (libmpi.so, libmpi_mpifh.so, libmpi_usempi.so, libopen-rte, libopen-pal) using "nm" and looking for symbols without ompi_ opal_ mpi_ etc prefixes. Signed-off-by: Mark Allen <[email protected]>
1 parent d782542 commit 878ab93

File tree

5 files changed

+138
-2
lines changed

5 files changed

+138
-2
lines changed

configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
2323
# Copyright (c) 2014-2016 Research Organization for Information Science
2424
# and Technology (RIST). All rights reserved.
25-
# Copyright (c) 2016 IBM Corporation. All rights reserved.
25+
# Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
2626
# $COPYRIGHT$
2727
#
2828
# Additional copyrights may follow
@@ -1426,6 +1426,7 @@ AC_CONFIG_FILES([
14261426
test/support/Makefile
14271427
test/threads/Makefile
14281428
test/util/Makefile
1429+
test/symbol_name/Makefile
14291430
])
14301431
m4_ifdef([project_ompi], [AC_CONFIG_FILES([test/monitoring/Makefile])])
14311432

test/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
1414
# Copyright (c) 2015-2016 Research Organization for Information Science
1515
# and Technology (RIST). All rights reserved.
16+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
1617
# $COPYRIGHT$
1718
#
1819
# Additional copyrights may follow
@@ -21,7 +22,7 @@
2122
#
2223

2324
# support needs to be first for dependencies
24-
SUBDIRS = support asm class threads datatype util dss
25+
SUBDIRS = support asm class threads datatype util dss symbol_name
2526
if PROJECT_OMPI
2627
SUBDIRS += monitoring
2728
endif

test/symbol_name/Makefile.am

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
3+
# $COPYRIGHT$
4+
#
5+
# Additional copyrights may follow
6+
#
7+
# $HEADER$
8+
#
9+
10+
TESTS = nmcheck_prefix
11+
12+
AM_TESTS_ENVIRONMENT = MYBASE='$(top_builddir)'; OMPI_LIBMPI_NAME=@OMPI_LIBMPI_NAME@; export MYBASE OMPI_LIBMPI_NAME;

test/symbol_name/nmcheck_prefix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
4+
5+
6+
# if there's no perl, skip the test
7+
perl -v > /dev/null 2>&1
8+
if [ $? -ne 0 ] ; then exit 0 ; fi
9+
10+
perl nmcheck_prefix.pl

test/symbol_name/nmcheck_prefix.pl

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/perl
2+
3+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
4+
5+
# env var MYBASE should be the top dir where ompi/ opal/ orte/ test/ etc live.
6+
# env var OMPI_LIBMPI_NAME should be @OMPI_LIBMPI_NAME@ from automake
7+
#
8+
# Most likely the libs we want to check are
9+
# ompi/.libs/lib<mpi>.so
10+
# ompi/mpi/fortran/mpif-h/.libs/lib<mpi>_mpifh.so
11+
# ompi/mpi/fortran/use-mpi-tkr/.libs/lib<mpi>_usempi.so
12+
# orte/.libs/libopen-rte.so
13+
# opal/.libs/libopen-pal.so
14+
# but I hate to assume those are the locations, so I'll use 'find' and
15+
# test whatever ".so"s are found.
16+
17+
@libs = ();
18+
$mpi = $ENV{OMPI_LIBMPI_NAME};
19+
for $name (
20+
"lib${mpi}.so",
21+
"lib${mpi}_mpifh.so",
22+
"lib${mpi}_usempi.so",
23+
"libopen-rte.so",
24+
"libopen-pal.so" )
25+
{
26+
for $loc (split(/\n/, `find $ENV{MYBASE} -name $name`)) {
27+
push @libs, $loc;
28+
}
29+
}
30+
31+
print "Checking for bad symbol names in the main libs:\n";
32+
$isbad = 0;
33+
for $lib (@libs) {
34+
print "checking $lib\n";
35+
check_lib_for_bad_exports($lib);
36+
}
37+
if ($isbad) { exit(-1); }
38+
exit(0);
39+
40+
41+
sub check_lib_for_bad_exports {
42+
my $lib = $_[0];
43+
my @symbols;
44+
my $s;
45+
46+
@symbols = get_nm($lib, 'all');
47+
48+
# grep to get rid of symbol prefixes that are considered acceptable,
49+
# leaving behind anything bad:
50+
@symbols = grep(!/^ompi_/i, @symbols);
51+
@symbols = grep(!/^opal_/i, @symbols);
52+
@symbols = grep(!/^orte_/i, @symbols);
53+
@symbols = grep(!/^orted_/i, @symbols);
54+
@symbols = grep(!/^mpi_/i, @symbols);
55+
@symbols = grep(!/^pmpi_/i, @symbols);
56+
@symbols = grep(!/^pmix_/i, @symbols);
57+
@symbols = grep(!/^mpit_/, @symbols);
58+
@symbols = grep(!/^ompit_/, @symbols);
59+
@symbols = grep(!/^MPIR_/, @symbols);
60+
@symbols = grep(!/^MPIX_/, @symbols);
61+
@symbols = grep(!/^mpidbg_dll_locations$/, @symbols);
62+
@symbols = grep(!/^mpimsgq_dll_locations$/, @symbols);
63+
64+
@symbols = grep(!/^mca_/, @symbols); # I'm tempted to call these bad
65+
@symbols = grep(!/^netpatterns_/, @symbols); # I'm tempted to call these bad
66+
67+
@symbols = grep(!/^_fini$/, @symbols);
68+
@symbols = grep(!/^_init$/, @symbols);
69+
@symbols = grep(!/^_edata$/, @symbols);
70+
@symbols = grep(!/^_end$/, @symbols);
71+
@symbols = grep(!/^__bss_start$/, @symbols);
72+
@symbols = grep(!/^__malloc_initialize_hook$/, @symbols);
73+
74+
# This is another section I'm not confident about, I'm not
75+
# familiar with libevent so for now I'm giving everything related
76+
# to it a pass. I'd like to change all these to opal_event_* but
77+
# not without confirmation from someone else first.
78+
@symbols = grep(!/^_event_debug_mode_on$/, @symbols);
79+
@symbols = grep(!/^event_enable_debug_output$/, @symbols);
80+
@symbols = grep(!/^event_global_current_base_$/, @symbols);
81+
@symbols = grep(!/^event_module_include$/, @symbols);
82+
@symbols = grep(!/^eventops$/, @symbols);
83+
84+
for $s (@symbols) {
85+
print " $s\n";
86+
$isbad = 1;
87+
}
88+
}
89+
90+
# get_nm /path/to/some/libfoo.so <func|wfunc|all>
91+
92+
sub get_nm {
93+
my $lib = $_[0];
94+
my $mode = $_[1];
95+
my $pattern;
96+
my $cmd;
97+
my @tmp;
98+
99+
$pattern = " [TWBCDVR] ";
100+
if ($mode eq 'func') { $pattern = " [T] "; }
101+
if ($mode eq 'wfunc') { $pattern = " [W] "; }
102+
103+
$cmd = "nm $lib";
104+
$cmd = "$cmd | grep \"$pattern\"";
105+
$cmd = "$cmd | sed -e 's/ *\$//' -e 's/.* //'";
106+
107+
@tmp = split(/\n/, qx#$cmd#);
108+
@tmp = sort(@tmp);
109+
110+
return(@tmp);
111+
}
112+

0 commit comments

Comments
 (0)