diff options
| author | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:49:54 +0900 |
|---|---|---|
| committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:49:54 +0900 |
| commit | e2810c9a248f4c7fbfae84bb32b6f7e01027458b (patch) | |
| tree | ae0b02a8491b969a1cee94ea16ffe42c559143c5 /lld/ELF/Writer.cpp | |
| parent | fa04eb4af95c1ca7377279728cb004bcd2324d01 (diff) | |
| parent | bdcf47e4bcb92889665825654bb80a8bbe30379e (diff) | |
Merge branch 'users/chapuni/cov/single/base' into users/chapuni/cov/single/switchusers/chapuni/cov/single/switch
Diffstat (limited to 'lld/ELF/Writer.cpp')
| -rw-r--r-- | lld/ELF/Writer.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 3e92b7653e31..fe4a0a15ae83 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1080,12 +1080,14 @@ static void maybeShuffle(Ctx &ctx, } } -// Builds section order for handling --symbol-ordering-file. +// Return section order within an InputSectionDescription. +// If both --symbol-ordering-file and call graph profile are present, the order +// file takes precedence, but the call graph profile is still used for symbols +// that don't appear in the order file. static DenseMap<const InputSectionBase *, int> buildSectionOrder(Ctx &ctx) { DenseMap<const InputSectionBase *, int> sectionOrder; - // Use the rarely used option --call-graph-ordering-file to sort sections. if (!ctx.arg.callGraphProfile.empty()) - return computeCallGraphProfileOrder(ctx); + sectionOrder = computeCallGraphProfileOrder(ctx); if (ctx.arg.symbolOrderingFile.empty()) return sectionOrder; @@ -1099,7 +1101,7 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder(Ctx &ctx) { // appear in the symbol ordering file have the lowest priority 0. // All explicitly mentioned symbols have negative (higher) priorities. DenseMap<CachedHashStringRef, SymbolOrderEntry> symbolOrder; - int priority = -ctx.arg.symbolOrderingFile.size(); + int priority = -sectionOrder.size() - ctx.arg.symbolOrderingFile.size(); for (StringRef s : ctx.arg.symbolOrderingFile) symbolOrder.insert({CachedHashStringRef(s), {priority++, false}}); @@ -1255,11 +1257,11 @@ static void sortSection(Ctx &ctx, OutputSection &osec, } } -// If no layout was provided by linker script, we want to apply default -// sorting for special input sections. This also handles --symbol-ordering-file. +// Sort sections within each InputSectionDescription. template <class ELFT> void Writer<ELFT>::sortInputSections() { - // Build the order once since it is expensive. + // Assign negative priorities. DenseMap<const InputSectionBase *, int> order = buildSectionOrder(ctx); + // Assign non-negative priorities due to --shuffle-sections. maybeShuffle(ctx, order); for (SectionCommand *cmd : ctx.script->sectionCommands) if (auto *osd = dyn_cast<OutputDesc>(cmd)) |
