[libc][compiler-rt] Resolve __errno_location vs __llvm_libc_errno ABI mismatch
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Enabling full-build coverage for llvm-libc (PR #221802) required linking hermetic tests against libclang_rt.profile.a. This failed with undefined references to __errno_location, requiring a temporary shim in libc/test/UnitTest/HermeticTestUtils.cpp that forwards __errno_location() to LIBC_NAMESPACE::__llvm_libc_errno().
Root Causes:
1. compiler-rt/lib/sanitizer_common/sanitizer_errno.h:24-40 hardcodes platform errno accessors and defaults to glibc's extern "C" int *__errno_location() on Linux instead of __llvm_libc_errno(). (See also dfsan_interceptors.cpp:126 and msan_interceptors.cpp:1452).
2. compiler-rt/lib/profile (InstrProfilingFile.c, InstrProfilingUtil.c) includes . When built against host glibc headers on Linux, errno expands to (*__errno_location()), whereas llvm-libc's generic-error-number-macros.h expands errno to (*__llvm_libc_errno()).
Tasks:
- Update compiler-rt/lib/sanitizer_common/sanitizer_errno.h to use __llvm_libc_errno when targeting llvm-libc.
- Ensure LLVM_ENABLE_RUNTIMES="libc;compiler-rt" with LLVM_LIBC_FULL_BUILD=ON compiles compiler-rt against llvm-libc's generated headers.
- Remove the temporary __errno_location shim from libc/test/UnitTest/HermeticTestUtils.cpp.
Contributor guide
Assessment
This issue has not been assessed yet.