+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.*".
}
}
-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
}
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
}
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 {
}
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
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" ""
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 "" ""
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]
}
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]
}
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.
"-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" "" \
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;
}
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 "*-*-*"
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"
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;
}