xref: /dpdk/devtools/check-symbol-change.sh (revision 7be78d027918dbc846e502780faf94d5acdf5f75)
14bec4818SNeil Horman#!/bin/sh
24bec4818SNeil Horman# SPDX-License-Identifier: BSD-3-Clause
34bec4818SNeil Horman# Copyright(c) 2018 Neil Horman <nhorman@tuxdriver.com>
44bec4818SNeil Horman
54bec4818SNeil Hormanbuild_map_changes()
64bec4818SNeil Horman{
75e45e7f0SThomas Monjalon	local fname="$1"
85e45e7f0SThomas Monjalon	local mapdb="$2"
94bec4818SNeil Horman
10084ca572SThomas Monjalon	cat "$fname" | awk '
114bec4818SNeil Horman		# Initialize our variables
124bec4818SNeil Horman		BEGIN {map="";sym="";ar="";sec=""; in_sec=0; in_map=0}
134bec4818SNeil Horman
144bec4818SNeil Horman		# Anything that starts with + or -, followed by an a
154bec4818SNeil Horman		# and ends in the string .map is the name of our map file
164bec4818SNeil Horman		# This may appear multiple times in a patch if multiple
174bec4818SNeil Horman		# map files are altered, and all section/symbol names
184bec4818SNeil Horman		# appearing between a triggering of this rule and the
194bec4818SNeil Horman		# next trigger of this rule are associated with this file
20f0888549SNithin Dabilpuram		/[-+] [ab]\/.*\.map/ {map=$2; in_map=1; next}
214bec4818SNeil Horman
22f0888549SNithin Dabilpuram		# The previous rule catches all .map files, anything else
23f0888549SNithin Dabilpuram		# indicates we left the map chunk.
24f0888549SNithin Dabilpuram		/[-+] [ab]\// {in_map=0}
254bec4818SNeil Horman
267281cf52SNeil Horman		# Triggering this rule, which starts a line and ends it
274bec4818SNeil Horman		# with a { identifies a versioned section.  The section name is
28*7be78d02SJosh Soref		# the rest of the line with the + and { symbols removed.
294bec4818SNeil Horman		# Triggering this rule sets in_sec to 1, which actives the
304bec4818SNeil Horman		# symbol rule below
317281cf52SNeil Horman		/^.*{/ {
32b0aa225bSDavid Marchand			gsub("+", "");
334bec4818SNeil Horman			if (in_map == 1) {
347281cf52SNeil Horman				sec=$(NF-1); in_sec=1;
354bec4818SNeil Horman			}
364bec4818SNeil Horman		}
374bec4818SNeil Horman
38*7be78d02SJosh Soref		# This rule identifies the end of a section, and disables the
394bec4818SNeil Horman		# symbol rule
404bec4818SNeil Horman		/.*}/ {in_sec=0}
414bec4818SNeil Horman
424bec4818SNeil Horman		# This rule matches on a + followed by any characters except a :
434bec4818SNeil Horman		# (which denotes a global vs local segment), and ends with a ;.
444bec4818SNeil Horman		# The semicolon is removed and the symbol is printed with its
454bec4818SNeil Horman		# association file name and version section, along with an
464bec4818SNeil Horman		# indicator that the symbol is a new addition.  Note this rule
474bec4818SNeil Horman		# only works if we have found a version section in the rule
484bec4818SNeil Horman		# above (hence the in_sec check) And found a map file (the
494bec4818SNeil Horman		# in_map check).  If we are not in a map chunk, do nothing.  If
504bec4818SNeil Horman		# we are in a map chunk but not a section chunk, record it as
514bec4818SNeil Horman		# unknown.
524bec4818SNeil Horman		/^+[^}].*[^:*];/ {gsub(";","");sym=$2;
534bec4818SNeil Horman			if (in_map == 1) {
544bec4818SNeil Horman				if (in_sec == 1) {
554bec4818SNeil Horman					print map " " sym " " sec " add"
564bec4818SNeil Horman				} else {
574bec4818SNeil Horman					print map " " sym " unknown add"
584bec4818SNeil Horman				}
594bec4818SNeil Horman			}
604bec4818SNeil Horman		}
614bec4818SNeil Horman
624bec4818SNeil Horman		# This is the same rule as above, but the rule matches on a
634bec4818SNeil Horman		# leading - rather than a +, denoting that the symbol is being
644bec4818SNeil Horman		# removed.
654bec4818SNeil Horman		/^-[^}].*[^:*];/ {gsub(";","");sym=$2;
664bec4818SNeil Horman			if (in_map == 1) {
674bec4818SNeil Horman				if (in_sec == 1) {
684bec4818SNeil Horman					print map " " sym " " sec " del"
694bec4818SNeil Horman				} else {
704bec4818SNeil Horman					print map " " sym " unknown del"
714bec4818SNeil Horman				}
724bec4818SNeil Horman			}
73084ca572SThomas Monjalon		}' > "$mapdb"
744bec4818SNeil Horman
75084ca572SThomas Monjalon		sort -u "$mapdb" > "$mapdb.2"
76084ca572SThomas Monjalon		mv -f "$mapdb.2" "$mapdb"
774bec4818SNeil Horman
784bec4818SNeil Horman}
794bec4818SNeil Horman
802c32cfdeSHaiyue Wangis_stable_section() {
812c32cfdeSHaiyue Wang	[ "$1" != 'EXPERIMENTAL' ] && [ "$1" != 'INTERNAL' ]
822c32cfdeSHaiyue Wang}
832c32cfdeSHaiyue Wang
844bec4818SNeil Hormancheck_for_rule_violations()
854bec4818SNeil Horman{
865e45e7f0SThomas Monjalon	local mapdb="$1"
874bec4818SNeil Horman	local mname
884bec4818SNeil Horman	local symname
894bec4818SNeil Horman	local secname
904bec4818SNeil Horman	local ar
914bec4818SNeil Horman	local ret=0
924bec4818SNeil Horman
934bec4818SNeil Horman	while read mname symname secname ar
944bec4818SNeil Horman	do
955e45e7f0SThomas Monjalon		if [ "$ar" = "add" ]
964bec4818SNeil Horman		then
974bec4818SNeil Horman
985e45e7f0SThomas Monjalon			if [ "$secname" = "unknown" ]
994bec4818SNeil Horman			then
1004bec4818SNeil Horman				# Just inform the user of this occurrence, but
1014bec4818SNeil Horman				# don't flag it as an error
102d4ef40f3SDavid Marchand				echo -n "INFO: symbol $symname is added but "
103*7be78d02SJosh Soref				echo -n "patch has insufficient context "
1044bec4818SNeil Horman				echo -n "to determine the section name "
1054bec4818SNeil Horman				echo -n "please ensure the version is "
1064bec4818SNeil Horman				echo "EXPERIMENTAL"
1074bec4818SNeil Horman				continue
1084bec4818SNeil Horman			fi
1094bec4818SNeil Horman
11036307578SDavid Marchand			oldsecname=$(sed -n \
11136307578SDavid Marchand			"s#$mname $symname \(.*\) del#\1#p" "$mapdb")
11236307578SDavid Marchand
1132c32cfdeSHaiyue Wang			# A symbol can not enter a stable section directly
114af14b150SDavid Marchand			if [ -z "$oldsecname" ]
1154bec4818SNeil Horman			then
1162c32cfdeSHaiyue Wang				if ! is_stable_section $secname
117af14b150SDavid Marchand				then
118af14b150SDavid Marchand					echo -n "INFO: symbol $symname has "
119af14b150SDavid Marchand					echo -n "been added to the "
1202c32cfdeSHaiyue Wang					echo -n "$secname section of the "
121af14b150SDavid Marchand					echo "version map"
122af14b150SDavid Marchand					continue
123af14b150SDavid Marchand				else
1244bec4818SNeil Horman					echo -n "ERROR: symbol $symname "
1250fc7178eSDavid Marchand					echo -n "is added in the $secname "
1260fc7178eSDavid Marchand					echo -n "section, but is expected to "
1270fc7178eSDavid Marchand					echo -n "be added in the EXPERIMENTAL "
1284bec4818SNeil Horman					echo "section of the version map"
1294bec4818SNeil Horman					ret=1
13036307578SDavid Marchand					continue
1314bec4818SNeil Horman				fi
132af14b150SDavid Marchand			fi
13336307578SDavid Marchand
134f0897131SDavid Marchand			# This symbol is moving inside a section, nothing to do
135f0897131SDavid Marchand			if [ "$oldsecname" = "$secname" ]
136f0897131SDavid Marchand			then
137f0897131SDavid Marchand				continue
138f0897131SDavid Marchand			fi
139f0897131SDavid Marchand
14036307578SDavid Marchand			# This symbol is moving between two sections (the
1412c32cfdeSHaiyue Wang			# original section is a stable section).
14236307578SDavid Marchand			# This can be legit, just warn.
1432c32cfdeSHaiyue Wang			if is_stable_section $oldsecname
14436307578SDavid Marchand			then
14536307578SDavid Marchand				echo -n "INFO: symbol $symname is being "
14636307578SDavid Marchand				echo -n "moved from $oldsecname to $secname. "
14736307578SDavid Marchand				echo -n "Ensure that it has gone through the "
14836307578SDavid Marchand				echo "deprecation process"
14936307578SDavid Marchand				continue
1504bec4818SNeil Horman			fi
1514bec4818SNeil Horman		else
1524bec4818SNeil Horman
15336307578SDavid Marchand			if ! grep -q "$mname $symname .* add" "$mapdb" && \
1542c32cfdeSHaiyue Wang			   is_stable_section $secname
1554bec4818SNeil Horman			then
1562c32cfdeSHaiyue Wang				# Just inform users that stable
1574bec4818SNeil Horman				# symbols need to go through a deprecation
1584bec4818SNeil Horman				# process
1594bec4818SNeil Horman				echo -n "INFO: symbol $symname is being "
1604bec4818SNeil Horman				echo -n "removed, ensure that it has "
1614bec4818SNeil Horman				echo "gone through the deprecation process"
1624bec4818SNeil Horman			fi
1634bec4818SNeil Horman		fi
164084ca572SThomas Monjalon	done < "$mapdb"
1654bec4818SNeil Horman
1664bec4818SNeil Horman	return $ret
1674bec4818SNeil Horman}
1684bec4818SNeil Horman
1694bec4818SNeil Hormantrap clean_and_exit_on_sig EXIT
1704bec4818SNeil Horman
171ff37ca5dSThomas Monjalonmapfile=`mktemp -t dpdk.mapdb.XXXXXX`
1724bec4818SNeil Hormanpatch=$1
1734bec4818SNeil Hormanexit_code=1
1744bec4818SNeil Horman
1754bec4818SNeil Hormanclean_and_exit_on_sig()
1764bec4818SNeil Horman{
177084ca572SThomas Monjalon	rm -f "$mapfile"
1784bec4818SNeil Horman	exit $exit_code
1794bec4818SNeil Horman}
1804bec4818SNeil Horman
181084ca572SThomas Monjalonbuild_map_changes "$patch" "$mapfile"
182084ca572SThomas Monjaloncheck_for_rule_violations "$mapfile"
1834bec4818SNeil Hormanexit_code=$?
184084ca572SThomas Monjalonrm -f "$mapfile"
1854bec4818SNeil Horman
1864bec4818SNeil Hormanexit $exit_code
187