[PATCH] D106219: [lld/mac] Change load command order to be more like ld64

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 17 08:28:46 PDT 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a reviewer: int3.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
thakis requested review of this revision.

No meaningful behavior change. Makes diffing `otool -l` output a bit easier.


https://reviews.llvm.org/D106219

Files:
  lld/MachO/Writer.cpp
  lld/test/MachO/load-command-sequence.s


Index: lld/test/MachO/load-command-sequence.s
===================================================================
--- lld/test/MachO/load-command-sequence.s
+++ lld/test/MachO/load-command-sequence.s
@@ -43,11 +43,13 @@
 # COMMON: cmd LC_DYSYMTAB
 
 # EXEC: cmd LC_LOAD_DYLINKER
-# EXEC: cmd LC_MAIN
 # DYLIB: cmd LC_ID_DYLIB
 
 # COMMON: cmd LC_UUID
 # COMMON: cmd LC_BUILD_VERSION
+
+# EXEC: cmd LC_MAIN
+
 # COMMON: cmd LC_LOAD_DYLIB
 
 .section __TEXT,__cstring
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -694,10 +694,6 @@
       make<LCDysymtab>(symtabSection, indirectSymtabSection));
   if (!config->umbrella.empty())
     in.header->addLoadCommand(make<LCSubFramework>(config->umbrella));
-  if (functionStartsSection)
-    in.header->addLoadCommand(make<LCFunctionStarts>(functionStartsSection));
-  if (dataInCodeSection)
-    in.header->addLoadCommand(make<LCDataInCode>(dataInCodeSection));
   if (config->emitEncryptionInfo)
     in.header->addLoadCommand(make<LCEncryptionInfo<LP>>());
   for (StringRef path : config->runtimePaths)
@@ -706,7 +702,6 @@
   switch (config->outputType) {
   case MH_EXECUTE:
     in.header->addLoadCommand(make<LCLoadDylinker>());
-    in.header->addLoadCommand(make<LCMain>());
     break;
   case MH_DYLIB:
     in.header->addLoadCommand(make<LCDylib>(LC_ID_DYLIB, config->installName,
@@ -727,6 +722,9 @@
   else
     in.header->addLoadCommand(make<LCMinVersion>(config->platformInfo));
 
+  if (config->outputType == MH_EXECUTE)
+    in.header->addLoadCommand(make<LCMain>());
+
   int64_t dylibOrdinal = 1;
   DenseMap<StringRef, int64_t> ordinalForInstallName;
   for (InputFile *file : inputFiles) {
@@ -793,6 +791,10 @@
     }
   }
 
+  if (functionStartsSection)
+    in.header->addLoadCommand(make<LCFunctionStarts>(functionStartsSection));
+  if (dataInCodeSection)
+    in.header->addLoadCommand(make<LCDataInCode>(dataInCodeSection));
   if (codeSignatureSection)
     in.header->addLoadCommand(make<LCCodeSignature>(codeSignatureSection));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106219.359564.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210717/a640105b/attachment.bin>


More information about the llvm-commits mailing list