From patchwork Fri Apr 1 04:54:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahdi Rakhshandehroo X-Patchwork-Id: 109119 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4CB21A0506; Mon, 4 Apr 2022 12:25:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 27FC64281F; Mon, 4 Apr 2022 12:25:10 +0200 (CEST) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by mails.dpdk.org (Postfix) with ESMTP id 625A44014F for ; Fri, 1 Apr 2022 06:54:37 +0200 (CEST) Received: by mail-qt1-f196.google.com with SMTP id v2so1324333qtc.5 for ; Thu, 31 Mar 2022 21:54:37 -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=3IBiI4Up2m6NBKJ5BUTtGU7lUJNMEbeVMa+L04yWML4=; b=K+msduehaTlCUvoqSjwDn5FCmj/qi2sx3WWrJwoY2jPg5cv6vpcx5kyR7Q0qaYGiG7 14bIagHEuhJ/nLXpKtdoSWx8X4zfcLV2/8mhuDkA7S22vWrendmgNfSJHKlqwXXhaH+W cOW4P6BGeef8VRNfR4HKk2DiCy9KQxto3+aXJ3vxgL0rgsXERRVzFDopY58felCYMdik gnp29IE49b52YiFjlIuaXPCTNPaQ391lR1oRDBdPytDU2yFbKzyC7ee9xoUUeE4UEkH1 FM5MmL32mxZtqp3COSiuxJslHS/eRY2PpssHCAJK/4XWRJIVwSS0Zv3EYUm6KDon8gJ7 cW4A== 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=3IBiI4Up2m6NBKJ5BUTtGU7lUJNMEbeVMa+L04yWML4=; b=OIRXk91AKssq26cZZ3zTrHWjHcr+WRHqLR1ir5p02ygFgVBV7+6Um3WXG0WpR1FCuy AePu6dgXPKMlhoeKauZMYeYq8/jApZnHqUqJD3BLcAxEEnkhcURPpSoExOCBXVZx215t ag0ZYE29e4lk3jatZ89cZqPJRa5yKqm6nV4H8d4quxmU3n5YV/p3XotlleFoGDTHaWpr yyh+CCJtRWki5BV9Txj74ySSmAqcJXeM5ttAheaX/1k7dhwEVws3fJKegik/wPGpmp/m KzOizAUi+pV0B4tGu9wtuskUTwMDPluQ7dAgd0vPifdV4eQRXsGYZv18uu38aAN1L8Eh KahA== X-Gm-Message-State: AOAM532eNnPIgTpYE/X+VJp1ZL6uiPXGsK1SiniLs2/WzmaoEmGnz3d0 cp+RgfDwShPhntwikXfdEDWPCYFs8WBoig== X-Google-Smtp-Source: ABdhPJxcysZJpv9FuATuPnjhhXGIqbH+AI2erKyEHk7Nujgs4pYPVHHE5Rp0QGkCmi28KZ3v3qvsQQ== X-Received: by 2002:a05:622a:1452:b0:2e1:a12b:ef6 with SMTP id v18-20020a05622a145200b002e1a12b0ef6mr7120649qtx.579.1648788876625; Thu, 31 Mar 2022 21:54:36 -0700 (PDT) Received: from mahdi-MS-7A34.attlocal.net ([2600:1700:2320:adc0:4c30:bd76:36bb:113d]) by smtp.gmail.com with ESMTPSA id 20-20020ac84e94000000b002e1d5505fb6sm1141171qtp.63.2022.03.31.21.54.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 21:54:36 -0700 (PDT) From: Mahdi Rakhshandehroo To: dev@dpdk.org Subject: [PATCH v2] meson: add support for clang LTO Date: Thu, 31 Mar 2022 21:54:35 -0700 Message-Id: <20220401045435.60172-1-mahdi.rakhshandehroo@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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 --- Forgot to remove get_linker_id() check from the previous patch - that function is only available in Meson >= 0.54. config/meson.build | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/config/meson.build b/config/meson.build index 7134e80..5425181 100644 --- a/config/meson.build +++ b/config/meson.build @@ -406,16 +406,21 @@ 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') + # TODO: enforce use of lld using cc.get_linker_id() with Meson >= 0.54 + 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'