[lld] 6323541 - [LLD][ELF] Skip non-SHF_ALLOC sections when checking max VA and max VA difference in relaxOnce() (#145863)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 18:02:09 PDT 2025


Author: Mingjie Xu
Date: 2025-07-01T09:02:06+08:00
New Revision: 6323541a2a56c5632fc3075873fb720e6da1da5c

URL: https://github.com/llvm/llvm-project/commit/6323541a2a56c5632fc3075873fb720e6da1da5c
DIFF: https://github.com/llvm/llvm-project/commit/6323541a2a56c5632fc3075873fb720e6da1da5c.diff

LOG: [LLD][ELF] Skip non-SHF_ALLOC sections when checking max VA and max VA difference in relaxOnce() (#145863)

For non-SHF_ALLOC sections, sh_addr is set to 0.
Skip sections without SHF_ALLOC flag, so `minVA` will not be set to 0
with non-SHF_ALLOC sections, and the size of non-SHF_ALLOC sections will
not contribute to `maxVA`.

Added: 
    

Modified: 
    lld/ELF/Arch/X86_64.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index 163505102d0ec..488f4803b2cb4 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -320,6 +320,8 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file,
 bool X86_64::relaxOnce(int pass) const {
   uint64_t minVA = UINT64_MAX, maxVA = 0;
   for (OutputSection *osec : ctx.outputSections) {
+    if (!(osec->flags & SHF_ALLOC))
+      continue;
     minVA = std::min(minVA, osec->addr);
     maxVA = std::max(maxVA, osec->addr + osec->size);
   }


        


More information about the llvm-commits mailing list