# Expect script for ld-weak tests
-# Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
#
-# This file is free software; you can redistribute it and/or modify
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
#
# Written by H.J. Lu (hjl@gnu.org)
# Eric Youngdale (eric@andante.jic.com)
# This test can only be run on a couple of ELF platforms.
# Square bracket expressions seem to confuse istarget.
# This is similar to the test that is used in ld-shared, BTW.
-if { ![istarget alpha*-*-linux*] \
- && ![istarget arm*-*-linux*] \
- && ![istarget hppa*64*-*-hpux*] \
- && ![istarget hppa*-*-linux*] \
- && ![istarget i?86-*-sysv4*] \
- && ![istarget i?86-*-unixware] \
- && ![istarget i?86-*-elf*] \
- && ![istarget i?86-*-linux*] \
- && ![istarget ia64-*-elf*] \
- && ![istarget ia64-*-linux*] \
- && ![istarget m68k-*-linux*] \
- && ![istarget mips*-*-irix5*] \
- && ![istarget mips*-*-linux*] \
- && ![istarget powerpc-*-elf*] \
- && ![istarget powerpc-*-linux*] \
- && ![istarget powerpc-*-sysv4*] \
- && ![istarget sh\[34\]*-*-linux*] \
- && ![istarget sparc*-*-elf] \
- && ![istarget sparc*-*-solaris2*] \
- && ![istarget sparc*-*-linux*] } {
+if { ![istarget alpha*-*-linux*]
+ && ![istarget arm*-*-linux*]
+ && ![istarget hppa*64*-*-hpux*]
+ && ![istarget hppa*-*-linux*]
+ && ![istarget i?86-*-sysv4*]
+ && ![istarget i?86-*-unixware]
+ && ![istarget i?86-*-elf*]
+ && ![istarget i?86-*-linux*]
+ && ![istarget i?86-*-gnu*]
+ && ![istarget ia64-*-elf*]
+ && ![istarget ia64-*-linux*]
+ && ![istarget m68k-*-linux*]
+ && ![istarget mips*-*-irix5*]
+ && ![istarget mips*-*-linux*]
+ && ![istarget powerpc*-*-elf*]
+ && ![istarget powerpc*-*-linux*]
+ && ![istarget powerpc*-*-sysv4*]
+ && ![istarget sh\[34\]*-*-linux*]
+ && ![istarget sparc*-*-elf]
+ && ![istarget sparc*-*-solaris2*]
+ && ![istarget sparc*-*-linux*]
+ && ![istarget x86_64-*-linux*]
+ && ![istarget *-*-nacl*] } {
return
}
-if { [istarget i?86-*-linux*aout*] \
- || [istarget i?86-*-linux*oldld*] \
- || [istarget m68k-*-linux*aout*] } {
+if { [istarget *-*-linux*aout*]
+ || [istarget *-*-linux*oldld*] } {
return
}
set tmpdir tmpdir
set DOBJDUMP_FLAGS --dynamic-syms
set SOBJDUMP_FLAGS --syms
-set shared --shared
+set shared "--shared -Wl,--no-as-needed"
+
#
# objdump_symstuff
if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
- verbose -log "$objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
-
- catch "exec $objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
+ set cmd "$objdump $SOBJDUMP_FLAGS $object | sed -n {s/^\\(\[0-9a-f\]* *\\)\\(\[gw\]\\)\\( *\\)\\(\[FO\]\\)/\\1\\2\\4\\3/;/foo$/p} > $tmpdir/objdump.out"
+ verbose -log $cmd
+ catch "exec $cmd" exec_output
set exec_output [prune_warnings $exec_output]
if [string match "" $exec_output] then {
perror "$expectfile doesn't exist"
return 0
}
-
+
if [file exists $tmpdir/objdump.out] then {
set file_b [open $tmpdir/objdump.out r]
} else {
close $file_a
while { [gets $file_b line] != $eof } {
- if [regexp "^#.*$" $line] then {
+ if [regexp {\.text.* \.[^ ]*$} $line] then {
+ # Discard defined powerpc64 dot-symbols
continue
} else {
lappend list_b $line
}
}
close $file_b
-
+
for { set i 0 } { $i < [llength $list_a] } { incr i } {
set line_a [lindex $list_a $i]
set line_b [lindex $list_b $i]
-
+
verbose "\t$expectfile: $i: $line_a" 3
verbose "\t/tmp/objdump.out: $i: $line_b" 3
} else {
verbose -log "\t$expectfile: $i: $line_a"
verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
-
+
return 0
}
}
-
+
if { [llength $list_a] != [llength $list_b] } {
verbose -log "Line count"
return 0
}
-
+
if $differences<1 then {
return 1
}
-
+
return 0
} else {
verbose -log "$exec_output"
if ![info exists DOBJDUMP_FLAGS] { set DOBJDUMP_FLAGS "" }
- verbose -log "$objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
-
- catch "exec $objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
+ set cmd "$objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
+ verbose -log $cmd
+ catch "exec $cmd" exec_output
set exec_output [prune_warnings $exec_output]
if [string match "" $exec_output] then {
warning "$expectfile doesn't exist"
return 0
}
-
+
if [file exists $tmpdir/objdump.out] then {
set file_b [open $tmpdir/objdump.out r]
} else {
close $file_a
while { [gets $file_b line] != $eof } {
- if [regexp "^#.*$" $line] then {
+ if [regexp {\.text.* \.[^ ]*$} $line] then {
+ # Discard defined powerpc64 dot-symbols
continue
} else {
lappend list_b $line
}
}
close $file_b
-
+
for { set i 0 } { $i < [llength $list_b] } { incr i } {
set line_b [lindex $list_b $i]
-
+
# The tests are rigged so that we should never export a symbol with the
# word 'hide' in it. Thus we just search for it, and bail if we find it.
if [regexp "hide" $line_b] then {
verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
-
+
return 0
}
if { $j >= [llength $list_a] } {
verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
-
+
return 0
}
}
-
+
if { [llength $list_a] != [llength $list_b] } {
verbose -log "Line count"
return 0
}
-
+
if $differences<1 then {
return 1
}
-
+
return 0
} else {
verbose -log "$exec_output"
return
}
- if {![string match "" $dynsymexp] \
+ if {![string match "" $dynsymexp]
&& ![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$dynsymexp]} {
fail $test
return
global CC
global objdump
global tmpdir
- global shared
global srcdir
global subdir
global exec_output
pass $test
}
-if [istarget mips*-*-*] {
+# 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 {
set picflag ""
} else {
# Unfortunately, the gcc argument is -fpic and the cc argument is
catch "exec $CC $picflag" exec_output
send_log "$exec_output\n"
verbose "--" "$exec_output"
- if { [string match "*illegal option*" $exec_output] \
- || [string match "*option ignored*" $exec_output] \
- || [string match "*unrecognized option*" $exec_output] \
+ if { [string match "*illegal option*" $exec_output]
+ || [string match "*option ignored*" $exec_output]
+ || [string match "*unrecognized option*" $exec_output]
|| [string match "*passed to ld*" $exec_output] } {
if [istarget *-*-sunos4*] {
set picflag "-pic"
return
}
-if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main1.c $tmpdir/main1.o] {
+if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/main1.c $tmpdir/main1.o] {
unresolved "ELF weak"
return
}
build_lib "ELF DSO weak func last DSO" libfoo "libbar.so foo.o" dsow.dsym
build_exec "ELF weak func first" foo "main.o bar.o" "" strong "" strong.sym
build_exec "ELF weak func last" foo "bar.o main.o" "" strong "" strong.sym
-build_exec "ELF weak func first DSO" foo "main.o libbar.so" "-Wl,-rpath,." weak weak.dsym ""
-build_exec "ELF weak func last DSO" foo "libbar.so main.o" "-Wl,-rpath,." weak weak.dsym ""
+build_exec "ELF weak func first DSO" foo "main.o libbar.so" "-Wl,-rpath,.,--no-as-needed" weak weak.dsym ""
+build_exec "ELF weak func last DSO" foo "libbar.so main.o" "-Wl,-rpath,.,--no-as-needed" weak weak.dsym ""
build_lib "ELF DSO weak data first" libfoo "bar1a.o foo1a.o" dsodata.dsym
build_lib "ELF DSO weak data last" libfoo "foo1a.o bar1a.o" dsodata.dsym
build_exec "ELF weak data last" foo "foo1a.o main1.o bar1a.o" "" strongdata "" strongdata.sym
build_exec "ELF weak data first common" foo "main1.o bar1a.o foo1b.o" "" strongdata "" strongcomm.sym
build_exec "ELF weak data last common" foo "foo1b.o main1.o bar1a.o" "" strongdata "" strongcomm.sym
-build_exec "ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
-build_exec "ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
-build_exec "ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
-build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
+build_exec "ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-Wl,-rpath,.,--no-as-needed" weakdata weakdata.dsym ""
+build_exec "ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-Wl,-rpath,.,--no-as-needed" weakdata weakdata.dsym ""
+build_exec "ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-Wl,-rpath,.,--no-as-needed" weakdata weakdata.dsym ""
+build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,-rpath,.,--no-as-needed" weakdata weakdata.dsym ""
if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_foo.o] {
unresolved "ELF weak (size)"
return
}
-build_exec "ELF weak size" size_main "size_main.o libsize_foo.so libsize_bar.so" "-Wl,-rpath,." size "" ""
+build_exec "ELF weak size" size_main "size_main.o libsize_foo.so libsize_bar.so" "-Wl,-rpath,.,--no-as-needed" size "" ""
verbose "size2"
run_dump_test $srcdir/$subdir/size2