@@ -435,6 +435,13 @@ function(add_libc_fuzzer target_name)
435
435
436
436
endfunction (add_libc_fuzzer )
437
437
438
+ # Get libgcc_s to be used in hermetic and integration tests.
439
+ if (NOT LIBC_COMPILER_SUPPORT_NOSTDLIBPP )
440
+ execute_process (COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libgcc_s.so.1
441
+ OUTPUT_VARIABLE LIBGCC_S_LOCATION )
442
+ string (STRIP ${LIBGCC_S_LOCATION} LIBGCC_S_LOCATION )
443
+ endif ()
444
+
438
445
# DEPRECATED: Use add_hermetic_test instead.
439
446
#
440
447
# Rule to add an integration test. An integration test is like a unit test
@@ -564,10 +571,13 @@ function(add_integration_test test_name)
564
571
565
572
if (LIBC_TARGET_ARCHITECTURE_IS_GPU )
566
573
target_link_options (${fq_build_target_name} PRIVATE -nostdlib -static )
567
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
574
+ elseif (LIBC_COMPILER_SUPPORT_NOSTDLIBPP )
568
575
target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
569
576
else ()
570
- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib -static )
577
+ # Older version of gcc does not support `nostdlib++` flag. We use
578
+ # `nostdlib` and link against libgcc_s, which cannot be linked statically.
579
+ target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib )
580
+ list (APPEND link_libraries ${LIBGCC_S_LOCATION} )
571
581
endif ()
572
582
target_link_libraries (
573
583
${fq_build_target_name}
@@ -743,10 +753,13 @@ function(add_libc_hermetic_test test_name)
743
753
744
754
if (LIBC_TARGET_ARCHITECTURE_IS_GPU )
745
755
target_link_options (${fq_build_target_name} PRIVATE -nostdlib -static )
746
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
756
+ elseif (LIBC_COMPILER_SUPPORT_NOSTDLIBPP )
747
757
target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
748
758
else ()
749
- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib -static )
759
+ # Older version of gcc does not support `nostdlib++` flag. We use
760
+ # `nostdlib` and link against libgcc_s, which cannot be linked statically.
761
+ target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib )
762
+ list (APPEND link_libraries ${LIBGCC_S_LOCATION} )
750
763
endif ()
751
764
target_link_libraries (
752
765
${fq_build_target_name}
0 commit comments