This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch,ld testsuite] Support check_lto_shared_available


Hello,

This patch implements the check_lto_shared_available improvement suggested by
H.J.Lu[1] as a part of fixing check_lto_available[2].

In abstract, check_lto_available checks if the compiler supports LTO by creating
an executable while check_lto_shared_available checks for LTO support as well as
LTO shared library support. This is essentially the old implementation of 
check_lto_available which has been recently modified but with the support for
cflags & ldflags from the board file.

This patch also modifies lto.exp to use check_lto_shared_available.

OK?

[1] https://sourceware.org/ml/binutils/2013-12/msg00136.html
[2] https://sourceware.org/ml/binutils/2013-12/msg00132.html

Tested for aarch64-none-elf, arm-none-eabi, arm-none-linux-gnueabihf and
x86_64-unknown-linux-gnu.

Regards
VP

ld/testsuite/ChangeLog:

2013-12-18  Vidya Praveen  <vidyapraveen@arm.com>

	* lib/ld-lib.exp (check_lto_shared_available): New check.
	* ld-plugin/lto.exp: Use check_lto_shared_available.

diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index c5249f0..82dc9d7 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -300,8 +300,7 @@ set lto_run_elf_tests {
 run_cc_link_tests $lto_link_tests
 
 # Restrict these to ELF targets that support shared libs and PIC.
-if { [is_elf_format]
-     && [run_host_cmd_yesno $CC "-shared -fPIC $srcdir/$subdir/dummy.c -o tmpdir/t.so"] } {
+if { [is_elf_format] && [check_lto_shared_available] } {
     run_cc_link_tests $lto_link_elf_tests
     set testname "PR ld/15146 (2)"
     set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index f22fa8e..b18dbbb 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1676,6 +1676,45 @@ proc check_lto_available { } {
     return $lto_available_saved
 }
 
+# Returns true if the target compiler supports LTO
+proc check_lto_shared_available { } {
+    global lto_shared_available_saved
+    global CC
+
+    set flags ""
+
+    if [board_info [target_info name] exists cflags] {
+        append flags " [board_info [target_info name] cflags]"
+    }
+
+    if [board_info [target_info name] exists ldflags] {
+        append flags " [board_info [target_info name] ldflags]"
+    }
+
+    if {![info exists lto_shared_available_saved]} {
+	# Check if gcc supports -flto -fuse-linker-plugin
+	if { [which $CC] == 0 } {
+	    set lto_shared_available_saved 0
+	    return 0
+	}
+	set basename "lto_shared"
+	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 "$flags -shared -B[pwd]/tmpdir/ld/ -flto -fuse-linker-plugin $src -o $output"]
+	if { [lindex $status 0] == 0 } {
+	    set lto_shared_available_saved 1
+	} else {
+	    set lto_shared_available_saved 0
+	}
+	file delete $src
+	file delete $output
+    }
+    return $lto_shared_available_saved
+}
+
 # Check if the assembler supports CFI statements.
 
 proc check_as_cfi { } {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]