[lld] 3bdc90e - [ELF] adjustOutputSections: update sortRank. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 14:56:47 PDT 2024


Author: Fangrui Song
Date: 2024-05-29T14:56:43-07:00
New Revision: 3bdc90e3ff4c9a18caeb3e6ad40fa5d15bbf9d5e

URL: https://github.com/llvm/llvm-project/commit/3bdc90e3ff4c9a18caeb3e6ad40fa5d15bbf9d5e
DIFF: https://github.com/llvm/llvm-project/commit/3bdc90e3ff4c9a18caeb3e6ad40fa5d15bbf9d5e.diff

LOG: [ELF] adjustOutputSections: update sortRank. NFC

... as flags have changed. This allows us to revisit the
`osd->osec.hasInputSections` condition in `getRankProximity` (originally
introduced as `Sec->Live` in https://reviews.llvm.org/D61197).

Added: 
    

Modified: 
    lld/ELF/LinkerScript.cpp
    lld/ELF/Writer.cpp
    lld/ELF/Writer.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 94a39034d629f..5062124ae6767 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -1249,9 +1249,11 @@ void LinkerScript::adjustOutputSections() {
 
     // We do not want to keep any special flags for output section
     // in case it is empty.
-    if (isEmpty)
+    if (isEmpty) {
       sec->flags =
           flags & ((sec->nonAlloc ? 0 : (uint64_t)SHF_ALLOC) | SHF_WRITE);
+      sec->sortRank = getSectionRank(*sec);
+    }
 
     // The code below may remove empty output sections. We should save the
     // specified program headers (if exist) and propagate them to subsequent

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index fe2e1900520a4..d2cc6d8ff5f2c 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -630,7 +630,7 @@ enum RankFlags {
   RF_BSS = 1 << 7,
 };
 
-static unsigned getSectionRank(OutputSection &osec) {
+unsigned elf::getSectionRank(OutputSection &osec) {
   unsigned rank = osec.partition * RF_PARTITION;
 
   // We want to put section specified by -T option first, so we

diff  --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h
index 7aa06dbcb131a..e3787987aca75 100644
--- a/lld/ELF/Writer.h
+++ b/lld/ELF/Writer.h
@@ -46,6 +46,7 @@ struct PhdrEntry {
 
 void addReservedSymbols();
 bool includeInSymtab(const Symbol &b);
+unsigned getSectionRank(OutputSection &osec);
 
 template <class ELFT> uint32_t calcMipsEFlags();
 


        


More information about the llvm-commits mailing list