DPDK patches and discussions
 help / color / mirror / Atom feed
From: Mahdi Rakhshandehroo <mahdi.rakhshandehroo@gmail.com>
To: dev@dpdk.org
Subject: [PATCH] meson: add support for clang LTO
Date: Thu, 31 Mar 2022 21:34:44 -0700	[thread overview]
Message-ID: <20220401043444.59396-1-mahdi.rakhshandehroo@gmail.com> (raw)

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 <mahdi.rakhshandehroo@gmail.com>
---
 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


                 reply	other threads:[~2022-04-04 10:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220401043444.59396-1-mahdi.rakhshandehroo@gmail.com \
    --to=mahdi.rakhshandehroo@gmail.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).