@@ -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_CC_SUPPORTS_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,8 +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
- else ( )
574
+ elseif ( LIBC_CC_SUPPORTS_NOSTDLIBPP )
568
575
target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
576
+ else ()
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} )
569
581
endif ()
570
582
target_link_libraries (
571
583
${fq_build_target_name}
@@ -741,8 +753,13 @@ function(add_libc_hermetic_test test_name)
741
753
742
754
if (LIBC_TARGET_ARCHITECTURE_IS_GPU )
743
755
target_link_options (${fq_build_target_name} PRIVATE -nostdlib -static )
744
- else ( )
756
+ elseif ( LIBC_CC_SUPPORTS_NOSTDLIBPP )
745
757
target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
758
+ else ()
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} )
746
763
endif ()
747
764
target_link_libraries (
748
765
${fq_build_target_name}
0 commit comments