Skip to content

Commit

Permalink
dlibs: make define_for_kernel work with kernels in any order
Browse files Browse the repository at this point in the history
An undocumented requirement of define_for_kernel (and thus
expand_for_kernel) is that when multiple kernel versions are specified,
they must be in ascending order.  This is because __process_element does
not stop searching for an expansion when one is found, and doesn't check
to see if each expansion it finds is more suitable than any it already
knows about: so if you list an expansion for 5.11.0 followed by one for
4.10.0, and build it against 5.11.6, __process_element will conclude
(correctly) that 5.11.0 matches, mark it as found, then keep scanning,
conclude that 4.10.0 matches too, and overwrite the already-found match,
even though 5.11.0 is a better match for 5.11.6 than 4.10.0 is.

This is easy to fix: in addition to remembering the found match,
remember what version it matched against, and only overwrite matches if
the potential match has a higher version number.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock committed Mar 17, 2021
1 parent ca1a31c commit cc2ce58
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libdtrace/d-kern.m4
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,22 @@ m4_define([[if_arch]],[[m4_ifelse(SUBST_ARCH,m4_quote($1),m4_quote($2))]])
* details.
*/
m4_define([[__process_element]], m4_dnl
[[m4_ifelse(m4_eval(SUBST_KERNEL[[ >= $1]]), 1, m4_dnl
[[m4_define([[__found]], [[$2]])]])]]) m4_dnl
[[m4_ifelse(m4_eval((SUBST_KERNEL[[ >= $1]]) && ($1 >= __found_version)), 1, m4_dnl
[[m4_define([[__found]], [[$2]]) m4_dnl
m4_define([[__found_version]], [[$1]])]])]]) m4_dnl

m4_define([[__cat]], [[$1$2]]) m4_dnl

m4_define([[__define_for_kernel]], [[ m4_dnl
m4_pushdef([[__found]], nil) m4_dnl
m4_pushdef([[__found_version]], 0) m4_dnl
m4_foreachq(kernel, m4_quote($2), [[ m4_dnl
__cat([[__process_element]], kernel) m4_dnl
]]) m4_dnl
m4_ifelse(__found, nil, m4_dnl
[[m4_define(m4_quote($1), [[$3]])]], m4_dnl
[[m4_define(m4_quote($1), __found)]]) m4_dnl
m4_popdef([[__found_version]]) m4_dnl
m4_popdef([[__found]]) m4_dnl
]]) m4_dnl

Expand Down

0 comments on commit cc2ce58

Please sign in to comment.