[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/2] xen: Fix check-endbr.sh with mawk


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 15 Jul 2022 14:26:50 +0100
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Luca Fancellu <Luca.Fancellu@xxxxxxx>, Mathieu Tarral <mathieu.tarral@xxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Delivery-date: Fri, 15 Jul 2022 13:27:25 +0000
  • Ironport-data: A9a23:LZ1TWqMOoOa/7AbvrR1Tl8FynXyQoLVcMsEvi/4bfWQNrUp20DcPx zdMXT3XPvnbZzCjL912aNm18BgD7JLWxoVgSgto+SlhQUwRpJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdleF+lH3dOCJQUBUjcmgXqD7BPPPJhd/TAplTDZJoR94kqsyj5UAbeKRWmthg vuv5ZyFULOZ82QsaDhMtPve8EgHUMna41v0gHRvPZing3eG/5UlJMp3Db28KXL+Xr5VEoaSL woU5Ojklo9x105F5uKNyt4XQGVTKlLhFVHmZk5tc7qjmnB/Shkaic7XAha+hXB/0F1ll/gpo DlEWAfZpQ0BZsUgk8xFO/VU/r0X0QSrN9YrLFDm2fF/wXEqfFPnxfdMNEw5OLZF491IGTpPz 94da24kO0Xra+KemNpXS8Fpj8UnasLqIJkeqjdryjSx4fQOGM6ZBf+QvJkBgWl21psm8fX2P qL1bRJGahjabgIJEVAQEJ8kx8+jh2Xlci0eo1WQzUYyyzeOlVwui+K1WDbTUvyWftdwmUTCn z7t5UD8IRQlL+649wPQpxpAgceQxHimCer+DoaQ8/d2gFye2yoPAQcMXF+TueO+lkm4XtteL wof/S9Ghaov8E2mSPHtUhv+p2SL1jY2VsBMCeQ85Eeow7DN/geCLmEeS3hKb9lOnOsrTjVs+ FaPlN7tASFHuaeQD3ma89+8jxm/JCwUJm8qfjIfQE0O5NyLiJE+iFfDQ8huFIaxj8bpAnfgz jaSti88ir4Py8kR2M2T4lTvkz+q4J/TQWYd/R7LV2io6gd4Yo+NZIGy71Xfq/FaI+6kokKp5 SZe3ZLEtaZXUM/LxHflrPgx8K+B7PCHEgXRjltUQoAayCz2+kSBeMMOyWQrTKt2CfroaQMFc WeK514OtMMCYyLxBUNkS9nvUpp3lMAMAfygD6mJNYQWP/CdYSfdpElTiVisM3cBeaTGuYU2I t+lfMmlFh724ow3nWPtF4/xPVLGrx3SJF8/prihlnxLKZLEOBaopU4taTNilNwR4qKeuxny+ N1CLcaMwBg3eLSgP3aHq9VDdgBQciNT6XXKRyt/L7TrH+abMDt5V6+5LU0JIeSJYJi5Zs+Xp yrgCye0OXL0hGHdKBXiV02PnIjHBM4lxVpiZHREFQ/xixALPNf0hI9CJsRfQFXS3LE6pRKCZ 6JeIJvo7zUmYmmvxgnxmrGm/d05JEnx3FzfV8dnCRBmF6Ndq8Xy0oeMVmPSGOMmUkJbaeNWT 2Wc6z7m
  • Ironport-hdrordr: A9a23:9u2/RK/CT4G883Uhn35uk+DaI+orL9Y04lQ7vn2YSXRuHPBw9v re5cjzuiWVtN98Yh0dcJW7Scy9qBDnhPhICOsqTNSftWDd0QPCRuxfBMnZslnd8kXFh4lgPM xbEpSWZueeMbEDt7eZ3DWF
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Anthony PERARD <anthony.perard@xxxxxxxxxx>

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@xxxxxxx>
Reported-by: Mathieu Tarral <mathieu.tarral@xxxxxxxxxxxxxx>
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Julien Grall <julien@xxxxxxx>
CC: Anthony PERARD <anthony.perard@xxxxxxxxxx>
CC: Luca Fancellu <Luca.Fancellu@xxxxxxx>
CC: Mathieu Tarral <mathieu.tarral@xxxxxxxxxxxxxx>
CC: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>

v2:
 * Add comment explaining what's going on.
 * Tweak commit message.  Add a note about the portibility issue.
---
 xen/tools/check-endbr.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/xen/tools/check-endbr.sh b/xen/tools/check-endbr.sh
index f633846b0f79..b3febd6a4ccc 100755
--- a/xen/tools/check-endbr.sh
+++ b/xen/tools/check-endbr.sh
@@ -64,6 +64,11 @@ ${OBJDUMP} -j .text $1 -d -w | grep '        endbr64 *$' | 
cut -f 1 -d ':' > $VALID &
 #    split the VMA in half so AWK's numeric addition is only working on 32 bit
 #    numbers, which don't lose precision.
 #
+# 4) MAWK doesn't support plain hex constants (an optional part of the POSIX
+#    spec), and GAWK and MAWK can't agree on how to work with hex constants in
+#    a string.  Use the shell to convert $vma_lo to decimal before passing to
+#    AWK.
+#
 eval $(${OBJDUMP} -j .text $1 -h |
     $AWK '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 8), 
substr($4, 9, 16)}')
 
@@ -79,7 +84,7 @@ then
 else
     grep -aob -e "$(printf '\363\17\36\372')" -e "$(printf '\363\17\36\373')" \
          -e "$(printf '\146\17\37\1')" $TEXT_BIN
-fi | $AWK -F':' '{printf "%s%x\n", "'$vma_hi'", int(0x'$vma_lo') + $1}' > $ALL
+fi | $AWK -F':' '{printf "%s%x\n", "'$vma_hi'", int('$((0x$vma_lo))') + $1}' > 
$ALL
 
 # Wait for $VALID to become complete
 wait
-- 
2.11.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.