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

[PATCH] livepatch-build: Check compiler version matches


  • To: <xen-devel@xxxxxxxxxxxxx>
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Tue, 21 Feb 2023 14:14:32 +0000
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Delivery-date: Tue, 21 Feb 2023 14:15:03 +0000
  • Ironport-data: A9a23:rqejVK37AVGWF/O8PfbD5dNxkn2cJEfYwER7XKvMYLTBsI5bp2EAn WEeUW+GPq3fZGbyeYx1Yd7g/E0D68eBxtVrSgVlpC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8tuTS93uDgNyo4GlD5gZkPKgQ1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfXXNj/ voIIgo2bw3Sgfyr/LCZSMxQr5F2RCXrFNt3VnBIyDjYCbAtQIzZQrWM7thdtNsyrpkQR7CEP ZNfMGcxKk2aOHWjOX9OYH46tP2vnWK5dzRXpUiKrK4zy2PS0BZwwP7mN9+9ltmiHJ0NxR/I+ T+Yl4j/KiA7aIWAlAqJyXCLi9fjgSfcUa5LFKLto5aGh3XMnzdOWXX6T2CTsfS/z0KzRd9bA 0gV4TY167g/8gqsVNaVdx6/pmSNslgDWt5TO+og4QqJx+zf5APxO4QfZmcfMpp87pZwHGF0k AbTxLsFGACDrpXJW1+W8KeelwizJHkTM3I+Zw0GaDcstoyLTJ4IsjrDSdNqEaiQh9LzGC3tz z3ikBXSl4n/nuZQifzloAmvbyaE48GQE1Vrvlm/sneNtFsRWWKzW2C/BbE3B95kJZ3RcFSOt WNsdyO2vLFXVsHleMBgrYww8FCVCxStamC0bb1HRcNJG9GRF5mLJNk43d2GDB01WvvogBewC KMphStf5YVIIFyhZrJtboS6BqwClPa/S4W8BqiEMYMVOvCdkTNrGwk0OCatM53FyhBwwcnTx 7/GGSpTMZrqIfs+l2fnLwvs+bQq2jo/1QvuqWPTlnyaPU6lTCfNE98taQLeBt3VGYvY+G05B f4DbZrVo/ieOcWiChTqHXk7cwlRdydiW8yrwyGVH8baSjdb9KgaI6e56dscl0ZNw8y5Ss+gE qmBZ3Jl
  • Ironport-hdrordr: A9a23:Hfu0M6khvru06LbsIh6sMiFp1qLpDfIJ3DAbv31ZSRFFG/Fw9v rPoB1/73TJYVkqNk3I9erwXZVoIkmyyXcW2+gs1N6ZNWGN1QeVxedZnPLfKlXbakrDH8FmpM VdmsNFebnN5DZB/LzHyTj9P9E8wMSWtICE7N2uskuEBmlRGsddBnxCe2Wm+5RNNXF77EwCZe Gh2vY=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

For reliable live patch generation, the compiler version used should
match the original binary. Check that this is the case and add a
--skip-compiler-check option to override this.

Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
 livepatch-build | 54 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 15 deletions(-)

diff --git a/livepatch-build b/livepatch-build
index 91d203b..e4b4dba 100755
--- a/livepatch-build
+++ b/livepatch-build
@@ -33,6 +33,7 @@ DEPENDS=
 XEN_DEPENDS=
 PRELINK=
 STRIP=0
+SKIP_COMPILER_CHECK=0
 XENSYMS=xen-syms
 
 warn() {
@@ -266,27 +267,44 @@ function create_patch()
     objcopy --set-section-flags .livepatch.xen_depends=alloc,readonly 
"${PATCHNAME}.livepatch"
 }
 
+check_compiler() {
+    orig_ver=$(readelf -p .comment "$XENSYMS" | grep -o 'GCC.*')
+
+    in_file=$(mktemp --suffix=.c)
+    out_file=$(mktemp --suffix=.o)
+    echo 'int main(void) {}' > "$in_file"
+    gcc -c -o "$out_file" "$in_file"
+    new_ver=$(readelf -p .comment "$out_file" | grep -o 'GCC.*')
+
+    rm -f "$infile" "$outfile"
+
+    if [ "$orig_ver" != "$new_ver" ]; then
+        die "Mismatched compiler version: Original \"$orig_ver\" New 
\"$new_ver\""
+    fi
+}
+
 usage() {
     echo "usage: $(basename $0) [options]" >&2
-    echo "        -h, --help         Show this help message" >&2
-    echo "        -s, --srcdir       Xen source directory" >&2
-    echo "        -p, --patch        Patch file" >&2
-    echo "        -c, --config       .config file" >&2
-    echo "        -o, --output       Output directory" >&2
-    echo "        -j, --cpus         Number of CPUs to use" >&2
-    echo "        -k, --skip         Skip build or diff phase" >&2
-    echo "        -d, --debug        Enable debug logging" >&2
-    echo "        --xen-debug        Build debug Xen (if your .config does not 
have the options)" >&2
-    echo "        --xen-syms         Build against a xen-syms" >&2
-    echo "        --depends          Required build-id" >&2
-    echo "        --xen-depends      Required Xen build-id" >&2
-    echo "        --prelink          Prelink" >&2
-    echo "        --strip            Remove all symbols that are not needed 
for relocation processing." >&2
+    echo "        -h, --help            Show this help message" >&2
+    echo "        -s, --srcdir          Xen source directory" >&2
+    echo "        -p, --patch           Patch file" >&2
+    echo "        -c, --config          .config file" >&2
+    echo "        -o, --output          Output directory" >&2
+    echo "        -j, --cpus            Number of CPUs to use" >&2
+    echo "        -k, --skip            Skip build or diff phase" >&2
+    echo "        -d, --debug           Enable debug logging" >&2
+    echo "        --xen-debug           Build debug Xen (if your .config does 
not have the options)" >&2
+    echo "        --xen-syms            Build against a xen-syms" >&2
+    echo "        --depends             Required build-id" >&2
+    echo "        --xen-depends         Required Xen build-id" >&2
+    echo "        --prelink             Prelink" >&2
+    echo "        --strip               Remove all symbols that are not needed 
for relocation processing." >&2
+    echo "        --skip-compiler-check Skip compiler version check." >&2
 }
 
 find_tools || die "can't find supporting tools"
 
-options=$(getopt -o hs:p:c:o:j:k:d -l 
"help,srcdir:,patch:,config:,output:,cpus:,skip:,debug,xen-debug,xen-syms:,depends:,xen-depends:,prelink,strip"
 -- "$@") || die "getopt failed"
+options=$(getopt -o hs:p:c:o:j:k:d -l 
"help,srcdir:,patch:,config:,output:,cpus:,skip:,debug,xen-debug,xen-syms:,depends:,xen-depends:,prelink,strip,skip-compiler-check"
 -- "$@") || die "getopt failed"
 
 eval set -- "$options"
 
@@ -358,6 +376,10 @@ while [[ $# -gt 0 ]]; do
             STRIP=1
             shift
             ;;
+        --skip-compiler-check)
+            SKIP_COMPILER_CHECK=1
+            shift
+            ;;
         --)
             shift
             break
@@ -383,6 +405,8 @@ OUTPUT="$(readlink -m -- "$outputarg")"
 [ -f "${PATCHFILE}" ] || die "Patchfile does not exist"
 [ -f "${CONFIGFILE}" ] || die ".config does not exist"
 
+[ -f "$XENSYMS" ] && [ "$SKIP_COMPILER_CHECK" -eq 0 ] && check_compiler
+
 PATCHNAME=$(make_patch_name "${PATCHFILE}")
 
 echo "Building LivePatch patch: ${PATCHNAME}"
-- 
2.31.1




 


Rackspace

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