[lld] [LLD][COFF] Add support for custom section layout (PR #152779)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 4 02:16:24 PDT 2025
================
@@ -1413,6 +1415,29 @@ void Writer::removeUnusedSections() {
llvm::erase_if(ctx.outputSections, isUnused);
}
+void Writer::layoutSections() {
+ llvm::TimeTraceScope timeScope("Layout sections");
+ if (ctx.config.sectionOrder.empty())
+ return;
+
+ llvm::stable_sort(ctx.outputSections,
+ [this](const OutputSection *a, const OutputSection *b) {
+ auto itA = ctx.config.sectionOrder.find(a->name.str());
+ auto itB = ctx.config.sectionOrder.find(b->name.str());
+ bool aInOrder = itA != ctx.config.sectionOrder.end();
+ bool bInOrder = itB != ctx.config.sectionOrder.end();
+
+ // Put unspecified sections after all specified sections
+ if (aInOrder && bInOrder) {
+ return itA->second < itB->second;
+ } else if (aInOrder && !bInOrder) {
+ return true;
+ } else {
+ return false;
----------------
kkent030315 wrote:
I agree, thanks for suggestion :)
https://github.com/llvm/llvm-project/pull/152779
More information about the llvm-commits
mailing list