aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-07-31 07:40:27 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-07-31 07:57:04 -0700
commite6a6c7676a7df49cfbbffda26eadd2032dbc2bbe (patch)
tree7399b145a808662b9c4b49959ba9c14a381f0c0c
parenta896df97b952d4f3feed8068eaa70147d12e0e28 (diff)
downloadgdb-e6a6c7676a7df49cfbbffda26eadd2032dbc2bbe.zip
gdb-e6a6c7676a7df49cfbbffda26eadd2032dbc2bbe.tar.gz
gdb-e6a6c7676a7df49cfbbffda26eadd2032dbc2bbe.tar.bz2
ld: Add -fno-lto to linker tests
LTO can be used to build binutils with $ CC="gcc -flto -ffat-lto-objects -Wl,--as-needed" CXX="g++ -flto -ffat-lto-objects -Wl,--as-needed" .../configure But not all linker tests are compatible with LTO. Pass -fno-lto to CC to disable LTO on linker tests by default. -flto is passed explicitly to CC in linker LTO tests. * testsuite/ld-elf/indirect.exp: Append -fno-lto to CC. * testsuite/ld-elfvers/vers.exp: Likewise. * testsuite/ld-elfweak/elfweak.exp: Likewise. * testsuite/ld-ifunc/ifunc.exp: Likewise. * testsuite/ld-plugin/lto.exp (no_lto): New. Add $no_lto to build pr15146c.so. * testsuite/lib/ld-lib.exp (at_least_gcc_version): Filter out -Wl,xxx options. (check_gcc_plugin_enabled): Likewise. (run_ld_link_exec_tests): Prepend -fno-lto to $cflags. (run_cc_link_tests): Likewise.
-rw-r--r--ld/ChangeLog14
-rw-r--r--ld/testsuite/ld-elf/indirect.exp32
-rw-r--r--ld/testsuite/ld-elfvers/vers.exp9
-rw-r--r--ld/testsuite/ld-elfweak/elfweak.exp50
-rw-r--r--ld/testsuite/ld-ifunc/ifunc.exp20
-rw-r--r--ld/testsuite/ld-plugin/lto.exp3
-rw-r--r--ld/testsuite/lib/ld-lib.exp18
7 files changed, 100 insertions, 46 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 13919b2..f5a42f1 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,17 @@
+2020-07-31 H.J. Lu <hongjiu.lu@intel.com>
+
+ * testsuite/ld-elf/indirect.exp: Append -fno-lto to CC.
+ * testsuite/ld-elfvers/vers.exp: Likewise.
+ * testsuite/ld-elfweak/elfweak.exp: Likewise.
+ * testsuite/ld-ifunc/ifunc.exp: Likewise.
+ * testsuite/ld-plugin/lto.exp (no_lto): New.
+ Add $no_lto to build pr15146c.so.
+ * testsuite/lib/ld-lib.exp (at_least_gcc_version): Filter out
+ -Wl,xxx options.
+ (check_gcc_plugin_enabled): Likewise.
+ (run_ld_link_exec_tests): Prepend -fno-lto to $cflags.
+ (run_cc_link_tests): Likewise.
+
2020-07-31 Shahab Vahedi <shahab@synopsys.com>
* scripttempl/elfarc.sc (.init_array): Keep ".init_array.*".
diff --git a/ld/testsuite/ld-elf/indirect.exp b/ld/testsuite/ld-elf/indirect.exp
index acda39e..8acae4d 100644
--- a/ld/testsuite/ld-elf/indirect.exp
+++ b/ld/testsuite/ld-elf/indirect.exp
@@ -58,19 +58,25 @@ proc check_link_message { cmd string testname } {
}
}
-if { ![ld_compile $CC $srcdir/$subdir/indirect1a.c tmpdir/indirect1a.o]
- || ![ld_compile $CC $srcdir/$subdir/indirect1b.c tmpdir/indirect1b.o]
- || ![ld_compile "$CC -fPIC" $srcdir/$subdir/indirect2.c tmpdir/indirect2.o]
- || ![ld_compile $CC $srcdir/$subdir/indirect3a.c tmpdir/indirect3a.o]
- || ![ld_compile $CC $srcdir/$subdir/indirect3b.c tmpdir/indirect3b.o]
- || ![ld_compile $CC $srcdir/$subdir/indirect4a.c tmpdir/indirect4a.o]
- || ![ld_compile $CC $srcdir/$subdir/indirect4b.c tmpdir/indirect4b.o]
- || ![ld_compile "$CC -O2 -fPIC -I../bfd" $srcdir/$subdir/pr18720a.c tmpdir/pr18720a.o]
- || ![ld_compile $CC $srcdir/$subdir/pr18720b.c tmpdir/pr18720b.o]
- || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553d.c tmpdir/pr19553d.o]
- || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553c.c tmpdir/pr19553c.o]
- || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553b.c tmpdir/pr19553b.o]
- || ![ld_compile $CC $srcdir/$subdir/pr19553a.c tmpdir/pr19553a.o] } {
+# Disable LTO for these tests.
+set cc_cmd "$CC"
+if {[check_lto_available]} {
+ append cc_cmd " -fno-lto"
+}
+
+if { ![ld_compile $cc_cmd $srcdir/$subdir/indirect1a.c tmpdir/indirect1a.o]
+ || ![ld_compile $cc_cmd $srcdir/$subdir/indirect1b.c tmpdir/indirect1b.o]
+ || ![ld_compile "$cc_cmd -fPIC" $srcdir/$subdir/indirect2.c tmpdir/indirect2.o]
+ || ![ld_compile $cc_cmd $srcdir/$subdir/indirect3a.c tmpdir/indirect3a.o]
+ || ![ld_compile $cc_cmd $srcdir/$subdir/indirect3b.c tmpdir/indirect3b.o]
+ || ![ld_compile $cc_cmd $srcdir/$subdir/indirect4a.c tmpdir/indirect4a.o]
+ || ![ld_compile $cc_cmd $srcdir/$subdir/indirect4b.c tmpdir/indirect4b.o]
+ || ![ld_compile "$cc_cmd -O2 -fPIC -I../bfd" $srcdir/$subdir/pr18720a.c tmpdir/pr18720a.o]
+ || ![ld_compile $cc_cmd $srcdir/$subdir/pr18720b.c tmpdir/pr18720b.o]
+ || ![ld_compile "$cc_cmd -fPIC" $srcdir/$subdir/pr19553d.c tmpdir/pr19553d.o]
+ || ![ld_compile "$cc_cmd -fPIC" $srcdir/$subdir/pr19553c.c tmpdir/pr19553c.o]
+ || ![ld_compile "$cc_cmd -fPIC" $srcdir/$subdir/pr19553b.c tmpdir/pr19553b.o]
+ || ![ld_compile $cc_cmd $srcdir/$subdir/pr19553a.c tmpdir/pr19553a.o] } {
unresolved "Indirect symbol tests"
return
}
diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp
index 82b79ad..299cdaa 100644
--- a/ld/testsuite/ld-elfvers/vers.exp
+++ b/ld/testsuite/ld-elfvers/vers.exp
@@ -708,7 +708,14 @@ proc build_exec { test source execname flags solibname verexp versymexp symexp }
set shared "--shared --no-undefined-version"
set script --version-script
- if ![ld_compile "$CC -S $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s] {
+
+ # Disable LTO for these tests.
+ set cc_cmd "$CC -S $CFLAGS"
+ if {[check_lto_available]} {
+ append cc_cmd " -fno-lto"
+ }
+
+ if ![ld_compile $cc_cmd $srcdir/$subdir/$source $tmpdir/$execname.s] {
unresolved "$test"
return
}
diff --git a/ld/testsuite/ld-elfweak/elfweak.exp b/ld/testsuite/ld-elfweak/elfweak.exp
index d319479..85da211 100644
--- a/ld/testsuite/ld-elfweak/elfweak.exp
+++ b/ld/testsuite/ld-elfweak/elfweak.exp
@@ -358,6 +358,12 @@ proc build_exec { test execname objs flags dat dynsymexp symexp} {
pass $test
}
+# Disable LTO for these tests.
+set cc_cmd "$CC"
+if {[check_lto_available]} {
+ append cc_cmd " -fno-lto"
+}
+
# Old version of GCC for MIPS default to enabling -fpic
# and get confused if it is used on the command line.
if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
@@ -380,20 +386,20 @@ if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
}
verbose "Using $picflag to compile PIC code"
-if {![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar.c $tmpdir/bar.o]
- || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c $tmpdir/main.o]
- || ![ld_link $CC $tmpdir/libbar.so "$shared $tmpdir/bar.o"]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo1a.c $tmpdir/foo1a.o]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo1b.c $tmpdir/foo1b.o]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/main1.c $tmpdir/main1.o]} then {
+if {![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar.c $tmpdir/bar.o]
+ || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/main.c $tmpdir/main.o]
+ || ![ld_link $cc_cmd $tmpdir/libbar.so "$shared $tmpdir/bar.o"]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/foo1a.c $tmpdir/foo1a.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/foo1b.c $tmpdir/foo1b.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/main1.c $tmpdir/main1.o]} then {
unresolved "ELF weak"
-} elseif {![ld_link $CC $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]
- || ![ld_link $CC $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]
- || ![ld_link $CC $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} then {
+} elseif {![ld_link $cc_cmd $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]
+ || ![ld_link $cc_cmd $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]
+ || ![ld_link $cc_cmd $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} then {
fail "ELF weak"
} else {
build_lib "ELF DSO weak func first" libfoo "foo.o bar.o" dso.dsym
@@ -420,10 +426,10 @@ if {![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o]
build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,--no-as-needed,-rpath,.,-rpath-link,." weakdata weakdata.dsym ""
}
-if {![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_foo.o]
- || ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_bar.c $tmpdir/size_bar_s.o]
- || ![ld_compile "$CC $CFLAGS $picflag -DSIZE_BIG" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o]
- || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/size_main.c $tmpdir/size_main.o]} then {
+if {![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_foo.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/size_bar.c $tmpdir/size_bar_s.o]
+ || ![ld_compile "$cc_cmd $CFLAGS $picflag -DSIZE_BIG" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o]
+ || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/size_main.c $tmpdir/size_main.o]} then {
unresolved "ELF weak (size)"
} else {
build_lib "ELF DSO small bar (size)" libsize_bar_s "size_bar_s.o" ""
@@ -435,11 +441,11 @@ if {![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_
verbose "size2"
run_dump_test $srcdir/$subdir/size2
-if {![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/alias.c $tmpdir/alias.o]
- || ![ld_link $CC $tmpdir/alias.so "$shared $tmpdir/alias.o"]
- || ![ld_compile "$CC $CFLAGS $NOSANTIZE_CFLAGS" $srcdir/$subdir/aliasmain.c $tmpdir/aliasmain.o]
- || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/weakref1.c $tmpdir/weakref1.o]
- || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/weakref2.c $tmpdir/weakref2.o]} then {
+if {![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/alias.c $tmpdir/alias.o]
+ || ![ld_link $cc_cmd $tmpdir/alias.so "$shared $tmpdir/alias.o"]
+ || ![ld_compile "$cc_cmd $CFLAGS $NOSANTIZE_CFLAGS" $srcdir/$subdir/aliasmain.c $tmpdir/aliasmain.o]
+ || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/weakref1.c $tmpdir/weakref1.o]
+ || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/weakref2.c $tmpdir/weakref2.o]} then {
unresolved "ELF weak (alias)"
} else {
build_exec "ELF weak (alias)" alias "aliasmain.o weakref1.o weakref2.o alias.so" "-Wl,-rpath=.,--no-as-needed" alias "" ""
diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp
index f67808c..63ab18d 100644
--- a/ld/testsuite/ld-ifunc/ifunc.exp
+++ b/ld/testsuite/ld-ifunc/ifunc.exp
@@ -182,24 +182,30 @@ proc contains_ifunc_reloc { binary_file } {
set fails 0
+# Disable LTO for these tests.
+set cc_cmd "$CC"
+if {[check_lto_available]} {
+ append cc_cmd " -fno-lto"
+}
+
# Create the object files, libraries and executables.
-if ![ld_compile "$CC -c -fPIC" "$srcdir/$subdir/prog.c" "tmpdir/shared_prog.o"] {
+if ![ld_compile "$cc_cmd -c -fPIC" "$srcdir/$subdir/prog.c" "tmpdir/shared_prog.o"] {
fail "Could not create a PIC object file"
set fails [expr $fails + 1]
}
-if ![ld_compile "$CC -c $NOPIE_CFLAGS" "$srcdir/$subdir/prog.c" "tmpdir/static_prog.o"] {
+if ![ld_compile "$cc_cmd -c $NOPIE_CFLAGS" "$srcdir/$subdir/prog.c" "tmpdir/static_prog.o"] {
fail "Could not create a non-PIC object file"
set fails [expr $fails + 1]
}
-if ![ld_compile "$CC -c -fPIC -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/shared_ifunc.o"] {
+if ![ld_compile "$cc_cmd -c -fPIC -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/shared_ifunc.o"] {
fail "Could not create a PIC object file containing an IFUNC symbol"
set fails [expr $fails + 1]
}
-if ![ld_compile "$CC -c $NOPIE_CFLAGS -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_ifunc.o"] {
+if ![ld_compile "$cc_cmd -c $NOPIE_CFLAGS -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_ifunc.o"] {
fail "Could not create a non-PIC object file containing an IFUNC symbol"
set fails [expr $fails + 1]
}
-if ![ld_compile "$CC -c -DWITHOUT_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_noifunc.o"] {
+if ![ld_compile "$cc_cmd -c -DWITHOUT_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_noifunc.o"] {
fail "Could not create an ordinary non-PIC object file"
set fails [expr $fails + 1]
}
@@ -207,11 +213,11 @@ if ![ld_assemble $as "$srcdir/ld-elf/empty.s" "tmpdir/empty.o"] {
fail "Could not create an empty object file"
set fails [expr $fails + 1]
}
-if ![ld_compile "$CC -c" "$srcdir/$subdir/test-1.c" "tmpdir/test-1.o"] {
+if ![ld_compile "$cc_cmd -c" "$srcdir/$subdir/test-1.c" "tmpdir/test-1.o"] {
fail "Could not create test-1.o"
set fails [expr $fails + 1]
}
-if ![ld_compile "$CC -fPIC -c" "$srcdir/$subdir/test-2.c" "tmpdir/test-2.o"] {
+if ![ld_compile "$cc_cmd -fPIC -c" "$srcdir/$subdir/test-2.c" "tmpdir/test-2.o"] {
fail "Could not create test-2.o"
set fails [expr $fails + 1]
}
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index a44b6cf..cb2973f 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -62,6 +62,7 @@ set lto_no_fat ""
if { [check_lto_fat_available] } {
set lto_fat "-ffat-lto-objects"
set lto_no_fat "-fno-fat-lto-objects"
+ set no_lto "-fno-lto"
}
# Simple LTO tests and generate input files for complex LTO tests.
@@ -322,7 +323,7 @@ set lto_link_elf_tests [list \
"-shared" "-O2 -fpic" \
{pr15146b.c} {} "pr15146b.so" "c"] \
[list "Build pr15146c.so" \
- "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \
+ "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic $no_lto" \
{pr15146c.c} {} "pr15146c.so" "c"] \
[list "PR ld/15146 (1)" \
"-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 1ec9bec..6628372 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -37,7 +37,9 @@ proc at_least_gcc_version { major minor } {
if { $CC == "" } {
return 0
}
- set state [remote_exec host $CC --version]
+ # Filter out -Wl, options.
+ regsub -all -- "-Wl,\[^ ^\t\]+" $CC "" cc_cmd
+ set state [remote_exec host $cc_cmd --version]
if { [lindex $state 0] != 0 } {
return 0;
}
@@ -693,6 +695,11 @@ proc run_ld_link_exec_tests { ldtests args } {
continue
}
+ # Add -fno-lto. LTO should be tested explicitly by $cflags.
+ if {[check_lto_available]} {
+ set cflags "-fno-lto $cflags"
+ }
+
foreach target $args {
if [match_target $target] {
setup_xfail "*-*-*"
@@ -852,6 +859,11 @@ proc run_cc_link_tests { ldtests } {
continue
}
+ # Add -fno-lto. LTO should be tested explicitly by $cflags.
+ if {[check_lto_available]} {
+ set cflags "-fno-lto $cflags"
+ }
+
#verbose -log "testname is $testname"
#verbose -log "ldflags is $ldflags"
#verbose -log "cflags is $cflags"
@@ -1209,7 +1221,9 @@ proc check_gcc_plugin_enabled { } {
if { $CC == ""} {
return 0
}
- set state [remote_exec host $CC -v]
+ # Filter out -Wl, options.
+ regsub -all -- "-Wl,\[^ ^\t\]+" $CC "" cc_cmd
+ set state [remote_exec host $cc_cmd -v]
if { [lindex $state 0] != 0 } {
return 0;
}