summaryrefslogtreecommitdiffstats
path: root/src/pmdk/utils/check-os.sh
blob: 64d371c1392ad7c9b5d1719d0b3bf3605699eb59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2019, Intel Corporation

#
# Used to check if there are no banned functions in .o file
#
# usage: ./check-os.sh [os.h path] [.o file] [.c file]

EXCLUDE="os_posix|os_thread_posix"
if [[ $2 =~ $EXCLUDE ]]; then
	echo "skip $2"
	exit 0
fi

symbols=$(nm --demangle --undefined-only --format=posix $2 | sed 's/ U *//g')
functions=$(cat $1 | tr '\n' '|')
functions=${functions%?} # remove trailing | character
out=$(
	for sym in $symbols
	do
		grep -wE $functions <<<"$sym"
	done | sed 's/$/\(\)/g')

[[ ! -z $out ]] &&
	echo -e "`pwd`/$3:1: non wrapped function(s):\n$out\nplease use os wrappers" &&
	rm -f $2 && # remove .o file as it don't match requirements
	exit 1

exit 0