From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DADB943037; Fri, 11 Aug 2023 21:22:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 73F0F432A1; Fri, 11 Aug 2023 21:21:19 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 1243940144 for ; Fri, 11 Aug 2023 21:21:02 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 011DC20FD0FC; Fri, 11 Aug 2023 12:21:00 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 011DC20FD0FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1691781661; bh=g+BXTEEiNabDbcIi5zWhPqN0MzamJTwYJAK6tvPHhd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F4YcurvVncGTmolDjfY8RfY5PPkKtJG7Nd0ciCedzoGnvdYkEz2tWOc0nq8j6q2uC STk4ho/G+N9pJVZgRhhHeyFET6/Z7PJY2CigUc6KucF3VDRlzsJtw7TG5ziWnPph6e Z5pRcWxQqlpjkhKXFigziuSSjJjvULikR+iKlSdQ= From: Tyler Retzlaff To: dev@dpdk.org Cc: Bruce Richardson , Konstantin Ananyev , Ciara Power , thomas@monjalon.net, david.marchand@redhat.com, mb@smartsharesystems.com, Tyler Retzlaff Subject: [PATCH v11 16/16] eal: define priority based ctor dtor for MSVC Date: Fri, 11 Aug 2023 12:20:58 -0700 Message-Id: <1691781658-32520-17-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1691781658-32520-1-git-send-email-roretzla@linux.microsoft.com> References: <1680558751-17931-1-git-send-email-roretzla@linux.microsoft.com> <1691781658-32520-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Provide RTE_INIT_PRIO and RTE_FINI_PRIO for MSVC allowing priority based equivalents to __attribute__(({constructor,destructor}) Signed-off-by: Tyler Retzlaff --- lib/eal/include/rte_common.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index cf7d8d8..791ceed 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -214,8 +214,29 @@ * Lowest number is the first to run. */ #ifndef RTE_INIT_PRIO /* Allow to override from EAL */ +#ifndef RTE_TOOLCHAIN_MSVC #define RTE_INIT_PRIO(func, prio) \ static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) +#else +/* definition from the Microsoft CRT */ +typedef int(__cdecl *_PIFV)(void); + +#define CTOR_SECTION_LOG ".CRT$XIB" +#define CTOR_SECTION_BUS ".CRT$XIC" +#define CTOR_SECTION_CLASS ".CRT$XID" +#define CTOR_SECTION_LAST ".CRT$XIY" + +#define CTOR_PRIORITY_TO_SECTION(priority) CTOR_SECTION_ ## priority + +#define RTE_INIT_PRIO(name, priority) \ + static void name(void); \ + static int __cdecl name ## _thunk(void) { name(); return 0; } \ + __pragma(const_seg(CTOR_PRIORITY_TO_SECTION(priority))) \ + __declspec(allocate(CTOR_PRIORITY_TO_SECTION(priority))) \ + _PIFV name ## _pointer = &name ## _thunk; \ + __pragma(const_seg()) \ + static void name(void) +#endif #endif /** @@ -239,8 +260,24 @@ static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) * Lowest number is the last to run. */ #ifndef RTE_FINI_PRIO /* Allow to override from EAL */ +#ifndef RTE_TOOLCHAIN_MSVC #define RTE_FINI_PRIO(func, prio) \ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) +#else +#define DTOR_SECTION_LOG "mydtor$B" +#define DTOR_SECTION_BUS "mydtor$C" +#define DTOR_SECTION_CLASS "mydtor$D" +#define DTOR_SECTION_LAST "mydtor$Y" + +#define DTOR_PRIORITY_TO_SECTION(priority) DTOR_SECTION_ ## priority + +#define RTE_FINI_PRIO(name, priority) \ + static void name(void); \ + __pragma(const_seg(DTOR_PRIORITY_TO_SECTION(priority))) \ + __declspec(allocate(DTOR_PRIORITY_TO_SECTION(priority))) name ## _pointer = &name; \ + __pragma(const_seg()) \ + static void name(void) +#endif #endif /** -- 1.8.3.1