[lld] 4976d1f - [ELF] Move SyntheticSection check from InputSection::writeTo to OutputSection::writeTo. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 27 23:28:57 PST 2022


Author: Fangrui Song
Date: 2022-02-27T23:28:52-08:00
New Revision: 4976d1fe58f89169efaca565c02c5e424ce266cb

URL: https://github.com/llvm/llvm-project/commit/4976d1fe58f89169efaca565c02c5e424ce266cb
DIFF: https://github.com/llvm/llvm-project/commit/4976d1fe58f89169efaca565c02c5e424ce266cb.diff

LOG: [ELF] Move SyntheticSection check from InputSection::writeTo to OutputSection::writeTo. NFC

Simplify code and make the heavyweight operation to the call site so that it is
clearer how to improve the inefficient scheduling in the future.

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/ELF/OutputSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index b76ee7a532eaf..12f5aefb26959 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -1213,11 +1213,6 @@ void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *buf,
 }
 
 template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
-  if (auto *s = dyn_cast<SyntheticSection>(this)) {
-    s->writeTo(buf);
-    return;
-  }
-
   if (LLVM_UNLIKELY(type == SHT_NOBITS))
     return;
   // If -r or --emit-relocs is given, then an InputSection

diff  --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 2960117f057fb..1e901b89272a5 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -431,7 +431,10 @@ template <class ELFT> void OutputSection::writeTo(uint8_t *buf) {
 
   parallelForEachN(0, sections.size(), [&](size_t i) {
     InputSection *isec = sections[i];
-    isec->writeTo<ELFT>(buf + isec->outSecOff);
+    if (auto *s = dyn_cast<SyntheticSection>(isec))
+      s->writeTo(buf + isec->outSecOff);
+    else
+      isec->writeTo<ELFT>(buf + isec->outSecOff);
 
     // Fill gaps between sections.
     if (nonZeroFiller) {


        


More information about the llvm-commits mailing list