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

[PATCH] x86: make embedded endbr64 check compatible with older GNU grep


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 24 Feb 2022 11:14:28 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=zhkz7XUOfkbAUL6lSDSMSMGj4W9BquadB21UquNDilc=; b=Tf8k2IZfk1B+UshpGS9g+W8J9EcS9onXa0Tn1J6IHEfKWWfuf4bhWxCZN7NwbjCvIXx7gg1ip0LDLPIc0WBjdhrIcVT86fggi8Meb2LzpoMv1xg4tcs38nEsxXIc6dph65G4flxwKJg0u81xvdInD7fM1VYXN+nFucyds++LDDgZWWyjHA6vZd85I7AMmoCgtbzBcthehxvx4X3JnfipNLDJGfpy+Y8CCMkbvXGGDA1bjHUq603Emj033xQyN5D1UzBinXNdV7fbwibluOw6BfG49lQiHxBSV2SpOm3OlSMKld4nTiL9jhL/l7QDgbnrKQwJTAzQq/Q6Yhjwygv44w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a78V4y121wmd+tF3k8ppQNxQn/Vh6NTmEKb7uWB+le14cSgoljhI/GF4Pf3OcpNhkkY7bLrxw2p1WpaklySNmeGg0WHXSDfAIcIRg0Zm2i/4uYEyT1H4MzQEVOFsfOX1rxlbwloa310c37NdsXhTr4VR9Cn6TJ2qsKwxxH+540yQ+PRNURIxZDWunRkfR/o42XXbS0VJZNWNG5OQvPN8YfquFpq6w8d0Wm+ej7I/SGXBdjGCvqycfCk2K7YHUc7OcfIr6fd2JP+k/5+CniNogoheaoKGD7HoNG54LkvMZcu4xV066nLgIrf86qrZchFAj9u6GNG+g+tEA9Ain7RFmg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 24 Feb 2022 10:14:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

With version 2.7 I'm observing support for binary searches, but
unreliable results: Only a subset of the supposed matches is actually
reported; for our pattern I've never observed any match. This same
version works fine when handing it a Perl regexp using hex or octal
escapes. Probe for support of -P and prefer that over the original
approach.

Fixes: 4d037425dccf ("x86: Build check for embedded endbr64 instructions")
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
If we were to fear -P having a different meaning elsewhere, we may need
to switch to the respective long option (--perl-regexp).

--- a/xen/tools/check-endbr.sh
+++ b/xen/tools/check-endbr.sh
@@ -24,6 +24,11 @@ BAD=$D/bad-addrs
 echo "X" | grep -aob "X" -q 2>/dev/null ||
     { echo "$MSG_PFX Warning: grep can't do binary searches" >&2; exit 0; }
 
+# Check whether grep supports Perl regexps. Older GNU grep doesn't reliably
+# find binary patterns otherwise.
+perl_re=true
+echo "X" | grep -aobP "\130" -q 2>/dev/null || perl_re=false
+
 #
 # First, look for all the valid endbr64 instructions.
 # A worst-case disassembly, viewed through cat -A, may look like:
@@ -60,8 +65,12 @@ 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)}')
 
 ${OBJCOPY} -j .text $1 -O binary $TEXT_BIN
-grep -aob "$(printf '\363\17\36\372')" $TEXT_BIN |
-    awk -F':' '{printf "%s%x\n", "'$vma_hi'", int(0x'$vma_lo') + $1}' > $ALL
+if $perl_re
+then
+    LC_ALL=C grep -aobP '\363\17\36\372' $TEXT_BIN
+else
+    grep -aob "$(printf '\363\17\36\372')" $TEXT_BIN
+fi | awk -F':' '{printf "%s%x\n", "'$vma_hi'", int(0x'$vma_lo') + $1}' > $ALL
 
 # Wait for $VALID to become complete
 wait




 


Rackspace

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