From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 1BDFA4696C3 for ; Tue, 14 Apr 2020 20:07:31 +0300 (MSK) Date: Tue, 14 Apr 2020 20:00:24 +0300 From: Igor Munkin Message-ID: <20200414170024.GL5713@tarantool.org> References: <20200312100549.31608-1-arkholga@tarantool.org> <20200414091803.GJ5713@tarantool.org> <184a4359-9531-a35e-b77a-554394346cdd@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <184a4359-9531-a35e-b77a-554394346cdd@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH] cmake: add LTO support for building luajit List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Olga Arkhangelskaia Cc: tarantool-patches@dev.tarantool.org Olya, Thanks for the fixes! There are still a couple nits below. On 14.04.20, Olga Arkhangelskaia wrote: > Hi once again! > > I have fixed your comments and pushed once again. See below. > > 14.04.2020 12:18, Igor Munkin пишет: > > Olya, > > > > Thanks for the patch! I left several comments below, please consider > > them. > > > > On 12.03.20, Olga Arkhangelskaia wrote: > >> Tarantool has LTO support, however while building luajit this opt. was > >> omitted. Patch adds necessary flag to turn it on. > >> > >> Minimum compiler/linker versions: clang 3.4, gcc 5.0+, ld 2.27+. > >> > >> Closes #3743 > >> --- > >> Branch: OKriw/gh-3743-LuaJIT-does-not-use-LTO-with-DENABLE_LTO=ON-full-ci > >> cmake/lto.cmake | 3 ++- > >> cmake/luajit.cmake | 26 ++++++++++++++++++++++++++ > >> 2 files changed, 28 insertions(+), 1 deletion(-) > >> > >> diff --git a/cmake/lto.cmake b/cmake/lto.cmake > >> index 95ade75f4..9f29f3324 100644 > >> --- a/cmake/lto.cmake > >> +++ b/cmake/lto.cmake > >> @@ -78,7 +78,8 @@ if (NOT TARGET_OS_DARWIN) > >> if (linker_version VERSION_LESS "2.31") > >> message(FATAL_ERROR "ld.bfd >= 2.31 is needed for LTO") > >> endif() > >> - elseif(matched_gold) > >> + > >> + elseif(matched_gold) > > Typo: there is a mess with whitespace above. > > > > However this chunk provides no changes except whitespace and newline. > > Please drop it. > > > Tarantool has LTO support, however while building luajit this opt. was > omitted. Patch adds necessary flag to turn it on. > > Minimum compiler/linker versions: clang 3.4, gcc 5.0+, ld 2.27+. > > Closes #3743 > --- >  cmake/luajit.cmake | 23 +++++++++++++++++++++++ >  1 file changed, 23 insertions(+) > > > >> set(linker_version ${CMAKE_MATCH_1}) > >> message(STATUS "Found ld.gold version: ${linker_version}") > >> > >> diff --git a/cmake/luajit.cmake b/cmake/luajit.cmake > >> index 072db8269..da1b4926d 100644 > >> --- a/cmake/luajit.cmake > >> +++ b/cmake/luajit.cmake > >> @@ -225,6 +225,32 @@ macro(luajit_build) > >> set(luajit_xcflags ${luajit_xcflags} -D${def}) > >> endforeach() > >> > >> + # Add LTO option to luajit > >> + if (CMAKE_INTERPROCEDURAL_OPTIMIZATION) > >> + message("Setting LTO flags for building luajit") > >> + # Clang opt to support LTO > >> + if (CMAKE_COMPILER_IS_CLANG AND > >> + NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.4) > > So, if clang toolchain is used but version is less than 3.4, then gcc > > toolchain settings are used. It's either totally wrong or definitely > > need to be clarified with a corresponding comment. > > > > Also, AFAICS LTO support for toolchain is checked via CheckIPOSupported > > CMake module. So additional check here looks to be excess or also need > > to be clarified. > > > >> + if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.9) > >> + set(luajit_cflags ${luajit_cflags} -flto=full) > >> + else() > >> + set(luajit_cflags ${luajit_cflags} -flto=full) > >> + endif() > > I see no difference in the branches above. > > > >> + if (NOT TARGET_OS_DARWIN) > >> + # Depending of compiler we need to set appropriate llvm/gcc-ar lib > >> + set (CMAKE_AR llvm-ar) > > What ar is used on systems different from Darwin based ones when clang > > toolchain is used? > > > >> + endif() > >> + # GNU opts to support lto > >> + else() > >> + #Due to some problems (bugs, slow work, etc) we support LTO only for 5.0+ > >> + #The same is for binutils prior 2.27 > >> + if (NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.0 > >> + AND NOT ${linker_version} VERSION_LESS 2.27) > >> + set(luajit_cflags ${luajit_cflags} -flto -fuse-linker-plugin -fno-fat-lto-objects) > >> + endif() > >> + set (CMAKE_AR gcc-ar) > > Could you please clarify why ar is set explicitly here? > > > >> + endif() > >> + endif() > +    # Add LTO option to luajit > +    if (CMAKE_INTERPROCEDURAL_OPTIMIZATION) > +           message("Setting LTO flags for building luajit") > +       # Clang opt to support LTO > +       if (CMAKE_COMPILER_IS_CLANG) > +           if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.9) > +               set(luajit_cflags ${luajit_cflags} -flto=full) > + else() > +               set(luajit_cflags ${luajit_cflags} -flto=thin) > + endif() Moved our discussion below: ================================================================================ > > I see no difference in the branches above. > > I have a mistake here (Thin LTO) - will wix it > > If version is above than 3.9 we can use -flto=thin What is the difference between "full" and "thin" values? Please drop a few words regarding it. ================================================================================ > +          # Depending of compiler we need to set appropriate > llvm/gcc-ar lib > +          set (CMAKE_AR llvm-ar) Moved our discussion below: ================================================================================ > > What ar is used on systems different from Darwin based ones when clang > > toolchain is used? > > > gcc-ar/ llvm-ar  is wrapper on ar that simply passes —plugin option. We > need it for LTO. > > ( See https://bugzilla.redhat.com/show_bug.cgi?id=1678826 > > https://lists.llvm.org/pipermail/llvm-dev/2018-March/122018.html) > It would be nice to leave a comment regarding it. ================================================================================ > +       # GNU opts to support lto Minor: Please move this comment under statement as the corresponding clang-related comment. > + else() > +          #Due to some problems (bugs, slow work, etc) we support LTO > only for 5.0+ > +          #The same is for binutils prior 2.27 Typo: Please separate # from the comment with a space. > +          if (NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.0 > +              AND NOT ${linker_version} VERSION_LESS 2.27) Are there any versions supporting LTO/IPO less than gcc-5.0 and ld-2.27? If yes, please mention why they don't fit our purposes. If not, I see no rationale for this condition. > +              set(luajit_cflags ${luajit_cflags} -flto > -fuse-linker-plugin -fno-fat-lto-objects) > + endif() > +          set (CMAKE_AR gcc-ar) Minor: there are some commands with a whitespace prior to parentheses and some without. Please adjust those you introduced within your changes to a single style. > + endif() > +    endif() > > Typo: there is a mess with indent above. Unfortunately I failed to find > > our CMake style guide, so please adjust your changes considering the > > code nearby. > > > >> # Pass the same toolchain that is used for building of > >> # tarantool itself, because tools from different toolchains > >> # can be incompatible. A compiler and a linker are already set > >> -- > >> 2.20.1 (Apple Git-117) > >> -- Best regards, IM