Skip to content

Commit 28c4076

Browse files
committed
Limit set of symbols exported from libdlt
Summary: This commit deals with issues potentially introduced in code linked to shared libdlt. The library previously exported all symbols by default, up to ~60 of which were not prefixed 'dlt*' and could conflict with symbols in the consumer code. After applying this commit only symbols prefixed 'dlt*' can be observed using $ nm --dynamic --defined-only ./build/src/lib/libdlt.so | cut -f3 -d' ' | sort which drastically reduces the chance of such conflicts. Brief: - explicit symbol export using DLT_EXPORT macro as provided by CMake's GenerateExportHeader module - rename get_filename_ext to dlt_get_filename_ext - rename getFileSerialNumber to dlt_get_file_serial_number - hide dlt_daemon's original main() in unit tests to avoid multiple definition on some platforms - add CMake 3.12's GenerateExportHeader to repository for backward-compatibility with pre-3.12 CMake (i.e. Ubuntu 18.04)
1 parent c13178d commit 28c4076

21 files changed

+842
-342
lines changed

cmake/compat/DltGenerateExportHeader.cmake

Lines changed: 442 additions & 0 deletions
Large diffs are not rendered by default.

cmake/compat/exportheader.cmake.in

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
#ifndef @INCLUDE_GUARD_NAME@
3+
#define @INCLUDE_GUARD_NAME@
4+
5+
#ifdef @STATIC_DEFINE@
6+
# define @EXPORT_MACRO_NAME@
7+
# define @NO_EXPORT_MACRO_NAME@
8+
#else
9+
# ifndef @EXPORT_MACRO_NAME@
10+
# ifdef @EXPORT_IMPORT_CONDITION@
11+
/* We are building this library */
12+
# define @EXPORT_MACRO_NAME@ @DEFINE_EXPORT@
13+
# else
14+
/* We are using this library */
15+
# define @EXPORT_MACRO_NAME@ @DEFINE_IMPORT@
16+
# endif
17+
# endif
18+
19+
# ifndef @NO_EXPORT_MACRO_NAME@
20+
# define @NO_EXPORT_MACRO_NAME@ @DEFINE_NO_EXPORT@
21+
# endif
22+
#endif
23+
24+
#ifndef @DEPRECATED_MACRO_NAME@
25+
# define @DEPRECATED_MACRO_NAME@ @DEFINE_DEPRECATED@
26+
#endif
27+
28+
#ifndef @DEPRECATED_MACRO_NAME@_EXPORT
29+
# define @DEPRECATED_MACRO_NAME@_EXPORT @EXPORT_MACRO_NAME@ @DEPRECATED_MACRO_NAME@
30+
#endif
31+
32+
#ifndef @DEPRECATED_MACRO_NAME@_NO_EXPORT
33+
# define @DEPRECATED_MACRO_NAME@_NO_EXPORT @NO_EXPORT_MACRO_NAME@ @DEPRECATED_MACRO_NAME@
34+
#endif
35+
36+
#if @DEFINE_NO_DEPRECATED@ /* DEFINE_NO_DEPRECATED */
37+
# ifndef @NO_DEPRECATED_MACRO_NAME@
38+
# define @NO_DEPRECATED_MACRO_NAME@
39+
# endif
40+
#endif
41+
@CUSTOM_CONTENT@
42+
#endif /* @INCLUDE_GUARD_NAME@ */

include/dlt/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ endif()
1919

2020
configure_file(dlt_user.h.in dlt_user.h)
2121

22+
if(CMAKE_VERSION VERSION_LESS "3.12")
23+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/compat")
24+
include(DltGenerateExportHeader) # compatibilty for pre-3.12 CMake
25+
else()
26+
include(GenerateExportHeader)
27+
endif()
28+
29+
generate_export_header(dlt)
30+
2231
set(HEADER_LIST dlt.h dlt_user_macros.h dlt_client.h dlt_protocol.h
2332
dlt_common.h dlt_types.h dlt_shm.h dlt_offline_trace.h
2433
dlt_filetransfer.h dlt_common_api.h dlt_multiple_files.h
2534
${CMAKE_CURRENT_BINARY_DIR}/dlt_version.h
26-
${CMAKE_CURRENT_BINARY_DIR}/dlt_user.h)
35+
${CMAKE_CURRENT_BINARY_DIR}/dlt_user.h
36+
${CMAKE_CURRENT_BINARY_DIR}/dlt_export.h)
2737

2838
if(WITH_DLT_DISABLE_MACRO)
2939
list(REMOVE_ITEM HEADER_LIST dlt_user_macros.h)

include/dlt/dlt_client.h

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
\{
7474
*/
7575

76+
# include "dlt_export.h"
7677
# include "dlt_types.h"
7778
# include "dlt_common.h"
7879
#include <stdbool.h>
@@ -106,8 +107,8 @@ typedef struct
106107
extern "C" {
107108
# endif
108109

109-
void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage *message, void *data));
110-
void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void *data));
110+
DLT_EXPORT void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage *message, void *data));
111+
DLT_EXPORT void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void *data));
111112

112113
/**
113114
* Initialising dlt client structure with a specific port
@@ -116,45 +117,45 @@ void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(
116117
* @param verbose if set to true verbose information is printed out.
117118
* @return negative value if there was an error
118119
*/
119-
int dlt_client_init_port(DltClient *client, int port, int verbose);
120+
DLT_EXPORT int dlt_client_init_port(DltClient *client, int port, int verbose);
120121

121122
/**
122123
* Initialising dlt client structure
123124
* @param client pointer to dlt client structure
124125
* @param verbose if set to true verbose information is printed out.
125126
* @return Value from DltReturnValue enum
126127
*/
127-
DltReturnValue dlt_client_init(DltClient *client, int verbose);
128+
DLT_EXPORT DltReturnValue dlt_client_init(DltClient *client, int verbose);
128129
/**
129130
* Connect to dlt daemon using the information from the dlt client structure
130131
* @param client pointer to dlt client structure
131132
* @param verbose if set to true verbose information is printed out.
132133
* @return Value from DltReturnValue enum
133134
*/
134-
DltReturnValue dlt_client_connect(DltClient *client, int verbose);
135+
DLT_EXPORT DltReturnValue dlt_client_connect(DltClient *client, int verbose);
135136
/**
136137
* Cleanup dlt client structure
137138
* @param client pointer to dlt client structure
138139
* @param verbose if set to true verbose information is printed out.
139140
* @return Value from DltReturnValue enum
140141
*/
141-
DltReturnValue dlt_client_cleanup(DltClient *client, int verbose);
142+
DLT_EXPORT DltReturnValue dlt_client_cleanup(DltClient *client, int verbose);
142143
/**
143144
* Main Loop of dlt client application
144145
* @param client pointer to dlt client structure
145146
* @param data pointer to data to be provided to the main loop
146147
* @param verbose if set to true verbose information is printed out.
147148
* @return Value from DltReturnValue enum
148149
*/
149-
DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose);
150+
DLT_EXPORT DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose);
150151

151152
/**
152153
* Send a message to the daemon through the socket.
153154
* @param client pointer to dlt client structure.
154155
* @param msg The message to be send in DLT format.
155156
* @return Value from DltReturnValue enum.
156157
*/
157-
DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage *msg);
158+
DLT_EXPORT DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage *msg);
158159

159160
/**
160161
* Send ancontrol message to the dlt daemon
@@ -165,7 +166,7 @@ DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage *
165166
* @param size Size of control message data
166167
* @return Value from DltReturnValue enum
167168
*/
168-
DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size);
169+
DLT_EXPORT DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size);
169170
/**
170171
* Send an injection message to the dlt daemon
171172
* @param client pointer to dlt client structure
@@ -176,7 +177,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti
176177
* @param size Size of injection data within buffer
177178
* @return Value from DltReturnValue enum
178179
*/
179-
DltReturnValue dlt_client_send_inject_msg(DltClient *client,
180+
DLT_EXPORT DltReturnValue dlt_client_send_inject_msg(DltClient *client,
180181
char *apid,
181182
char *ctid,
182183
uint32_t serviceID,
@@ -190,35 +191,35 @@ DltReturnValue dlt_client_send_inject_msg(DltClient *client,
190191
* @param logLevel Log Level
191192
* @return Value from DltReturnValue enum
192193
*/
193-
DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel);
194+
DLT_EXPORT DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel);
194195
/**
195196
* Send an request to get log info message to the dlt daemon
196197
* @param client pointer to dlt client structure
197198
* @return negative value if there was an error
198199
*/
199-
int dlt_client_get_log_info(DltClient *client);
200+
DLT_EXPORT int dlt_client_get_log_info(DltClient *client);
200201
/**
201202
* Send an request to get default log level to the dlt daemon
202203
* @param client pointer to dlt client structure
203204
* @return negative value if there was an error
204205
*/
205-
DltReturnValue dlt_client_get_default_log_level(DltClient *client);
206+
DLT_EXPORT DltReturnValue dlt_client_get_default_log_level(DltClient *client);
206207
/**
207208
* Send an request to get software version to the dlt daemon
208209
* @param client pointer to dlt client structure
209210
* @return negative value if there was an error
210211
*/
211-
int dlt_client_get_software_version(DltClient *client);
212+
DLT_EXPORT int dlt_client_get_software_version(DltClient *client);
212213
/**
213214
* Initialise get log info structure
214215
* @return void
215216
*/
216-
void dlt_getloginfo_init(void);
217+
DLT_EXPORT void dlt_getloginfo_init(void);
217218
/**
218219
* To free the memory allocated for app description in get log info
219220
* @return void
220221
*/
221-
void dlt_getloginfo_free(void);
222+
DLT_EXPORT void dlt_getloginfo_free(void);
222223
/**
223224
* Send a set trace status message to the dlt daemon
224225
* @param client pointer to dlt client structure
@@ -227,118 +228,118 @@ void dlt_getloginfo_free(void);
227228
* @param traceStatus Default Trace Status
228229
* @return Value from DltReturnValue enum
229230
*/
230-
DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus);
231+
DLT_EXPORT DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus);
231232
/**
232233
* Send the default log level to the dlt daemon
233234
* @param client pointer to dlt client structure
234235
* @param defaultLogLevel Default Log Level
235236
* @return Value from DltReturnValue enum
236237
*/
237-
DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel);
238+
DLT_EXPORT DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel);
238239
/**
239240
* Send the log level to all contexts registered with dlt daemon
240241
* @param client pointer to dlt client structure
241242
* @param LogLevel Log Level to be set
242243
* @return Value from DltReturnValue enum
243244
*/
244-
DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel);
245+
DLT_EXPORT DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel);
245246
/**
246247
* Send the default trace status to the dlt daemon
247248
* @param client pointer to dlt client structure
248249
* @param defaultTraceStatus Default Trace Status
249250
* @return Value from DltReturnValue enum
250251
*/
251-
DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t defaultTraceStatus);
252+
DLT_EXPORT DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t defaultTraceStatus);
252253
/**
253254
* Send the trace status to all contexts registered with dlt daemon
254255
* @param client pointer to dlt client structure
255256
* @param traceStatus trace status to be set
256257
* @return Value from DltReturnValue enum
257258
*/
258-
DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t traceStatus);
259+
DLT_EXPORT DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t traceStatus);
259260
/**
260261
* Send the timing pakets status to the dlt daemon
261262
* @param client pointer to dlt client structure
262263
* @param timingPakets Timing pakets enabled
263264
* @return Value from DltReturnValue enum
264265
*/
265-
DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets);
266+
DLT_EXPORT DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets);
266267
/**
267268
* Send the store config command to the dlt daemon
268269
* @param client pointer to dlt client structure
269270
* @return Value from DltReturnValue enum
270271
*/
271-
DltReturnValue dlt_client_send_store_config(DltClient *client);
272+
DLT_EXPORT DltReturnValue dlt_client_send_store_config(DltClient *client);
272273
/**
273274
* Send the reset to factory default command to the dlt daemon
274275
* @param client pointer to dlt client structure
275276
* @return Value from DltReturnValue enum
276277
*/
277-
DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client);
278+
DLT_EXPORT DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client);
278279

279280
/**
280281
* Set baudrate within dlt client structure
281282
* @param client pointer to dlt client structure
282283
* @param baudrate Baudrate
283284
* @return Value from DltReturnValue enum
284285
*/
285-
DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate);
286+
DLT_EXPORT DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate);
286287

287288
/**
288289
* Set mode within dlt client structure
289290
* @param client pointer to dlt client structure
290291
* @param mode DltClientMode
291292
* @return Value from DltReturnValue enum
292293
*/
293-
DltReturnValue dlt_client_set_mode(DltClient *client, DltClientMode mode);
294+
DLT_EXPORT DltReturnValue dlt_client_set_mode(DltClient *client, DltClientMode mode);
294295

295296
/**
296297
* Set server ip
297298
* @param client pointer to dlt client structure
298299
* @param ipaddr pointer to command line argument
299300
* @return negative value if there was an error
300301
*/
301-
int dlt_client_set_server_ip(DltClient *client, char *ipaddr);
302+
DLT_EXPORT int dlt_client_set_server_ip(DltClient *client, char *ipaddr);
302303

303304
/**
304305
* Set server UDP host receiver interface address
305306
* @param client pointer to dlt client structure
306307
* @param hostip pointer to multicast group address
307308
* @return negative value if there was an error
308309
*/
309-
int dlt_client_set_host_if_address(DltClient *client, char *hostip);
310+
DLT_EXPORT int dlt_client_set_host_if_address(DltClient *client, char *hostip);
310311

311312
/**
312313
* Set serial device
313314
* @param client pointer to dlt client structure
314315
* @param serial_device pointer to command line argument
315316
* @return negative value if there was an error
316317
*/
317-
int dlt_client_set_serial_device(DltClient *client, char *serial_device);
318+
DLT_EXPORT int dlt_client_set_serial_device(DltClient *client, char *serial_device);
318319

319320
/**
320321
* Set socket path
321322
* @param client pointer to dlt client structure
322323
* @param socket_path pointer to socket path string
323324
* @return negative value if there was an error
324325
*/
325-
int dlt_client_set_socket_path(DltClient *client, char *socket_path);
326+
DLT_EXPORT int dlt_client_set_socket_path(DltClient *client, char *socket_path);
326327

327328
/**
328329
* Parse GET_LOG_INFO response text
329330
* @param resp GET_LOG_INFO response
330331
* @param resp_text response text represented by ASCII
331332
* @return Value from DltReturnValue enum
332333
*/
333-
DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp,
334+
DLT_EXPORT DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp,
334335
char *resp_text);
335336

336337
/**
337338
* Free memory allocated for get log info message
338339
* @param resp response
339340
* @return 0 on success, -1 otherwise
340341
*/
341-
int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp);
342+
DLT_EXPORT int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp);
342343
# ifdef __cplusplus
343344
}
344345
# endif

0 commit comments

Comments
 (0)