[lld] ELF: Introduce --shuffle-padding flag. (PR #117653)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 16:04:37 PST 2024


pcc wrote:

> Sticking to the code here. I'm coming at this from a world where linker scripts are common. I think it should be possible to deal with the additional address requirements by disabling the padding in these cases.
> 
> A possible alternative that wouldn't involve a ShufflePadding section is to randomly double the section alignment. For a target like AArch64 where the most common alignment will be 4 and section size is a multiple of 4, then this will roughly approximate adding padding sections, albeit with half the sections already on an 8-byte boundary so it may need a higher probability to balance. I think some CPU targets overalign functions to cache-line boundaries at higher optimisation levels so there's less of an impact.

I considered increasing alignment but decided against it because that could introduce its own biases. For example, it makes functions more likely to be moved to a single cache line, but for the experiment scenario we want a roughly equal likelihood of the function being moved either to or from a single cache line because that matches the probabilities in a real world scenario. Increasing alignment isn't necessarily immune to an implicit expectation in a linker script either (e.g. it could assume that certain input sections have certain alignments).

The padding sections are a bit like range extension thunk sections which should already work with linker scripts (and are inserted at a similar point, after linker script processing) so I don't foresee any significant problems from the use of these two features together per se. I think that implicit expectations in linker scripts can be addressed in a followup change that would allow the user to override the output section names that receive padding (like `--shuffle-sections` already does). For the time being, by using the two features together, the user is essentially warranting that their linker script is compatible with shuffle padding with the default set of output section names.

https://github.com/llvm/llvm-project/pull/117653


More information about the llvm-commits mailing list