Skip to content

[llvm-objcopy][MachO] Align __LINKEDIT entries to pointer size - #203680

Merged
drodriguez merged 1 commit into
llvm:mainfrom
goranmoomin:llvm-objcopy-macho-linkedit-align
Jun 20, 2026
Merged

drodriguez merged 1 commit into
llvm:mainfrom
goranmoomin:llvm-objcopy-macho-linkedit-align

Conversation

@goranmoomin

@goranmoomin goranmoomin commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Align Mach-O __LINKEDIT entries to the target pointer size when building the tail layout. This matches the behavior of ld64 and lld-macho.

dyld on macOS 27 rejects loading dylibs with misaligned __LINKEDIT entries.

See #203678 for details and the motivation of this fix.

AI Tool Use Disclosure:

Regarding the PR and the linked issue, I have personally wrote every single part of the PR by myself, and have/ran/verified every single part of the issue report as well without any AI tool usage.

I have used LLM-based coding agents only for debugging purposes, e.g. to figure out why the dylib was not loading (from the original bug report), and figuring out how to build, run, and test my local llvm-objcopy.

@github-actions

Copy link
Copy Markdown

Hello @goranmoomin 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-llvm-binary-utilities

Author: Sungbin Jo (goranmoomin)

Changes

Align Mach-O __LINKEDIT entries to the target pointer size when building the tail layout. This matches the behavior of ld64 and lld-macho.

dyld on macOS 27 rejects loading dylibs with misaligned __LINKEDIT entries.

See #203678 for the motivation of this fix.


Patch is 23.83 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/203680.diff

6 Files Affected:

  • (modified) llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp (+51-35)
  • (modified) llvm/lib/ObjCopy/MachO/MachOObject.h (+25)
  • (modified) llvm/lib/ObjCopy/MachO/MachOWriter.cpp (+12-12)
  • (modified) llvm/test/tools/llvm-objcopy/MachO/linkedit-order-1.test (+12-11)
  • (modified) llvm/test/tools/llvm-objcopy/MachO/linkedit-order-2.test (+9-8)
  • (modified) llvm/test/tools/llvm-objcopy/MachO/symbol-table.test (+2-2)
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 8660c903c617d..2f720454dc609 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
+#include <utility>
 
 using namespace llvm;
 using namespace llvm::objcopy::macho;
@@ -235,18 +236,20 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) {
          "Incorrect tail offset");
   Offset = std::max(Offset, HeaderSize + O.Header.SizeOfCmds);
 
+  const uint64_t LinkEditAlign = Is64Bit ? 8 : 4;
+
   // The exports trie can be in either LC_DYLD_INFO or in
   // LC_DYLD_EXPORTS_TRIE, but not both.
-  size_t DyldInfoExportsTrieSize = 0;
-  size_t DyldExportsTrieSize = 0;
+  uint64_t DyldInfoExportsTrieSize = 0;
+  uint64_t DyldExportsTrieSize = 0;
   for (const auto &LC : O.LoadCommands) {
     switch (LC.MachOLoadCommand.load_command_data.cmd) {
     case MachO::LC_DYLD_INFO:
     case MachO::LC_DYLD_INFO_ONLY:
-      DyldInfoExportsTrieSize = O.Exports.Trie.size();
+      DyldInfoExportsTrieSize = O.Exports.getSize(LinkEditAlign);
       break;
     case MachO::LC_DYLD_EXPORTS_TRIE:
-      DyldExportsTrieSize = O.Exports.Trie.size();
+      DyldExportsTrieSize = O.Exports.getSize(LinkEditAlign);
       break;
     default:
       break;
@@ -263,28 +266,42 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) {
   // trie, chained fixups, dyld exports trie, function starts, data-in-code,
   // symbol table, indirect symbol table, symbol table strings,
   // dylib codesign drs, and code signature.
-  auto updateOffset = [&Offset](size_t Size) {
+  auto updateOffset = [&Offset, LinkEditAlign](uint64_t Size) {
+    Offset = alignTo(Offset, LinkEditAlign);
     uint64_t PreviousOffset = Offset;
-    Offset += Size;
-    return PreviousOffset;
+    uint64_t PaddedSize = alignTo(Size, LinkEditAlign);
+    Offset += PaddedSize;
+    return std::make_pair(PreviousOffset, PaddedSize);
   };
 
-  uint64_t StartOfRebaseInfo = updateOffset(O.Rebases.Opcodes.size());
-  uint64_t StartOfBindingInfo = updateOffset(O.Binds.Opcodes.size());
-  uint64_t StartOfWeakBindingInfo = updateOffset(O.WeakBinds.Opcodes.size());
-  uint64_t StartOfLazyBindingInfo = updateOffset(O.LazyBinds.Opcodes.size());
-  uint64_t StartOfExportTrie = updateOffset(DyldInfoExportsTrieSize);
-  uint64_t StartOfChainedFixups = updateOffset(O.ChainedFixups.Data.size());
-  uint64_t StartOfDyldExportsTrie = updateOffset(DyldExportsTrieSize);
-  uint64_t StartOfFunctionStarts = updateOffset(O.FunctionStarts.Data.size());
-  uint64_t StartOfDataInCode = updateOffset(O.DataInCode.Data.size());
-  uint64_t StartOfLinkerOptimizationHint =
-      updateOffset(O.LinkerOptimizationHint.Data.size());
-  uint64_t StartOfSymbols = updateOffset(NListSize * O.SymTable.Symbols.size());
+  auto [StartOfRebaseInfo, RebaseInfoSize] =
+      updateOffset(O.Rebases.getSize(LinkEditAlign));
+  auto [StartOfBindingInfo, BindingInfoSize] =
+      updateOffset(O.Binds.getSize(LinkEditAlign));
+  auto [StartOfWeakBindingInfo, WeakBindingInfoSize] =
+      updateOffset(O.WeakBinds.getSize(LinkEditAlign));
+  auto [StartOfLazyBindingInfo, LazyBindingInfoSize] =
+      updateOffset(O.LazyBinds.getSize(LinkEditAlign));
+  auto [StartOfExportTrie, ExportTrieSize] =
+      updateOffset(DyldInfoExportsTrieSize);
+  auto [StartOfChainedFixups, ChainedFixupsSize] =
+      updateOffset(O.ChainedFixups.getSize(LinkEditAlign));
+  auto [StartOfDyldExportsTrie, DyldExportsTrieSizeOut] =
+      updateOffset(DyldExportsTrieSize);
+  auto [StartOfFunctionStarts, FunctionStartsSize] =
+      updateOffset(O.FunctionStarts.getSize(LinkEditAlign));
+  auto [StartOfDataInCode, DataInCodeSize] =
+      updateOffset(O.DataInCode.getSize(LinkEditAlign));
+  auto [StartOfLinkerOptimizationHint, LinkerOptimizationHintSize] =
+      updateOffset(O.LinkerOptimizationHint.getSize(LinkEditAlign));
+  uint64_t StartOfSymbols =
+      updateOffset(NListSize * O.SymTable.Symbols.size()).first;
   uint64_t StartOfIndirectSymbols =
-      updateOffset(sizeof(uint32_t) * O.IndirectSymTable.Symbols.size());
-  uint64_t StartOfSymbolStrings = updateOffset(StrTableBuilder.getSize());
-  uint64_t StartOfDylibCodeSignDRs = updateOffset(O.DylibCodeSignDRs.Data.size());
+      updateOffset(sizeof(uint32_t) * O.IndirectSymTable.Symbols.size()).first;
+  auto [StartOfSymbolStrings, SymbolStringsSize] =
+      updateOffset(StrTableBuilder.getSize());
+  auto [StartOfDylibCodeSignDRs, DylibCodeSignDRsSize] =
+      updateOffset(O.DylibCodeSignDRs.getSize(LinkEditAlign));
 
   uint64_t StartOfCodeSignature = Offset;
   uint32_t CodeSignatureSize = 0;
@@ -343,13 +360,13 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) {
       break;
     case MachO::LC_DYLIB_CODE_SIGN_DRS:
       MLC.linkedit_data_command_data.dataoff = StartOfDylibCodeSignDRs;
-      MLC.linkedit_data_command_data.datasize = O.DylibCodeSignDRs.Data.size();
+      MLC.linkedit_data_command_data.datasize = DylibCodeSignDRsSize;
       break;
     case MachO::LC_SYMTAB:
       MLC.symtab_command_data.symoff = StartOfSymbols;
       MLC.symtab_command_data.nsyms = O.SymTable.Symbols.size();
       MLC.symtab_command_data.stroff = StartOfSymbolStrings;
-      MLC.symtab_command_data.strsize = StrTableBuilder.getSize();
+      MLC.symtab_command_data.strsize = SymbolStringsSize;
       break;
     case MachO::LC_DYSYMTAB: {
       if (MLC.dysymtab_command_data.ntoc != 0 ||
@@ -368,42 +385,41 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) {
     }
     case MachO::LC_DATA_IN_CODE:
       MLC.linkedit_data_command_data.dataoff = StartOfDataInCode;
-      MLC.linkedit_data_command_data.datasize = O.DataInCode.Data.size();
+      MLC.linkedit_data_command_data.datasize = DataInCodeSize;
       break;
     case MachO::LC_LINKER_OPTIMIZATION_HINT:
       MLC.linkedit_data_command_data.dataoff = StartOfLinkerOptimizationHint;
-      MLC.linkedit_data_command_data.datasize =
-          O.LinkerOptimizationHint.Data.size();
+      MLC.linkedit_data_command_data.datasize = LinkerOptimizationHintSize;
       break;
     case MachO::LC_FUNCTION_STARTS:
       MLC.linkedit_data_command_data.dataoff = StartOfFunctionStarts;
-      MLC.linkedit_data_command_data.datasize = O.FunctionStarts.Data.size();
+      MLC.linkedit_data_command_data.datasize = FunctionStartsSize;
       break;
     case MachO::LC_DYLD_CHAINED_FIXUPS:
       MLC.linkedit_data_command_data.dataoff = StartOfChainedFixups;
-      MLC.linkedit_data_command_data.datasize = O.ChainedFixups.Data.size();
+      MLC.linkedit_data_command_data.datasize = ChainedFixupsSize;
       break;
     case MachO::LC_DYLD_EXPORTS_TRIE:
       MLC.linkedit_data_command_data.dataoff = StartOfDyldExportsTrie;
-      MLC.linkedit_data_command_data.datasize = DyldExportsTrieSize;
+      MLC.linkedit_data_command_data.datasize = DyldExportsTrieSizeOut;
       break;
     case MachO::LC_DYLD_INFO:
     case MachO::LC_DYLD_INFO_ONLY:
       MLC.dyld_info_command_data.rebase_off =
           O.Rebases.Opcodes.empty() ? 0 : StartOfRebaseInfo;
-      MLC.dyld_info_command_data.rebase_size = O.Rebases.Opcodes.size();
+      MLC.dyld_info_command_data.rebase_size = RebaseInfoSize;
       MLC.dyld_info_command_data.bind_off =
           O.Binds.Opcodes.empty() ? 0 : StartOfBindingInfo;
-      MLC.dyld_info_command_data.bind_size = O.Binds.Opcodes.size();
+      MLC.dyld_info_command_data.bind_size = BindingInfoSize;
       MLC.dyld_info_command_data.weak_bind_off =
           O.WeakBinds.Opcodes.empty() ? 0 : StartOfWeakBindingInfo;
-      MLC.dyld_info_command_data.weak_bind_size = O.WeakBinds.Opcodes.size();
+      MLC.dyld_info_command_data.weak_bind_size = WeakBindingInfoSize;
       MLC.dyld_info_command_data.lazy_bind_off =
           O.LazyBinds.Opcodes.empty() ? 0 : StartOfLazyBindingInfo;
-      MLC.dyld_info_command_data.lazy_bind_size = O.LazyBinds.Opcodes.size();
+      MLC.dyld_info_command_data.lazy_bind_size = LazyBindingInfoSize;
       MLC.dyld_info_command_data.export_off =
           O.Exports.Trie.empty() ? 0 : StartOfExportTrie;
-      MLC.dyld_info_command_data.export_size = DyldInfoExportsTrieSize;
+      MLC.dyld_info_command_data.export_size = ExportTrieSize;
       break;
     // Note that LC_ENCRYPTION_INFO.cryptoff despite its name and the comment in
     // <mach-o/loader.h> is not an offset in the binary file, instead, it is a
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.h b/llvm/lib/ObjCopy/MachO/MachOObject.h
index 86c6b120fa6c3..8ea5c01c466fe 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.h
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.h
@@ -13,6 +13,7 @@
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/ObjectYAML/DWARFYAML.h"
+#include "llvm/Support/Alignment.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/YAMLTraits.h"
 #include <cstdint>
@@ -213,6 +214,10 @@ struct RebaseInfo {
   // At the moment we do not parse this info (and it is simply copied over),
   // but the proper support will be added later.
   ArrayRef<uint8_t> Opcodes;
+
+  uint64_t getSize(uint64_t Alignment) const {
+    return alignTo(Opcodes.size(), Alignment);
+  }
 };
 
 /// The location of the bind info inside the binary is described by
@@ -229,6 +234,10 @@ struct BindInfo {
   // At the moment we do not parse this info (and it is simply copied over),
   // but the proper support will be added later.
   ArrayRef<uint8_t> Opcodes;
+
+  uint64_t getSize(uint64_t Alignment) const {
+    return alignTo(Opcodes.size(), Alignment);
+  }
 };
 
 /// The location of the weak bind info inside the binary is described by
@@ -247,6 +256,10 @@ struct WeakBindInfo {
   // At the moment we do not parse this info (and it is simply copied over),
   // but the proper support will be added later.
   ArrayRef<uint8_t> Opcodes;
+
+  uint64_t getSize(uint64_t Alignment) const {
+    return alignTo(Opcodes.size(), Alignment);
+  }
 };
 
 /// The location of the lazy bind info inside the binary is described by
@@ -260,6 +273,10 @@ struct WeakBindInfo {
 /// to lazy_bind_off to get the information on what to bind.
 struct LazyBindInfo {
   ArrayRef<uint8_t> Opcodes;
+
+  uint64_t getSize(uint64_t Alignment) const {
+    return alignTo(Opcodes.size(), Alignment);
+  }
 };
 
 /// The location of the export info inside the binary is described by
@@ -290,10 +307,18 @@ struct LazyBindInfo {
 /// edge points to.
 struct ExportInfo {
   ArrayRef<uint8_t> Trie;
+
+  uint64_t getSize(uint64_t Alignment) const {
+    return alignTo(Trie.size(), Alignment);
+  }
 };
 
 struct LinkData {
   ArrayRef<uint8_t> Data;
+
+  uint64_t getSize(uint64_t Alignment) const {
+    return alignTo(Data.size(), Alignment);
+  }
 };
 
 struct Object {
diff --git a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
index 07514dd2f8d6a..911e22927e559 100644
--- a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
@@ -55,29 +55,29 @@ size_t MachOWriter::totalSize() const {
         O.LoadCommands[*O.DyLdInfoCommandIndex]
             .MachOLoadCommand.dyld_info_command_data;
     if (DyLdInfoCommand.rebase_off) {
-      assert((DyLdInfoCommand.rebase_size == O.Rebases.Opcodes.size()) &&
+      assert((DyLdInfoCommand.rebase_size >= O.Rebases.Opcodes.size()) &&
              "Incorrect rebase opcodes size");
       Ends.push_back(DyLdInfoCommand.rebase_off + DyLdInfoCommand.rebase_size);
     }
     if (DyLdInfoCommand.bind_off) {
-      assert((DyLdInfoCommand.bind_size == O.Binds.Opcodes.size()) &&
+      assert((DyLdInfoCommand.bind_size >= O.Binds.Opcodes.size()) &&
              "Incorrect bind opcodes size");
       Ends.push_back(DyLdInfoCommand.bind_off + DyLdInfoCommand.bind_size);
     }
     if (DyLdInfoCommand.weak_bind_off) {
-      assert((DyLdInfoCommand.weak_bind_size == O.WeakBinds.Opcodes.size()) &&
+      assert((DyLdInfoCommand.weak_bind_size >= O.WeakBinds.Opcodes.size()) &&
              "Incorrect weak bind opcodes size");
       Ends.push_back(DyLdInfoCommand.weak_bind_off +
                      DyLdInfoCommand.weak_bind_size);
     }
     if (DyLdInfoCommand.lazy_bind_off) {
-      assert((DyLdInfoCommand.lazy_bind_size == O.LazyBinds.Opcodes.size()) &&
+      assert((DyLdInfoCommand.lazy_bind_size >= O.LazyBinds.Opcodes.size()) &&
              "Incorrect lazy bind opcodes size");
       Ends.push_back(DyLdInfoCommand.lazy_bind_off +
                      DyLdInfoCommand.lazy_bind_size);
     }
     if (DyLdInfoCommand.export_off) {
-      assert((DyLdInfoCommand.export_size == O.Exports.Trie.size()) &&
+      assert((DyLdInfoCommand.export_size >= O.Exports.Trie.size()) &&
              "Incorrect trie size");
       Ends.push_back(DyLdInfoCommand.export_off + DyLdInfoCommand.export_size);
     }
@@ -320,7 +320,7 @@ void MachOWriter::writeRebaseInfo() {
       O.LoadCommands[*O.DyLdInfoCommandIndex]
           .MachOLoadCommand.dyld_info_command_data;
   char *Out = Buf->getBufferStart() + DyLdInfoCommand.rebase_off;
-  assert((DyLdInfoCommand.rebase_size == O.Rebases.Opcodes.size()) &&
+  assert((DyLdInfoCommand.rebase_size >= O.Rebases.Opcodes.size()) &&
          "Incorrect rebase opcodes size");
   memcpy(Out, O.Rebases.Opcodes.data(), O.Rebases.Opcodes.size());
 }
@@ -332,7 +332,7 @@ void MachOWriter::writeBindInfo() {
       O.LoadCommands[*O.DyLdInfoCommandIndex]
           .MachOLoadCommand.dyld_info_command_data;
   char *Out = Buf->getBufferStart() + DyLdInfoCommand.bind_off;
-  assert((DyLdInfoCommand.bind_size == O.Binds.Opcodes.size()) &&
+  assert((DyLdInfoCommand.bind_size >= O.Binds.Opcodes.size()) &&
          "Incorrect bind opcodes size");
   memcpy(Out, O.Binds.Opcodes.data(), O.Binds.Opcodes.size());
 }
@@ -344,7 +344,7 @@ void MachOWriter::writeWeakBindInfo() {
       O.LoadCommands[*O.DyLdInfoCommandIndex]
           .MachOLoadCommand.dyld_info_command_data;
   char *Out = Buf->getBufferStart() + DyLdInfoCommand.weak_bind_off;
-  assert((DyLdInfoCommand.weak_bind_size == O.WeakBinds.Opcodes.size()) &&
+  assert((DyLdInfoCommand.weak_bind_size >= O.WeakBinds.Opcodes.size()) &&
          "Incorrect weak bind opcodes size");
   memcpy(Out, O.WeakBinds.Opcodes.data(), O.WeakBinds.Opcodes.size());
 }
@@ -356,7 +356,7 @@ void MachOWriter::writeLazyBindInfo() {
       O.LoadCommands[*O.DyLdInfoCommandIndex]
           .MachOLoadCommand.dyld_info_command_data;
   char *Out = Buf->getBufferStart() + DyLdInfoCommand.lazy_bind_off;
-  assert((DyLdInfoCommand.lazy_bind_size == O.LazyBinds.Opcodes.size()) &&
+  assert((DyLdInfoCommand.lazy_bind_size >= O.LazyBinds.Opcodes.size()) &&
          "Incorrect lazy bind opcodes size");
   memcpy(Out, O.LazyBinds.Opcodes.data(), O.LazyBinds.Opcodes.size());
 }
@@ -368,7 +368,7 @@ void MachOWriter::writeExportInfo() {
       O.LoadCommands[*O.DyLdInfoCommandIndex]
           .MachOLoadCommand.dyld_info_command_data;
   char *Out = Buf->getBufferStart() + DyLdInfoCommand.export_off;
-  assert((DyLdInfoCommand.export_size == O.Exports.Trie.size()) &&
+  assert((DyLdInfoCommand.export_size >= O.Exports.Trie.size()) &&
          "Incorrect export trie size");
   memcpy(Out, O.Exports.Trie.data(), O.Exports.Trie.size());
 }
@@ -398,7 +398,7 @@ void MachOWriter::writeLinkData(std::optional<size_t> LCIndex,
   const MachO::linkedit_data_command &LinkEditDataCommand =
       O.LoadCommands[*LCIndex].MachOLoadCommand.linkedit_data_command_data;
   char *Out = Buf->getBufferStart() + LinkEditDataCommand.dataoff;
-  assert((LinkEditDataCommand.datasize == LD.Data.size()) &&
+  assert((LinkEditDataCommand.datasize >= LD.Data.size()) &&
          "Incorrect data size");
   memcpy(Out, LD.Data.data(), LD.Data.size());
 }
@@ -575,7 +575,7 @@ void MachOWriter::writeExportsTrieData() {
       O.LoadCommands[*O.ExportsTrieCommandIndex]
           .MachOLoadCommand.linkedit_data_command_data;
   char *Out = Buf->getBufferStart() + ExportsTrieCmd.dataoff;
-  assert((ExportsTrieCmd.datasize == O.Exports.Trie.size()) &&
+  assert((ExportsTrieCmd.datasize >= O.Exports.Trie.size()) &&
          "Incorrect export trie size");
   memcpy(Out, O.Exports.Trie.data(), O.Exports.Trie.size());
 }
diff --git a/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-1.test b/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-1.test
index 4915f344c1e7e..1ca55ba46be74 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-1.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-1.test
@@ -14,24 +14,25 @@
 # CHECK: fileoff:         [[#LINKEDIT_FILEOFF:]]
 # CHECK: filesize:        [[#LINKEDIT_FILESIZE:]]
 
+## LINKEDIT entries are aligned to the target word size.
 # CHECK: cmd:             LC_DYLD_INFO_ONLY
-# CHECK: rebase_off:      [[#REBASE_OFF: LINKEDIT_FILEOFF]]
+# CHECK: rebase_off:      [[#REBASE_OFF: mul(div(LINKEDIT_FILEOFF + 7, 8), 8)]]
 # CHECK: rebase_size:     [[#REBASE_SIZE:]]
-# CHECK: bind_off:        [[#BIND_OFF: REBASE_OFF + REBASE_SIZE]]
+# CHECK: bind_off:        [[#BIND_OFF: mul(div(REBASE_OFF + REBASE_SIZE + 7, 8), 8)]]
 # CHECK: bind_size:       [[#BIND_SIZE:]]
-# CHECK: weak_bind_off:   [[#WEAK_BIND_OFF: BIND_OFF + BIND_SIZE]]
+# CHECK: weak_bind_off:   [[#WEAK_BIND_OFF: mul(div(BIND_OFF + BIND_SIZE + 7, 8), 8)]]
 # CHECK: weak_bind_size:  [[#WEAK_BIND_SIZE:]]
-# CHECK: lazy_bind_off:   [[#LAZY_BIND_OFF: WEAK_BIND_OFF + WEAK_BIND_SIZE]]
+# CHECK: lazy_bind_off:   [[#LAZY_BIND_OFF: mul(div(WEAK_BIND_OFF + WEAK_BIND_SIZE + 7, 8), 8)]]
 # CHECK: lazy_bind_size:  [[#LAZY_BIND_SIZE:]]
-# CHECK: export_off:      [[#EXPORTS_OFF:LAZY_BIND_OFF + LAZY_BIND_SIZE]]
+# CHECK: export_off:      [[#EXPORTS_OFF: mul(div(LAZY_BIND_OFF + LAZY_BIND_SIZE + 7, 8), 8)]]
 # CHECK: export_size:     [[#EXPORTS_SIZE:]]
 
 # CHECK: cmd:             LC_FUNCTION_STARTS
-# CHECK: dataoff:         [[#FUNCTION_STARTS_FILEOFF: EXPORTS_OFF + EXPORTS_SIZE]]
+# CHECK: dataoff:         [[#FUNCTION_STARTS_FILEOFF: mul(div(EXPORTS_OFF + EXPORTS_SIZE + 7, 8), 8)]]
 # CHECK: datasize:        [[#FUNCTION_STARTS_FILESIZE:]]
 
 # CHECK: cmd:             LC_DATA_IN_CODE
-# CHECK: dataoff:         [[#DATA_IN_CODE_FILEOFF: FUNCTION_STARTS_FILEOFF + FUNCTION_STARTS_FILESIZE]]
+# CHECK: dataoff:         [[#DATA_IN_CODE_FILEOFF: mul(div(FUNCTION_STARTS_FILEOFF + FUNCTION_STARTS_FILESIZE + 7, 8), 8)]]
 # CHECK: datasize:        [[#DATA_IN_CODE_FILESIZE:]]
 
 ## Jump over LC_CODE_SIGNATURE, which needs to be checked last
@@ -39,24 +40,24 @@
 # CHECK: --- !mach-o
 
 # CHECK: cmd:             LC_SYMTAB
-# CHECK: symoff:          [[#SYMTAB_SYMOFF: DATA_IN_CODE_FILEOFF + DATA_IN_CODE_FILESIZE]]
+# CHECK: symoff:          [[#SYMTAB_SYMOFF: mul(div(DATA_IN_CODE_FILEOFF + DATA_IN_CODE_FILESIZE + 7, 8), 8)]]
 # CHECK: nsyms:           [[#SYMTAB_NSYMS:]]
 
 ## Skip over the strings table offset/size (part of LC_SYMTAB) until next loop.
 
 # CHECK: cmd:             LC_DYSYMTAB
-# CHECK: indirectsymoff:  [[#DYSYMTAB_INDIRECTSYMOFF: SYMTAB_SYMOFF + mul(SYMTAB_NSYMS, 16)]]
+# CHECK: indirectsymoff:  [[#DYSYMTAB_INDIRECTSYMOFF: mul(div(SYMTAB_SYMOFF + mul(SYMTAB_NSYMS, 16) + 7, 8), 8)]]
 # CHECK: nindirectsyms:   [[#DYSYMTAB_NINDIRECTSYMS:]]
 
 # CHECK: --- !mach-o
 
 # CHECK: cmd:             LC_SYMTAB
-# CHECK: stroff:          [[#SYMTAB_STROFF: DYSYMTAB_INDIRECTSYMOFF + mul(DYSYMTAB_NINDIRECTSYMS, 4)]]
+# CHECK: stroff:          [[#SYMTAB_STROFF: mul(div(DYSYMTAB_INDIRECTSYMOFF + mul(DYSYMTAB_NINDIRECTSYMS, 4) + 7, 8), 8)]]
 # CHECK: strsize:         [[#SYMTAB_STRSIZE:]]
 
 # CHECK: cmd:             LC_CODE_SIGNATURE
 ## LC_CODE_SIGNATURE needs to be aligned to 16 bytes boundaries.
-# CHECK: dataoff:         [[#CODE_SIGNATURE_FILEOFF: mul(div(SYMTAB_STROFF + SYMTAB_STRSIZE + 8, 16), 16)]]
+# CHECK: dataoff:         [[#CODE_SIGNATURE_FILEOFF: mul(div(SYMTAB_STROFF + SYMTAB_STRSIZE + 15, 16), 16)]]
 # CHECK: datasize:        [[#CODE_SIGNATURE_FILESIZE:LINKEDIT_FILEOFF + LINKEDIT_FILESIZE - CODE_SIGNATURE_FILEOFF]]
 
 --- !mach-o
diff --git a/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-2.test b/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-2.test
index 0c5521ece0e44..3ed61e301d841 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-2.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/linkedit-order-2.test
@@ -1...
[truncated]

@goranmoomin

Copy link
Copy Markdown
Contributor Author

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.

Yes, I did.

@jh7370 jh7370 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not looked in detail at the testing as much of it goes over my head due to a lack of Mach-O knowledge, but I did want to check, is there testing for both 4 byte and 8 byte alignment cases?

I'll add a few reviewers to help check the Mach-O specifics of this PR.

Comment thread llvm/lib/ObjCopy/MachO/MachOObject.h Resolved

@alexander-shaposhnikov alexander-shaposhnikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@goranmoomin
goranmoomin force-pushed the llvm-objcopy-macho-linkedit-align branch 2 times, most recently from 9c7af73 to 491d100 Compare June 15, 2026 13:51
@goranmoomin

Copy link
Copy Markdown
Contributor Author

Is there testing for both 4 byte and 8 byte alignment cases?

So the two linkedit-order-*.test files are updated to match behavior so that LINKEDIT entries that are followed by other entries without a size field are also aligned (as it should have been).

I wanted to introduce a new test that verifies that all sections are aligned per word size (in both architectures), but currently struggling in that mostly because I'm not sure how to check whether a variable is 4/8-byte aligned (i.e. mod 8 == 0) in FileCheck.

@goranmoomin
goranmoomin force-pushed the llvm-objcopy-macho-linkedit-align branch from 491d100 to 52dd986 Compare June 15, 2026 15:25
@goranmoomin

Copy link
Copy Markdown
Contributor Author

I added a linkedit-alignment.test test case for checking the alignment for both cases.

@drodriguez drodriguez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the end result is good, but I think some changes might make the intention of the code a little bit clearer.

Comment thread llvm/lib/ObjCopy/MachO/MachOObject.cpp Resolved
@goranmoomin
goranmoomin force-pushed the llvm-objcopy-macho-linkedit-align branch 4 times, most recently from 9a12a6c to e2b59f5 Compare June 15, 2026 20:57

@drodriguez drodriguez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goranmoomin : for next time, please reference https://llvm.org/docs/GitHub.html#updating-pull-requests about updating PRs. The review is easier if you push new commits. Things can be squashed together when merging or before merge, when the review has already been done.

That said, it looks like the branch might need some update to be merged with main according to the warning, so feel free to rebase into a recent main.

LGTM otherwise.

PD: I did not realize the asserts were checking against the calculated padded size. Not aweseome, but no easy way to avoid. I think paddedLinkEditEntrySize is a good solution for that. Makes it clear what's happening, and should provide consistent values.

@goranmoomin
goranmoomin force-pushed the llvm-objcopy-macho-linkedit-align branch from e2b59f5 to b96854b Compare June 16, 2026 17:08
@goranmoomin

goranmoomin commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor Author

for next time, please reference llvm.org/docs/GitHub.html#updating-pull-requests about updating PRs.

Was not aware of the PR conventions for llvm, sorry for that! Will do as instructed next time.

feel free to rebase into a recent main.

Updated!

Align Mach-O __LINKEDIT entries to the target pointer size when
building the tail layout. This matches the behavior of ld64 and
lld-macho.

dyld on macOS 27 rejects loading dylibs with misaligned __LINKEDIT
entries.
@goranmoomin
goranmoomin force-pushed the llvm-objcopy-macho-linkedit-align branch from b96854b to 5823523 Compare June 19, 2026 03:31
@goranmoomin

Copy link
Copy Markdown
Contributor Author

Rebased again on a recent main.

I'm not really familiar with the llvm contributing process, is the merging of this patch blocked by the remaining reviewer, or do I have to take some action to proceed? Or should I just wait?

@drodriguez
drodriguez enabled auto-merge (squash) June 20, 2026 19:12
@drodriguez

Copy link
Copy Markdown
Contributor

I'm not really familiar with the llvm contributing process, is the merging of this patch blocked by the remaining reviewer, or do I have to take some action to proceed? Or should I just wait?

I was leaving the PR open for review by other people, and then I forgot about it. Started the CI checks and set it to auto-merge if they pass. Sorry about that.

@drodriguez
drodriguez merged commit 18c1cbc into llvm:main Jun 20, 2026
10 of 11 checks passed
@github-actions

Copy link
Copy Markdown

@goranmoomin Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

drodriguez added a commit that referenced this pull request Jun 20, 2026
During the review of #203680 I noticed that Mach-O objcopy files seems
to use `alignTo` and import `Alignment.h` to align some offsets to page
boundaries and similar requirements. However, the `alignTo` in
`Alignment.h`, while being intended for powers of 2, requires using an
alignment of type `llvm::Align`, and needs explicit conversion from
`uint64_t` and similar. Single `Alignment.h` includes `MathExtras.h`,
the `alignTo` being invoked ends up being a generic `alignTo` that does
not require powers of 2, and perform divisions and multiplications.
While some of those might be optimized by the compiler into efficient
power of 2 operations, there's an explicit `alignToPowerOf2` version
that is optimized and asserts the alignment is a power of 2 (with
asserts enabled). Since all the alignments should be power of 2 for the
Mach-O binary format, change from `alignTo` to `alignToPowerOf2` to make
the fact more visible (and get the extra safety net of the assertions).

As expected, the test suite of objcopy doesn't show any regressions, but
I have not done a performance benchmark around this either.
@goranmoomin
goranmoomin deleted the llvm-objcopy-macho-linkedit-align branch June 22, 2026 06:18
@rorth

rorth commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This patch broke the Solaris/sparcv9 buildbot. Most likely an endianess issue.

@goranmoomin

Copy link
Copy Markdown
Contributor Author

This patch broke the Solaris/sparcv9 buildbot. Most likely an endianess issue.

PR #205044 should address the failures on the sparcv9 and s390x buildbots. Seems like a bug in yaml2obj.

drodriguez pushed a commit that referenced this pull request Jun 22, 2026
This is a follow-up of PR #203680 that added the test case
`linkedit-alignment.test`, which currently fails on big-endian buildbots
(see: https://lab.llvm.org/buildbot/#/builders/98/builds/3084 and
https://lab.llvm.org/buildbot/#/builders/114/builds/906).

The failure seems to be on `yaml2obj`, where `writeDynamicSymbolTable`
emits an indirect symbol table in host byte order rather than the
specified object's byte order (i.e. the `IsLittleEndian` field value).

This PR adds the missing swap and a regression test that round-trips all
endian-sensitive fields with both endianness values.
cuviper pushed a commit to rust-lang/llvm-project that referenced this pull request Jun 24, 2026
…203680)

Align Mach-O __LINKEDIT entries to the target pointer size when building
the tail layout. This matches the behavior of ld64 and lld-macho.

dyld on macOS 27 rejects loading dylibs with misaligned __LINKEDIT
entries.

See llvm#203678 for details and the motivation of this fix.

AI Tool Use Disclosure:

Regarding the PR and the linked issue, I have personally wrote every
single part of the PR by myself, and have/ran/verified every single part
of the issue report as well without any AI tool usage.

I have used LLM-based coding agents only for debugging purposes, e.g. to
figure out why the dylib was not loading (from the original bug report),
and figuring out how to build, run, and test my local `llvm-objcopy`.

(cherry picked from commit 18c1cbc)
cuviper pushed a commit to rust-lang/llvm-project that referenced this pull request Jun 24, 2026
…05044)

This is a follow-up of PR llvm#203680 that added the test case
`linkedit-alignment.test`, which currently fails on big-endian buildbots
(see: https://lab.llvm.org/buildbot/#/builders/98/builds/3084 and
https://lab.llvm.org/buildbot/#/builders/114/builds/906).

The failure seems to be on `yaml2obj`, where `writeDynamicSymbolTable`
emits an indirect symbol table in host byte order rather than the
specified object's byte order (i.e. the `IsLittleEndian` field value).

This PR adds the missing swap and a regression test that round-trips all
endian-sensitive fields with both endianness values.

(cherry picked from commit 6e56216)
reckenrode added a commit to reckenrode/nixpkgs that referenced this pull request Oct 11, 2026
NixOS#567431 omitted the updated tests
from llvm/llvm-project#203680 in the patch
backport, but patches to the tests were required. Now they are included.

llvm/llvm-project#205044 is also cherry-picked
into this patch to avoid test failures on big-endian architectures.
matt2e added a commit to block/buzz that referenced this pull request Oct 26, 2026
…#8598)

## Summary

Bump the pinned Rust toolchain from 1.95.0 to 1.98.1 so release builds
work on macOS 27 hosts.

Rust ≤ 1.97 strips Apple-target artifacts with its bundled
`llvm-objcopy`, which leaves the Mach-O `LC_SYMTAB` string pool
(`__LINKEDIT`) only 4-byte aligned. macOS 27's dyld refuses to `dlopen`
such images (`mis-aligned LINKEDIT string pool`). Because cargo applies
the release profile's default `strip = "debuginfo"` to proc-macro dylibs
too, `cargo build --release` of any crate that uses sqlx macros
(`buzz-db`, `buzz-relay`, `buzz-admin`, …) fails on macOS 27: rustc
cannot load `libsqlx_macros-*.dylib`. Dev builds pass because the dev
profile does not strip, which is why this only shows up as a
release/packaging failure.

The fix (llvm/llvm-project#203680, pulled into rustc by
rust-lang/rust#158410 for rust-lang/rust#157750) first shipped in Rust
1.98.0 and was never backported to 1.97.x. `block/buzz-app` pinned
1.98.1 for the same failure in block/buzz-app#529. With this bump the
`CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_STRIP=none` / custom-linker
workarounds people have been using locally are no longer needed.

### What changes

Two commits: the toolchain bump (with the desktop clippy fixes), then
the workspace clippy fixes.

| Location | Change |
|---|---|
| `rust-toolchain.toml` | `channel = "1.95.0"` → `"1.98.1"` (profile
unchanged) |
| `Dockerfile`, `Dockerfile.push-gateway` | `ARG RUST_VERSION=1.95` →
`1.98` |
| `Dockerfile.sprig` | `rust:1.98-alpine3.22` with the manifest-list
digest verified on Docker Hub (shared by the `1.98` and `1.98.1` tags) |
| `.github/workflows/release.yml` | `dtolnay/rust-toolchain` pinned to
the tip of its `1.98.1` branch (`18f04874`) for the Windows desktop
release job |
| `benchmarks/harbor-buzz-orchestra` | `RUST_IMAGE = rust:1.98-alpine` |
| `_ci-rust.yml`, `windows-canary.yml`, `app_state_tests.rs` | stale
"1.95" comments reworded; the `unknown_lints` allow stays with a
version-agnostic rationale |
| `desktop/src-tauri` | lints clippy 1.98 newly raises under `-D
warnings`: `chunks_exact_to_as_chunks` at five fixed-width PCM/UTF-16
decoders, `needless_borrows_for_generic_args` on the `Copy` `norm`
closure in `config_bridge/reader.rs`, and a redundant `Engine as _`
import in `hpke_key_backup_tests.rs` that `use super::*` already
provides |
| Workspace crates (9) | the 30 lints clippy 1.98 newly raises in `cargo
clippy --workspace --all-targets -- -D warnings`, listed below |

Workspace lint fixes:

| Lint | Sites | Fix |
|---|---|---|
| `result_large_err` (20) | `buzz-relay` `api/git/transport.rs` (8),
`api/git/settings.rs` (6), `api/gifs.rs`, `api/workflows.rs`,
`api/profiles.rs`; `buzz-push-gateway` `verify_installation_assertion` |
Clippy 1.98 now checks `async fn`s, so every `async fn … -> Result<_,
axum::response::Response>` trips it. These follow the existing allow
pattern in `api/media.rs` and `nip_fi_http.rs` ("Response is the natural
error type for axum handlers"): module-level in the two git files,
per-function elsewhere. Boxing `Response` would touch every handler for
no runtime benefit. |
| `chunks_exact_to_as_chunks` (3) | `buzz-media` MP4 brand scan;
`buzz-voice` npy f32 reader and stereo test fixture | `chunks_exact(N)`
→ `as_chunks::<N>().0` |
| `question_mark` (3) | `buzz-acp` queue flush fallback and
slash-command mention skip; `buzz-agent` `find_git_root` | `match … {
None => return None }` → `?` |
| `useless_format` (2) | `buzz-auth` nip_fi startup test policies |
`format!("…")` → `"…".to_string()` |
| `useless_borrows_in_formatting` (1) | `buzz-pairing-cli` secret print
| drop the borrow |
| `manual_noop_waker` (1) | `buzz-sdk` broker test `block_on` |
`Waker::noop()` (stable since 1.85) |

All `as_chunks` rewrites keep `chunks_exact`'s remainder-dropping
semantics, and `as_chunks` is stable since 1.88, which is the MSRV.

One change in `api/git/transport.rs` is not a lint fix. Staging that
file trips the pre-commit secret scanner on its existing test-only ES256
fixture (`GIT_TEST_EC_PEM`), and the scanner only honours a suppression
marker on the flagged line. So the `\`-continued string literal is
rewritten as a byte-identical `concat!` whose `BEGIN` line carries
`sadscan:disable kingfisher.privkey.2`.

Left as is on purpose: `Cargo.toml` `rust-version = "1.88.0"` (MSRV
floor, a separate concern), the README/CONTRIBUTING "1.88+" text, Hermit
(no Rust packages there), the lockfiles, and the `(1.95.0)` comment in
`scripts/start-isolated-test-relay.sh` (the pre-commit secret scanner
flags that file's pre-existing dev-only `DATABASE_URL` whenever it is
staged).

### Related issue
Fixes #8074

### Testing
All under rustc/clippy 1.98.1 on a macOS 27 host (Darwin 27.0.0,
aarch64), with no `RUSTFLAGS` / `SDKROOT` / strip overrides in the
environment:

- `cargo build --release -p buzz-db` (the #8074 repro: the release
profile strips the proc-macro dylib): **builds**. The resulting
`libsqlx_macros-*.dylib` (14 MB) has `LC_SYMTAB stroff % 8 == 0` per
`otool -l`. The same build on 1.95.0 died with `mis-aligned LINKEDIT
string pool`.
- `just clippy` (workspace, `-D warnings`) and `cargo fmt --check`
(workspace and `desktop/src-tauri`): pass
- `just desktop-tauri-clippy` (default and `mesh-llm` feature sets):
pass
- `just test-unit`: every crate passes. The `buzz-acp` binary failed
only under pre-push lane contention; rerun solo it is 1060 passed, 0
failed.
- `just desktop-tauri-test`: 3422 passed, 0 failed
- After the lint fixes: lib/bin unit tests for `buzz-acp`, `buzz-agent`,
`buzz-auth`, `buzz-media`, `buzz-voice`, `buzz-sdk`, `buzz-pairing-cli`,
and `buzz-relay`'s `api::git::transport` tests, including the
Postgres-backed
`enforce_mode_git_pack_routes_missing_assertion_exact_bytes`, which
parses the rewritten PEM: pass

`cfg(windows)` code was not linted locally (no Windows target
installed). CI's Windows Rust job runs workspace clippy for
`x86_64-pc-windows-msvc`, and that passes on this branch. CI also builds
the relay, push-gateway and sprig images on the new `rust:1.98` bases
for amd64 and arm64.

No runtime behavior changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Matt Toohey <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
AnthonyRonning added a commit to MaplePrivacyLabs/Maple that referenced this pull request Oct 29, 2026
These are no-ops on Xcode 26.5 and needed before the Xcode 27.1 pin.

- Agent shell: link Rust with Xcode's clang as well. nixpkgs' ld64
  cannot read the macOS 27 SDK's .tbd stubs (they list arm64e.x1), so
  build scripts failed to link (_strerror_r undefined).
- Research and Agent: stop stripping build scripts and proc-macros in
  release builds. rustc strips Apple outputs with rust-objcopy, which
  doesn't pad __LINKEDIT entries, so chained-fixup images (deployment
  target 12+) can end up with a 4-byte-aligned string table. macOS 27's
  dyld refuses such dylibs once they're linked against the macOS 27 SDK,
  so rustc could not load zerofrom-derive ("can't find crate").
  Executables aren't checked, so shipped binaries keep their strip
  settings. Upstream fix: llvm/llvm-project#203680.
- test-canonical-macho: Xcode 27's ld sorts local absolute symbols, so
  both fixtures came out in the same order. Swap the entries to recreate
  the input-order variant older linkers emitted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AnthonyRonning added a commit to MaplePrivacyLabs/Maple that referenced this pull request Oct 29, 2026
These are no-ops on Xcode 26.5 and needed before the Xcode 27.1 pin.

- Agent shell: link Rust with Xcode's clang as well. nixpkgs' ld64
  cannot read the macOS 27 SDK's .tbd stubs (they list arm64e.x1), so
  build scripts failed to link (_strerror_r undefined).
- Research and Agent: stop stripping build scripts and proc-macros in
  release builds. rustc strips Apple outputs with rust-objcopy, which
  doesn't pad __LINKEDIT entries, so chained-fixup images (deployment
  target 12+) can end up with a 4-byte-aligned string table. macOS 27's
  dyld refuses such dylibs once they're linked against the macOS 27 SDK,
  so rustc could not load zerofrom-derive ("can't find crate").
  Executables aren't checked, so shipped binaries keep their strip
  settings. Upstream fix: llvm/llvm-project#203680.
- test-canonical-macho: Xcode 27's ld sorts local absolute symbols, so
  both fixtures came out in the same order. Swap the entries to recreate
  the input-order variant older linkers emitted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AnthonyRonning added a commit to MaplePrivacyLabs/Maple that referenced this pull request Oct 30, 2026
These are no-ops on Xcode 26.5 and needed before the Xcode 27.1 pin.

- Agent shell: link Rust with Xcode's clang as well. nixpkgs' ld64
  cannot read the macOS 27 SDK's .tbd stubs (they list arm64e.x1), so
  build scripts failed to link (_strerror_r undefined).
- Research and Agent: stop stripping build scripts and proc-macros in
  release builds. rustc strips Apple outputs with rust-objcopy, which
  doesn't pad __LINKEDIT entries, so chained-fixup images (deployment
  target 12+) can end up with a 4-byte-aligned string table. macOS 27's
  dyld refuses such dylibs once they're linked against the macOS 27 SDK,
  so rustc could not load zerofrom-derive ("can't find crate").
  Executables aren't checked, so shipped binaries keep their strip
  settings. Upstream fix: llvm/llvm-project#203680.
- test-canonical-macho: Xcode 27's ld sorts local absolute symbols, so
  both fixtures came out in the same order. Swap the entries to recreate
  the input-order variant older linkers emitted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AnthonyRonning added a commit to MaplePrivacyLabs/Maple that referenced this pull request Oct 30, 2026
* ci: accept suffixed Xcode installs with the pinned build

Blacksmith's macOS 27 image mounts 27.1 (27A9275) as
Xcode_27.1_Release_Candidate.app, while GitHub's xcode-27 image installs
it as Xcode_27.1.app. Consider Xcode_<version>_*.app installs too;
selection still requires the exact pinned build and still skips betas.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: make Agent and Research builds work with the macOS 27 SDK

These are no-ops on Xcode 26.5 and needed before the Xcode 27.1 pin.

- Agent shell: link Rust with Xcode's clang as well. nixpkgs' ld64
  cannot read the macOS 27 SDK's .tbd stubs (they list arm64e.x1), so
  build scripts failed to link (_strerror_r undefined).
- Research and Agent: stop stripping build scripts and proc-macros in
  release builds. rustc strips Apple outputs with rust-objcopy, which
  doesn't pad __LINKEDIT entries, so chained-fixup images (deployment
  target 12+) can end up with a 4-byte-aligned string table. macOS 27's
  dyld refuses such dylibs once they're linked against the macOS 27 SDK,
  so rustc could not load zerofrom-derive ("can't find crate").
  Executables aren't checked, so shipped binaries keep their strip
  settings. Upstream fix: llvm/llvm-project#203680.
- test-canonical-macho: Xcode 27's ld sorts local absolute symbols, so
  both fixtures came out in the same order. Swap the entries to recreate
  the input-order variant older linkers emitted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: pin Xcode 27.1 and move Apple jobs to the Xcode 27 images

Xcode 27.1 (27A9275) adds the iOS 27.1 SDK and iPhone Duo support, and
App Store Connect requires the iOS 27 SDK from April 2027. The macOS 26
images have no Xcode 27, so every job that selects the pin moves:

- Blacksmith blacksmith-6vcpu-macos-26 -> blacksmith-6vcpu-macos-27:
  lanes.MACOS and ci.yml's special jobs in lockstep, plus the signed and
  release builders (agent-desktop-build, desktop-build, mobile-build,
  ios-dev-testflight, release, proxy-rust).
- GitHub macos-26 -> xcode-27: artifact verifiers, signing, TestFlight
  and the nightly provider suite.
- actionlint knows neither label yet.
- iOS ONNX Runtime builds for iOS 16.0 (the app's minimum) instead of
  13.0, because Xcode 27 only targets iOS 15.0-27.1. The hash pins move
  to 27A9275, from a local Xcode 27.1 build that reproduces them.
- Docs, the outage advice and the StoreKit harness name the new
  versions; the stale project.pbxproj.backup goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: compile Agent Metal shaders on Blacksmith macOS 27

Blacksmith's macOS 27 image has no Metal Toolchain for Xcode 27.1 and
cannot download it (the MobileAsset catalog fetch fails), while GitHub's
xcode-27 image ships it.

- A new export runs on xcode-27 and uploads the toolchain as a one-day
  artifact (.github/actions/export-metal-toolchain). The jobs that
  compile gpui's shaders import it (import-metal-toolchain): the signed
  macOS build in agent-desktop-build.yml and, in ci.yml, the macOS
  packaging rehearsal.
- Lanes gain `requires`. The planner adds a required lane to every plan
  that selects the lane requiring it, dispatches included, so
  metal-toolchain runs exactly when agent-package-macos does. lint
  checks that requirements exist, form no cycle, select nothing on their
  own, and that the requiring job needs them.
- agent-macos (PR Clippy) and agent-full-macos (the native suite) build
  gpui with runtime_shaders and need no Metal. Compiled shaders are
  proven by master's signed Prod build on every Agent push, the nightly
  Dev build and ci:package. Toolchain changes now also select
  agent-full-macos on master.
- Cache keys include the Xcode pin, so an upgrade never restores objects
  built against the previous SDK: the macOS lanes' cache_files, the
  packaging rehearsal's key prefix, and the signed build's release key
  (cargo_graph_key.py takes optional pin files; C4 expects the pin for
  macos-build only, so the Windows and Linux keys are unchanged).
- The policy tests know GitHub's per-Xcode labels are GitHub-hosted, so
  the attesting signing job may run on xcode-27.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: build iOS for the Research app's iOS-only sources

The UIScene manifest (Info.ios.plist), the plugins' Swift sources and the
vendored tao's iOS platform layer only compile into the iOS app, yet no
path of research-ios covered them, so a change there ran no iOS build
unless someone added ci:ios.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: keep dev-profile proc-macros unstripped on macOS 27 too

ci.yml sets CARGO_PROFILE_DEV_DEBUG=0, and Cargo strips build scripts
and proc-macros whenever their profile has no debug info, so dev builds
hit the same rust-objcopy alignment bug as release builds:
research-dev-macos (tauri build --debug, deployment target 13.4) failed
with "can't find crate for `zerofrom_derive`" on Xcode 27.1. Reproduced
locally with CI's settings; the dev build-override fixes it. The Agent
gets the same setting, because its dev lanes only pass today on rustc's
default deployment target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: rebuild the signed Agent when the Metal Toolchain actions change

agent-desktop-build.yml's macOS build now runs the export and import
actions, but AGENT_DESKTOP did not list them: a master push that changed
only them skipped the signed build, and no PR lane ran them without
ci:package, so a broken edit could pass ci-ok and break the next Prod
build. They join AGENT_DESKTOP and agent-package-macos's paths, a test
derives every local action the signed builds run from the workflow, and
the skill says when ci:package is the PR proof (Metal actions, gpui/zed
bumps, Xcode pin changes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: keep launching the signed Agent on macOS 26

Verify downloaded macOS was the only job that launches the signed Agent
(verify-release.sh runs --version, the duplicate-runtime check and the GUI
smoke test), and the Xcode 27 move put it on macOS 27, the same macOS the
build links against. It goes back to macos-26, where most users run the app,
and drops the pinned-Xcode step: it builds nothing and the image's default
Xcode suffices. Research's two artifact verifiers never select Xcode, so
they return to macos-26 as well instead of depending on the preview
xcode-27 image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: harden the Metal Toolchain handoff

- The export uploads with overwrite, so "Re-run all jobs" can upload the
  same artifact name again in the run.
- The import notes that the artifact lives one day: a later re-run needs
  the export job re-run too. It also captures `xcodebuild -showComponent`
  before matching, so grep -q cannot fail the pipeline under pipefail.
- metal-toolchain is active only where agent-package-macos is (PR side and
  nightly), so a master fallback plan never runs the export alone. lint
  now requires a required lane's events to stay within its requirers', and
  rejects an OpenSecret selector on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: apply the cache and artifact policy to composite action steps

The policy tests that keep pull requests from saving caches or reading
another run's artifacts walked only workflow steps, and the Metal Toolchain
import is the first local composite action with an artifact step that runs
in a PR job: a `run-id` added to its download, or a cache save inside it,
passed every test. Both tests now walk each local composite action's steps
in the job that uses it, downloads may not pass a `github-token` either,
and a fixture test proves a violation inside a composite is seen. The
GITHUB_HOSTED comment no longer contradicts its pattern.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: build Android for the Research app's Android-only sources

research-android did not select the vendored tao's Android layer, which
carries Maple's null-intent hardening, nor the vendored plugins' Kotlin
sources: research-rust never compiles cfg(target_os = "android") code, so
an edit there ran no Android build without ci:android. They join its paths,
like the iOS-only sources in research-ios, which gains tao's platform/ios.rs.
The research-ios comment notes the iOS 27.1 Simulator download each run
makes on Blacksmith's macOS 27 image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: describe the Xcode-pinned release key, the Metal artifact and xcode-27

Comments and docs move with behaviour:

- The CI design, the debugging guide, repository-workflows.md and the
  macOS builder's restore comment say the macOS release key also hashes
  scripts/ci/apple-toolchain.json, so an Xcode pin change makes the next
  macOS Prod build cold.
- The Metal Toolchain artifact lives one day: the re-run guidance and the
  Agent build doc say to re-run the export job with a macOS build retried
  more than a day later.
- repository-workflows.md and the CI runner table name the jobs that depend
  on GitHub's preview xcode-27 label, and what to switch to if it is renamed
  or retired.
- changing-ci.md states the full rule for required lanes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: drop the Agent's strip override, which only stalled its caches

The Agent builds with Rust 1.98.0, whose stripped proc-macros keep an
8-byte-aligned string table with the macOS 27 SDK at deployment
targets 13.4 and 15.0. Research's Rust 1.94.1 leaves the same dylibs
4-byte aligned, which is what macOS 27's dyld refuses. A release check
of the whole Agent app at 15.0 passes on Xcode 27.1 without the
override, so the Agent never needed it.

It wasn't free either. The Agent's manifest is a virtual workspace
manifest, which rust-cache does not hash, so the override changed no
cache key. Linux and Windows Agent lanes restored master's cache as a
full match and rebuilt everything downstream of a proc-macro:
agent-test compiled 604 crates instead of 10, and agent-windows 196
instead of 3, taking 11 min. A full match also skips the save, so
master would never have refreshed those caches.

Research keeps both overrides. Its comment now says they can go once
the root flake pins Rust 1.98 or newer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: link the native build-info fixture with Cargo's linker

The fixture test calls rustc directly, so it linked with `cc`, which in
the Agent's Nix shell is nixpkgs' clang wrapper. Its ld64 cannot read
the macOS 27 SDK's .tbd stubs, so `just ci` failed on a Mac with Xcode
27.1 selected. The test now passes the host's
CARGO_TARGET_<host>_LINKER, which the shell sets to Xcode's clang, as
Cargo would. CI runs this suite only on Linux, where the test skips.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants