When compiler-rt is configured as a runtime, the configure-time target detection for builtins is done in compile-only mode, which is basically a test of whether the newly-built clang can compile a simple program with an additional flag (-m32 and -m64 in my case). The problem is that on my Debian system clang can compile int foo(int x, int y) { return x + y; } with -m32 but fails to include limits.h (or any other target-specific header) for the i386 target:
$ /path/to/build/./bin/clang --target=x86_64-unknown-linux-gnu -DVISIBILITY_HIDDEN -O3 -DNDEBUG -m32 -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -MD -MT CMakeFiles/clang_rt.builtins-i386.dir/absvdi2.c.o -MF CMakeFiles/clang_rt.builtins-i386.dir/absvdi2.c.o.d -o CMakeFiles/clang_rt.builtins-i386.dir/absvdi2.c.o -c /path/to/src/compiler-rt/lib/builtins/absvdi2.c In file included from /path/to/src/compiler-rt/lib/builtins/absvdi2.c:13: In file included from /path/to/src/compiler-rt/lib/builtins/int_lib.h:93: In file included from /path/to/build/lib/clang/15.0.0/include/limits.h:21: In file included from /usr/include/limits.h:25: /usr/include/features.h:364:12: fatal error: 'sys/cdefs.h' file not found # include <sys/cdefs.h> ^~~~~~~~~~~~~ 1 error generated.
This is an attempt to make the target detection more robust: extend the test program with #include <limits.h>. A small problem here is that we might need to include either sys/limits.h or machine/limits.h instead. So, the first attempt to solve this is to simply iterate over possible system header names and accept the target if any of the headers is available.
This seems incorrect. limits.h is the standard header and should be available. This seems more related to -m32 requiring the 32-bit compatibility headers on Linux. The other headers are not the same header in different locations.