Skip to content

release/23.x: [ld64.lld, llvm-otool, lldb] Minimal arm64e.x1 support - #224185

Closed
keith wants to merge 3 commits into
llvm:release/23.xfrom
keith:ks/xcode-27-sdk
Closed

keith wants to merge 3 commits into
llvm:release/23.xfrom
keith:ks/xcode-27-sdk

Conversation

@keith

@keith keith commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

This cherry picks 2 changes:

These are required to use ld64.lld to link against the Xcode 27 SDK which was just released this week.

In order to avoid an ABI breakage on this branch I put the new fields at the end of the changed types

@keith

keith commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

@tstellar manual ping since I manually created this 2 change cherry pick

@llvmorg-github-actions

llvmorg-github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

@llvm/pr-subscribers-lld-macho
@llvm/pr-subscribers-lldb
@llvm/pr-subscribers-lld

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

Author: Keith Smiley (keith)

Changes

This cherry picks 2 changes:

These are required to use ld64.lld to link against the Xcode 27 SDK which was just released this week.


Full diff: https://github.com/llvm/llvm-project/pull/224185.diff

13 Files Affected:

  • (added) lld/test/MachO/arm64-x1.s (+20)
  • (modified) lldb/include/lldb/Host/SafeMachO.h (+1)
  • (modified) llvm/include/llvm/BinaryFormat/MachO.h (+1)
  • (modified) llvm/include/llvm/TargetParser/Triple.h (+6)
  • (modified) llvm/include/llvm/TextAPI/Architecture.def (+1-1)
  • (modified) llvm/lib/BinaryFormat/MachO.cpp (+2)
  • (modified) llvm/lib/Object/MachOObjectFile.cpp (+6)
  • (modified) llvm/lib/TargetParser/Triple.cpp (+5)
  • (modified) llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test (+5)
  • (added) llvm/test/tools/llvm-readobj/macho-arm64e_x1.test (+17)
  • (modified) llvm/tools/llvm-objdump/MachODump.cpp (+7)
  • (modified) llvm/tools/llvm-readobj/MachODumper.cpp (+1)
  • (modified) llvm/unittests/BinaryFormat/MachOTest.cpp (+2)
diff --git a/lld/test/MachO/arm64-x1.s b/lld/test/MachO/arm64-x1.s
new file mode 100644
index 0000000000000..67b7debc47132
--- /dev/null
+++ b/lld/test/MachO/arm64-x1.s
@@ -0,0 +1,20 @@
+# REQUIRES: aarch64
+
+## Test that arm64.x1-macos is ignored instead of causing an error.
+## linked re-exported dylibs that only declare arm64e-macos targets, even if targeting arm64.
+# arm64 and arm64e are ABI compatible (same CPU type), and ld64 accepts this.
+
+# RUN: rm -rf %t; split-file --no-leading-lines %s %t
+
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o %t/test.o /dev/null
+
+# RUN: %no-arg-lld -syslibroot %t/sdk -lSystem -dylib -arch arm64 \
+# RUN:     -platform_version macos 15 26 %t/test.o -o /dev/null
+
+#--- sdk/usr/lib/libSystem.tbd
+--- !tapi-tbd
+tbd-version:      4
+targets:          [ arm64-macos, arm64e.x1-macos ]
+install-name:     '/usr/lib/libSystem.dylib'
+current-version:  0001.001.1
+...
diff --git a/lldb/include/lldb/Host/SafeMachO.h b/lldb/include/lldb/Host/SafeMachO.h
index cfb57571d0e3e..4e9a42faf9656 100644
--- a/lldb/include/lldb/Host/SafeMachO.h
+++ b/lldb/include/lldb/Host/SafeMachO.h
@@ -97,6 +97,7 @@
 #undef CPU_SUBTYPE_ARM64E
 #undef CPU_SUBTYPE_ARM64_32_V8
 #undef CPU_SUBTYPE_ARM64_V8
+#undef CPU_SUBTYPE_ARM64E_X1
 #undef CPU_SUBTYPE_ARM64_ALL
 
 #undef CPU_SUBTYPE_SPARC_ALL
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h b/llvm/include/llvm/BinaryFormat/MachO.h
index bea1bcaf2bf75..ab06b6c356348 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -1703,6 +1703,7 @@ enum CPUSubTypeARM64 : uint32_t {
   CPU_SUBTYPE_ARM64_ALL = 0,
   CPU_SUBTYPE_ARM64_V8 = 1,
   CPU_SUBTYPE_ARM64E = 2,
+  CPU_SUBTYPE_ARM64E_X1 = 12,
 
   // arm64e uses the capability bits to encode ptrauth ABI information.
   // Bit 63 marks the binary as Versioned.
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index d819c4975b13e..ebc65d0b6eac5 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -156,6 +156,7 @@ class Triple {
     ARMSubArch_v4t,
 
     AArch64SubArch_arm64e,
+    AArch64SubArch_arm64e_x1,
     AArch64SubArch_arm64ec,
     AArch64SubArch_lfi,
 
@@ -1218,6 +1219,11 @@ class Triple {
            getSubArch() == Triple::AArch64SubArch_arm64e;
   }
 
+  bool isArm64e_x1() const {
+    return getArch() == Triple::aarch64 &&
+           getSubArch() == Triple::AArch64SubArch_arm64e_x1;
+  }
+
   // Tests whether the target is N32.
   bool isABIN32() const {
     EnvironmentType Env = getEnvironment();
diff --git a/llvm/include/llvm/TextAPI/Architecture.def b/llvm/include/llvm/TextAPI/Architecture.def
index 0caf58e1825d9..33d549035ee65 100644
--- a/llvm/include/llvm/TextAPI/Architecture.def
+++ b/llvm/include/llvm/TextAPI/Architecture.def
@@ -39,7 +39,7 @@ ARCHINFO(armv8_1m_main, armv8.1m.main, MachO::CPU_TYPE_ARM, MachO::CPU_SUBTYPE_A
 ///
 ARCHINFO(arm64, arm64, MachO::CPU_TYPE_ARM64, MachO::CPU_SUBTYPE_ARM64_ALL, 64)
 ARCHINFO(arm64e, arm64e, MachO::CPU_TYPE_ARM64, MachO::CPU_SUBTYPE_ARM64E, 64)
-
+ARCHINFO(arm64e_x1, arm64e.x1, MachO::CPU_TYPE_ARM64, MachO::CPU_SUBTYPE_ARM64E_X1, 64)
 
 ///
 /// ARM64_32 architectures sorted by cpu sub type id
diff --git a/llvm/lib/BinaryFormat/MachO.cpp b/llvm/lib/BinaryFormat/MachO.cpp
index 046a79bbd7c5f..923ae478f31d1 100644
--- a/llvm/lib/BinaryFormat/MachO.cpp
+++ b/llvm/lib/BinaryFormat/MachO.cpp
@@ -66,6 +66,8 @@ static MachO::CPUSubTypeARM64 getARM64SubType(const Triple &T) {
     return (MachO::CPUSubTypeARM64)MachO::CPU_SUBTYPE_ARM64_32_V8;
   if (T.isArm64e())
     return MachO::CPU_SUBTYPE_ARM64E;
+  if (T.isArm64e_x1())
+    return MachO::CPU_SUBTYPE_ARM64E_X1;
 
   return MachO::CPU_SUBTYPE_ARM64_ALL;
 }
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 3342c99e245ca..c28bcf1e3fb4c 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -2874,6 +2874,12 @@ Triple MachOObjectFile::getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
       if (ArchFlag)
         *ArchFlag = "arm64e";
       return Triple("arm64e-apple-darwin");
+    case MachO::CPU_SUBTYPE_ARM64E_X1:
+      if (McpuDefault)
+        *McpuDefault = "apple-a20";
+      if (ArchFlag)
+        *ArchFlag = "arm64e.x1";
+      return Triple("arm64e.x1-apple-darwin");
     default:
       return Triple();
     }
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 356782c1f6ad4..2e4fe7ce70887 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -192,6 +192,8 @@ StringRef Triple::getArchName(ArchType Kind, SubArchType SubArch) {
       return "arm64ec";
     if (SubArch == AArch64SubArch_arm64e)
       return "arm64e";
+    if (SubArch == AArch64SubArch_arm64e_x1)
+      return "arm64e.x1";
     if (SubArch == AArch64SubArch_lfi)
       return "aarch64_lfi";
     break;
@@ -656,6 +658,7 @@ Triple::ArchType Triple::parseArch(StringRef ArchName) {
           .Case("arm64", Triple::aarch64)
           .Case("arm64_32", Triple::aarch64_32)
           .Case("arm64e", Triple::aarch64)
+          .Case("arm64e.x1", Triple::aarch64)
           .Case("arm64ec", Triple::aarch64)
           .Case("arm", Triple::arm)
           .Case("armeb", Triple::armeb)
@@ -783,6 +786,8 @@ Triple::SubArchType Triple::parseSubArch(StringRef SubArchName) {
 
   if (SubArchName == "arm64e")
     return Triple::AArch64SubArch_arm64e;
+  if (SubArchName == "arm64e.x1")
+    return Triple::AArch64SubArch_arm64e_x1;
 
   if (SubArchName == "arm64ec")
     return Triple::AArch64SubArch_arm64ec;
diff --git a/llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test b/llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test
index 910ee019f3293..4361ac938796a 100644
--- a/llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test
+++ b/llvm/test/tools/llvm-readobj/MachO/file-headers-arm64.test
@@ -13,6 +13,11 @@
 # RUN: llvm-readobj -h %t.arm64e \
 # RUN:  | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64e --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64E (0x2)"
 
+## Check subtype Arm64E.X1:
+# RUN: yaml2obj %s -o %t.arm64e.x1 -DSUBTYPE=0xC
+# RUN: llvm-readobj -h %t.arm64e.x1 \
+# RUN:  | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.arm64e.x1 --check-prefix=ARM64 -DSUBTYPE="CPU_SUBTYPE_ARM64E_X1 (0xC)"
+
 #      ARM64:File: [[FILE]]
 # ARM64-NEXT:Format: Mach-O arm64
 # ARM64-NEXT:Arch: aarch64
diff --git a/llvm/test/tools/llvm-readobj/macho-arm64e_x1.test b/llvm/test/tools/llvm-readobj/macho-arm64e_x1.test
new file mode 100644
index 0000000000000..d6ea66911b7eb
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/macho-arm64e_x1.test
@@ -0,0 +1,17 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-readobj -h %t.o | FileCheck %s
+
+# CHECK: Magic: Magic64 (0xFEEDFACF)
+# CHECK: CpuType: Arm64 (0x100000C)
+# CHECK: CpuSubType: CPU_SUBTYPE_ARM64E_X1 (0xC)
+
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x0100000C
+  cpusubtype:      0x0000000C
+  filetype:        0x00000001
+  ncmds:           0
+  sizeofcmds:      0
+  flags:           0x00000000
+  reserved:        0x00000000
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index 8b5a56b0db095..7a52df2aeeeaf 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -2344,6 +2344,10 @@ static void printCPUType(uint32_t cputype, uint32_t cpusubtype) {
       outs() << "    cputype CPU_TYPE_ARM64\n";
       outs() << "    cpusubtype CPU_SUBTYPE_ARM64E\n";
       break;
+    case MachO::CPU_SUBTYPE_ARM64E_X1:
+      outs() << "    cputype CPU_TYPE_ARM64\n";
+      outs() << "    cpusubtype CPU_SUBTYPE_ARM64E_X1\n";
+      break;
     default:
       printUnknownCPUType(cputype, cpusubtype);
       break;
@@ -8472,6 +8476,9 @@ static void PrintMachHeader(uint32_t magic, uint32_t cputype,
       case MachO::CPU_SUBTYPE_ARM64E:
         outs() << "          E";
         break;
+      case MachO::CPU_SUBTYPE_ARM64E_X1:
+        outs() << "       E.X1";
+        break;
       default:
         outs() << format(" %10d", cpusubtype & ~MachO::CPU_SUBTYPE_MASK);
         break;
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index f5b3cf203204f..f768d3b704498 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -189,6 +189,7 @@ constexpr EnumStringDef<uint32_t> MachOHeaderCpuSubtypesARM64Defs[] = {
     LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_ALL),
     LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64_V8),
     LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64E),
+    LLVM_READOBJ_ENUM_ENT(MachO, CPU_SUBTYPE_ARM64E_X1),
 };
 constexpr auto MachOHeaderCpuSubtypesARM64 =
     BUILD_ENUM_STRINGS(MachOHeaderCpuSubtypesARM64Defs);
diff --git a/llvm/unittests/BinaryFormat/MachOTest.cpp b/llvm/unittests/BinaryFormat/MachOTest.cpp
index 91558f7838016..01545da18454e 100644
--- a/llvm/unittests/BinaryFormat/MachOTest.cpp
+++ b/llvm/unittests/BinaryFormat/MachOTest.cpp
@@ -66,6 +66,7 @@ TEST(MachOTest, CPUType) {
   CHECK_CPUTYPE("thumbv7-apple-darwin", MachO::CPU_TYPE_ARM);
   CHECK_CPUTYPE("arm64-apple-darwin", MachO::CPU_TYPE_ARM64);
   CHECK_CPUTYPE("arm64e-apple-darwin", MachO::CPU_TYPE_ARM64);
+  CHECK_CPUTYPE("arm64e.x1-apple-darwin", MachO::CPU_TYPE_ARM64);
   CHECK_CPUTYPE("arm64_32-apple-darwin", MachO::CPU_TYPE_ARM64_32);
 
   {
@@ -107,6 +108,7 @@ TEST(MachOTest, CPUSubType) {
   CHECK_CPUSUBTYPE("thumbv6-apple-darwin", MachO::CPU_SUBTYPE_ARM_V6);
   CHECK_CPUSUBTYPE("arm64-apple-darwin", MachO::CPU_SUBTYPE_ARM64_ALL);
   CHECK_CPUSUBTYPE("arm64e-apple-darwin", MachO::CPU_SUBTYPE_ARM64E);
+  CHECK_CPUSUBTYPE("arm64e.x1-apple-darwin", MachO::CPU_SUBTYPE_ARM64E_X1);
   CHECK_CPUSUBTYPE("arm64_32-apple-darwin", MachO::CPU_SUBTYPE_ARM64_32_V8);
   CHECK_CPUSUBTYPE("armv8m.main-apple-darwin", MachO::CPU_SUBTYPE_ARM_V8M_MAIN);
   CHECK_CPUSUBTYPE("armv8m.base-apple-darwin", MachO::CPU_SUBTYPE_ARM_V8M_BASE);

@keith

keith commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

the abi change is true

@nico

nico commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

the abi change is true

I'm not sure what this is supposed to mean 😅

@nico

nico commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

I'm not sure what this is supposed to mean 😅

Aha, it means that the step "LLVM ABI Tests" is failing. Looking at the output of the "Upload ABI Comparison" step, it flags that enum Triple::SubArchType has a bunch of entries changing meaning due to this inserting a value in the middle, and a handful entries for the llvm::MachO::Architecture enum too.

That could break actual code, which isn't great for a point release. Maybe we could change the commits on just the branch to add the values at the end of the enum?

@keith

keith commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

I assume even moving things to the end would be abi breaking since most of the enums have the unknown type field at the end (and i assume hardcoding this field to be after that would risk breaking other things)

@keith

keith commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

I think we'd have to do this, wdyt?

diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index ebc65d0b6eac..c5af232523c6 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -156,7 +156,6 @@ public:
     ARMSubArch_v4t,
 
     AArch64SubArch_arm64e,
-    AArch64SubArch_arm64e_x1,
     AArch64SubArch_arm64ec,
     AArch64SubArch_lfi,
 
@@ -274,7 +273,9 @@ public:
     AMDGPUSubArch13,
     AMDGPUSubArch1310,
     FirstAMDGPUSubArch = AMDGPUSubArch6,
-    LastAMDGPUSubArch = AMDGPUSubArch1310
+    LastAMDGPUSubArch = AMDGPUSubArch1310,
+
+    AArch64SubArch_arm64e_x1
   };
   enum VendorType {
     UnknownVendor,
diff --git a/llvm/include/llvm/TextAPI/Architecture.h b/llvm/include/llvm/TextAPI/Architecture.h
index 2ca199489f1d..8c1e182e2175 100644
--- a/llvm/include/llvm/TextAPI/Architecture.h
+++ b/llvm/include/llvm/TextAPI/Architecture.h
@@ -26,10 +26,27 @@ namespace MachO {
 
 /// Defines the architecture slices that are supported by Text-based Stub files.
 enum Architecture : uint8_t {
-#define ARCHINFO(Arch, Name, Type, SubType, NumBits) AK_##Arch,
-#include "llvm/TextAPI/Architecture.def"
-#undef ARCHINFO
-  AK_unknown, // this has to go last.
+  AK_i386,
+  AK_x86_64,
+  AK_x86_64h,
+  AK_armv4t,
+  AK_armv6,
+  AK_armv5,
+  AK_armv7,
+  AK_armv7s,
+  AK_armv7k,
+  AK_armv6m,
+  AK_armv7m,
+  AK_armv7em,
+  AK_armv8m_main,
+  AK_armv8m_base,
+  AK_armv8_1m_main,
+  AK_arm64,
+  AK_arm64e,
+  AK_arm64_32,
+  AK_riscv32,
+  AK_unknown,
+  AK_arm64e_x1,
 };
 
 /// Convert a CPU Type and Subtype pair to an architecture slice.

@dyung

dyung commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

We generally try to avoid taking ABI breaking changes unless there is a really good reason to do so at this stage of the release. What would be the consequences if we did not take these two changes on the release branch?

arxdeus added a commit to arxdeus/xcross that referenced this pull request Sep 19, 2026
….lld

Xcode 27 SDKs declare the new `arm64e.x1` CPU subtype
(`CPU_SUBTYPE_ARM64E_X1`, 12) beside `arm64e` in every `.tbd`. LLVM only
learned that name in llvm/llvm-project#222721, which landed on `main`
after the 23.x branch and whose backport (llvm/llvm-project#224185) is
still open, so every released linker rejects the whole document:

    ld64.lld: error: could not load TAPI file at .../UIKit.tbd: malformed file
    .../UIKit.tbd:3:32: error: unknown architecture
    targets: [ arm64e-ios, arm64e.x1-ios ]

Rename the unknown slice to the ABI-compatible `arm64e` rather than
delete it: the reader tolerates duplicate targets everywhere it accepts
a target list, while stripping can empty a `targets:` list and fail just
as fatally with "is incompatible with arm64". The rename is also a token
substitution, so it costs one pass instead of list surgery.

Rewriting happens as entries are written by `sdk install`, so hard-link
group members and the symlink copies Windows materializes all land
patched. Bundles installed by an older xcross carry no stamp and are
repaired on resolve, which avoids a multi-gigabyte reinstall; a stamped
bundle costs one small file read. A bundle whose stubs could not all be
written is left unstamped so a later run retries. Both linker call sites
translate the raw diagnostic into guidance naming the cause.

Verified against a real Xcode SDK: 705 stubs with `arm64e.x1` injected
as Xcode 27 ships them fail to link, link cleanly after the rewrite, and
produce identical load commands and undefined-symbol bindings.
arxdeus added a commit to arxdeus/xcross that referenced this pull request Sep 21, 2026
….lld (#78)

* fix(darwin_sdk_kit): rewrite arm64e.x1 stub targets for released ld64.lld

Xcode 27 SDKs declare the new `arm64e.x1` CPU subtype
(`CPU_SUBTYPE_ARM64E_X1`, 12) beside `arm64e` in every `.tbd`. LLVM only
learned that name in llvm/llvm-project#222721, which landed on `main`
after the 23.x branch and whose backport (llvm/llvm-project#224185) is
still open, so every released linker rejects the whole document:

    ld64.lld: error: could not load TAPI file at .../UIKit.tbd: malformed file
    .../UIKit.tbd:3:32: error: unknown architecture
    targets: [ arm64e-ios, arm64e.x1-ios ]

Rename the unknown slice to the ABI-compatible `arm64e` rather than
delete it: the reader tolerates duplicate targets everywhere it accepts
a target list, while stripping can empty a `targets:` list and fail just
as fatally with "is incompatible with arm64". The rename is also a token
substitution, so it costs one pass instead of list surgery.

Rewriting happens as entries are written by `sdk install`, so hard-link
group members and the symlink copies Windows materializes all land
patched. Bundles installed by an older xcross carry no stamp and are
repaired on resolve, which avoids a multi-gigabyte reinstall; a stamped
bundle costs one small file read. A bundle whose stubs could not all be
written is left unstamped so a later run retries. Both linker call sites
translate the raw diagnostic into guidance naming the cause.

Verified against a real Xcode SDK: 705 stubs with `arm64e.x1` injected
as Xcode 27 ships them fail to link, link cleanly after the rewrite, and
produce identical load commands and undefined-symbol bindings.

* refactor(darwin_sdk_kit): split the tbd rewrite by concern

`TbdTargets` had grown four jobs in one class: the rewriting rules, file
and directory I/O, stamp bookkeeping, and linker error formatting. Split
them so each reads on its own:

- `tbd_architecture_rewrite.dart` owns the rules and the `arm64e.x1`
  rationale, and is pure text with no I/O.
- `tbd_bundle_patch.dart` owns the on-disk pass and the stamp, with the
  per-file branches named by a `_FileOutcome` enum instead of counter
  bumps inside a try block.
- `tbd_linker_diagnostic.dart` owns recognizing and explaining the
  failure, and now also `explainFailures`, which both linker call sites
  share instead of repeating catch/rethrow. `wrap` is typed
  `Exception Function(String)` so each caller keeps its own error type;
  the analyzer caught a test passing `StateError` through it.

Also lift the Windows long-path helper into `cli_kit` as
`HostPaths.long`, replacing five copies (the one this feature added plus
four that predate it), with a `windows` seam so the Win32 form is
testable from any host. The copies had drifted: one checked the `\\?\`
prefix before normalizing and another after, which are equivalent only
because normalize preserves the prefix.

No behavior change: 910 tests pass, including the real-`ld64.lld`
acceptance test that links against an SDK carrying injected `arm64e.x1`
slices, and its negative control.

* feat(sdk): require Swift 6.4+ for Xcode 27 Darwin SDKs

Xcode 27's SDK ships `.swiftinterface` files and text stubs in a dialect
Swift 6.3 and earlier reject. The failure surfaces much later as a parse
error inside a system module, which is nearly impossible to trace back
to the toolchain.

Check the pairing in `sdk install` twice, once from the archive name
before the hours-long extraction and once from the extracted SDK, and in
`doctor` so a host that downgraded Swift after installing still hears
about it.

* fix(flutter): build SwiftPM plugins with Swift 6.4

Swift 6.4 makes `swiftbuild` the default SwiftPM build system. It only
knows the Apple platforms a host Xcode registers, so a cross host fails
with "unable to find platform for 'iphoneos'" before anything compiles.
It also drops the per-triple level from the scratch layout, so the build
description this code reads moves from `<scratch>/<triple>/debug` to
`<scratch>/out/debug`.

Pin `--build-system native`, the engine that supports the cross build,
and resolve the target build directory instead of hardcoding it, so a
stale `out/debug` from a default-engine run cannot be picked up.

* fix(flutter): realign native-asset LINKEDIT string tables for dyld

`ld64.lld` packs `LC_SYMTAB.stroff` directly after the indirect symbol
table with no padding. That table holds 4-byte entries, so an odd symbol
count leaves the string table 4-byte aligned. Apple's linker always pads
to 8, and dyld on iOS 26 enforces it:

    mis-aligned LINKEDIT string pool, fileOffset=0x000A7794

The app reached that only at runtime, as a Dart `Failed to load dynamic
library` for the affected framework. Flutter kept running without it, so
the user saw a black screen and no diagnostic naming the real cause.

Slide the string table forward the few bytes needed and shorten it by the
same amount, consuming the NUL padding the linker leaves at the end. Byte
`stroff + i` becomes `newStroff + i`, so every `n_strx` index still
resolves to its original name and the file keeps its exact length: no
offset outside the string table moves. The shift is skipped unless the
bytes it would drop are NUL and the indirect table ends exactly where the
strings begin, so an unexpected layout is left untouched rather than
corrupted.

Runs after thinning and before signing, so the signature covers the
repaired bytes.

* test(flutter): pin the aligner to the broken LINKEDIT layout only

The realignment runs over every native-asset binary, so the guarantee
that matters is the one about the files it must not touch: anything a
correct linker produced, which is what Apple ld64 and Xcode 26 / Swift
6.3 toolchains emit.

Sweep the indirect-symbol counts that keep the string table aligned and
assert the bytes come back identical, so a future change to the repair
cannot start rewriting healthy binaries unnoticed.
@keith

keith commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

What would be the consequences if we did not take these two changes on the release branch?

users cannot link mach-o binaries with the current production Apple SDKs + lld.

I pushed a commit that differs from main that attempts to avoid the ABI break, but we'll have to see what CI / reviewers think about it. Wdyt @nico?

@dyung dyung moved this from Needs Merge to Needs Review in LLVM Release Status Sep 22, 2026
@nico

nico commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

(The red bot is TEST 'cross-project-tests :: debuginfo-tests/dexter/feature_tests/scripts/parser/invalid-script-nodes.test, which is unrelated.)

@keith

keith commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

updated the description to include that

nico and others added 3 commits September 25, 2026 10:24
Just enough for `llvm-otool -hv` to dump the cpusubtype, and for
ld64.lld to not reject .tbd files that have an arm64e.x1 slice.

This is needed to link mac binaries against the macOS 27 SDK.

(cherry picked from commit b8007a8)
ehartford pushed a commit to withlang-dev/with that referenced this pull request Sep 28, 2026
…annot read (#1826)

Xcode 27's SDK lists `arm64e.x1-macos` (CPU_SUBTYPE_ARM64E_X1, 12) in
the targets of every .tbd stub. Our ld64.lld 22.1.6 rejects the whole
stub (llvm/lib/TextAPI/TextStub.cpp ScalarTraits<Target>::input,
"unknown architecture": Architecture.def has no arm64e.x1), so with
SDKROOT at that SDK libSystem, libc++ and libm were all unreadable and
the build died at the stage2 lld link with hundreds of undefined
symbols. comp_host_sdk_path returned SDKROOT unchecked.

The llvm-link-metadata actions now ask the linker before writing the
response files: an empty dylib linked with the build's own ld64.lld
against -lSystem -lc++ -lm under -syslibroot <sdk>, the libraries the
stage link reads. When it fails, the build stops there, before stage1,
naming the SDK, whether SDKROOT or the default chose it, the linker and
its LLVM version, and the stub entry TextAPI rejected:

  unreadable: .../MacOSX27.0.sdk/usr/lib/libSystem.tbd:4:20: unknown
  architecture 'arm64e.x1-macos'

and a default SDK the linker does read (probed the same way), as the
SDKROOT to set. Any other probe failure prints lld's error lines. The
SDK is never swapped silently: SDKROOT is the programmer's choice. A
missing SDK (SDKROOT unset, no CLT or Xcode SDK) is refused the same way
instead of writing a response file with no -syslibroot.

comp_host_sdk_path reads SDKROOT through the action's env_input, so the
metadata actions that bake the path in name it as their own input rather
than relying on sdk-llvm's graph-level read being inherited.

The root fix is the linker: llvm/llvm-project#222721 (b8007a8e, main,
2026-09-11) adds arm64e.x1 to TextAPI; no LLVM release carries it yet
(23.x backport: llvm/llvm-project#224185, open). Refs #1826.
ehartford added a commit to withlang-dev/with that referenced this pull request Sep 28, 2026
…annot read (#1826) (#1840)

Xcode 27's SDK lists `arm64e.x1-macos` (CPU_SUBTYPE_ARM64E_X1, 12) in
the targets of every .tbd stub. Our ld64.lld 22.1.6 rejects the whole
stub (llvm/lib/TextAPI/TextStub.cpp ScalarTraits<Target>::input,
"unknown architecture": Architecture.def has no arm64e.x1), so with
SDKROOT at that SDK libSystem, libc++ and libm were all unreadable and
the build died at the stage2 lld link with hundreds of undefined
symbols. comp_host_sdk_path returned SDKROOT unchecked.

The llvm-link-metadata actions now ask the linker before writing the
response files: an empty dylib linked with the build's own ld64.lld
against -lSystem -lc++ -lm under -syslibroot <sdk>, the libraries the
stage link reads. When it fails, the build stops there, before stage1,
naming the SDK, whether SDKROOT or the default chose it, the linker and
its LLVM version, and the stub entry TextAPI rejected:

  unreadable: .../MacOSX27.0.sdk/usr/lib/libSystem.tbd:4:20: unknown
  architecture 'arm64e.x1-macos'

and a default SDK the linker does read (probed the same way), as the
SDKROOT to set. Any other probe failure prints lld's error lines. The
SDK is never swapped silently: SDKROOT is the programmer's choice. A
missing SDK (SDKROOT unset, no CLT or Xcode SDK) is refused the same way
instead of writing a response file with no -syslibroot.

comp_host_sdk_path reads SDKROOT through the action's env_input, so the
metadata actions that bake the path in name it as their own input rather
than relying on sdk-llvm's graph-level read being inherited.

The root fix is the linker: llvm/llvm-project#222721 (b8007a8e, main,
2026-09-11) adds arm64e.x1 to TextAPI; no LLVM release carries it yet
(23.x backport: llvm/llvm-project#224185, open). Refs #1826.

Co-authored-by: Eric Hartford <[email protected]>
ehartford pushed a commit to withlang-dev/with that referenced this pull request Sep 29, 2026
….1.6 source step (#1826)

Xcode 27's SDK lists the arm64e.x1 slice (CPU_SUBTYPE_ARM64E_X1 = 12) in
every .tbd stub, and TextAPI rejects a stub with a target it cannot
parse, so ld64.lld 22.1.6 could not read libSystem, libc++ or libm. The
upstream fix, "[ld64.lld, llvm-otool] Minimal arm64e.x1 support"
(b8007a8e, main 2026-09-11), is in no release: 22.1.8 and 23.1.2 lack
it and the 23.x backport (llvm/llvm-project#224185) is still open.

The sdk-llvm-source step now inserts the two lines lld needs — the
ARCHINFO(arm64e_x1, arm64e.x1, …) entry in TextAPI/Architecture.def and
CPU_SUBTYPE_ARM64E_X1 = 12 in BinaryFormat/MachO.h — after their exact
anchor lines, on a fresh extraction and on a tree extracted before the
patch existed. A missing or duplicated anchor fails the step; a line
already present is left alone. The patch is pinned to 22.1.6: any other
COMPILER_LLVM_VERSION fails the step until the patch is deleted (an LLVM
that carries b8007a8e) or re-anchored, so it cannot outlive its version.
Refs #1826.
@tru

tru commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Manually merged in ee66426.

@tru tru closed this Sep 29, 2026
@keith
keith deleted the ks/xcode-27-sdk branch September 29, 2026 16:45
ehartford added a commit to withlang-dev/with that referenced this pull request Sep 29, 2026
)

* sdk: backport arm64e.x1 (llvm/llvm-project b8007a8e) into the LLVM 22.1.6 source step (#1826)

Xcode 27's SDK lists the arm64e.x1 slice (CPU_SUBTYPE_ARM64E_X1 = 12) in
every .tbd stub, and TextAPI rejects a stub with a target it cannot
parse, so ld64.lld 22.1.6 could not read libSystem, libc++ or libm. The
upstream fix, "[ld64.lld, llvm-otool] Minimal arm64e.x1 support"
(b8007a8e, main 2026-09-11), is in no release: 22.1.8 and 23.1.2 lack
it and the 23.x backport (llvm/llvm-project#224185) is still open.

The sdk-llvm-source step now inserts the two lines lld needs — the
ARCHINFO(arm64e_x1, arm64e.x1, …) entry in TextAPI/Architecture.def and
CPU_SUBTYPE_ARM64E_X1 = 12 in BinaryFormat/MachO.h — after their exact
anchor lines, on a fresh extraction and on a tree extracted before the
patch existed. A missing or duplicated anchor fails the step; a line
already present is left alone. The patch is pinned to 22.1.6: any other
COMPILER_LLVM_VERSION fails the step until the patch is deleted (an LLVM
that carries b8007a8e) or re-anchored, so it cannot outlive its version.
Refs #1826.

* sdk: every SDK subprocess runs with the shell's toolchain-flag variables empty

CMake folds LDFLAGS, CPPFLAGS, CFLAGS, CXXFLAGS and the *_PATH search
variables from the environment into every compile and link line. On a
shell carrying a package manager's LLVM (LDFLAGS=-L/opt/llvm-22.1.6/lib),
the SDK's ninja linked that LLVM's libc++ ahead of the sysroot's and died
with undefined std::length_error symbols (2026-09-28, while rebuilding
the darwin SDK for #1826). The SDK is built by the tools the graph names
and nothing else: sdk_run_capture now runs every subprocess through a
ProcessSpec that sets those variables empty.

* ci: SDK canary — the pre-stage SDK link check against the newest Xcode SDK, nightly and on request (#1826)

`with build :sdk-host-link-check` runs the probe every compiler build
runs before its stage links (#1840's comp_require_linkable_host_sdk) on
its own, and sdk-canary.yml runs it on macos-latest and on GitHub's
xcode-27 preview image with SDKROOT at the newest MacOSX<ver>.sdk under
/Applications/Xcode*.app (or an SDK given at dispatch). A slice this
LLVM's TextAPI cannot parse fails the lane naming the SDK, the linker
and the rejected stub target, before that SDK is every developer's
default SDKROOT. A canary, not a merge signal (D56).

* nightly-release: darwin-aarch64 pins the republished SDK nightly-sdk-20260928-3ae5c9ec0b31 (#1826)

with-llvm-sdk-22.1.6-darwin-aarch64.tar.gz built from source at 3ae5c9e
with the arm64e.x1 backport; its ld64.lld links against Xcode 27's SDK.
sha256 dd824534e89fe9570558036a69fcddfecb6075b0fcad1bfa7f502c67272de7a4.

* sdk-host-link-check: the verdict is the output file; LLVM_PREFIX is the action's input

Under the pinned seed a standalone action in a built tree evaluates at
comptime, where print (generic over Display) does not resolve, so the
check and the source-step backport no longer print; the check writes
"<lld> (LLVM <ver>) reads <sdk>" to its output and the canary lane cats
it. LLVM_PREFIX is now the action's env_input: the check is about one
linker, and pointing at another SDK re-runs it instead of a cache hit
(verified: the pre-backport lld against Xcode 27 fails naming
arm64e.x1-macos; the republished lld passes).

* sdk-canary: the seed pin follows seed.lock (nightly-20260929-local-1-2fa54a7197df)

The canary workflow this layer adds was written before the seed moved;
seed-driver refused its stale pin in the stack battery.

---------

Co-authored-by: Eric Hartford <[email protected]>
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Oct 2, 2026
Update LLVM submodule to latest release/23.x branch

Updates to rust-lang/llvm-project#200.

This includes LLVM 23.1.2, and a bunch of commits from LLVM 23.1.3 (which is yet unreleased).

In particular, it includes llvm/llvm-project#224185 (llvm/llvm-project#222721), which should fix #162928.

r? nikic
@bors rollup=never
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Oct 3, 2026
Update LLVM submodule to latest release/23.x branch

Updates to rust-lang/llvm-project#200.

This includes LLVM 23.1.2, and a bunch of commits from LLVM 23.1.3 (which is yet unreleased).

In particular, it includes llvm/llvm-project#224185 (llvm/llvm-project#222721), which should fix #162928.

r? nikic
@bors rollup=never
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Oct 3, 2026
Update LLVM submodule to latest release/23.x branch

Updates to rust-lang/llvm-project#200.

This includes LLVM 23.1.2, and a bunch of commits from LLVM 23.1.3 (which is yet unreleased).

In particular, it includes llvm/llvm-project#224185 (llvm/llvm-project#222721), which should fix #162928.

r? nikic
@bors rollup=never
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Oct 5, 2026
Update LLVM submodule to latest release/23.x branch

Updates to rust-lang/llvm-project#200.

This includes LLVM 23.1.2, and a bunch of commits from LLVM 23.1.3 (which is yet unreleased).

In particular, it includes llvm/llvm-project#224185 (llvm/llvm-project#222721), which should fix rust-lang/rust#162928.

r? nikic
@bors rollup=never
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Oct 5, 2026
Update LLVM submodule to latest release/23.x branch

Updates to rust-lang/llvm-project#200.

This includes LLVM 23.1.2, and a bunch of commits from LLVM 23.1.3 (which is yet unreleased).

In particular, it includes llvm/llvm-project#224185 (llvm/llvm-project#222721), which should fix rust-lang/rust#162928.

r? nikic
@bors rollup=never
programskillforverification pushed a commit to programskillforverification/miri that referenced this pull request Oct 5, 2026
Update LLVM submodule to latest release/23.x branch

Updates to rust-lang/llvm-project#200.

This includes LLVM 23.1.2, and a bunch of commits from LLVM 23.1.3 (which is yet unreleased).

In particular, it includes llvm/llvm-project#224185 (llvm/llvm-project#222721), which should fix rust-lang/rust#162928.

r? nikic
@bors rollup=never
byAbas added a commit to byAbas/archgram that referenced this pull request Oct 7, 2026
…SDK (#99)

## What and why

On a Mac whose Command Line Tools default to the macOS 27 SDK, nothing
in this repository links. `cargo build` fails with `rust-lld: error:
could not load TAPI file … libSystem.tbd: malformed file … unknown
architecture arm64e.x1`.

- **The cause:** the SDK's `.tbd` stubs list a new target, `arm64e.x1`.
LLVM's linker rejects a stub it cannot read
([rust-lang/rust#162928](rust-lang/rust#162928)).
- **The fix upstream:** in LLVM
([llvm/llvm-project#222721](llvm/llvm-project#222721),
backported in
[#224185](llvm/llvm-project#224185)). It reaches
Rust only in 1.101.0, due on 2026-12-24
([rust-lang/rust#163615](rust-lang/rust#163615),
milestone 1.101.0; [releases.rs](https://releases.rs/)).
- **Tested on this Mac:** the `rust-lld` of 1.98.1 (pinned), 1.99.0 and
1.100.0-beta.4 all fail; 1.101.0-nightly links.
- **CI:** it passes today only because `macos-latest` is the
`macos-26-arm64` image, with Xcode 26. When it moves to the 27 SDK, CI
and the macOS release builds fail the same way.

`.cargo/config.toml` now leaves macOS to rustc's default, Apple's
linker. It ships with Apple's SDK, so it reads it, and a new SDK cannot
outrun it the way it outran `rust-lld`. Windows keeps `rust-lld`.

The reasons the file gave for `rust-lld` do not hold on macOS:
- **Speed:** a release rebuild took 0.55 s with Apple's linker, against
0.53 s.
- **"The same linker everywhere":** Linux already used its system
linker.

The comment now says why each platform links as it does.

## Not in this change

- Moving to Rust 1.101 once it is out. With Apple's linker, nothing here
waits for it.
- Linux and Windows, which are unchanged.

## How it was checked

On this Mac, with the default SDK (`xcrun --show-sdk-version`: 27.0),
and no `SDKROOT` or linker set in the environment:
- From `cargo clean`: `cargo fmt --check`, `cargo clippy --workspace
--all-targets --locked -- -D warnings` and `cargo test --workspace
--locked` pass (177 tests).
- The launcher's tests, the README copy check and the three
`scripts/*.test` pass.
- A release build, `archgram 0.7.0`, draws `examples/linkshort.json` to
the same bytes as archgram 0.7.0 from npm, which CI built with
`rust-lld`. The linker changes nothing archgram draws.
- CI's macOS jobs run on Xcode 26, where Apple's linker reads that SDK
too.

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

Co-authored-by: Claude Opus 5.5 <[email protected]>
@nico

nico commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Manually merged in ee66426.

(and 8f747d6 and 532fa5a – thanks for merging!)

GauravPawar101 pushed a commit to GauravPawar101/rust-analyzer that referenced this pull request Oct 12, 2026
Update LLVM submodule to latest release/23.x branch

Updates to rust-lang/llvm-project#200.

This includes LLVM 23.1.2, and a bunch of commits from LLVM 23.1.3 (which is yet unreleased).

In particular, it includes llvm/llvm-project#224185 (llvm/llvm-project#222721), which should fix rust-lang/rust#162928.

r? nikic
@bors rollup=never
helly25 pushed a commit to bazel-contrib/toolchains_llvm that referenced this pull request Oct 12, 2026
LLVM 23.1.3 includes the ld64.lld arm64e.x1 backport
(llvm/llvm-project#224185), so its bundled linker reads current macOS
SDK TAPI stubs. The warning added in #870 matches every `23.` version.
It still fires for 23.1.3 and advises `linker = "auto"`. On older Xcode
versions that advice can break ThinLTO: we saw Xcode 16's ld use its own
libLTO and reject clang 20 bitcode.

- Limit `llvm_23_macos_uses_bundled_linker` to 23.x releases before
23.1.3, using the existing `versions` helper.
- Name 23.1.3 as the fixed release in the warning text and in the
README.
- Add a `23.1.3 defaults -> False` case to `linker_version_test`.

Testing:
- `bazel test //toolchain/internal:all` passes, 19 tests.
- `buildifier --lint=warn` is clean on the changed `.bzl` files.
- On an Apple Silicon Mac with the macOS 27.0 SDK, LLVM 23.1.3's bundled
ld64.lld linked cgo and C++ targets, including ThinLTO objects, with no
linker override.

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

Development

Successfully merging this pull request may close these issues.

6 participants