2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2018 Neil Horman <nhorman@tuxdriver.com>
11 # Initialize our variables
12 BEGIN {map="";sym="";ar="";sec=""; in_sec=0; in_map=0}
14 # Anything that starts with + or -, followed by an a
15 # and ends in the string .map is the name of our map file
16 # This may appear multiple times in a patch if multiple
17 # map files are altered, and all section/symbol names
18 # appearing between a triggering of this rule and the
19 # next trigger of this rule are associated with this file
20 /[-+] [ab]\/.*\.map/ {map=$2; in_map=1; next}
22 # The previous rule catches all .map files, anything else
23 # indicates we left the map chunk.
24 /[-+] [ab]\// {in_map=0}
26 # Triggering this rule, which starts a line and ends it
27 # with a { identifies a versioned section. The section name is
28 # the rest of the line with the + and { symbols remvoed.
29 # Triggering this rule sets in_sec to 1, which actives the
34 sec=$(NF-1); in_sec=1;
38 # This rule idenfies the end of a section, and disables the
42 # This rule matches on a + followed by any characters except a :
43 # (which denotes a global vs local segment), and ends with a ;.
44 # The semicolon is removed and the symbol is printed with its
45 # association file name and version section, along with an
46 # indicator that the symbol is a new addition. Note this rule
47 # only works if we have found a version section in the rule
48 # above (hence the in_sec check) And found a map file (the
49 # in_map check). If we are not in a map chunk, do nothing. If
50 # we are in a map chunk but not a section chunk, record it as
52 /^+[^}].*[^:*];/ {gsub(";","");sym=$2;
55 print map " " sym " " sec " add"
57 print map " " sym " unknown add"
62 # This is the same rule as above, but the rule matches on a
63 # leading - rather than a +, denoting that the symbol is being
65 /^-[^}].*[^:*];/ {gsub(";","");sym=$2;
68 print map " " sym " " sec " del"
70 print map " " sym " unknown del"
75 sort -u "$mapdb" > "$mapdb.2"
76 mv -f "$mapdb.2" "$mapdb"
80 check_for_rule_violations()
89 while read mname symname secname ar
94 if [ "$secname" = "unknown" ]
96 # Just inform the user of this occurrence, but
97 # don't flag it as an error
98 echo -n "INFO: symbol $symname is added but "
99 echo -n "patch has insuficient context "
100 echo -n "to determine the section name "
101 echo -n "please ensure the version is "
106 oldsecname=$(sed -n \
107 "s#$mname $symname \(.*\) del#\1#p" "$mapdb")
109 # A symbol can not enter a non experimental
111 if [ -z "$oldsecname" ]
113 if [ "$secname" = 'EXPERIMENTAL' ]
115 echo -n "INFO: symbol $symname has "
116 echo -n "been added to the "
117 echo -n "EXPERIMENTAL section of the "
121 echo -n "ERROR: symbol $symname "
122 echo -n "is added in the $secname "
123 echo -n "section, but is expected to "
124 echo -n "be added in the EXPERIMENTAL "
125 echo "section of the version map"
131 # This symbol is moving inside a section, nothing to do
132 if [ "$oldsecname" = "$secname" ]
137 # This symbol is moving between two sections (the
138 # original section is not experimental).
139 # This can be legit, just warn.
140 if [ "$oldsecname" != 'EXPERIMENTAL' ]
142 echo -n "INFO: symbol $symname is being "
143 echo -n "moved from $oldsecname to $secname. "
144 echo -n "Ensure that it has gone through the "
145 echo "deprecation process"
150 if ! grep -q "$mname $symname .* add" "$mapdb" && \
151 [ "$secname" != "EXPERIMENTAL" ]
153 # Just inform users that non-experimenal
154 # symbols need to go through a deprecation
156 echo -n "INFO: symbol $symname is being "
157 echo -n "removed, ensure that it has "
158 echo "gone through the deprecation process"
166 trap clean_and_exit_on_sig EXIT
168 mapfile=`mktemp -t dpdk.mapdb.XXXXXX`
172 clean_and_exit_on_sig()
178 build_map_changes "$patch" "$mapfile"
179 check_for_rule_violations "$mapfile"