From 304f95aca6cd33717d8b489271c22a93cbc39aa0 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 24 Mar 2023 18:51:23 +0000 Subject: [PATCH] Set __attribute__((used)) on all exported symbols. Issue #657 --- src/util.h | 2 +- src/vhpi/vhpi-model.c | 27 +++++++++++++++++++++++++++ src/vhpi/vhpi-util.c | 24 +++++++++++++++--------- src/vhpi/vhpi-util.h | 9 ++++----- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/util.h b/src/util.h index e1372796..7584eb55 100644 --- a/src/util.h +++ b/src/util.h @@ -293,7 +293,7 @@ void _local_free(void *ptr); #ifdef __MINGW32__ #define DLLEXPORT __declspec(dllexport) #else -#define DLLEXPORT +#define DLLEXPORT __attribute__((used)) #endif typedef enum { diff --git a/src/vhpi/vhpi-model.c b/src/vhpi/vhpi-model.c index 9342bb01..85ce6319 100644 --- a/src/vhpi/vhpi-model.c +++ b/src/vhpi/vhpi-model.c @@ -480,6 +480,7 @@ static rt_signal_t *vhpi_get_signal(c_abstractDecl *decl) //////////////////////////////////////////////////////////////////////////////// // Public API +DLLEXPORT int vhpi_release_handle(vhpiHandleT handle) { vhpi_clear_error(); @@ -489,6 +490,7 @@ int vhpi_release_handle(vhpiHandleT handle) return 0; } +DLLEXPORT vhpiHandleT vhpi_register_cb(vhpiCbDataT *cb_data_p, int32_t flags) { vhpi_clear_error(); @@ -552,6 +554,7 @@ vhpiHandleT vhpi_register_cb(vhpiCbDataT *cb_data_p, int32_t flags) return NULL; } +DLLEXPORT int vhpi_remove_cb(vhpiHandleT handle) { vhpi_clear_error(); @@ -569,6 +572,7 @@ int vhpi_remove_cb(vhpiHandleT handle) VHPI_MISSING; } +DLLEXPORT int vhpi_disable_cb(vhpiHandleT cb_obj) { vhpi_clear_error(); @@ -586,6 +590,7 @@ int vhpi_disable_cb(vhpiHandleT cb_obj) VHPI_MISSING; } +DLLEXPORT int vhpi_enable_cb(vhpiHandleT cb_obj) { vhpi_clear_error(); @@ -603,11 +608,13 @@ int vhpi_enable_cb(vhpiHandleT cb_obj) VHPI_MISSING; } +DLLEXPORT int vhpi_get_cb_info(vhpiHandleT object, vhpiCbDataT *cb_data_p) { VHPI_MISSING; } +DLLEXPORT vhpiHandleT vhpi_handle(vhpiOneToOneT type, vhpiHandleT referenceHandle) { vhpi_clear_error(); @@ -656,6 +663,7 @@ vhpiHandleT vhpi_handle(vhpiOneToOneT type, vhpiHandleT referenceHandle) } } +DLLEXPORT vhpiHandleT vhpi_handle_by_name(const char *name, vhpiHandleT scope) { vhpi_clear_error(); @@ -696,6 +704,7 @@ vhpiHandleT vhpi_handle_by_name(const char *name, vhpiHandleT scope) return NULL; } +DLLEXPORT vhpiHandleT vhpi_handle_by_index(vhpiOneToManyT itRel, vhpiHandleT parent, int32_t index) @@ -728,6 +737,7 @@ vhpiHandleT vhpi_handle_by_index(vhpiOneToManyT itRel, } } +DLLEXPORT vhpiHandleT vhpi_iterator(vhpiOneToManyT type, vhpiHandleT handle) { VHPI_TRACE("type=%s handle=%s", vhpi_one_to_many_str(type), @@ -736,11 +746,13 @@ vhpiHandleT vhpi_iterator(vhpiOneToManyT type, vhpiHandleT handle) VHPI_MISSING; } +DLLEXPORT vhpiHandleT vhpi_scan(vhpiHandleT iterator) { VHPI_MISSING; } +DLLEXPORT vhpiIntT vhpi_get(vhpiIntPropertyT property, vhpiHandleT handle) { vhpi_clear_error(); @@ -789,6 +801,7 @@ vhpiIntT vhpi_get(vhpiIntPropertyT property, vhpiHandleT handle) } } +DLLEXPORT const vhpiCharT *vhpi_get_str(vhpiStrPropertyT property, vhpiHandleT handle) { vhpi_clear_error(); @@ -816,12 +829,14 @@ const vhpiCharT *vhpi_get_str(vhpiStrPropertyT property, vhpiHandleT handle) } } +DLLEXPORT vhpiRealT vhpi_get_real(vhpiRealPropertyT property, vhpiHandleT object) { VHPI_MISSING; } +DLLEXPORT vhpiPhysT vhpi_get_phys(vhpiPhysPropertyT property, vhpiHandleT handle) { @@ -881,6 +896,7 @@ vhpiPhysT vhpi_get_phys(vhpiPhysPropertyT property, return invalid; } +DLLEXPORT int vhpi_get_value(vhpiHandleT expr, vhpiValueT *value_p) { vhpi_clear_error(); @@ -1053,6 +1069,7 @@ int vhpi_get_value(vhpiHandleT expr, vhpiValueT *value_p) } } +DLLEXPORT int vhpi_put_value(vhpiHandleT handle, vhpiValueT *value_p, vhpiPutValueModeT mode) @@ -1150,6 +1167,7 @@ int vhpi_put_value(vhpiHandleT handle, } } +DLLEXPORT int vhpi_protected_call(vhpiHandleT varHdl, vhpiUserFctT userFct, void *userData) @@ -1157,6 +1175,7 @@ int vhpi_protected_call(vhpiHandleT varHdl, VHPI_MISSING; } +DLLEXPORT int vhpi_schedule_transaction(vhpiHandleT drivHdl, vhpiValueT *value_p, uint32_t numValues, @@ -1167,12 +1186,14 @@ int vhpi_schedule_transaction(vhpiHandleT drivHdl, VHPI_MISSING; } +DLLEXPORT int vhpi_format_value(const vhpiValueT *in_value_p, vhpiValueT *out_value_p) { VHPI_MISSING; } +DLLEXPORT void vhpi_get_time(vhpiTimeT *time_p, long *cycles) { vhpi_clear_error(); @@ -1191,11 +1212,13 @@ void vhpi_get_time(vhpiTimeT *time_p, long *cycles) *cycles = deltas; } +DLLEXPORT int vhpi_get_next_time(vhpiTimeT *time_p) { VHPI_MISSING; } +DLLEXPORT int vhpi_control(vhpiSimControlT command, ...) { vhpi_clear_error(); @@ -1219,6 +1242,7 @@ int vhpi_control(vhpiSimControlT command, ...) } } +DLLEXPORT vhpiHandleT vhpi_create(vhpiClassKindT kind, vhpiHandleT handle1, vhpiHandleT handle2) @@ -1226,16 +1250,19 @@ vhpiHandleT vhpi_create(vhpiClassKindT kind, VHPI_MISSING; } +DLLEXPORT int vhpi_get_foreignf_info(vhpiHandleT hdl, vhpiForeignDataT *foreignDatap) { VHPI_MISSING; } +DLLEXPORT size_t vhpi_get_data(int32_t id, void *dataLoc, size_t numBytes) { VHPI_MISSING; } +DLLEXPORT size_t vhpi_put_data(int32_t id, void *dataLoc, size_t numBytes) { VHPI_MISSING; diff --git a/src/vhpi/vhpi-util.c b/src/vhpi/vhpi-util.c index 9197e10f..e1935cf7 100644 --- a/src/vhpi/vhpi-util.c +++ b/src/vhpi/vhpi-util.c @@ -33,15 +33,16 @@ static vhpiErrorInfoT last_error; //////////////////////////////////////////////////////////////////////////////// // Public API -const vhpiPhysT vhpiFS = { 0, 1 }; -const vhpiPhysT vhpiPS = { 0, 0x3e8 }; -const vhpiPhysT vhpiNS = { 0, 0xf4240 }; -const vhpiPhysT vhpiUS = { 0, 0x3b9aca00 }; -const vhpiPhysT vhpiMS = { 0xe8, 0xd4a51000 }; -const vhpiPhysT vhpiS = { 0x38d7e, 0xa4c68000 }; -const vhpiPhysT vhpiMN = { 0xd529ae, 0x9e860000 }; -const vhpiPhysT vhpiHR = { 0x31f5c4ed, 0x27680000 }; - +DLLEXPORT const vhpiPhysT vhpiFS = { 0, 1 }; +DLLEXPORT const vhpiPhysT vhpiPS = { 0, 0x3e8 }; +DLLEXPORT const vhpiPhysT vhpiNS = { 0, 0xf4240 }; +DLLEXPORT const vhpiPhysT vhpiUS = { 0, 0x3b9aca00 }; +DLLEXPORT const vhpiPhysT vhpiMS = { 0xe8, 0xd4a51000 }; +DLLEXPORT const vhpiPhysT vhpiS = { 0x38d7e, 0xa4c68000 }; +DLLEXPORT const vhpiPhysT vhpiMN = { 0xd529ae, 0x9e860000 }; +DLLEXPORT const vhpiPhysT vhpiHR = { 0x31f5c4ed, 0x27680000 }; + +DLLEXPORT int vhpi_printf(const char *format, ...) { vhpi_clear_error(); @@ -55,6 +56,7 @@ int vhpi_printf(const char *format, ...) return ret; } +DLLEXPORT int vhpi_vprintf(const char *format, va_list args) { vhpi_clear_error(); @@ -64,6 +66,7 @@ int vhpi_vprintf(const char *format, va_list args) return strlen(buf); } +DLLEXPORT int vhpi_compare_handles(vhpiHandleT handle1, vhpiHandleT handle2) { vhpi_clear_error(); @@ -73,6 +76,7 @@ int vhpi_compare_handles(vhpiHandleT handle1, vhpiHandleT handle2) return handle1 == handle2; } +DLLEXPORT int vhpi_check_error(vhpiErrorInfoT *error_info_p) { if (last_error.severity == 0) @@ -83,6 +87,7 @@ int vhpi_check_error(vhpiErrorInfoT *error_info_p) } } +DLLEXPORT int vhpi_assert(vhpiSeverityT severity, char *formatmsg, ...) { vhpi_clear_error(); @@ -117,6 +122,7 @@ int vhpi_assert(vhpiSeverityT severity, char *formatmsg, ...) return 0; } +DLLEXPORT int vhpi_is_printable(char ch) { if (ch < 32) diff --git a/src/vhpi/vhpi-util.h b/src/vhpi/vhpi-util.h index fbef0811..a7f1e54b 100644 --- a/src/vhpi/vhpi-util.h +++ b/src/vhpi/vhpi-util.h @@ -1,5 +1,5 @@ // -// Copyright (C) 2014-2022 Nick Gasson +// Copyright (C) 2014-2023 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,10 +21,9 @@ #include "prim.h" #include "rt/rt.h" -#if defined __MINGW32__ || defined __CYGWIN__ -#define PLI_DLLISPEC __declspec(dllexport) -#define PLI_DLLESPEC __declspec(dllimport) -#endif +// We use our own DLLEXPORT macro +#define PLI_DLLISPEC +#define PLI_DLLESPEC #include "vhpi/vhpi_user.h" -- 2.39.2