From 107ce71849bccb8749a9ff369f22641f092be432 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Thu, 24 Mar 2022 06:58:46 +0000 Subject: [PATCH] [libc] Use real objects and archives in integration tests. Previously, we used empty, non-ELF crti.o, crtn.o, libm.a and libc++.a files. Instead, we now still use dummies but they are real ELF object files and archives. --- libc/cmake/modules/LLVMLibCTestRules.cmake | 26 +++++++++++++++++--------- libc/loader/linux/CMakeLists.txt | 12 ++++++++++++ libc/loader/linux/crti.cpp | 0 libc/loader/linux/crtn.cpp | 0 libc/test/CMakeLists.txt | 4 ++++ libc/test/integration/CMakeLists.txt | 10 ++++++++++ libc/test/integration/dummy.cpp | 0 7 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 libc/loader/linux/crti.cpp create mode 100644 libc/loader/linux/crtn.cpp create mode 100644 libc/test/integration/dummy.cpp diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index edbeaaf..3bbebb0 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -294,6 +294,11 @@ endfunction(add_libc_fuzzer) # The DEPENDS list can be empty. If not empty, it should be a list of # targets added with add_entrypoint_object or add_object_library. function(add_integration_test test_name) + get_fq_target_name(${test_name} fq_target_name) + if(NOT (${LIBC_TARGET_OS} STREQUAL "linux")) + message(STATUS "Skipping ${fq_target_name} as it is not available on ${LIBC_TARGET_OS}.") + return() + endif() cmake_parse_arguments( "INTEGRATION_TEST" "" # No optional arguments @@ -301,7 +306,6 @@ function(add_integration_test test_name) "SRCS;HDRS;DEPENDS;ARGS;ENV" # Multi-value arguments ${ARGN} ) - get_fq_target_name(${test_name} fq_target_name) if(NOT INTEGRATION_TEST_SUITE) message(FATAL_ERROR "SUITE not specified for ${fq_target_name}") @@ -339,21 +343,23 @@ function(add_integration_test test_name) file(MAKE_DIRECTORY ${sysroot}/include) set(sysroot_lib ${sysroot}/lib) file(MAKE_DIRECTORY ${sysroot_lib}) - # Add dummy crti.o, crtn.o, libm.a and libc++.a - file(TOUCH ${sysroot_lib}/crti.o) - file(TOUCH ${sysroot_lib}/crtn.o) - file(TOUCH ${sysroot_lib}/libm.a) - file(TOUCH ${sysroot_lib}/libc++.a) - # Copy the loader object get_target_property(loader_object_file ${INTEGRATION_TEST_LOADER} LOADER_OBJECT) + get_target_property(crti_object_file libc.loader.linux.crti LOADER_OBJECT) + get_target_property(crtn_object_file libc.loader.linux.crtn LOADER_OBJECT) + set(dummy_archive $/lib$.a) if(NOT loader_object_file) message(FATAL_ERROR "Missing LOADER_OBJECT property of ${INTEGRATION_TEST_LOADER}.") endif() set(loader_dst ${sysroot_lib}/${LIBC_TARGET_ARCHITECTURE}-linux-gnu/crt1.o) add_custom_command( - OUTPUT ${loader_dst} + OUTPUT ${loader_dst} ${sysroot}/lib/crti.o ${sysroot}/lib/crtn.o ${sysroot}/lib/libm.a ${sysroot}/lib/libc++.a COMMAND cmake -E copy ${loader_object_file} ${loader_dst} - DEPENDS ${INTEGRATION_TEST_LOADER} + COMMAND cmake -E copy ${crti_object_file} ${sysroot}/lib + COMMAND cmake -E copy ${crtn_object_file} ${sysroot}/lib + # We copy the dummy archive as libm.a and libc++.a as the compiler drivers expect them. + COMMAND cmake -E copy ${dummy_archive} ${sysroot}/lib/libm.a + COMMAND cmake -E copy ${dummy_archive} ${sysroot}/lib/libc++.a + DEPENDS ${INTEGRATION_TEST_LOADER} libc.loader.linux.crti libc.loader.linux.crtn libc_integration_test_dummy ) add_custom_target( ${fq_target_name}.__copy_loader__ @@ -374,6 +380,8 @@ function(add_integration_test test_name) ${INTEGRATION_TEST_SRCS} ${INTEGRATION_TEST_HDRS} ) + set_target_properties(${fq_target_name} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories( ${fq_target_name} PRIVATE diff --git a/libc/loader/linux/CMakeLists.txt b/libc/loader/linux/CMakeLists.txt index 1454abd..b803945 100644 --- a/libc/loader/linux/CMakeLists.txt +++ b/libc/loader/linux/CMakeLists.txt @@ -71,3 +71,15 @@ add_loader_object( DEPENDS .${LIBC_TARGET_ARCHITECTURE}.crt1 ) + +add_loader_object( + crti + SRC + crti.cpp +) + +add_loader_object( + crtn + SRC + crtn.cpp +) diff --git a/libc/loader/linux/crti.cpp b/libc/loader/linux/crti.cpp new file mode 100644 index 0000000..e69de29 diff --git a/libc/loader/linux/crtn.cpp b/libc/loader/linux/crtn.cpp new file mode 100644 index 0000000..e69de29 diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt index 181d5cc..85f8902 100644 --- a/libc/test/CMakeLists.txt +++ b/libc/test/CMakeLists.txt @@ -18,4 +18,8 @@ if(NOT LLVM_LIBC_FULL_BUILD) return() endif() +if(NOT (${LIBC_TARGET_OS} STREQUAL "linux")) + # Integration tests are currently only available for linux. + return() +endif() add_subdirectory(integration) diff --git a/libc/test/integration/CMakeLists.txt b/libc/test/integration/CMakeLists.txt index 336cf4f..393084d 100644 --- a/libc/test/integration/CMakeLists.txt +++ b/libc/test/integration/CMakeLists.txt @@ -1,5 +1,15 @@ add_custom_target(libc-integration-tests) +add_library( + libc_integration_test_dummy + STATIC + dummy.cpp +) +set_target_properties(libc_integration_test_dummy + PROPERTIES + ARCHIVE_OUTPUT_NAME dummy + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_subdirectory(loader) add_subdirectory(scudo) add_subdirectory(src) diff --git a/libc/test/integration/dummy.cpp b/libc/test/integration/dummy.cpp new file mode 100644 index 0000000..e69de29 -- 2.7.4