This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Add check_lto_available
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Fri, 7 Dec 2012 09:58:14 -0800
- Subject: PATCH: Add check_lto_available
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
I checked in this patch to add check_lto_available to check if
compiler supports LTO.
H.J.
---
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ChangeLog,v
retrieving revision 1.1637
diff -u -p -r1.1637 ChangeLog
--- ChangeLog 7 Dec 2012 17:53:03 -0000 1.1637
+++ ChangeLog 7 Dec 2012 17:55:20 -0000
@@ -1,5 +1,10 @@
2012-12-07 H.J. Lu <hongjiu.lu@intel.com>
+ * lib/ld-lib.exp (check_lto_available): New. Check if compiler
+ supports LTO.
+
+2012-12-07 H.J. Lu <hongjiu.lu@intel.com>
+
* lib/ld-lib.exp (run_cc_link_tests): Properly check linker
warnings.
Index: lib/ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.99
diff -u -p -r1.99 ld-lib.exp
--- lib/ld-lib.exp 7 Dec 2012 17:53:04 -0000 1.99
+++ lib/ld-lib.exp 7 Dec 2012 17:55:20 -0000
@@ -1614,6 +1614,34 @@ proc check_plugin_api_available { } {
return $plugin_api_available_saved
}
+# Returns true if the target compiler supports LTO
+proc check_lto_available { } {
+ global lto_available_saved
+ global CC
+ if {![info exists lto_available_saved]} {
+ # Check if gcc supports -flto -fuse-linker-plugin
+ if { [which $CC] == 0 } {
+ set lto_available_saved 0
+ return 0
+ }
+ set basename "lto"
+ set src ${basename}[pid].c
+ set output ${basename}[pid].so
+ set f [open $src "w"]
+ puts $f ""
+ close $f
+ set status [remote_exec host $CC "-shared -B[pwd]/tmpdir/ld/ -flto -fuse-linker-plugin $src -o $output"]
+ if { [lindex $status 0] == 0 } {
+ set lto_available_saved 1
+ } else {
+ set lto_available_saved 0
+ }
+ file delete $src
+ file delete $output
+ }
+ return $lto_available_saved
+}
+
# Check if the assembler supports CFI statements.
proc check_as_cfi { } {