<pre style='margin:0'>
Chris Jones (cjones051073) pushed a commit to branch master
in repository macports-ports.
</pre>
<p><a href="https://github.com/macports/macports-ports/commit/70088c9cf4ce312082ecf721d7a4776df8b1eca7">https://github.com/macports/macports-ports/commit/70088c9cf4ce312082ecf721d7a4776df8b1eca7</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 70088c9cf4ce312082ecf721d7a4776df8b1eca7
</span>Author: Mark Mentovai <mark@mentovai.com>
AuthorDate: Thu Sep 26 10:08:43 2024 -0400
<span style='display:block; white-space:pre;color:#404040;'> clang-15: Move libc++*.* libraries to libc++ sub-dir, fix install names
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This applies a1d4865220b5, which addressed this for clang-16–18 for
</span><span style='display:block; white-space:pre;color:#404040;'> https://trac.macports.org/ticket/68640, to clang-15, to fix a bug
</span><span style='display:block; white-space:pre;color:#404040;'> observed while running clang-15 as a linker driver on macOS 15.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> When running as a linker driver, clang provides ld with clang’s own LTO
</span><span style='display:block; white-space:pre;color:#404040;'> plugin by invoking ld with `-lto_library
</span><span style='display:block; white-space:pre;color:#404040;'> ${PREFIX}/libexec/llvm-15/lib/libLTO.dylib`. Upon receipt of these
</span><span style='display:block; white-space:pre;color:#404040;'> arguments, Xcode ld currently loads the plugin by re-`execve`ing itself
</span><span style='display:block; white-space:pre;color:#404040;'> with DYLD_LIBRARY_PATH=${PREFIX}/libexec/llvm-15/lib in effect, causing
</span><span style='display:block; white-space:pre;color:#404040;'> dyld to prefer libLTO.dylib in that directory over the
</span><span style='display:block; white-space:pre;color:#404040;'> @rpath/libLTO.dylib that ld requests to load via a Mach-O load command.
</span><span style='display:block; white-space:pre;color:#404040;'> With DYLD_LIBRARY_PATH in effect, dyld can potentially use any other
</span><span style='display:block; white-space:pre;color:#404040;'> module in that same directory to satisfy any other Mach-O load command.
</span><span style='display:block; white-space:pre;color:#404040;'> In this case, the directory contained both libc++.dylib and
</span><span style='display:block; white-space:pre;color:#404040;'> libc++abi.dylib from clang, and dyld used these to replace the libraries
</span><span style='display:block; white-space:pre;color:#404040;'> of the same name ordinarily provided by the OS in /usr/lib (via the dyld
</span><span style='display:block; white-space:pre;color:#404040;'> shared cache). This is undesirable in general, but occurred silently on
</span><span style='display:block; white-space:pre;color:#404040;'> macOS < 15. It became noticeable on macOS 15 because system libraries
</span><span style='display:block; white-space:pre;color:#404040;'> that depend on libc++abi.dylib now reference symbols that are present in
</span><span style='display:block; white-space:pre;color:#404040;'> the system’s version, but not in clang’s, causing messages such as
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> dyld[60301]: symbol '__ZnwmSt19__type_descriptor_t' missing from root that overrides /usr/lib/libc++abi.dylib. Use of that symbol in /usr/lib/swift/libswiftCore.dylib is being set to 0xBAD4007.
</span><span style='display:block; white-space:pre;color:#404040;'> dyld[60301]: symbol '__ZdlPvSt19__type_descriptor_t' missing from root that overrides /usr/lib/libc++abi.dylib. Use of that symbol in /usr/lib/swift/libswiftCore.dylib is being set to 0xBAD4007.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> repeated for every system library that references those symbols. These
</span><span style='display:block; white-space:pre;color:#404040;'> messages warn of potential run-time bugs due to dyld intentionally
</span><span style='display:block; white-space:pre;color:#404040;'> mis-resolving the missing symbols.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> As clang should not seek to replace the system’s libc++ with its own in
</span><span style='display:block; white-space:pre;color:#404040;'> system libraries, this was a latent problem even pre-macOS 15.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> The workaround moves clang’s libc++ libraries to a new subdirectory,
</span><span style='display:block; white-space:pre;color:#404040;'> ${PREFIX}/libexec/llvm-15/lib/libc++, where they will not be found or
</span><span style='display:block; white-space:pre;color:#404040;'> used even with DYLD_LIBRARY_PATH set to ${PREFIX}/libexec/llvm-15/lib as
</span><span style='display:block; white-space:pre;color:#404040;'> it is when clang runs the linker.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This also contains a fix for the LC_INSTALL_NAMEs of libc++.dylib and
</span><span style='display:block; white-space:pre;color:#404040;'> libc++abi.dylib, which should have been recorded as @rpath-relative, but
</span><span style='display:block; white-space:pre;color:#404040;'> due to an error in the Portfile’s handling of CMAKE_INSTALL_NAME_DIR,
</span><span style='display:block; white-space:pre;color:#404040;'> were instead recorded using absolute paths rooted at
</span><span style='display:block; white-space:pre;color:#404040;'> ${PREFIX}/libexec/llvm-15/lib. When the libraries were moved elsewhere,
</span><span style='display:block; white-space:pre;color:#404040;'> they tripped MacPorts’ check for linking errors due to libc++.dylib’s
</span><span style='display:block; white-space:pre;color:#404040;'> dependency on libc++abi.dylib at a path where it was no longer
</span><span style='display:block; white-space:pre;color:#404040;'> installed. Discussion at
</span><span style='display:block; white-space:pre;color:#404040;'> https://github.com/macports/macports-ports/pull/25918#issuecomment-2377971503.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This is an observable change in the installed clang-15 package, but the
</span><span style='display:block; white-space:pre;color:#404040;'> revision is not being bumped in this commit because this change is being
</span><span style='display:block; white-space:pre;color:#404040;'> merged atomically in #25918 with another change that updates clang-15’s
</span><span style='display:block; white-space:pre;color:#404040;'> revision.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> References: https://trac.macports.org/ticket/70779
</span>---
lang/llvm-15/Portfile | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/lang/llvm-15/Portfile b/lang/llvm-15/Portfile
</span><span style='display:block; white-space:pre;color:#808080;'>index 40cbc1b3e0d..e9a37d6188f 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/lang/llvm-15/Portfile
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/lang/llvm-15/Portfile
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -62,15 +62,14 @@ cmake.build_type Release
</span> cmake.install_rpath
configure.pre_args-delete \
<span style='display:block; white-space:pre;background:#ffe0e0;'>- -DCMAKE_INSTALL_NAME_DIR=${cmake.install_prefix}/lib \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- -DCMAKE_INSTALL_RPATH=${cmake.install_prefix}/lib
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ -DCMAKE_INSTALL_NAME_DIR="${cmake.install_prefix}/lib"
</span>
configure.pre_args-replace \
-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF
configure.pre_args-replace \
<span style='display:block; white-space:pre;background:#ffe0e0;'>- -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;${cmake.install_prefix}\;/usr" \
</span> -DCMAKE_SYSTEM_PREFIX_PATH="${cmake.install_prefix}\;${prefix}\;/usr"
configure.args-append \
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -456,6 +455,16 @@ post-destroot {
</span> macos-setup-codesign.sh \
${lldb_scripts_destdir}
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {${subport} eq "clang-${llvm_version}"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # move libc++ libraries out of default location to prevent accidental linkage
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set libcxx_dir ${destroot}${sub_prefix}/lib/libc++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ xinstall -d ${libcxx_dir}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ foreach f [glob -nocomplain ${destroot}${sub_prefix}/lib/libc++*.*] {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Moving ${f} to ${libcxx_dir}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ move ${f} ${libcxx_dir}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span> }
if {${subport} eq "clang-${llvm_version}"} {
</pre><pre style='margin:0'>
</pre>