[lld] f79e7a5 - [lld-macho] Have inputOrder default to less than INT_MAX

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 20 16:49:39 PDT 2021


Author: Jez Ng
Date: 2021-06-20T19:49:27-04:00
New Revision: f79e7a5a48181b5d7ff3170f1617e4f7ba8d0fb8

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

LOG: [lld-macho] Have inputOrder default to less than INT_MAX

We make it less than INT_MAX in order not to conflict with the ordering
of zerofill sections, which must always be placed at the end of their
segment.

This is the more structural fix for the issue addressed in {D104596}.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D104607

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/OutputSection.h
    lld/MachO/OutputSegment.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 074695f35cf7f..a162682a5d6cb 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1341,6 +1341,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
           }
         }
       }
+      assert(inputSections.size() < UnspecifiedInputOrder);
     }
 
     if (config->deadStrip)

diff  --git a/lld/MachO/OutputSection.h b/lld/MachO/OutputSection.h
index 45a3b48b6eb71..e3a4f20cbfcd4 100644
--- a/lld/MachO/OutputSection.h
+++ b/lld/MachO/OutputSection.h
@@ -20,6 +20,12 @@ namespace macho {
 class InputSection;
 class OutputSegment;
 
+// The default order value for OutputSections that are not constructed from
+// InputSections (i.e. SyntheticSections). We make it less than INT_MAX in order
+// not to conflict with the ordering of zerofill sections, which must always be
+// placed at the end of their segment.
+constexpr int UnspecifiedInputOrder = std::numeric_limits<int>::max() - 1024;
+
 // Output sections represent the finalized sections present within the final
 // linked executable. They can represent special sections (like the symbol
 // table), or represent coalesced sections from the various inputs given to the
@@ -61,7 +67,7 @@ class OutputSection {
   // For output sections that don't have explicit ordering requirements, their
   // output order should be based on the order of the input sections they
   // contain.
-  int inputOrder = std::numeric_limits<int>::max();
+  int inputOrder = UnspecifiedInputOrder;
 
   uint32_t index = 0;
   uint64_t addr = 0;

diff  --git a/lld/MachO/OutputSegment.h b/lld/MachO/OutputSegment.h
index 10cca2a1caad3..cd1fabbc7cf30 100644
--- a/lld/MachO/OutputSegment.h
+++ b/lld/MachO/OutputSegment.h
@@ -51,7 +51,7 @@ class OutputSegment {
   uint64_t fileOff = 0;
   uint64_t fileSize = 0;
   uint64_t vmSize = 0;
-  int inputOrder = std::numeric_limits<int>::max();
+  int inputOrder = UnspecifiedInputOrder;
   StringRef name;
   uint32_t maxProt = 0;
   uint32_t initProt = 0;


        


More information about the llvm-commits mailing list