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

[PATCH v2 2/5] xen/tools: remove usages of `stat -c` in check-endbr.sh


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Thu, 12 Feb 2026 15:46:15 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/Neh6QaVEtW9q3mlfrOk5GxOs2RNXIp81nmsab9QjLs=; b=eqYtf+vbxHd4cnxYgatZZsALnR6LjA92tnj5JFnyjXBPV3JPbS+hWcs9tuiRciTjGVK1hdsnJYk9d0DsTZpGbmA6+R4Rf0LaGHXa3zVH6ufqA4XSC1i1x2jRetp/GpPhixcfMw4Um06eYIy9tRhQxBOyfcLHeRTglkpm8swHRBjshurTQC8GCkKMEwgxxNyxj0ryygOJP24X4sU7AmrfZ1umpO9hvV0Somtpjk1Nd7/fwQj5Xy+KaXrECiFqDGh/pqYbQ3bko+1Dm1usH2iktEi6jdJhfxGWsnpn0wSOH+idwxvlxpqvQ22r0JcAtMRfggT9znIpX5lukTe+muCeMg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HDEt8Nkys8WGkSI+raz67/GydavdObuct+rVESTwMqv9FQIP4bDiBXp17kc3Vpa2q0gQpo+g9V5OYi7dsnBmhn0JUi4E9Cqc0uAdw2WrbAEXK0xavr0PHlD5vVLPtOTMtfPu8QSExF7TrV/lTk7w9ifbvps1ssKELv5uayywsbTE1RZ1kf0mS/7las+sm5xiQU90Vb3H8idUmeP+U6U+suzUZZEHTS/dJjoD0M7d+zSifeiW7rFVPVeprFcfR6r4Oc+v27KCnvZ8acWal33Qx3xTQZrJNC1BKUr24ALrq0AkrAzX4n3BIiwIfKFNmnbMK/m4AkJNsp9Fn4FYJJaZQw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • Delivery-date: Thu, 12 Feb 2026 14:46:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The `-c` option to stat is not POSIX compatible, and hence prevents the
check-endbr.sh script from running reliably.

The first instance of `stat -c` can be removed by fetching the section size
from the output of objdump itself, which the script already parses to get
the VMA values.

The other two instances can be replaced by counting the lines in the
respective files.  Those files contain list of addresses, so the size in
bytes is not strictly needed, we can count the number of lines instead.

Suggested-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Acked-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
---
Changes since v1:
 - Use $(()) to convert from hex to decimal.
---
 xen/tools/check-endbr.sh | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/xen/tools/check-endbr.sh b/xen/tools/check-endbr.sh
index bf153a570db4..aaaa9ebe6bd7 100755
--- a/xen/tools/check-endbr.sh
+++ b/xen/tools/check-endbr.sh
@@ -92,14 +92,13 @@ ${OBJDUMP} -j .text $1 -d -w | grep '       endbr64 *$' | 
cut -f 1 -d ':' > $VALID &
 #    check nevertheless.
 #
 eval $(${OBJDUMP} -j .text $1 -h |
-    $AWK '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 9), 
substr($4, 10, 16)}')
+    $AWK '$2 == ".text" {printf "bin_sz=%s\nvma_hi=%s\nvma_lo=%s\n", "0x" $3, 
substr($4, 1, 9), substr($4, 10, 16)}')
 
-${OBJCOPY} -j .text $1 -O binary $TEXT_BIN
-
-bin_sz=$(stat -c '%s' $TEXT_BIN)
-[ "$bin_sz" -ge $(((1 << 28) - $vma_lo)) ] &&
+[ "$(($bin_sz))" -ge $(((1 << 28) - $vma_lo)) ] &&
     { echo "$MSG_PFX Error: .text offsets must not exceed 256M" >&2; exit 1; }
 
+${OBJCOPY} -j .text $1 -O binary $TEXT_BIN
+
 # instruction:    hex:           oct:
 # endbr64         f3 0f 1e fa    363 017 036 372
 # endbr32         f3 0f 1e fb    363 017 036 373
@@ -116,8 +115,8 @@ fi | $AWK -F':' '{printf "%s%07x\n", "'$vma_hi'", 
int('$((0x$vma_lo))') + $1}' >
 wait
 
 # Sanity check $VALID and $ALL, in case the string parsing bitrots
-val_sz=$(stat -c '%s' $VALID)
-all_sz=$(stat -c '%s' $ALL)
+val_sz=$(wc -l < $VALID)
+all_sz=$(wc -l < $ALL)
 [ "$val_sz" -eq 0 ]         && { echo "$MSG_PFX Error: Empty valid-addrs" >&2; 
exit 1; }
 [ "$all_sz" -eq 0 ]         && { echo "$MSG_PFX Error: Empty all-addrs" >&2; 
exit 1; }
 [ "$all_sz" -lt "$val_sz" ] && { echo "$MSG_PFX Error: More valid-addrs than 
all-addrs" >&2; exit 1; }
-- 
2.51.0




 


Rackspace

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