]> xenbits.xensource.com Git - livepatch-build-tools.git/commitdiff
livepatch-build: Strip transient or unneeded symbols
authorPawel Wieczorkiewicz <wipawel@amazon.de>
Tue, 26 Nov 2019 12:25:10 +0000 (12:25 +0000)
committerRoss Lagerwall <ross.lagerwall@citrix.com>
Thu, 6 Feb 2020 16:41:06 +0000 (16:41 +0000)
In the process of creating a final hotpatch module file make sure to
strip all transient symbols that have not been caught and removed by
create-diff-object processing. For now these are only the hooks
kpatch load/unload symbols.

For all new object files that are carried along for the final linking
the transient hooks symbols are not stripped and neither are any
unneeded symbols. Strip the transient hooks symbols explicitly from
resulting object file.
Add a new option '--strip' to additionally strip all unneeded symbols
from new object files.

Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
livepatch-build

index b8a1728c5ad368cc63f977797b7a87024b5da784..9e5bad3f86f8704d0c543de8c7c6c7cac609974a 100755 (executable)
@@ -32,6 +32,7 @@ SKIP=
 DEPENDS=
 XEN_DEPENDS=
 PRELINK=
+STRIP=0
 XENSYMS=xen-syms
 
 warn() {
@@ -111,6 +112,28 @@ function build_special()
     unset LIVEPATCH_CAPTURE_DIR
 }
 
+strip_extra_symbols ()
+{
+    local -r FILE="$1"
+    local -a STRIP_CMD_OPTS=()
+    local -a SYM_PREFIX=("livepatch_load_data_"
+                         "livepatch_unload_data_"
+                         "livepatch_preapply_data_"
+                         "livepatch_apply_data_"
+                         "livepatch_postapply_data_"
+                         "livepatch_prerevert_data_"
+                         "livepatch_revert_data_"
+                         "livepatch_postrevert_data_")
+
+    STRIP_CMD_OPTS+=("-w")
+    for sym in "${SYM_PREFIX[@]}"; do
+        STRIP_CMD_OPTS+=("-N")
+        STRIP_CMD_OPTS+=("\"${sym}*\"")
+    done
+
+    strip "${STRIP_CMD_OPTS[@]}" "$FILE"
+}
+
 function create_patch()
 {
     echo "Extracting new and modified ELF sections..."
@@ -150,6 +173,7 @@ function create_patch()
     NEW_FILES=$(comm -23 <(cd patched/xen && find . -type f -name '*.o' | sort) <(cd original/xen && find . -type f -name '*.o' | sort))
     for i in $NEW_FILES; do
         cp "patched/$i" "output/$i"
+        [[ $STRIP -eq 1 ]] && strip --strip-unneeded "output/$i"
         CHANGED=1
     done
 
@@ -176,6 +200,8 @@ function create_patch()
         "${TOOLSDIR}"/prelink $debugopt output.o "${PATCHNAME}.livepatch" "$XENSYMS" &>> "${OUTPUT}/prelink.log" || die
     fi
 
+    strip_extra_symbols "${PATCHNAME}.livepatch"
+
     objcopy --add-section .livepatch.depends=depends.bin "${PATCHNAME}.livepatch"
     objcopy --set-section-flags .livepatch.depends=alloc,readonly "${PATCHNAME}.livepatch"
 
@@ -198,11 +224,12 @@ usage() {
     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
 }
 
 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" -- "$@") || 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" -- "$@") || die "getopt failed"
 
 eval set -- "$options"
 
@@ -270,6 +297,10 @@ while [[ $# -gt 0 ]]; do
             PRELINK=--resolve
             shift
             ;;
+        --strip)
+            STRIP=1
+            shift
+            ;;
         --)
             shift
             break