[libcxx-commits] [libcxx] [libc++] Fix the locale base API on Linux with musl (PR #167980)

Mr. Walls via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 4 13:48:59 PST 2025


reactive-firewall wrote:

> IIUC it would be more correct for us to say something like
> 
> ```
> #  elif defined(_LIBCPP_USING_GLIBC)
> #    include <__locale_dir/support/glibc.h>
> ```
> 
> than what we do today, i.e.
> 
> ```
> #  elif defined(__linux__)
> #    include <__locale_dir/support/linux.h>
> ```
> 
> Would you agree?

Indeed, it would be more correct. The GHI llvm/llvm-project#167977 would likely (IMHO) be resolved by such an approach, albeit I'm not familiar enough with all the uses of "<__locale_dir/support/linux.h>" (as it is now) to be sure of the totality of such a change.

TL;DR - as a technical note the only confirmed issue I'm aware of is the difference in how musl conditionally declares the `_l` functions based on the symbol `_GNU_SOURCE` see llvm/llvm-project#167977 - but they are currently implemented in musl v1.2.5 to just voidcast the local argument and wrap the `strto`* non-locale variants (IIUC with an UTF-8 assumption citing ISO 9989:2011+)

And in detail it would be more correct to:

check for `__STDC__` to know there is _any_ libc (e.g. glibc, musl libc, bsd's libc, etc.), for generic commonalities.

e.g. something like:
```
#  if defined(__STDC_₎ || defined(_LIBCPP_HAS_LIBC)
#    include <__locale_dir/support/generic.h>
#    if defined(__linux__)
#      include <__locale_dir/support/linux.h>
#      if defined(_LIBCPP_USING_GLIBC)
#         include <__locale_dir/support/glibc.h>
#      else /* non-glibc + some libc = can assume musl */
#        if defined(_GNU_SOURCE)
#         include <__locale_dir/support/musl.h>
#        else
           /* warning No support for locale api functions */
#        endif
#    else /* non-linux libc */
#      if defined(_BSD_SOURCE)
#        include <__locale_dir/support/musl.h> /* e.g. other stuff currently wrapped in linux.h/freebsd.h */
#      else
         /* e.g. apple's system_c.dylib libc, etc. */
#      endif
#    endif
#  endif /* missing libc */
```

but that felt too monolithic/intrusive for my first-go-around (as I'm not very comfortable with glibc specifics)

https://github.com/llvm/llvm-project/pull/167980


More information about the libcxx-commits mailing list