diff mbox series

[19/20] livepatch-build: Strip transient or unneeded symbols

Message ID 20190821082056.91090-20-wipawel@amazon.de (mailing list archive)
State Superseded
Headers show
Series livepatch-build-tools: new features and fixes | expand

Commit Message

Wieczorkiewicz, Pawel Aug. 21, 2019, 8:20 a.m. UTC
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 them explicitly from resulting object file.

Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
---
 livepatch-build | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/livepatch-build b/livepatch-build
index 3f0530e..cc71640 100755
--- a/livepatch-build
+++ b/livepatch-build
@@ -111,6 +111,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 +172,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 --strip-unneeded "output/$i"
         CHANGED=1
     done
 
@@ -176,6 +199,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"