[lld] ELF: Introduce --shuffle-padding option. (PR #117653)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 29 22:35:59 PST 2024
================
@@ -1444,6 +1444,38 @@ static void finalizeSynthetic(Ctx &ctx, SyntheticSection *sec) {
}
}
+static bool canInsertPadding(OutputSection *sec) {
+ StringRef s = sec->name;
+ return s == ".bss" || s == ".data" || s == ".data.rel.ro" || s == ".rodata" ||
+ s.starts_with(".text");
+}
+
+static void shufflePadding(Ctx &ctx) {
+ std::mt19937 g(*ctx.arg.shufflePadding);
+ PhdrEntry *curPtLoad = nullptr;
+ for (OutputSection *os : ctx.outputSections) {
+ if (!canInsertPadding(os))
+ continue;
+ for (SectionCommand *bc : os->commands) {
+ if (auto *isd = dyn_cast<InputSectionDescription>(bc)) {
+ SmallVector<InputSection *, 0> tmp;
+ if (os->ptLoad != curPtLoad) {
+ tmp.push_back(
+ make<ShufflePaddingSection>(ctx, g() % ctx.arg.maxPageSize, os));
+ curPtLoad = os->ptLoad;
+ }
+ for (InputSection *isec : isd->sections) {
+ if (g() < (1 << 28))
----------------
MaskRay wrote:
1<<28 needs a comment. This should be configurable by the command line option.
https://github.com/llvm/llvm-project/pull/117653
More information about the llvm-commits
mailing list