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 74003A0506; Mon, 4 Apr 2022 12:25:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 434474281A; Mon, 4 Apr 2022 12:25:09 +0200 (CEST) Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by mails.dpdk.org (Postfix) with ESMTP id 3A1644014F for ; Fri, 1 Apr 2022 06:34:46 +0200 (CEST) Received: by mail-ot1-f67.google.com with SMTP id n19-20020a9d7113000000b005cd9cff76c3so1383855otj.1 for ; Thu, 31 Mar 2022 21:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=neYEPs7y7t3kgGOMJz8b5xkzd0WVn3n7BnML/dxOvbo=; b=co1wXht/AoUlU8A3/mAH8MJwmIipmgttXBsV/j1hTfRhlu0qp8WFoyzZ2Uy4Y6XkPG Rg1SmF9CeioeuFDjVd2AHBVQI7Hrdc8wc9amB9RdVrhk8ZWfuVSWFlCZ0Y+i6vH/0teG GbBrbio0qb3duUIPhpss9rMDfdrEEvNp+5c4MnveSoaXFH7XOdedu+1RznHjApgGAVEP dYghVCmt1fLK/0s/PkWgVBorXhC+BjaybLaq01j5H62j2hojyP8G7EId1cooqbOIr0K0 8tVcMGiD+Q5FCKQNRv42Wwe690ticNPQIyACRzw9G93cEpz7fgLpsX4l1kaESvSBs4Fb sCqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=neYEPs7y7t3kgGOMJz8b5xkzd0WVn3n7BnML/dxOvbo=; b=rSWfgv4fiMbgbWl7JUSUAWfXU3LhcefgSneBTdOEUL4GI5KscjkE1m8SSqrCziwafc zZkiGEIOlHMeiGf/EKhVWYbeAVQWU85zYiqQ64rLDaqfecRXfmpscIOj+eXg3IjRdnHg h7UPEyb5Mg43pMdv9VAOF88h4xJ8Np6aoTEqP0Ip/8r8/uTBS2TeFo+LyHZCfTwqO7+M du4/5OvMCrw8cc3gAeyGsytkLMb1B/gY6supcPfRt0Pc+FllJAeE/N+wlMU4GotwknJc QZhWpxnux3a7MjJEy/ddz4v1ngT3Xb+XtaaEiBo8hMOMGulZ+buLYFeiF5smsULOpFl5 DIhQ== X-Gm-Message-State: AOAM533EieKfu6xGCSheX732gtSleR2EN1LJuBhAsWQWZ2Z7EsKcC/3r INVVb4mjHe0HiNoNlr3WtD91IeYgBh4f9Q== X-Google-Smtp-Source: ABdhPJxg+aHBTFCfE1FyuYZD/zFO+s6h1a/3j29rnPzCACMu8b+XubGHA7ercoj9CJLUAOyY0twFrg== X-Received: by 2002:a05:6830:40a9:b0:5c9:4a8d:ab1f with SMTP id x41-20020a05683040a900b005c94a8dab1fmr6963667ott.288.1648787685304; Thu, 31 Mar 2022 21:34:45 -0700 (PDT) Received: from mahdi-MS-7A34.attlocal.net ([2600:1700:2320:adc0:4c30:bd76:36bb:113d]) by smtp.gmail.com with ESMTPSA id hg14-20020a056870790e00b000e1c070a73asm52353oab.55.2022.03.31.21.34.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 21:34:45 -0700 (PDT) From: Mahdi Rakhshandehroo To: dev@dpdk.org Subject: [PATCH] meson: add support for clang LTO Date: Thu, 31 Mar 2022 21:34:44 -0700 Message-Id: <20220401043444.59396-1-mahdi.rakhshandehroo@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 04 Apr 2022 12:25:07 +0200 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 Currently, building DPDK with clang + LTO is unsupported, which is a showstopper for cross-language interprocedural optimizations. The root cause is that pmdinfogen expects to scan through the section headers of generated ELF object files, but clang's "-flto" flag generates LLVM bitcode instead. This patch enables LTO builds with clang, provided that the linker is set to lld. The mechanism of action is clang's "-fembed-bitcode" flag, which acts similarly to gcc's "-ffat-lto-objects" - the compiler outputs a normal ELF object file that keeps pmdinfogen happy, but also embeds IR bitcode in a special section of the ELF that lld can then use to construct the final binary. Signed-off-by: Mahdi Rakhshandehroo --- config/meson.build | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/config/meson.build b/config/meson.build index 7134e80..c109b38 100644 --- a/config/meson.build +++ b/config/meson.build @@ -406,16 +406,22 @@ if is_windows endif if get_option('b_lto') - if cc.has_argument('-ffat-lto-objects') + if cc.get_id() == 'gcc' and cc.has_argument('-ffat-lto-objects') add_project_arguments('-ffat-lto-objects', language: 'c') + + # workaround for gcc bug 81440 + if cc.version().version_compare('<8.0') + add_project_arguments('-Wno-lto-type-mismatch', language: 'c') + add_project_link_arguments('-Wno-lto-type-mismatch', language: 'c') + endif + elif cc.get_id() == 'clang' and cc.has_argument('-fembed-bitcode') + if cc.get_linker_id() != 'ld.lld' + error('compiling with clang and LTO requires the lld linker') + add_project_arguments('-fno-lto', '-fembed-bitcode', language: 'c') + endif else error('compiler does not support fat LTO objects - please turn LTO off') endif - # workaround for gcc bug 81440 - if cc.get_id() == 'gcc' and cc.version().version_compare('<8.0') - add_project_arguments('-Wno-lto-type-mismatch', language: 'c') - add_project_link_arguments('-Wno-lto-type-mismatch', language: 'c') - endif endif if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address,undefined' -- 2.25.1