`check_pie_supported()` fails with Clang's source-based code coverage flags on FreeBSD
To compile code with Clang's [Source-based Code Coverage](https://clang.llvm.org/docs/SourceBasedCodeCoverage.html) enabled, the `-fprofile-instr-generate -fcoverage-mapping` options must be passed to the compiler. However, this causes the `check_pie_supported()` function to fail on FreeBSD 14.1: ``` $ env CXXFLAGS="-fprofile-instr-generate -fcoverage-mapping" cmake -B build -- The CXX compiler identification is Clang 18.1.5 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Warning at CMakeLists.txt:6 (message): PIE is not supported at link time: PIE (CXX): Change Dir: '/home/hebasto/PIE_TEST/build/CMakeFiles/CMakeScratch/TryCompile-q84aom' Run Build Command(s): /usr/local/bin/cmake -E env VERBOSE=1 /usr/local/bin/gmake -f Makefile cmTC_848c6/fast /usr/local/bin/gmake -f CMakeFiles/cmTC_848c6.dir/build.make CMakeFiles/cmTC_848c6.dir/build gmake[1]: Entering directory '/home/hebasto/PIE_TEST/build/CMakeFiles/CMakeScratch/TryCompile-q84aom' Building CXX object CMakeFiles/cmTC_848c6.dir/src.cxx.o /usr/bin/c++ -DCMAKE_CXX_LINK_PIE_SUPPORTED -fprofile-instr-generate -fcoverage-mapping -MD -MT CMakeFiles/cmTC_848c6.dir/src.cxx.o -MF CMakeFiles/cmTC_848c6.dir/src.cxx.o.d -o CMakeFiles/cmTC_848c6.dir/src.cxx.o -c /home/hebasto/PIE_TEST/build/CMakeFiles/CMakeScratch/TryCompile-q84aom/src.cxx Linking CXX executable cmTC_848c6 /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_848c6.dir/link.txt --verbose=1 /usr/bin/c++ -fprofile-instr-generate -fcoverage-mapping -fPIE -pie CMakeFiles/cmTC_848c6.dir/src.cxx.o -o cmTC_848c6 ld: error: relocation R_X86_64_32S cannot be used against local symbol; recompile with -fPIC >>> defined in CMakeFiles/cmTC_848c6.dir/src.cxx.o >>> referenced by src.cxx >>> CMakeFiles/cmTC_848c6.dir/src.cxx.o:(main) ld: error: relocation R_X86_64_32S cannot be used against local symbol; recompile with -fPIC >>> defined in CMakeFiles/cmTC_848c6.dir/src.cxx.o >>> referenced by src.cxx >>> CMakeFiles/cmTC_848c6.dir/src.cxx.o:(main) c++: error: linker command failed with exit code 1 (use -v to see invocation) gmake[1]: *** [CMakeFiles/cmTC_848c6.dir/build.make:100: cmTC_848c6] Error 1 gmake[1]: Leaving directory '/home/hebasto/PIE_TEST/build/CMakeFiles/CMakeScratch/TryCompile-q84aom' gmake: *** [Makefile:127: cmTC_848c6/fast] Error 2 . -- Configuring done (0.2s) -- Generating done (0.0s) -- Build files have been written to: /home/hebasto/PIE_TEST/build ``` ``` $ cat CMakeLists.txt cmake_minimum_required(VERSION 3.14) project(test CXX) include(CheckPIESupported) check_pie_supported(OUTPUT_VARIABLE output LANGUAGES CXX) if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED) message(WARNING "PIE is not supported at link time: ${output}.") endif() ```
issue