+
+proc objcopy_test_readelf {testname srcfile} {
+ global OBJCOPY
+ global OBJCOPYFLAGS
+ global READELF
+ global srcdir
+ global subdir
+
+ if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
+ unresolved "objcopy ($testname)"
+ return
+ }
+
+ verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"
+ set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
+ if { [lindex $exec_output 0] != 0
+ || ![string match "" [lindex $exec_output 1]] } then {
+ fail "objcopy ($testname)"
+ return
+ }
+
+ verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out"
+ set exec_output [remote_exec host "$READELF -a tmpdir/bintest.o" "" "/dev/null" "tmpdir/bintest.o.out"]
+ if { [lindex $exec_output 0] != 0 } then {
+ unresolved "objcopy ($testname)"
+ return
+ }
+ set exec_output [prune_warnings [lindex $exec_output 1]]
+ if ![string match "" $exec_output] then {
+ unresolved "objcopy ($testname)"
+ return
+ }
+
+ verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out"
+ set exec_output [remote_exec host "$READELF -a tmpdir/copy.o" "" "/dev/null" "tmpdir/copy.o.out"]
+ if { [lindex $exec_output 0] != 0 } then {
+ unresolved "objcopy ($testname)"
+ return
+ }
+ set exec_output [prune_warnings [lindex $exec_output 1]]
+ if ![string match "" $exec_output] then {
+ unresolved "objcopy ($testname)"
+ return
+ }
+
+ verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out"
+ catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output
+ set exec_output [prune_warnings $exec_output]
+
+ if [string match "" $exec_output] then {
+ pass "objcopy ($testname)"
+ } else {
+ fail "objcopy ($testname)"
+ }
+}
+
+# ia64 specific tests
+if { ([istarget "ia64-*-elf*"]
+ || [istarget "ia64-*-linux*"]) } {
+ objcopy_test "ia64 link order" link-order.s
+}
+
+# ELF specific tests
+if [is_elf_format] {
+ objcopy_test "ELF unknown section type" unknown.s
+ objcopy_test_readelf "ELF group" group.s
+ objcopy_test_readelf "ELF group" group-2.s
+ objcopy_test_readelf "ELF group" group-3.s
+ objcopy_test_readelf "ELF group" group-4.s
+ run_dump_test "group-5"
+ run_dump_test "copy-1"
+ run_dump_test "note-1"
+}
+
+run_dump_test "copy-2"
+run_dump_test "copy-3"
+run_dump_test "copy-4"
+
+if [is_elf_format] {
+ run_dump_test "strip-1"
+ run_dump_test "strip-2"
+ run_dump_test "strip-3"
+ run_dump_test "strip-4"
+ run_dump_test "strip-5"
+ run_dump_test "strip-6"
+ run_dump_test "strip-7"
+ run_dump_test "strip-8"
+ run_dump_test "strip-9"
+ if { ![istarget "*-*-hpux*"]
+ && ![istarget "msp*-*-*"] } {
+ run_dump_test "strip-10"
+ }
+
+ if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } {
+ # Check to make sure we don't strip a symbol named in relocations.
+ set test "objcopy keeps symbols needed by relocs"
+
+ set srcfile $srcdir/$subdir/needed-by-reloc.s
+
+ if {![binutils_assemble $srcfile tmpdir/bintest.o]} then {
+ unresolved $test
+ } else {
+ set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"]
+
+ if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] {
+ pass $test
+ } else {
+ fail $test
+ }
+ }
+ }
+
+ run_dump_test "localize-hidden-1"
+ run_dump_test "testranges"
+ run_dump_test "testranges-ia64"
+
+ run_dump_test "add-section"
+ run_dump_test "add-empty-section"
+
+ run_dump_test "exclude-1a"
+ run_dump_test "exclude-1b"
+}
+run_dump_test "localize-hidden-2"