<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58277>58277</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            ld64.lld: error: too many personalities (4) for compact unwind to encode
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          glandium
      </td>
    </tr>
</table>

<pre>
    (Largely a copy/paste from https://github.com/rust-lang/rust/issues/102754)

When mixing ObjC, C++ and Rust in the same binary on aarch64-apple-darwin targets (e.g. like in Firefox), lld from LLVM 15 complains about "too many personalities". This does not happen with lld from LLVM 14 because AIUI it had limited support for compact unwind info (or no support at all). This does not happen with ld64.

For some reason, since https://github.com/rust-lang/rust/pull/92845, this code in lld is hit: https://github.com/llvm/llvm-project/blob/d30dccd21f2c3bc1ed6cd054c131436a1af548e1/lld/MachO/UnwindInfoSection.cpp#L300

Ultimately, this leads to https://github.com/llvm/llvm-project/blob/d30dccd21f2c3bc1ed6cd054c131436a1af548e1/lld/MachO/UnwindInfoSection.cpp#L378
where there are 4 personalities instead of 3:
- `___objc_personality_v0`,
- `___gxx_personality_v0`,
- `_rust_eh_personality`
- `<internal>`

With previous rust versions, only the first three ones would be there. It looks like the relocation that triggers the `<internal>` is related to the `rust_eh_personality` function in `library/std/src/personality/gcc.rs` itself.

STR:
- Create a `bar.cc` file with content:
```
#include <stdexcept>

extern "C" void qux();

void bar() { qux(); throw std::runtime_error("foo"); }
```
- Create a `foo.m` file with content:
```
void foo() { @try {} @finally {} }
```
- Create a `qux.rs` file with content:
```
#![crate_type = "staticlib"]

extern "C" {
    fn foo();
}

#[no_mangle]
pub unsafe extern "C" fn qux() {
    println!("foo");
    foo();
}
```
- Create a `Makefile` file with content:
```
TARGET = --target=aarch64-apple-darwin

lib.dylib: bar.o foo.o libqux.a
        clang++ -o $@ $^ -fuse-ld=lld -dynamiclib $(TARGET) -lobjc

bar.o: bar.cc
        clang++ -o $@ -c $^ $(TARGET)

foo.o: foo.m
        clang -o $@ -c $^ $(TARGET)

libqux.a: qux.rs
        rustc $^ $(TARGET)
```
- Get clang 15 + lld and make sure it's in your `$PATH`.
- Get rustc beta and make sure it's in your `$PATH`.
- Set `SDKROOT` to point to a macOS SDK
- Run `make`

This does not happen on x86_64-apple-darwin, but interestingly the list of personalities there is:
- `___objc_personality_v0`,
- `___gxx_personality_v0`,
- `<internal>`
(no `_rust_eh_personality`).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV1tT4zYU_jXOiyYeR3YuPOSBy7Jlyg4dYLePGVmWE-0qlivJkPz7fkcOIaEpWzrTmYKxLevoO_cLpa2284TPboVbKrNlgknbbhN-3QofFKudXbNVCK1P8nN8xbXUYdWVqbRrLFznw9CIZrl7x0N73ymPl1HGp-Mi4WdJdpVk5_3995Vq2FpvdLNkd-X3y4RfMtwucDHRVOweIEw3LKwU82KtWKkb4bbMNkwIJ1eTYija1qhhJdwz0ZHcwTOooNJlyoz-oej8tXaqthviDg7GVL0qt7ffvrDRGEquWyN045kobRdwnAdr2Vo0W9Yq520jjA6a9OApe1xpzyqrPGtsYCsIACWeYYe3wAUrlRSdV-z85usN00RcQaa1Dqpivmtb6wKrrYsCCBlY10CLChLXlnTATmP3hAKXMdDhXRGqSZEemvgaIN7CdE4JKEL6e91I9UE_th2xvj7js2JMGIEkkLaK5iW9sVzpALz3gI15enkMW2e_K0nYpbElHlWeVVJWfFRzmZdypKqJrLJxIUf5qMgnYiTqcTFTowhQ4f5FyNUdnl-j1W5gtAcAatuksm0Tnt_mWXZoiq8m6LUICOy9BkaJyrNg_09CT2e9uM8r5RSFPu4Cf8VxLMLwyEkElK1ZTpLHQ0OWTLLFYmHL73LxSr9dPGXYgN7HZMvN5qdUFAELtTqkI6JXiiS_1E1QDntJ_mm_t0txisrWqSdtO88Iiz0BCAp78oJtUGYovWv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