diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt --- a/compiler-rt/include/CMakeLists.txt +++ b/compiler-rt/include/CMakeLists.txt @@ -1,3 +1,6 @@ +set(GCOV_COMPAT_HEADERS + gcov.h) + if (COMPILER_RT_BUILD_SANITIZERS) set(SANITIZER_HEADERS sanitizer/allocator_interface.h @@ -25,6 +28,7 @@ endif(COMPILER_RT_BUILD_XRAY) set(COMPILER_RT_HEADERS + ${GCOV_COMPAT_HEADERS} ${SANITIZER_HEADERS} ${XRAY_HEADERS}) @@ -46,6 +50,11 @@ add_dependencies(compiler-rt compiler-rt-headers) set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") +# Install gcov compat headers. +install(FILES ${GCOV_COMPAT_HEADERS} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + DESTINATION ${COMPILER_RT_INSTALL_PATH}/include) + # Install sanitizer headers. install(FILES ${SANITIZER_HEADERS} COMPONENT compiler-rt-headers diff --git a/compiler-rt/include/gcov.h b/compiler-rt/include/gcov.h new file mode 100644 --- /dev/null +++ b/compiler-rt/include/gcov.h @@ -0,0 +1,23 @@ +//===-- gcov.h ------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file provides the public interface for functions which are available to +// end-users when using gcov(3). +// +//===----------------------------------------------------------------------===// + +#ifndef COMPILER_RT_GCOV_H +#define COMPILER_RT_GCOV_H + +/* + * - Write profile information/counters out to their appropriate GCDA files. + * - Reset profile counters to zero. + */ +extern void __gcov_flush(void); + +#endif diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt --- a/compiler-rt/lib/profile/CMakeLists.txt +++ b/compiler-rt/lib/profile/CMakeLists.txt @@ -74,6 +74,8 @@ InstrProfilingUtil.h WindowsMMap.h) +include_directories(../../include) + if(WIN32) list(APPEND PROFILE_SOURCES WindowsMMap.c) endif() diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c --- a/compiler-rt/lib/profile/GCDAProfiling.c +++ b/compiler-rt/lib/profile/GCDAProfiling.c @@ -46,6 +46,8 @@ #include #endif +#include + #if defined(_MSC_VER) typedef unsigned char uint8_t; typedef unsigned int uint32_t; @@ -619,7 +621,7 @@ fn_list_insert(&flush_fn_list, fn); } -void __gcov_flush() { +void __gcov_flush(void) { struct fn_node* curr = flush_fn_list.head; while (curr) { diff --git a/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c b/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c --- a/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c +++ b/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c @@ -1,3 +1,6 @@ +#include +#include + int main(void) { __gcov_flush(); diff --git a/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-terminate.c b/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-terminate.c --- a/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-terminate.c +++ b/compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-terminate.c @@ -1,3 +1,5 @@ +#include + int main(void) { int i = 22; diff --git a/compiler-rt/test/profile/Inputs/instrprof-shared-main-gcov-flush.c b/compiler-rt/test/profile/Inputs/instrprof-shared-main-gcov-flush.c --- a/compiler-rt/test/profile/Inputs/instrprof-shared-main-gcov-flush.c +++ b/compiler-rt/test/profile/Inputs/instrprof-shared-main-gcov-flush.c @@ -1,5 +1,6 @@ +#include + extern void foo(int n); -extern void __gcov_flush(void); int bar1 = 0; int bar2 = 1;