diff mbox series

[1/3] livepatch: use basename to perform object file matching

Message ID 20220310150834.98815-2-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show
Series livepatch: further fixes | expand

Commit Message

Roger Pau Monné March 10, 2022, 3:08 p.m. UTC
The changes in the Xen build logic has resulted in the compiler and
objcopy being called from xen/ instead of relative to each object
directory. This requires using basename so that the directory is not
taken into account when checking against the list of files to be
explicitly ignored.

Also adjust the paths used to store the differing object files, as
with the current logic the resulting path will be wrong when using
newer Xen versions, changed_objs would end containing entries like:

xen/arch/x86/hvm/vmx/arch/x86/hvm/vmx/vmx.o

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 livepatch-gcc | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Doebel, Bjoern March 10, 2022, 5:22 p.m. UTC | #1
On 10.03.22 16:08, Roger Pau Monne wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> The changes in the Xen build logic has resulted in the compiler and
> objcopy being called from xen/ instead of relative to each object
> directory. This requires using basename so that the directory is not
> taken into account when checking against the list of files to be
> explicitly ignored.
> 
> Also adjust the paths used to store the differing object files, as
> with the current logic the resulting path will be wrong when using
> newer Xen versions, changed_objs would end containing entries like:
> 
> xen/arch/x86/hvm/vmx/arch/x86/hvm/vmx/vmx.o
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
>   livepatch-gcc | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/livepatch-gcc b/livepatch-gcc
> index 91333d5..fe782e0 100755
> --- a/livepatch-gcc
> +++ b/livepatch-gcc
> @@ -32,10 +32,10 @@ if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then
>           if [ "$1" = "-o" ]; then
>               obj=$2
>               [[ $2 = */.tmp_*.o ]] && obj=${2/.tmp_/}
> -            case "$obj" in
> +            case "$(basename $obj)" in
>               version.o|\
>               debug.o|\
> -            efi/check.o|\
> +            check.o|\
>               *.xen-syms.*.o|\
>               *.xen.efi.*.o|\
>               built_in.o|\
> @@ -46,6 +46,7 @@ if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then
>               *.o)
>                   path="$(pwd)/$(dirname $obj)"
>                   dir="${path#$LIVEPATCH_BUILD_DIR}"
> +                obj=$(basename $obj)
>                   if [ -n "$LIVEPATCH_CAPTURE_DIR" -a -d "$LIVEPATCH_CAPTURE_DIR" ]; then
>                       echo "$dir/$obj" >> "${LIVEPATCH_CAPTURE_DIR}/changed_objs"
>                       keep=yes
> @@ -61,15 +62,16 @@ if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then
>   done
>   elif [[ "$TOOLCHAINCMD" =~ $OBJCOPY_RE ]] ; then
>       obj="${!#}"
> -    case "$obj" in
> +    case "$(basename $obj)" in
>           version.o|\
>           debug.o|\
> -        efi/check.o|\
> +        check.o|\
>           .*.o)
>               ;;
>           *.o)
>               path="$(pwd)/$(dirname $obj)"
>               dir="${path#$LIVEPATCH_BUILD_DIR}"
> +            obj=$(basename $obj)
>               if [ -n "$LIVEPATCH_CAPTURE_DIR" -a -d "$LIVEPATCH_CAPTURE_DIR" ]; then
>                   echo "$dir/$obj" >> "${LIVEPATCH_CAPTURE_DIR}/changed_objs"
>                   keep=yes
> @@ -85,7 +87,7 @@ ret="$?"
> 
>   if [[ "$keep" = "yes" ]] ; then
>       mkdir -p "$(dirname $LIVEPATCH_CAPTURE_DIR/$dir/$obj)"
> -    cp "$obj" "$LIVEPATCH_CAPTURE_DIR/$dir/$obj"
> +    cp "$path/$obj" "$LIVEPATCH_CAPTURE_DIR/$dir/$obj"
>   fi
> 
>   exit "$ret"
> --
> 2.34.1

Reviewed-by: Bjoern Doebel <doebel@amazon.de>



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
diff mbox series

Patch

diff --git a/livepatch-gcc b/livepatch-gcc
index 91333d5..fe782e0 100755
--- a/livepatch-gcc
+++ b/livepatch-gcc
@@ -32,10 +32,10 @@  if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then
         if [ "$1" = "-o" ]; then
             obj=$2
             [[ $2 = */.tmp_*.o ]] && obj=${2/.tmp_/}
-            case "$obj" in
+            case "$(basename $obj)" in
             version.o|\
             debug.o|\
-            efi/check.o|\
+            check.o|\
             *.xen-syms.*.o|\
             *.xen.efi.*.o|\
             built_in.o|\
@@ -46,6 +46,7 @@  if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then
             *.o)
                 path="$(pwd)/$(dirname $obj)"
                 dir="${path#$LIVEPATCH_BUILD_DIR}"
+                obj=$(basename $obj)
                 if [ -n "$LIVEPATCH_CAPTURE_DIR" -a -d "$LIVEPATCH_CAPTURE_DIR" ]; then
                     echo "$dir/$obj" >> "${LIVEPATCH_CAPTURE_DIR}/changed_objs"
                     keep=yes
@@ -61,15 +62,16 @@  if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then
 done
 elif [[ "$TOOLCHAINCMD" =~ $OBJCOPY_RE ]] ; then
     obj="${!#}"
-    case "$obj" in
+    case "$(basename $obj)" in
         version.o|\
         debug.o|\
-        efi/check.o|\
+        check.o|\
         .*.o)
             ;;
         *.o)
             path="$(pwd)/$(dirname $obj)"
             dir="${path#$LIVEPATCH_BUILD_DIR}"
+            obj=$(basename $obj)
             if [ -n "$LIVEPATCH_CAPTURE_DIR" -a -d "$LIVEPATCH_CAPTURE_DIR" ]; then
                 echo "$dir/$obj" >> "${LIVEPATCH_CAPTURE_DIR}/changed_objs"
                 keep=yes
@@ -85,7 +87,7 @@  ret="$?"
 
 if [[ "$keep" = "yes" ]] ; then
     mkdir -p "$(dirname $LIVEPATCH_CAPTURE_DIR/$dir/$obj)"
-    cp "$obj" "$LIVEPATCH_CAPTURE_DIR/$dir/$obj"
+    cp "$path/$obj" "$LIVEPATCH_CAPTURE_DIR/$dir/$obj"
 fi
 
 exit "$ret"