Skip to content

swift: linking packages with c++ interop fails with both gnu ld and lld #570491

Closed

Description

@WeetHet

Nixpkgs version

  • Unstable (26.11)

Describe the bug

Building a swift package with C++ interop enabled fails with a linking error:

ld.bfd: /nix/store/…-stdlib-6.2.4-dev/lib/libswiftCxx.a(Cxx.o): unrecognized relocation type 0x13b in section `swift5_typeref'
ld.bfd: final link failed: bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Changing the linker to lld (swiftpmFlags = [ "-Xswiftc" "-use-ld=lld" ]) ends up with a different set of errors:

ld.lld: error: corrupt input file: version definition index 0 for symbol $ss12_SmallStringVyABSgSRys5UInt8VGcfC is out of bounds
ld.lld: error: corrupt input file: version definition index 0 for symbol $ss6SIMD64V8highHalfs6SIMD32VyxGvs is out of bounds
ld.lld: error: corrupt input file: version definition index 0 for symbol $ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys6UInt64VSgAFm_0I0QztKFTq is out of bounds
ld.lld: error: corrupt input file: version definition index 0 for symbol $sSeTL is out of bounds
ld.lld: error: corrupt input file: version definition index 0 for symbol $ss5UInt8V5WordsVMa is out of bounds

Steps to reproduce

Try to build the following Swift package with main.swift:

import CxxStdlib

let hello = std.string("Hello, C++!")
print(Array(hello).count)
// swift-tools-version: 6.2

import PackageDescription

let package = Package(
  name: "Repro",
  targets: [
    .executableTarget(
      name: "Repro",
      swiftSettings: [.interoperabilityMode(.Cxx)]
    )
  ]
)
{
  pkgs ? import <nixpkgs> { },
}:
pkgs.swiftPackages.stdenv.mkDerivation {
  name = "swift-cxx-interop-link-repro";

  src = ./.;

  strictDeps = true;

  nativeBuildInputs = [
    pkgs.swiftPackages.swift
    pkgs.swiftPackages.swiftpm
  ];

  installPhase = ''
    runHook preInstall
    "$(swiftpmBinPath)/Repro" | tee "$out"
    runHook postInstall
  '';
}

Expected behaviour

Linking should finish successfully independent of what linker is being used

System metadata

  • system: "aarch64-linux"
  • host os: Linux 6.8.0-117-generic
  • multi-user?: yes
  • sandbox: no
  • version: nix-env (Nix) 2.35.2
  • channels(root): ""
  • nixpkgs: /nix/store/y4g1nqn7vc8gxh49ni12cpksg9xc154y-source

Notify maintainers

cc @reckenrode @Samasaur1 @stephank


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

Activity

  1. added
    0.kind: bug
    on Oct 5, 2026
  2. reckenrode commented on Oct 8, 2026

    @reckenrode
    Contributor

    I’m switching Swift to use LLD on both Darwin and Linux to build the compiler and the stdlib. It appears to fix both of these issues. That work will land along with Swift 6.4, which I’m still targeting for 26.11.

  3. reckenrode commented on Oct 13, 2026

    @reckenrode
    Contributor

    Quick change of plans. I am going to start landing some of the cleanups and fixes ahead of my Swift 6.4 branch. I still want to get Swift 6.4 into 26.11, but these can go straight to master and not have to wait on a staging cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions