Swift and Clang interop broken with Clang 13 on Linux

First time here and possibly the wrong topic. My apologies in advance.

I recently attempted to update my Linux CI to clang-13 and found that my Swift <--> C protobuf interop is broken. I'm unsure if this is the right forum to ask but the error message is mysterious enough it might be of interest here.

The error occurs when trying to link Apple's Swift Protobuf:

ld.lld: error: undefined hidden symbol: __start_swift5_protocols
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
>>> the encapsulation symbol needs to be retained under --gc-sections properly; consider -z nostart-stop-gc (see https://lld.llvm.org/ELF/start-stop-gc)

ld.lld: error: undefined hidden symbol: __stop_swift5_protocols
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __start_swift5_protocol_conformances

I put the full error log on the repro section of this repo.

This only happens when I use clang-13 on Linux. clang-13 (bundled with the latest XCode) on MacOS and clang-12 on Linux works fine. I tested it with Swift 5.4.1, 5.4.2, and 5.5.2.

To my untrained eyes, it looks like something changed with clang between 12 and 13 so that some kind of hidden symbols are no longer being linked in by default.

Any ideas?

I've seen this before, but I forget where and what made it go away.

How do you setup the Swift toolchain that you're using on linux, downloading it from swift.org or using some distro package? If the former, the system clang shouldn't be used anyway, as I think the compiler and SPM prefer the clang that ships in the Swift toolchain, whereas Swift distro packages may change that.

Even more unusual is that it's trying to link with lld, as Swift 5.5 still favors the gold linker. Is this because of the Bazel build you're using? It would help to see the Swift commands that your Bazel build is generating: that is the source of this error.