Skip to content

Commit af3caee

Browse files
authored
Reduce symbol visibility of runtime (#181)
1 parent a29c235 commit af3caee

File tree

17 files changed

+174
-106
lines changed

17 files changed

+174
-106
lines changed

CMakePresets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@
138138
],
139139
"cacheVariables": {
140140
"TYPEART_ASAN": "OFF",
141-
"TYPEART_UBSAN": "OFF"
141+
"TYPEART_UBSAN": "OFF",
142+
"TYPEART_CI_RUN": "ON"
142143
}
143144
},
144145
{

cmake/typeartToolchainOptions.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ mark_as_advanced(TYPEART_CONFIG_DIR_IS_SHARE)
9494
option(TYPEART_USE_LEGACY_WRAPPER "Use the old TypeART compiler wrapper" OFF)
9595
# mark_as_advanced(TYPEART_USE_NEW_PASSMANAGER)
9696

97+
option(TYPEART_INSTALL_TYPES_LIB "Install types library" OFF)
98+
option(TYPEART_INSTALL_SYSTEM_LIB "Install system library" OFF)
99+
97100
# if(LLVM_VERSION_MAJOR VERSION_GREATER_EQUAL "18")
98101
# set(TYPEART_USE_NEW_PASSMANAGER ON CACHE BOOL ON FORCE)
99102
# endif()

lib/mpi_interceptor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set_property(TARGET ${TYPEART_PREFIX}_MPITool PROPERTY C_STANDARD_REQUIRED TRUE)
1919
typeart_target_define_file_basename(${TYPEART_PREFIX}_MPITool)
2020

2121
target_include_directories(${TYPEART_PREFIX}_MPITool ${warning_guard}
22-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib>
22+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib/runtime>
2323
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
2424
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
2525
)

lib/mpi_interceptor/InterceptorFunctions.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#ifndef TEST_MPI_INTERCEPTOR_INTERCEPTORFUNCTIONS_H_
1414
#define TEST_MPI_INTERCEPTOR_INTERCEPTORFUNCTIONS_H_
1515

16-
#include "runtime/RuntimeInterface.h"
16+
#include "RuntimeExport.h"
17+
#include "RuntimeInterface.h"
1718

1819
#include <mpi.h>
1920
#include <stdatomic.h>
@@ -22,8 +23,9 @@
2223
#include <sys/resource.h>
2324
#include <sys/time.h>
2425

25-
int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, int mpi_count, int const_adr);
26-
void ta_print_loc(const void* call_adr);
26+
TYPEART_NO_EXPORT int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, int mpi_count,
27+
int const_adr);
28+
TYPEART_NO_EXPORT void ta_print_loc(const void* call_adr);
2729

2830
typedef struct CallCounter {
2931
_Atomic size_t send;
@@ -42,31 +44,34 @@ typedef struct MPISemCounter {
4244

4345
static MPICounter mcounter = {0, 0, 0};
4446

45-
void ta_check_send(const char* name, const void* called_from, const void* sendbuf, int count, MPI_Datatype dtype) {
47+
TYPEART_NO_EXPORT void ta_check_send(const char* name, const void* called_from, const void* sendbuf, int count,
48+
MPI_Datatype dtype) {
4649
++counter.send;
4750
ta_check_buffer(name, called_from, sendbuf, count, 1);
4851
}
4952

50-
void ta_check_recv(const char* name, const void* called_from, void* recvbuf, int count, MPI_Datatype dtype) {
53+
TYPEART_NO_EXPORT void ta_check_recv(const char* name, const void* called_from, void* recvbuf, int count,
54+
MPI_Datatype dtype) {
5155
++counter.recv;
5256
ta_check_buffer(name, called_from, recvbuf, count, 0);
5357
}
5458

55-
void ta_check_send_and_recv(const char* name, const void* called_from, const void* sendbuf, int sendcount,
56-
MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype) {
59+
TYPEART_NO_EXPORT void ta_check_send_and_recv(const char* name, const void* called_from, const void* sendbuf,
60+
int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
61+
MPI_Datatype recvtype) {
5762
++counter.send_recv;
5863
ta_check_send(name, called_from, sendbuf, sendcount, sendtype);
5964
ta_check_recv(name, called_from, recvbuf, recvcount, recvtype);
6065
}
6166

62-
void ta_unsupported_mpi_call(const char* name, const void* called_from) {
67+
TYPEART_NO_EXPORT void ta_unsupported_mpi_call(const char* name, const void* called_from) {
6368
++counter.unsupported;
6469
fprintf(stderr, "[Error] The MPI function %s is currently not checked by TypeArt", name);
6570
ta_print_loc(called_from);
6671
// exit(0);
6772
}
6873

69-
const char* ta_get_error_message(typeart_status status) {
74+
TYPEART_NO_EXPORT const char* ta_get_error_message(typeart_status status) {
7075
switch (status) {
7176
case TYPEART_OK:
7277
return "No errors";
@@ -85,7 +90,8 @@ const char* ta_get_error_message(typeart_status status) {
8590
}
8691
}
8792

88-
int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, int mpi_count, int const_adr) {
93+
TYPEART_NO_EXPORT int ta_check_buffer(const char* mpi_name, const void* called_from, const void* buf, int mpi_count,
94+
int const_adr) {
8995
if (mpi_count <= 0) {
9096
++mcounter.null_count;
9197
return 1;
@@ -119,7 +125,7 @@ int ta_check_buffer(const char* mpi_name, const void* called_from, const void* b
119125
return 1;
120126
}
121127

122-
void ta_print_loc(const void* call_adr) {
128+
TYPEART_NO_EXPORT void ta_print_loc(const void* call_adr) {
123129
const char* exe = getenv("TYPEART_EXE_TARGET");
124130
if (exe == NULL || exe[0] == '\0') {
125131
return;
@@ -138,7 +144,7 @@ void ta_print_loc(const void* call_adr) {
138144
}
139145
}
140146

141-
void ta_exit() {
147+
TYPEART_NO_EXPORT void ta_exit() {
142148
// Called at MPI_Finalize time
143149
int rank = 0;
144150
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

lib/runtime/CMakeLists.txt

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@ set_target_properties(
4040
)
4141
add_library(typeart::Runtime ALIAS ${TYPEART_PREFIX}_Runtime)
4242

43+
include(GenerateExportHeader)
44+
generate_export_header(${TYPEART_PREFIX}_Runtime
45+
BASE_NAME TYPEART
46+
EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/RuntimeExport.h"
47+
)
48+
49+
set_target_properties(${TYPEART_PREFIX}_Runtime PROPERTIES
50+
CXX_VISIBILITY_PRESET hidden
51+
VISIBILITY_INLINES_HIDDEN ON
52+
)
53+
54+
if(UNIX AND NOT APPLE)
55+
set(LINKER_MAP_CONTENTS
56+
[=[{
57+
global:
58+
typeart_*;
59+
__typeart_*;
60+
local:
61+
*;
62+
};]=])
63+
64+
set(RUNTIME_MAP_FILE "${CMAKE_CURRENT_BINARY_DIR}/Runtime.map")
65+
file(WRITE "${RUNTIME_MAP_FILE}" "${LINKER_MAP_CONTENTS}")
66+
67+
target_link_options(${TYPEART_PREFIX}_Runtime PRIVATE
68+
"-Wl,--version-script,${RUNTIME_MAP_FILE}"
69+
)
70+
71+
set_target_properties(${TYPEART_PREFIX}_Runtime PROPERTIES
72+
LINK_DEPENDS "${RUNTIME_MAP_FILE}"
73+
)
74+
endif()
75+
4376
target_link_libraries(
4477
${TYPEART_PREFIX}_Runtime
4578
PRIVATE typeart::TypesStatic
@@ -59,6 +92,7 @@ target_include_directories(
5992
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
6093
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib/runtime>
6194
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib/typelib>
95+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
6296
PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib/passes/support>
6397
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib>
6498
)
@@ -97,8 +131,10 @@ make_tidy_check(${TYPEART_PREFIX}_Runtime "${RUNTIME_LIB_SOURCES}")
97131
set(CONFIG_NAME ${PROJECT_NAME}Runtime)
98132
set(TARGETS_EXPORT_NAME ${CONFIG_NAME}Targets)
99133

100-
install(FILES RuntimeInterface.h
101-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
134+
install(FILES
135+
RuntimeInterface.h
136+
"${CMAKE_CURRENT_BINARY_DIR}/RuntimeExport.h"
137+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
102138
)
103139

104140
install(

lib/runtime/CallbackInterface.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef TYPEART_CALLBACKINTERFACE_H
1414
#define TYPEART_CALLBACKINTERFACE_H
1515

16+
#include "RuntimeExport.h"
17+
1618
#ifdef __cplusplus
1719
#include <cstddef>
1820
#else
@@ -23,28 +25,28 @@
2325
#ifdef __cplusplus
2426
extern "C" {
2527
#endif
26-
void __typeart_alloc(const void* addr, int type_id, size_t count);
28+
TYPEART_EXPORT void __typeart_alloc(const void* addr, int type_id, size_t count);
2729

28-
void __typeart_alloc_global(const void* addr, int type_id, size_t count);
29-
void __typeart_free(const void* addr);
30+
TYPEART_EXPORT void __typeart_alloc_global(const void* addr, int type_id, size_t count);
31+
TYPEART_EXPORT void __typeart_free(const void* addr);
3032

31-
void __typeart_alloc_stack(const void* addr, int type_id, size_t count);
32-
void __typeart_leave_scope(int alloca_count);
33+
TYPEART_EXPORT void __typeart_alloc_stack(const void* addr, int type_id, size_t count);
34+
TYPEART_EXPORT void __typeart_leave_scope(int alloca_count);
3335

3436
// Called from OpenMP context
35-
void __typeart_alloc_omp(const void* addr, int type_id, size_t count);
36-
void __typeart_free_omp(const void* addr);
37-
void __typeart_alloc_stack_omp(const void* addr, int type_id, size_t count);
38-
void __typeart_leave_scope_omp(int alloca_count);
37+
TYPEART_EXPORT void __typeart_alloc_omp(const void* addr, int type_id, size_t count);
38+
TYPEART_EXPORT void __typeart_free_omp(const void* addr);
39+
TYPEART_EXPORT void __typeart_alloc_stack_omp(const void* addr, int type_id, size_t count);
40+
TYPEART_EXPORT void __typeart_leave_scope_omp(int alloca_count);
3941

4042
// Called for inlined type definitions mode
41-
void __typeart_alloc_mty(const void* addr, const void* info, size_t count);
42-
void __typeart_alloc_global_mty(const void* addr, const void* info, size_t count);
43-
void __typeart_alloc_stack_mty(const void* addr, const void* info, size_t count);
44-
void __typeart_register_type(const void* type);
43+
TYPEART_EXPORT void __typeart_alloc_mty(const void* addr, const void* info, size_t count);
44+
TYPEART_EXPORT void __typeart_alloc_global_mty(const void* addr, const void* info, size_t count);
45+
TYPEART_EXPORT void __typeart_alloc_stack_mty(const void* addr, const void* info, size_t count);
46+
TYPEART_EXPORT void __typeart_register_type(const void* type);
4547

46-
void __typeart_alloc_global_mty_omp(const void* addr, const void* info, size_t count);
47-
void __typeart_alloc_stack_mty_omp(const void* addr, const void* info, size_t count);
48+
TYPEART_EXPORT void __typeart_alloc_global_mty_omp(const void* addr, const void* info, size_t count);
49+
TYPEART_EXPORT void __typeart_alloc_stack_mty_omp(const void* addr, const void* info, size_t count);
4850
#ifdef __cplusplus
4951
}
5052
#endif

0 commit comments

Comments
 (0)