On 30.11.2023 18:37, Roger Pau Monné wrote: > On Thu, Nov 30, 2023 at 05:55:07PM +0100, Jan Beulich wrote: >> On 28.11.2023 11:03, Roger Pau Monne wrote: >>> The minimal function size requirements for livepatch are either 5 bytes (for >>> jmp) or 9 bytes (for endbr + jmp). Ensure that functions are always at >>> least >>> that size by requesting the compiled to align the functions to 8 or 16 >>> bytes, >>> depending on whether Xen is build with IBT support. >> >> How is alignment going to enforce minimum function size? If a function is >> last in a section, there may not be any padding added (ahead of linking at >> least). The trailing padding also isn't part of the function. > > If each function lives in it's own section (by using > -ffunction-sections), and each section is aligned, then I think we can > guarantee that there will always be enough padding space? > > Even the last function/section on the .text block would still be > aligned, and as long as the function alignment <= SECTION_ALIGN > there will be enough padding left. I should add some build time > assert that CONFIG_CC_FUNCTION_ALIGNMENT <= SECTION_ALIGN.
I'm not sure of there being a requirement for a section to be padded to its alignment. If the following section has smaller alignment, it could be made start earlier. Of course our linker scripts might guarantee this ... > While the trailing padding is not part of the function itself, I don't > see issues in overwriting it with the replacement function code. If it's really padding, yes. Jan