[lld] 3b42fc8 - [ELF] Simplify sortSection. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 25 16:57:52 PDT 2021
Author: Fangrui Song
Date: 2021-10-25T16:57:46-07:00
New Revision: 3b42fc8a07c37e47efae80c931eff7e63103e0e9
URL: https://github.com/llvm/llvm-project/commit/3b42fc8a07c37e47efae80c931eff7e63103e0e9
DIFF: https://github.com/llvm/llvm-project/commit/3b42fc8a07c37e47efae80c931eff7e63103e0e9.diff
LOG: [ELF] Simplify sortSection. NFC
Added:
Modified:
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index d8df753a25f0..516b5b9cd147 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1483,29 +1483,19 @@ static void sortSection(OutputSection *sec,
if (auto *isd = dyn_cast<InputSectionDescription>(b))
sortISDBySectionOrder(isd, order);
- // Sort input sections by section name suffixes for
- // __attribute__((init_priority(N))).
- if (name == ".init_array" || name == ".fini_array") {
- if (!script->hasSectionsCommand)
- sec->sortInitFini();
+ if (script->hasSectionsCommand)
return;
- }
- // Sort input sections by the special rule for .ctors and .dtors.
- if (name == ".ctors" || name == ".dtors") {
- if (!script->hasSectionsCommand)
- sec->sortCtorsDtors();
- return;
- }
-
- // .toc is allocated just after .got and is accessed using GOT-relative
- // relocations. Object files compiled with small code model have an
- // addressable range of [.got, .got + 0xFFFC] for GOT-relative relocations.
- // To reduce the risk of relocation overflow, .toc contents are sorted so that
- // sections having smaller relocation offsets are at beginning of .toc
- if (config->emachine == EM_PPC64 && name == ".toc") {
- if (script->hasSectionsCommand)
- return;
+ if (name == ".init_array" || name == ".fini_array") {
+ sec->sortInitFini();
+ } else if (name == ".ctors" || name == ".dtors") {
+ sec->sortCtorsDtors();
+ } else if (config->emachine == EM_PPC64 && name == ".toc") {
+ // .toc is allocated just after .got and is accessed using GOT-relative
+ // relocations. Object files compiled with small code model have an
+ // addressable range of [.got, .got + 0xFFFC] for GOT-relative relocations.
+ // To reduce the risk of relocation overflow, .toc contents are sorted so
+ // that sections having smaller relocation offsets are at beginning of .toc
assert(sec->sectionCommands.size() == 1);
auto *isd = cast<InputSectionDescription>(sec->sectionCommands[0]);
llvm::stable_sort(isd->sections,
@@ -1513,7 +1503,6 @@ static void sortSection(OutputSection *sec,
return a->file->ppc64SmallCodeModelTocRelocs &&
!b->file->ppc64SmallCodeModelTocRelocs;
});
- return;
}
}
More information about the llvm-commits
mailing list