use portable macro for weak linking
cover use portable macro for weak linking
MSVC uses pragmas to indicate weak linking, so the old __rte_weak attribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.
Andre Muezerie (5):
lib/eal: add portable macro for weak linking app/test-compress-perf: use portable macro for weak linking drivers/bus: use portable macro for weak linking drivers/common: use portable macro for weak linking drivers/net: use portable macro for weak linking
app/test-compress-perf/main.c | 36 ++++++++++++------------ drivers/bus/auxiliary/auxiliary_common.c | 8 +++--- drivers/common/nitrox/nitrox_device.c | 16 +++++------ drivers/common/qat/qat_qp.c | 4 +-- drivers/net/enic/enic_main.c | 4 +-- drivers/net/fm10k/fm10k_ethdev.c | 32 ++++++++++----------- drivers/net/hns3/hns3_rxtx.c | 28 +++++++++--------- drivers/net/nfp/nfdk/nfp_nfdk_vec_stub.c | 4 +-- drivers/net/nfp/nfp_rxtx_vec_stub.c | 8 +++--- drivers/net/virtio/virtio_rxtx.c | 8 +++--- drivers/net/virtio/virtio_rxtx_simple.c | 4 +-- lib/eal/include/rte_common.h | 14 ++++++++- 12 files changed, 89 insertions(+), 77 deletions(-)
--
2.47.0.vfs.0.3
PATCH 1/5 lib/eal: add portable macro for weak linking
MSVC uses pragmas to indicate weak linking, so the old __rte_weak attribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.
This patch adds macro RTE_WEAK and deprecates __rte_weak.
--- lib/eal/include/rte_common.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
lib/eal/include/rte_common.h +13 -1
@@ -137,10 +137,22 @@ typedef uint16_t unaligned_uint16_t;#define RTE_DEPRECATED (x)#endif +/** +* @deprecated +* @see RTE_WEAK +*/ +#define __rte_weak (RTE_DEPRECATED(__rte_weak) __attribute__((__weak__))) +/** * Mark a function or variable to a weak reference. */ -#define __rte_weak __attribute__((__weak__)) +#ifdef RTE_TOOLCHAIN_MSVC +#define RTE_WEAK (FUNC_NAME ) \ + (__pragma(comment(linker, "/alternatename:" #FUNC_NAME "=rte_weak_" \ + #FUNC_NAME)) rte_weak_ ## FUNC_NAME) +#else +#define RTE_WEAK (FUNC_NAME ) (__attribute__((__weak__)) FUNC_NAME) +#endif /** * Mark a function to be pure.
Signature · 1 line
2.47.0.vfs.0.3
PATCH 2/5 app/test-compress-perf: use portable macro for weak linking
In reply to Andre MuezerieMSVC uses pragmas to indicate weak linking, so the old __rte_weak attribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.
This patch replaces __rte_weak with macro RTE_WEAK.
--- app/test-compress-perf/main.c | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
app/test-compress-perf/main.c +18 -18
@@ -522,8 +522,8 @@ main(int argc, char **argv)return ret; } -__rte_weak void * -cperf_cyclecount_test_constructor(uint8_t dev_id __rte_unused, +void * +RTE_WEAK(cperf_cyclecount_test_constructor)(uint8_t dev_id __rte_unused, uint16_t qp_id __rte_unused, struct comp_test_data *options __rte_unused) {
@@ -531,20 +531,20 @@ cperf_cyclecount_test_constructor(uint8_t dev_id __rte_unused,return NULL ; } -__rte_weak void -cperf_cyclecount_test_destructor(void *arg __rte_unused) +void +RTE_WEAK(cperf_cyclecount_test_destructor)(void *arg __rte_unused) {RTE_LOG (INFO ,USER1 ,"Something wrong happened!!!\n" ); } -__rte_weak int -cperf_cyclecount_test_runner(void *test_ctx __rte_unused) +int +RTE_WEAK(cperf_cyclecount_test_runner)(void *test_ctx __rte_unused) {return 0 ; } -__rte_weak void * -cperf_throughput_test_constructor(uint8_t dev_id __rte_unused, +void * +RTE_WEAK(cperf_throughput_test_constructor)(uint8_t dev_id __rte_unused, uint16_t qp_id __rte_unused, struct comp_test_data *options __rte_unused) {
@@ -552,19 +552,19 @@ cperf_throughput_test_constructor(uint8_t dev_id __rte_unused,return NULL ; } -__rte_weak void -cperf_throughput_test_destructor(void *arg __rte_unused) +void +RTE_WEAK(cperf_throughput_test_destructor)(void *arg __rte_unused) { } -__rte_weak int -cperf_throughput_test_runner(void *test_ctx __rte_unused) +int +RTE_WEAK(cperf_throughput_test_runner)(void *test_ctx __rte_unused) {return 0 ; } -__rte_weak void * -cperf_verify_test_constructor(uint8_t dev_id __rte_unused, +void * +RTE_WEAK(cperf_verify_test_constructor)(uint8_t dev_id __rte_unused, uint16_t qp_id __rte_unused, struct comp_test_data *options __rte_unused) {
@@ -572,14 +572,14 @@ cperf_verify_test_constructor(uint8_t dev_id __rte_unused,return NULL ; } -__rte_weak void -cperf_verify_test_destructor(void *arg __rte_unused) +void +RTE_WEAK(cperf_verify_test_destructor)(void *arg __rte_unused) { } -__rte_weak int -cperf_verify_test_runner(void *test_ctx __rte_unused) +int +RTE_WEAK(cperf_verify_test_runner)(void *test_ctx __rte_unused) {return 0 ; }
Signature · 1 line
2.47.0.vfs.0.3
PATCH 3/5 drivers/bus: use portable macro for weak linking
In reply to Andre MuezerieMSVC uses pragmas to indicate weak linking, so the old __rte_weak attribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.
This patch replaces __rte_weak with macro RTE_WEAK.
--- drivers/bus/auxiliary/auxiliary_common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/bus/auxiliary/auxiliary_common.c +4 -4
@@ -41,8 +41,8 @@ auxiliary_devargs_lookup(const char *name)* * Stub for OS not supporting auxiliary bus. */ -__rte_weak bool -auxiliary_dev_exists (const char *name) +bool +RTE_WEAK (auxiliary_dev_exists )(const char *name) {RTE_SET_USED (name);return false;
@@ -53,8 +53,8 @@ auxiliary_dev_exists(const char *name)* * Stub for OS not supporting auxiliary bus. */ -__rte_weak int -auxiliary_scan (void ) +int +RTE_WEAK (auxiliary_scan )(void ) {return 0 ; }
Signature · 1 line
2.47.0.vfs.0.3
PATCH 4/5 drivers/common: use portable macro for weak linking
In reply to Andre MuezerieMSVC uses pragmas to indicate weak linking, so the old __rte_weak attribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.
This patch replaces __rte_weak with macro RTE_WEAK.
--- drivers/common/nitrox/nitrox_device.c | 16 ++++++++-------- drivers/common/qat/qat_qp.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/common/nitrox/nitrox_device.c +8 -8
@@ -133,29 +133,29 @@ static struct rte_pci_driver nitrox_pmd = { .remove = nitrox_pci_remove, }; -__rte_weak int -nitrox_sym_pmd_create (struct nitrox_device *ndev) +int +RTE_WEAK (nitrox_sym_pmd_create )(struct nitrox_device *ndev) {RTE_SET_USED (ndev);return 0 ; } -__rte_weak int -nitrox_sym_pmd_destroy (struct nitrox_device *ndev) +int +RTE_WEAK (nitrox_sym_pmd_destroy )(struct nitrox_device *ndev) {RTE_SET_USED (ndev);return 0 ; } -__rte_weak int -nitrox_comp_pmd_create (struct nitrox_device *ndev) +int +RTE_WEAK (nitrox_comp_pmd_create )(struct nitrox_device *ndev) {RTE_SET_USED (ndev);return 0 ; } -__rte_weak int -nitrox_comp_pmd_destroy (struct nitrox_device *ndev) +int +RTE_WEAK (nitrox_comp_pmd_destroy )(struct nitrox_device *ndev) {RTE_SET_USED (ndev);return 0 ;
drivers/common/qat/qat_qp.c +2 -2
@@ -945,8 +945,8 @@ qat_cq_get_fw_cipher_crc_cap(struct qat_qp *qp) }#endif -__rte_weak int -qat_comp_process_response(void **op __rte_unused, uint8_t *resp __rte_unused, +int +RTE_WEAK(qat_comp_process_response)(void **op __rte_unused, uint8_t *resp __rte_unused, void *op_cookie __rte_unused, uint64_t *dequeue_err_count __rte_unused) {
Signature · 1 line
2.47.0.vfs.0.3
PATCH 5/5 drivers/net: use portable macro for weak linking
In reply to Andre MuezerieMSVC uses pragmas to indicate weak linking, so the old __rte_weak attribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.
This patch replaces __rte_weak with macro RTE_WEAK.
--- drivers/net/enic/enic_main.c | 4 +-- drivers/net/fm10k/fm10k_ethdev.c | 32 ++++++++++++------------ drivers/net/hns3/hns3_rxtx.c | 28 ++++++++++----------- drivers/net/nfp/nfdk/nfp_nfdk_vec_stub.c | 4 +-- drivers/net/nfp/nfp_rxtx_vec_stub.c | 8 +++--- drivers/net/virtio/virtio_rxtx.c | 8 +++--- drivers/net/virtio/virtio_rxtx_simple.c | 4 +-- 7 files changed, 44 insertions(+), 44 deletions(-)
drivers/net/enic/enic_main.c +2 -2
@@ -513,8 +513,8 @@ static void enic_prep_wq_for_simple_tx(struct enic *enic, uint16_t queue_idx)* The 'strong' version is in enic_rxtx_vec_avx2.c. This weak version is used * used when that file is not compiled. */ -__rte_weak bool -enic_use_vector_rx_handler(__rte_unused struct rte_eth_dev *eth_dev) +bool +RTE_WEAK(enic_use_vector_rx_handler)(__rte_unused struct rte_eth_dev *eth_dev) {return false; }
drivers/net/fm10k/fm10k_ethdev.c +16 -16
@@ -130,14 +130,14 @@ fm10k_mbx_unlock(struct fm10k_hw *hw) }/* Stubs needed for linkage when vPMD is disabled */ -__rte_weak int -fm10k_rx_vec_condition_check(__rte_unused struct rte_eth_dev *dev) +int +RTE_WEAK(fm10k_rx_vec_condition_check)(__rte_unused struct rte_eth_dev *dev) {return -1 ; } -__rte_weak uint16_t -fm10k_recv_pkts_vec ( +uint16_t +RTE_WEAK (fm10k_recv_pkts_vec )( __rte_unused void *rx_queue, __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts)
@@ -145,8 +145,8 @@ fm10k_recv_pkts_vec(return 0 ; } -__rte_weak uint16_t -fm10k_recv_scattered_pkts_vec ( +uint16_t +RTE_WEAK (fm10k_recv_scattered_pkts_vec )( __rte_unused void *rx_queue, __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts)
@@ -154,34 +154,34 @@ fm10k_recv_scattered_pkts_vec(return 0 ; } -__rte_weak int -fm10k_rxq_vec_setup(__rte_unused struct fm10k_rx_queue *rxq) +int +RTE_WEAK(fm10k_rxq_vec_setup)(__rte_unused struct fm10k_rx_queue *rxq) {return -1 ; } -__rte_weak void -fm10k_rx_queue_release_mbufs_vec ( +void +RTE_WEAK (fm10k_rx_queue_release_mbufs_vec )( __rte_unused struct fm10k_rx_queue *rxq) {return ; } -__rte_weak void -fm10k_txq_vec_setup(__rte_unused struct fm10k_tx_queue *txq) +void +RTE_WEAK(fm10k_txq_vec_setup)(__rte_unused struct fm10k_tx_queue *txq) {return ; } -__rte_weak int -fm10k_tx_vec_condition_check(__rte_unused struct fm10k_tx_queue *txq) +int +RTE_WEAK(fm10k_tx_vec_condition_check)(__rte_unused struct fm10k_tx_queue *txq) {return -1 ; } -__rte_weak uint16_t -fm10k_xmit_fixed_burst_vec(__rte_unused void *tx_queue, +uint16_t +RTE_WEAK(fm10k_xmit_fixed_burst_vec)(__rte_unused void *tx_queue, __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts) {
drivers/net/hns3/hns3_rxtx.c +14 -14
@@ -2787,27 +2787,27 @@ hns3_recv_scattered_pkts(void *rx_queue,return nb_rx; } -void __rte_weak -hns3_rxq_vec_setup(__rte_unused struct hns3_rx_queue *rxq) +void +RTE_WEAK(hns3_rxq_vec_setup)(__rte_unused struct hns3_rx_queue *rxq) { } -int __rte_weak -hns3_rx_check_vec_support(__rte_unused struct rte_eth_dev *dev) +int +RTE_WEAK(hns3_rx_check_vec_support)(__rte_unused struct rte_eth_dev *dev) {return -ENOTSUP ; } -uint16_t __rte_weak -hns3_recv_pkts_vec(__rte_unused void *rx_queue, +uint16_t +RTE_WEAK(hns3_recv_pkts_vec)(__rte_unused void *rx_queue, __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts) {return 0 ; } -uint16_t __rte_weak -hns3_recv_pkts_vec_sve(__rte_unused void *rx_queue, +uint16_t +RTE_WEAK(hns3_recv_pkts_vec_sve)(__rte_unused void *rx_queue, __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts) {
@@ -4256,22 +4256,22 @@ hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)return nb_tx; } -int __rte_weak -hns3_tx_check_vec_support(__rte_unused struct rte_eth_dev *dev) +int +RTE_WEAK(hns3_tx_check_vec_support)(__rte_unused struct rte_eth_dev *dev) {return -ENOTSUP ; } -uint16_t __rte_weak -hns3_xmit_pkts_vec(__rte_unused void *tx_queue, +uint16_t +RTE_WEAK(hns3_xmit_pkts_vec)(__rte_unused void *tx_queue, __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts) {return 0 ; } -uint16_t __rte_weak -hns3_xmit_pkts_vec_sve(void __rte_unused * tx_queue, +uint16_t +RTE_WEAK(hns3_xmit_pkts_vec_sve)(void __rte_unused * tx_queue, struct rte_mbuf __rte_unused **tx_pkts, uint16_t __rte_unused nb_pkts) {
drivers/net/nfp/nfdk/nfp_nfdk_vec_stub.c +2 -2
@@ -5,8 +5,8 @@#include "nfp_nfdk_vec.h" -uint16_t __rte_weak -nfp_net_nfdk_vec_avx2_xmit_pkts(__rte_unused void *tx_queue, +uint16_t +RTE_WEAK(nfp_net_nfdk_vec_avx2_xmit_pkts)(__rte_unused void *tx_queue, __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts) {
drivers/net/nfp/nfp_rxtx_vec_stub.c +4 -4
@@ -10,14 +10,14 @@#include "nfp_rxtx_vec.h" -bool __rte_weak -nfp_net_get_avx2_supported (void ) +bool +RTE_WEAK (nfp_net_get_avx2_supported )(void ) {return false; } -uint16_t __rte_weak -nfp_net_vec_avx2_recv_pkts(__rte_unused void *rx_queue, +uint16_t +RTE_WEAK(nfp_net_vec_avx2_recv_pkts)(__rte_unused void *rx_queue, __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts) {
drivers/net/virtio/virtio_rxtx.c +4 -4
@@ -2045,16 +2045,16 @@ virtio_xmit_pkts_inorder(void *tx_queue,return nb_tx; } -__rte_weak uint16_t -virtio_recv_pkts_packed_vec(void *rx_queue __rte_unused, +uint16_t +RTE_WEAK(virtio_recv_pkts_packed_vec)(void *rx_queue __rte_unused, struct rte_mbuf **rx_pkts __rte_unused, uint16_t nb_pkts __rte_unused) {return 0 ; } -__rte_weak uint16_t -virtio_xmit_pkts_packed_vec(void *tx_queue __rte_unused, +uint16_t +RTE_WEAK(virtio_xmit_pkts_packed_vec)(void *tx_queue __rte_unused, struct rte_mbuf **tx_pkts __rte_unused, uint16_t nb_pkts __rte_unused) {
drivers/net/virtio/virtio_rxtx_simple.c +2 -2
@@ -48,8 +48,8 @@ virtio_rxq_vec_setup(struct virtnet_rx *rxq) }/* Stub for linkage when arch specific implementation is not available */ -__rte_weak uint16_t -virtio_recv_pkts_vec(void *rx_queue __rte_unused, +uint16_t +RTE_WEAK(virtio_recv_pkts_vec)(void *rx_queue __rte_unused, struct rte_mbuf **rx_pkts __rte_unused, uint16_t nb_pkts __rte_unused) {
Signature · 1 line
2.47.0.vfs.0.3
Quoted 11 lines · Andre Muezerie
MSVC uses pragmas to indicate weak linking, so the old
__rte_weakattribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.Andre Muezerie (5):
lib/eal: add portable macro for weak linking app/test-compress-perf: use portable macro for weak linkingdrivers/bus: use portable macro for weak linkingdrivers/common: use portable macro for weak linkingdrivers/net: use portable macro for weak linking
I am not a fan of the weak linking stuff in the first place. Reading the code with __rte_weak, I always wonder which symbol is used when... I prefer explicit linking and no duplicate symbols end up in the binaries.
I posted a RFC, can you have a look?
https://inbox.dpdk.org/dev/[email protected]/
Signature · 1 line
David Marchand
Quoted 14 lines · David Marchand
Quoted 11 lines · Andre Muezerie
MSVC uses pragmas to indicate weak linking, so the old
__rte_weakattribute needs to made into a macro so that the same syntax can be used for MSVC and other compilers like gcc.Andre Muezerie (5):
lib/eal: add portable macro for weak linking app/test-compress-perf: use portable macro for weak linkingdrivers/bus: use portable macro for weak linkingdrivers/common: use portable macro for weak linkingdrivers/net: use portable macro for weak linking
Quoted 10 lines
I am not a fan of the weak linking stuff in the first place. Reading the code with
__rte_weak, I always wonder which symbol is used when... I prefer explicit linking and no duplicate symbols end up in the binaries.I posted a RFC, can you have a look?
https://inbox.dpdk.org/dev/[email protected]/Signature · 1 line
David Marchand
I also had the same questions about which symbols were being used the first time I looked at the code. Therefore, I think your proposal makes the code easier to understand and is a better approach. --
Andre Muezerie