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

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 20 15:13:23 PDT 2021


int3 created this revision.
int3 added reviewers: lld-macho, thakis.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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: [lld/mac] Make sure __thread_ptrs is in front of __thread_bss <https://reviews.llvm.org/D104596>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104607

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


Index: lld/MachO/OutputSegment.h
===================================================================
--- lld/MachO/OutputSegment.h
+++ lld/MachO/OutputSegment.h
@@ -51,7 +51,7 @@
   uint64_t fileOff = 0;
   uint64_t fileSize = 0;
   uint64_t vmSize = 0;
-  int inputOrder = std::numeric_limits<int>::max();
+  int inputOrder = UNSPECIFIED_INPUT_ORDER;
   StringRef name;
   uint32_t maxProt = 0;
   uint32_t initProt = 0;
Index: lld/MachO/OutputSection.h
===================================================================
--- lld/MachO/OutputSection.h
+++ lld/MachO/OutputSection.h
@@ -20,6 +20,12 @@
 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 UNSPECIFIED_INPUT_ORDER = 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 @@
   // 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 = UNSPECIFIED_INPUT_ORDER;
 
   uint32_t index = 0;
   uint64_t addr = 0;
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1341,6 +1341,7 @@
           }
         }
       }
+      assert(inputSections.size() < UNSPECIFIED_INPUT_ORDER);
     }
 
     if (config->deadStrip)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104607.353245.patch
Type: text/x-patch
Size: 1879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210620/01dee634/attachment.bin>


More information about the llvm-commits mailing list