[Chapel Merge] Workaround LLVM and libc++ issue

Branch: refs/heads/main
Revision: b3636e6e5566fc9a0e7b2ce58a2499c3803ea790
Author: jabraham17
Link: Workaround LLVM and libc++ issue by jabraham17 · Pull Request #28374 · chapel-lang/chapel · GitHub
Log Message:
Workaround LLVM and libc++ issue (#28374)

Adds a workaround for linking against C++ libraries in Chapel with LLVM
21 (specifically issues with linking re2)

We saw errors like:

Undefined symbols for architecture arm64:
  "std::__1::__hash_memory(void const*, unsigned long)", referenced from:
      std::__1::hash<re2::DFA::State*>::operator()[abi:ne210107](re2::DFA::State*) const in libre2.a[6](dfa.o)
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

and

> Undefined symbols for architecture arm64:
>   "std::__1::__hash_memory(void const*, unsigned long)", referenced from:
>       re2::DFA::BuildAllStates(std::__1::function<void (int const*, bool)> const&) in libre2.a[6](dfa.o)
>       std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<std::__1::__hash_value_type<re2::DFA::State*, int>, void*>*>, bool> std::__1::__hash_table<std::__1::__hash_value_type<re2::DFA::State*, int>, std::__1::__unordered_map_hasher<re2::DFA::State*, std::__1::pair<re2::DFA::State* const, int>, std::__1::hash<re2::DFA::State*>, std::__1::equal_to<re2::DFA::State*>, true>, std::__1::__unordered_map_equal<re2::DFA::State*, std::__1::pair<re2::DFA::State* const, int>, std::__1::equal_to<re2::DFA::State*>, std::__1::hash<re2::DFA::State*>, true>, std::__1::allocator<std::__1::pair<re2::DFA::State* const, int>>>::__emplace_unique_key_args<re2::DFA::State*, re2::DFA::State*&, int>(re2::DFA::State* const&, re2::DFA::State*&, int&&) in libre2.a[6](dfa.o)
>       std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<std::__1::__hash_value_type<re2::DFA::State*, int>, void*>*>, bool> std::__1::__hash_table<std::__1::__hash_value_type<re2::DFA::State*, int>, std::__1::__unordered_map_hasher<re2::DFA::State*, std::__1::pair<re2::DFA::State* const, int>, std::__1::hash<re2::DFA::State*>, std::__1::equal_to<re2::DFA::State*>, true>, std::__1::__unordered_map_equal<re2::DFA::State*, std::__1::pair<re2::DFA::State* const, int>, std::__1::equal_to<re2::DFA::State*>, std::__1::hash<re2::DFA::State*>, true>, std::__1::allocator<std::__1::pair<re2::DFA::State* const, int>>>::__emplace_unique_key_args<re2::DFA::State*, std::__1::piecewise_construct_t const&, std::__1::tuple<re2::DFA::State* const&>, std::__1::tuple<>>(re2::DFA::State* const&, std::__1::piecewise_construct_t const&, std::__1::tuple<re2::DFA::State* const&>&&, std::__1::tuple<>&&) in libre2.a[6](dfa.o)
> ld: symbol(s) not found for architecture arm64
> clang++: error: linker command failed with exit code 1 (use -v to see invocation)
> error: Make Binary - Linking

This was traced to be caused by
[D148266] [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang · Issue #77653 · llvm/llvm-project · GitHub and
Undefined reference issues when mixing Homebrew LLVM 21.1.0 with system libc++ · Issue #235411 · Homebrew/homebrew-core · GitHub. This is an
upstream issue, but its possible to workaround the issue by explicitly
linking against the libc++ shipped with LLVM. See
Undefined reference issues when mixing Homebrew LLVM 21.1.0 with system libc++ · Issue #235411 · Homebrew/homebrew-core · GitHub

We have only seen this problem with a homebrew LLVM and on Macs, so the
fix is restricted to MacOS.

[Reviewed by @benharsh]

Compare: Comparing c137153a1043a297929c684f4d0cd7979fdf9241...bb523044adf8b1da896b8e227a00b2481171eb18 · chapel-lang/chapel · GitHub

Diff:
M util/chplenv/chpl_llvm.py
M util/chplenv/chpl_re2.py
https://github.com/chapel-lang/chapel/pull/28374.diff