]> xenbits.xensource.com Git - livepatch-build-tools.git/commitdiff
livepatch-build-tools: account for section alignment when calculating function size
authorRoger Pau Monne <roger.pau@citrix.com>
Tue, 28 Nov 2023 09:21:52 +0000 (10:21 +0100)
committerRoss Lagerwall <ross.lagerwall@citrix.com>
Wed, 6 Dec 2023 11:32:57 +0000 (11:32 +0000)
Forcing function section alignment at the compiler level ensures that enough
space is present in the text section so that at least a jump can be encoded in
the old function body to switch to the newly loaded code payload.

Modify create-diff-object to account for any section alignment when calculating
the size of the old function.

When used with a suitable -falign-function compiler parameter on the Xen
hypervisor build this ensures that all functions have enough space to
accommodate for any control flow instructions plus a jump.

Note that while the rounding could be applied to all (text) symbols, it's not
required, as the size is only relevant for functions that are live patched, and
hence only do the rounding when calculating the old (previous) function size.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
common.h
create-diff-object.c

index 0d3e5f1dd3b5619cac30d464f9485a9a389c7f54..5ff9ef6ca8e98bd5633e410b18421fb806afeb8e 100644 (file)
--- a/common.h
+++ b/common.h
@@ -37,6 +37,8 @@ extern char *childobj;
        list_add_tail(&(_new)->list, (_list)); \
 }
 
+#define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1))
+
 enum loglevel {
        DEBUG,
        NORMAL
index d0e14e3a62bbaed17d554d9f23640a1249d693a0..fed360a9aa6891b7f83af95371babb5cc6f2aa2d 100644 (file)
@@ -2015,6 +2015,11 @@ static void livepatch_create_patches_sections(struct kpatch_elf *kelf,
                                        ERROR("lookup_global_symbol %s",
                                              sym->name);
                        }
+
+                       /* Take into account section alignment for padding. */
+                       result.size = ROUNDUP(result.size,
+                                             sym->sec->sh.sh_addralign);
+
                        log_debug("lookup for %s @ 0x%016lx len %lu\n",
                                  sym->name, result.value, result.size);