[PATCH v2 2/3] livepatch-build-tools: remove usage of gawk

Roger Pau Monne posted 3 patches 12 months ago
[PATCH v2 2/3] livepatch-build-tools: remove usage of gawk
Posted by Roger Pau Monne 12 months ago
And instead use plain awk.

Since plain awk cannot do the conversion from hex to decimal, use the shell
(bash) printf to convert the (maybe) hexadecimal output of readelf.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v1:
 - Use shell printf to convert.
---
 livepatch-build | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/livepatch-build b/livepatch-build
index 305644037ee7..e2ccce4f7fd7 100755
--- a/livepatch-build
+++ b/livepatch-build
@@ -423,14 +423,15 @@ if [ "${SKIP}" != "build" ]; then
     echo "Reading special section data"
     # Using xen-syms built in the previous step by build_full().
     SPECIAL_VARS=$(readelf -wi "$OUTPUT/xen-syms" |
-               gawk --non-decimal-data '
+               awk '
                BEGIN { a = b = e = 0 }
                a == 0 && /DW_AT_name.* alt_instr/ {a = 1; next}
                b == 0 && /DW_AT_name.* bug_frame/ {b = 1; next}
                e == 0 && /DW_AT_name.* exception_table_entry/ {e = 1; next}
-               a == 1 {printf("export ALT_STRUCT_SIZE=%d\n", $4); a = 2}
-               b == 1 {printf("export BUG_STRUCT_SIZE=%d\n", $4); b = 2}
-               e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2}
+               # Use shell printf to (possibly) convert from hex to decimal
+               a == 1 {printf("export ALT_STRUCT_SIZE=`printf \"%%d\" \"%s\"`\n", $4); a = 2}
+               b == 1 {printf("export BUG_STRUCT_SIZE=`printf \"%%d\" \"%s\"`\n", $4); b = 2}
+               e == 1 {printf("export EX_STRUCT_SIZE=`printf \"%%d\" \"%s\"`\n", $4); e = 2}
                a == 2 && b == 2 && e == 2 {exit}')
     [[ -n $SPECIAL_VARS ]] && eval "$SPECIAL_VARS"
     if [[ -z $ALT_STRUCT_SIZE ]] || [[ -z $BUG_STRUCT_SIZE ]] || [[ -z $EX_STRUCT_SIZE ]]; then
-- 
2.43.0