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>
---
Changes since v2:
- New in this version.
---
common.h | 2 ++
create-diff-object.c | 5 +++++
2 files changed, 7 insertions(+)
diff --git a/common.h b/common.h
index 0d3e5f1dd3b5..5ff9ef6ca8e9 100644
--- 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
diff --git a/create-diff-object.c b/create-diff-object.c
index d0e14e3a62bb..fed360a9aa68 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -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);
--
2.43.0