[lld] ELF: Introduce --randomize-section-padding option. (PR #117653)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 15:00:33 PST 2024
================
@@ -1444,6 +1444,39 @@ 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 randomizeSectionPadding(Ctx &ctx) {
+ std::mt19937 g(*ctx.arg.randomizeSectionPadding);
+ 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<RandomizePaddingSection>(
----------------
pcc wrote:
Okay, added a test with a linker script.
https://github.com/llvm/llvm-project/pull/117653
More information about the llvm-commits
mailing list