xen: Fix check-endbr.sh with mawk
authorAnthony PERARD <anthony.perard@citrix.com>
Thu, 14 Jul 2022 14:39:06 +0000 (15:39 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 18 Jul 2022 14:31:18 +0000 (15:31 +0100)
commitb2ebe879a44428957e147be52e8bf5227e36e723
tree425c82e980f99933504e9f773c25d68159dde0c8
parenta5fb66f4513c2c2d222dcc3753163b15690bd003
xen: Fix check-endbr.sh with mawk

check-endbr.sh works with gawk, but fails with mawk. The produced $ALL
file is smaller as it is missing 0x$vma_lo on every line.  With mawk,
int(0x2A) just produces 0, instead of the expected value.

The use of hexadecimal-constant in awk is an optional part of the posix
spec, and mawk doesn't seems to implemented.

There is a way to convert an hexadecimal to a number be putting it in a
string, and awk as I understand is supposed to use strtod() to convert
the string to a number when needed. The expression 'int("0x15") + 21'
would produce the expected value in `mawk` but now `gawk` won't convert
the string to a number unless we use the option "--non-decimal-data".

So let's convert the hexadecimal number before using it in the awk
script. The shell as no issue with dealing with hexadecimal-constant so
we'll simply use the expression "$(( 0x15 ))" to convert the value
before using it in awk.

Note: This does introduce a latent portability bug, which fixed in a separate
      change to avoid mixing complexity/explanations.

Fixes: 4d037425dc ("x86: Build check for embedded endbr64 instructions")
Resolves: xen-project/xen#26
Reported-by: Luca Fancellu <Luca.Fancellu@arm.com>
Reported-by: Mathieu Tarral <mathieu.tarral@protonmail.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/tools/check-endbr.sh