Skip to contentSkip to conversation

package/kmsxx: add patch to fix LTO support

PATCH New Arnout Vandecappelle (Essensium/Mind) 3 participants 5 messages Aug 26, 2016 – Aug 27, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/kmsxx: add patch to fix LTO support

The LTO support in the kmsxx package uses the host gcc-ar and gcc-ranlib instead of the ones from the cross-toolchain. Add a patch that tries to find the right one based on CMAKE_C_COMPILER.

Fixes:
http://autobuild.buildroot.net/results/16a/16a38a4277dd1152a5955d62cb92f85447791ef3

Possibly also fixes:
http://autobuild.buildroot.net/results/f3c/f3c48da3a9706cd366c0e0a96c3cd0ff959f2a78
(it fails later, possibly because an incompatible host ar)

---
Thomas P. proposed to instead add a variable for LTO_AR and LTO_RANLIB that we would override. However, this version works and is upstreamable and currently we don't even "know" if cross-gcc-ar exists or not.

CMake actually has a target property INTERPROCEDURAL_OPTIMIZATION but it seems that this is currently only implemented for Intel ICC. Cfr.
https://cmake.org/Bug/view.php?id=15939

---
 ...001-Fix-LTO-support-for-cross-compilation.patch | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch
package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch new file +45 -0
new file mode 100644
index 0000000..9b4a582
@@ -0,0 +1,45 @@
+From 5da1f631bc753655ac94b08a6233eecd0d451327 Mon Sep 17 00:00:00 2001
+From: "Arnout Vandecappelle (Essensium/Mind)" <[email protected]>
+Date: Fri, 26 Aug 2016 21:55:06 +0200
+Subject: [PATCH] Fix LTO support for cross-compilation.
+
+When cross-compiling, the ar and ranlib to be used for LTO are prefixed
+by the cross-tuple. gcc-ar and gcc-ranlib may not exist. Cfr.
+http://autobuild.buildroot.net/results/f3c/f3c48da3a9706cd366c0e0a96c3cd0ff959f2a78/
+
+Therefore, search for an appropriate lto-ar and lto-ranlib before
+enabling LTO.
+
+Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <[email protected]>
+---
+Submitted upstream: https://github.com/tomba/kmsxx/pull/14
+---
+ CMakeLists.txt | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index e5b5ea5..c61c81d 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -39,9 +39,15 @@ if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
+     CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
+ 
+     if (HAS_LTO_FLAG)
+-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+-        set(CMAKE_AR gcc-ar)
+-        set(CMAKE_RANLIB gcc-ranlib)
++        find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar)
++        find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib" /usr/bin/gcc-ranlib)
++        if (LTO_AR AND LTO_RANLIB)
++            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
++            set(CMAKE_AR "${LTO_AR}")
++            set(CMAKE_RANLIB "${LTO_RANLIB}")
++        else()
++            message(STATUS "gcc-ar or gcc-ranlib not found, disabling LTO")
++        endif()
+     endif()
+ endif()
+ 
+-- 
+2.9.3
+
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/1 package/kmsxx: add patch to fix LTO support

Hello,

Quoted 3 lines · Arnout Vandecappelle (Essensium/Mind)

The LTO support in the kmsxx package uses the host gcc-ar and gcc-ranlib instead of the ones from the cross-toolchain. Add a patch that tries to find the right one based on CMAKE_C_COMPILER.

Thanks for this patch! One quick question though.

Quoted 6 lines

+ if (HAS_LTO_FLAG)

+-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+-        set(CMAKE_AR gcc-ar)
+-        set(CMAKE_RANLIB gcc-ranlib)
++        find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar)
++        find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib" /usr/bin/gcc-ranlib)

Why is the last attempted value for AR "gcc-ar", and for RANLIB it's "/usr/bin/gcc-ranlib" ? I.e while just the program name in one case, and a full path in the other case.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#3 lore raw

PATCH 1/1 package/kmsxx: add patch to fix LTO support

In reply to Arnout Vandecappelle (Essensium/Mind)

Hi all,

Quoted 73 lines · Arnout Vandecappelle (Essensium/Mind)

The LTO support in the kmsxx package uses the host gcc-ar and gcc-ranlib
instead of the ones from the cross-toolchain. Add a patch that tries to find the right one based on CMAKE_C_COMPILER.

Fixes:
http://autobuild.buildroot.net/results/16a/16a38a4277dd1152a5955d62cb92f85447791ef3

Possibly also fixes:
http://autobuild.buildroot.net/results/f3c/f3c48da3a9706cd366c0e0a96c3cd0ff959f2a78
(it fails later, possibly because an incompatible host ar)

---
Thomas P. proposed to instead add a variable for LTO_AR and LTO_RANLIB that we would override. However, this version works and is upstreamable and currently we don't even "know" if cross-gcc-ar exists or not.

CMake actually has a target property INTERPROCEDURAL_OPTIMIZATION but it seems that this is currently only implemented for Intel ICC. Cfr.
https://cmake.org/Bug/view.php?id=15939
---
...001-Fix-LTO-support-for-cross-compilation.patch | 45
++++++++++++++++++++++

1 file changed, 45 insertions(+)

create mode 100644 package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch

diff --git a/package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch b/package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch new file mode 100644
index 0000000..9b4a582

package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch new file +6 -0
@@ -0,0 +1,45 @@
+From 5da1f631bc753655ac94b08a6233eecd0d451327 Mon Sep 17 00:00:00 2001
+From: "Arnout Vandecappelle (Essensium/Mind)" <[email protected]>
+Date: Fri, 26 Aug 2016 21:55:06 +0200
+Subject: [PATCH] Fix LTO support for cross-compilation.
+
+When cross-compiling, the ar and ranlib to be used for LTO are

prefixed

package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch new file +26 -0
+by the cross-tuple. gcc-ar and gcc-ranlib may not exist. Cfr.
+http://autobuild.buildroot.net/results/f3c/f3c48da3a9706cd366c0e0a96c3cd0ff959f2a78/
+
+Therefore, search for an appropriate lto-ar and lto-ranlib before
+enabling LTO.
+
+Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <[email protected]>
+---
+Submitted upstream: https://github.com/tomba/kmsxx/pull/14
+---
+ CMakeLists.txt | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index e5b5ea5..c61c81d 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -39,9 +39,15 @@ if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
+     CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
+ 
+     if (HAS_LTO_FLAG)
+-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+-        set(CMAKE_AR gcc-ar)
+-        set(CMAKE_RANLIB gcc-ranlib)
++        find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar)
++        find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib"

/usr/bin/gcc-ranlib)
++ if (LTO_AR AND LTO_RANLIB)

Quoted 3 lines
++            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
++            set(CMAKE_AR "${LTO_AR}")
++            set(CMAKE_RANLIB "${LTO_RANLIB}")

These definitions belong to the toolchainfile.cmake file IMHO, but it can be moved there in a follow-up patch.

Regards,

Quoted 10 lines

++ else()
++ message(STATUS "gcc-ar or gcc-ranlib not found, disabling
LTO")
++ endif()

package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch new file +6 -0
+     endif()
+ endif()
+ 
+-- 
+2.9.3
+
Signature · 1 line
Samuel
#2 lore raw

PATCH 1/1 package/kmsxx: add patch to fix LTO support

In reply to Thomas Petazzoni
Quoted 17 lines · Thomas Petazzoni

Hello,

Quoted 3 lines · Arnout Vandecappelle (Essensium/Mind)

The LTO support in the kmsxx package uses the host gcc-ar and gcc-ranlib instead of the ones from the cross-toolchain. Add a patch that tries to find the right one based on CMAKE_C_COMPILER.

Thanks for this patch! One quick question though.

Quoted 6 lines

+ if (HAS_LTO_FLAG)

+-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+-        set(CMAKE_AR gcc-ar)
+-        set(CMAKE_RANLIB gcc-ranlib)
++        find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar)
++        find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib" /usr/bin/gcc-ranlib)
Quoted 3 lines

Why is the last attempted value for AR "gcc-ar", and for RANLIB it's "/usr/bin/gcc-ranlib" ? I.e while just the program name in one case, and a full path in the other case.

The /usr/bin/gcc-ranlib is obviously wrong. That was a left-over from a test to
be sure that find_program also finds it if the full path is given.

I'll send a v2.

Regards,
Arnout

Quoted 5 lines

Thanks,

Thomas

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#4 lore raw

PATCH 1/1 package/kmsxx: add patch to fix LTO support

In reply to Samuel Martin
Quoted 7 lines · Samuel Martin

Hi all,

Quoted 4 lines · Arnout Vandecappelle (Essensium/Mind)

The LTO support in the kmsxx package uses the host gcc-ar and gcc-ranlib
instead of the ones from the cross-toolchain. Add a patch that tries to find the right one based on CMAKE_C_COMPILER.

[snip]

Quoted 12 lines
Quoted 11 lines

+ if (HAS_LTO_FLAG)

+-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+-        set(CMAKE_AR gcc-ar)
+-        set(CMAKE_RANLIB gcc-ranlib)
++        find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar)
++        find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib"
/usr/bin/gcc-ranlib)
++        if (LTO_AR AND LTO_RANLIB)
++            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
++            set(CMAKE_AR "${LTO_AR}")
++            set(CMAKE_RANLIB "${LTO_RANLIB}")
Quoted 1 line

These definitions belong to the toolchainfile.cmake file IMHO, but it can be moved there in a follow-up patch.

Well, even if it is in toolchainfile.cmake, this patch is needed because the
CMakeLists.txt will just blindly override the defaults.

But at the moment, we don't have global LTO support. We can build an internal
toolchain with LTO support, but it's up to individual packages to enable/use it. Which makes sense, because LTO is still a bit experimental and possibly breaks things.

So we could add a global LTO_AR and LTO_RANLIB to our toolchainfile.cmake, but
since no package would make use of it, it wouldn't make a whole lot of sense.

Regards,
Arnout

Quoted 14 lines

Regards,

Quoted 10 lines

++ else()
++ message(STATUS "gcc-ar or gcc-ranlib not found, disabling
LTO")
++ endif()

package/kmsxx/0001-Fix-LTO-support-for-cross-compilation.patch new file +6 -0
+     endif()
+ endif()
+ 
+-- 
+2.9.3
+
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF