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

    <tr>
        <th>Summary</th>
        <td>
            Universal build of llvm/lldb for macOS now requires 10.14 as deployment target
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lldb,
            platform:macos
      </td>
    </tr>

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

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

<pre>
    For redistribution of llvm and associated tools, I build it as universal binaries for macOS. I do this by passing `-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9` to CMake - so I simply do one build, where each object file is compiled for both architectures at once.

(A better universal build would be to do two full builds in parallel and then merge all the binaries with `lipo` - but that's much more effort. This kind of single-build universal binaries have some minor downsides, e.g. if building on x86_64, the arm64 version of the binaries still default to targeting `x86_64-apple-darwin`. But for a toolchain that primarily is meant for cross compiling targeting other OSes, this is a quite good compromise.)

Since switching to C++17, this build configuration fails with errors like these:
```
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:641:7: error: aligned deallocation function of type 'void (void *, std::align_val_t) noexcept' is only available on macOS 10.14 or newer
class RegisterContextDarwin_arm64_Mach : public RegisterContextDarwin_arm64 {
      ^
```

The root cause for this seems to be that data types that require 16 byte alignment now triggers calls to aligned new/delete - which is only available since macOS 10.14. And this is only required for the arm64 part of the compilation - apparently, the regular new/delete is enough for 16 byte alignment on x86_64, but for arm64, it needs the newer aligned new/delete.

This is a somewhat silly situation, because in the universal binary, the x86_64 part of the binary, which doesn't need the modern aligned new/delete, is the part where it makes sense to target an older deployment target. For arm64, there's no need to target anything below 11.0 anyway (the first public release of arm64 macOS). If one would make the universal binaries by doing two separate compilations, it would be easy to set different deployment targets for them each - but if doing a single build for two architectures, it's no longer possible to target versions below 10.14.

This only seems to be an issue in LLDB - if only building e.g. llvm, lld, clang, it works fine to keep targeting older versions. Presumably, the issue could be also be avoided by not using types that requires larger alignments.

The core issue can be reproduced with a test snippet like this:
```c++
class MyClass {
public:
  virtual ~MyClass() {}
  __uint128_t var;
};
```
```
$ clang++ -c aligned.cpp -c -std=c++17 -mmacosx-version-min=10.13 -arch arm64
aligned.cpp:4:11: error: aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on macOS 10.14 or newer
  virtual ~MyClass() {}
          ^
aligned.cpp:4:11: note: if you supply your own aligned allocation functions, use -faligned-allocation to silence this diagnostic
1 error generated.
```
If either of the parameters is tweaked; changing to `-std=c++14`, setting `-mmacosx-version-min=10.14` or `-arch x86_64`, the compilation of the test snippet succeeds.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1V01z47gR_TXSBSWWqG8ddJAtO9nKOJ4ae6uSkwokWxR2QIIBQGv07_MaIGXJ9qZySFwyKZJQ43X3637NzBTnzaOxwlKhnLcqa70ytTAHofVbJWRdCOmcyZX0VAhvjHaDyb34TWSt0oVQHo9FW6s3sk5qkalaWkVOHGCzkvnzS4K1hRH-qJzIzqKBNVWXYrAYj3b3T9u_PeyfX_6x3_64_-tvrw_3r7__eHgZTHfSVovZYHr3a7XYL2bieunu4fu3538-Pfz9df-6_fGXh1csT8fJGhaBT9w_yZ8kRsIZbOxU1egz729qipAZ_elIlgTJ_ChM9gflXhyUJgGEuakafC0C_sz4o5A2PyqPNa2FW9LDUk7JYLwbjLfdcbLaioy8J3sdiRCfk2lxzIiRcRRORhxa3T11QtUIiJVakw6h9keqRUW2JIGbfPke0ZMCGjipVWPY1xGMeCyRfjBZOlG18KYy7NcB4H0iXjnkPxXMIpscdE2jiOqLfB3lGyFmFYlK1fC9MKfaqYJCtikpE6EOETVnDwyJmeGnjDLkS7DRjj030J1X8Kagg2y151B4CRd9x4NoaSSbBgALaU-qxt1E3ME9ToMMtMuPEtFid0VjVQXDSCwcrEjWcV1ujeszyKbfN0EekZvn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