Skip to content

Commit bcbb306

Browse files
committed
[lld/mac] Change load command order to be more like ld64
No meaningful behavior change. Makes diffing `otool -l` output a bit easier. Differential Revision: https://reviews.llvm.org/D106219
1 parent a2cc67e commit bcbb306

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lld/MachO/Writer.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,6 @@ template <class LP> void Writer::createLoadCommands() {
690690
make<LCDysymtab>(symtabSection, indirectSymtabSection));
691691
if (!config->umbrella.empty())
692692
in.header->addLoadCommand(make<LCSubFramework>(config->umbrella));
693-
if (functionStartsSection)
694-
in.header->addLoadCommand(make<LCFunctionStarts>(functionStartsSection));
695-
if (dataInCodeSection)
696-
in.header->addLoadCommand(make<LCDataInCode>(dataInCodeSection));
697693
if (config->emitEncryptionInfo)
698694
in.header->addLoadCommand(make<LCEncryptionInfo<LP>>());
699695
for (StringRef path : config->runtimePaths)
@@ -702,7 +698,6 @@ template <class LP> void Writer::createLoadCommands() {
702698
switch (config->outputType) {
703699
case MH_EXECUTE:
704700
in.header->addLoadCommand(make<LCLoadDylinker>());
705-
in.header->addLoadCommand(make<LCMain>());
706701
break;
707702
case MH_DYLIB:
708703
in.header->addLoadCommand(make<LCDylib>(LC_ID_DYLIB, config->installName,
@@ -723,6 +718,10 @@ template <class LP> void Writer::createLoadCommands() {
723718
else
724719
in.header->addLoadCommand(make<LCMinVersion>(config->platformInfo));
725720

721+
// This is down here to match ld64's load command order.
722+
if (config->outputType == MH_EXECUTE)
723+
in.header->addLoadCommand(make<LCMain>());
724+
726725
int64_t dylibOrdinal = 1;
727726
DenseMap<StringRef, int64_t> ordinalForInstallName;
728727
for (InputFile *file : inputFiles) {
@@ -789,6 +788,10 @@ template <class LP> void Writer::createLoadCommands() {
789788
}
790789
}
791790

791+
if (functionStartsSection)
792+
in.header->addLoadCommand(make<LCFunctionStarts>(functionStartsSection));
793+
if (dataInCodeSection)
794+
in.header->addLoadCommand(make<LCDataInCode>(dataInCodeSection));
792795
if (codeSignatureSection)
793796
in.header->addLoadCommand(make<LCCodeSignature>(codeSignatureSection));
794797

lld/test/MachO/load-command-sequence.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
# COMMON: cmd LC_DYSYMTAB
4444

4545
# EXEC: cmd LC_LOAD_DYLINKER
46-
# EXEC: cmd LC_MAIN
4746
# DYLIB: cmd LC_ID_DYLIB
4847

4948
# COMMON: cmd LC_UUID
5049
# COMMON: cmd LC_BUILD_VERSION
50+
51+
# EXEC: cmd LC_MAIN
52+
5153
# COMMON: cmd LC_LOAD_DYLIB
5254

5355
.section __TEXT,__cstring

0 commit comments

Comments
 (0)